pi-rfid-jukebox/jukebox/scripts.js

32 lines
636 B
JavaScript
Raw Normal View History

2019-12-14 21:19:06 +00:00
"use strict";
const { execFile } = require('child_process');
const glob = require('glob');
const util = require('util');
const globPromise = util.promisify(glob);
class ScriptRunner {
constructor(config) {
this.config = config;
}
find(tag) {
return globPromise(this.config.script_path + '/**/' + tag + '*.sh').then(files => {
return new Promise((resolve, reject) => {
if (files.length === 1) {
execFile(files[0]);
resolve(true);
}
resolve(false);
});
});
}
}
module.exports = function(config) {
return new ScriptRunner(config);
};
// vim:ts=2 sw=2 et: