Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
setTimeout(function () {
client.destroy();
if (!fs.existsSync(rootDir + 'tmp/node_modules/' + appName + '.js-controller')) {
console.log('installJsController: no js-controller => install from git');
child_process.execSync('npm install https://github.com/' + appName + '/' + appName + '.js-controller/tarball/master --prefix ./ --production', {
cwd: rootDir + 'tmp/',
stdio: [0, 1, 2]
});
} else {
console.log('Setup js-controller...');
let __pid;
if (debug) {
// start controller
child_process.exec('node ' + appName + '.js setup first', {
cwd: rootDir + 'tmp/node_modules/' + appName + '.js-controller',
stdio: [0, 1, 2]
});
} else {
child_process.fork(appName + '.js', ['setup', 'first'], {
cwd: rootDir + 'tmp/node_modules/' + appName + '.js-controller',
stdio: [0, 1, 2, 'ipc']
});
}
}
// let npm install admin and run setup
checkIsControllerInstalled(function () {
let _pid;
if (fs.existsSync(rootDir + 'node_modules/' + appName + '.js-controller/' + appName + '.js')) {
const { exec } = require('child_process');
const semver = require('semver');
const currentDir = process.cwd();
exec('tns --version', (err, stdout, stderr) => {
if (err) {
// node couldn't execute the command
console.log(`tns --version err: ${err}`);
return;
}
const tnsVersion = semver.major(stdout);
// execute 'tns plugin build' for {N} version > 4. This command builds .aar in platforms/android folder.
if (tnsVersion >= 4) {
console.log(`executing 'tns plugin build' in ${currentDir}`);
exec(`cd ${currentDir} && tns plugin build`);
}
});
function applyIotDeviceAction(actionMetadata) {
// Execute the codesend program and pass it the arguments it needs
var encoding = actionMetadata.encoding;
var delay = actionMetadata.delay;
// Build the transmit command that sends the signal to the
/// 433MHz IoT device
var transmitCommand = appConfig.transmitterProgram + " " + encoding + " " + delay;
winston.debug("Sending command to device: " + transmitCommand);
// Now execute the transmit command
exec(transmitCommand, function (error, stdout, stderr) {
winston.info("stdout: " + stdout);
winston.info('stderr: ' + stderr);
if (error) {
winston.error("Error while invoking command '" + transmitCommand + ": " + error.message.toString());
}
});
}
// Output the package.json for this pack
packageJsonStr = beautify(JSON.stringify(newPackageJson), {indent_size: 2});
if (packageJsonStr == beautify(JSON.stringify(packageJson), {indent_size: 2})) {
return nextPack();
}
fs.writeFileSync(path.join(machinesDir, machineDir, 'package.json'), packageJsonStr);
// Write out the index file
fs.writeFileSync(path.join(machinesDir, machineDir, 'index.js'), "module.exports = require('machine').pack({pkg: require('./package.json'), dir: __dirname});");
// If there are dependencies, run npm install
if(_.keys(newPackageJson.dependencies).length) {
var cwd = path.join(machinesDir, machineDir);
exec('npm install', {cwd: cwd}, function(err, stdout) {
if (err) {return nextPack(err);}
nextPack();
});
}
// Otherwise we don't need to install anything
else {
return nextPack();
}
}
}, cb);
} else {
if (configuration[options[i].option]) {
if (options[i].remove) {
if (debug) console.log("Configuring Snapcast (removing "+options[i].option+")...")
delete configuration[options[i].option];
} else {
if (debug) console.log("Configuring Snapcast (commenting out "+options[i].option+")...")
configuration[options[i].option].comment = true;
}
}
}
}
}
writeSnapcastConfiguration();
if (relaunch) {
exec("systemctl restart snapcastmpris.service", function(error, stdout, stderr) {
if (error) {
if (debug) console.error("Relaunching Snapcast failed: "+error);
if (callback) callback(false, error);
} else {
if (debug) console.error("Snapcast was relaunched.");
if (callback) callback(true);
}
});
} else {
if (callback) callback(true);
}
/*} else {
if (callback) callback(false);
}*/
}
function syncRepo(callback) {
var callbackCalled;
console.log('Syncing the repo with command ' + config.syncCmd);
var child = child_process.exec(config.syncCmd, function (err, stdout, stderr) {
if (callbackCalled) {
return;
}
var isNonEmptyString = function (s) {
return typeof s === 'string' && s.length > 0;
}
if (err) {
console.log('Failed to sync the repo: ');
console.log(err);
if (isNonEmptyString(stderr)) {
console.log('Stderr of sync command:');
console.log(stderr);
}
setTimeout(function() {
exec("cat /proc/stat", function(err, stdout, stderr) {
if (!err) {
output2 = stdout.split(/[\n\r]{1,2}/);
res.cpuload = 0;
for (var i = 0; i < 1; i++) {
var cpu_stat_1 = output1[i + 1].split(/\s/);
var cpu_stat_2 = output2[i + 1].split(/\s/);
var info1 = {
user : parseInt(cpu_stat_1[1]),
nice : parseInt(cpu_stat_1[2]),
system : parseInt(cpu_stat_1[3]),
idle : parseInt(cpu_stat_1[4])
};
var info2 = {
user : parseInt(cpu_stat_2[1]),
nice : parseInt(cpu_stat_2[2]),
function extract(filename, callback) {
console.log('Extracting ' + filename);
exec('tar xzvf ' + filename, function (err, stdout, stderr) {
if (err) {
console.log(stdout);
console.log(stderr);
return;
}
console.log('Complete!');
callback();
});
}
var path = require('path');
var fs = require('fs');
var util = require('./lib/util');
if (os.type() === 'Linux') {
var linuxPath = path.join(process.cwd(), 'lib', 'pngdefry', 'bin', 'linux');
var pngdefryPath = path.join(process.cwd(), 'lib', 'pngdefry', 'source', 'pngdefry');
if (!util.fsExistsSync(linuxPath)) {
fs.mkdirSync(linuxPath);
}
var makeFileDir = path.join(process.cwd(), 'lib', 'pngdefry', 'source');
var command = 'cd ' + makeFileDir + ' && make';
cp.exec(command, {}, function(error, stdout, stderr) {
if (error) {
throw new Error('install fail');
}
cp.exec('mv ' + pngdefryPath + ' ' + linuxPath, {});
});
}
let promise = new Promise(function(resolve, reject){
exec(command, (error, stdout, stderr) => {
if (error) {
log(chalk.red('exec error:',error));
reject(new Error(error));
return;
}
if(stdout!==''){
log(chalk.green('stdout:',stdout));
}
if(stderr!==''){
log(chalk.red('stderr:',stderr));
}
resolve();
});