Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
console.log('Install adapter...');
var startFile = 'node_modules/' + appName + '.js-controller/' + appName + '.js';
// make first install
if (debug) {
child_process.execSync('node ' + startFile + ' add ' + customName + ' --enabled false', {
cwd: rootDir + 'tmp',
stdio: [0, 1, 2]
});
checkIsAdapterInstalled(function (error) {
if (error) console.error(error);
console.log('Adapter installed.');
if (cb) cb();
});
} else {
// add controller
var _pid = child_process.fork(startFile, ['add', customName, '--enabled', 'false'], {
cwd: rootDir + 'tmp',
stdio: [0, 1, 2, 'ipc']
});
waitForEnd(_pid, function () {
checkIsAdapterInstalled(function (error) {
if (error) console.error(error);
console.log('Adapter installed.');
if (cb) cb();
});
});
}
}
let cliOpts = ['start',
'--port', this.opts.packagerPort,
'--projectRoots', root,
'--assetRoots', root,
];
if (options.reset) {
cliOpts.push('--reset-cache');
}
// Run the copy of Node that's embedded in Electron by setting the
// ELECTRON_RUN_AS_NODE environment variable
// Note: the CLI script sets up graceful-fs and sets ulimit to 4096 in the
// child process
let packagerProcess = child_process.fork(this.opts.cliPath, cliOpts, {
cwd: path.dirname(path.dirname(this.opts.cliPath)),
env: {
...process.env,
NODE_PATH: null,
ELECTRON_RUN_AS_NODE: 1,
},
silent: true,
});
process.on('exit', () => {
packagerProcess.kill();
});
this._packager = packagerProcess;
this._packager.stdout.setEncoding('utf8');
this._packager.stderr.setEncoding('utf8');
this._packager.stdout.on('data', (data) => {
this.emit('stdout', data);
const loadPlugin = (newPlugin) => {
const plugin = {};
plugin.name = newPlugin.PLUGIN_NAME;
plugin.cp = fork(newPlugin.PLUGIN_PATH, [], { silent: true });
plugin.cp.on('message', msg => route(msg));
plugin.cp.stdout.on('data', data => console.log(`[${newPlugin.PLUGIN_NAME}]`, data.toString()));
plugin.cp.stderr.on('data', data => console.error(`[${newPlugin.PLUGIN_NAME}]`, data.toString()));
plugins[newPlugin.PLUGIN_NAME] = plugin;
return send(newPlugin.PLUGIN_NAME, 'MASTER', { action: 'init', payload: conf });
};
function createServer(config, procOptions) {
var deferred = q.defer();
if (!procOptions) {
procOptions = {};
}
procOptions.execArgv = [];
var serverProcess = require('child_process').fork('./test-server', procOptions);
var serverStartedCallback = function(m) {
serverProcess.removeListener('message', arguments.callee);
var success = m.serverStarted;
if (success) {
deferred.resolve(serverProcess);
}
else {
deferred.reject('Failure starting test server' + JSON.stringify(m));
console.log("Failure starting test server!");
}
};
//Setup listener for when server starts and sends a message back
function doFork(path, args, env) {
path = require.resolve(path);
const opts = {
silent: true,
env,
};
const subprocess = fork(path, args, opts);
subprocess.stdout.on('data', (data) => logger.info(data.toString()));
subprocess.stderr.on('data', (data) => console.error(data.toString()));
return subprocess;
}
beforeEach(() => {
if (!this.opts.faasRuntimePath) {
fail('opts.faasRuntimePath is unspecified.');
} else if (!this.opts.handlerDefinitionPath) {
fail('opts.handlerDefinitionPath is unspecified.');
}
this.messagesFromBackend = [];
this.messagesFromDownstreamDummy = [];
this.messagesFromFaasRuntime = [];
let backendPromise;
if (this.opts.startBackend) {
this.backend = fork(path.join(__dirname, '../backend_stub'), {
stdio: config.getAppStdio(),
env: Object.assign(
{
BACKEND_PORT: config.backendPort,
BACKEND_UNRESPONSIVE: this.opts.startBackend === 'unresponsive'
},
process.env,
this.opts.env
)
});
this.backend.on('message', message => {
this.messagesFromBackend.push(message);
});
backendPromise = this.waitUntilBackendIsUp();
} else {
backendPromise = Promise.resolve();
const loadPlugin = (newPlugin) => {
const plugin = {};
plugin.name = newPlugin.PLUGIN_NAME;
plugin.cp = fork(newPlugin.PLUGIN_PATH, [], { silent: true, detached: true });
plugin.cp.on('message', msg => route(msg));
plugin.cp.stdout.on('data', data => console.log(`[${newPlugin.PLUGIN_NAME}]`, data.toString()));
plugin.cp.stderr.on('data', data => console.error(`[${newPlugin.PLUGIN_NAME}]`, data.toString()));
plugins[newPlugin.PLUGIN_NAME] = plugin;
return send(plugin, { action: 'init', payload: conf });
};
var restartFun = function restartFun() {
console.log(colors.yellow('anyproxy\u5F02\u5E38\u9000\u51FA\uFF0C\u5C1D\u8BD5\u91CD\u542F'));
var childProxy = childProcess.fork(__dirname + '/externalChildProcess');
childProxy.send({
type: 'restart',
ports: ports
});
childProxy.on('exit', function (e) {
restartFun();
});
};
childProxy.on('exit', function (e) {
const loadPlugin = (newPlugin) => {
const plugin = {};
plugin.name = newPlugin.PLUGIN_NAME;
plugin.cp = fork(newPlugin.PLUGIN_PATH, [], { silent: true, detached: true });
plugin.cp.on('message', msg => route(msg));
plugin.cp.stdout.on('data', (data) => {
logger.info(`[${newPlugin.PLUGIN_NAME}] ${data.toString()}`);
});
plugin.cp.stderr.on('data', (data) => {
logger.error(`[${newPlugin.PLUGIN_NAME}] ${data.toString()}`);
});
plugins[newPlugin.PLUGIN_NAME] = plugin;
return send(plugin, { action: 'init', payload: conf });
};
var server = (function startup() {
var child = cp.fork(paths.build + '/server.js', nodeArgs, {
env: assign({NODE_ENV: 'development'}, process.env)
})
child.once('message', function(message) {
if (message.match(/^online$/)) {
if (browserSync) {
browserSync.reload()
}
if (!started) {
started = true
gulp.watch(src.server, function() {
$.util.log('Restarting development server.')
server.kill('SIGTERM')
server = startup()
})
cb()
}