Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return patterns.map(pattern => pattern.replace(ARGS_PATTERN, (whole, indirectionMark, id, options) => {
if (indirectionMark != null) {
throw Error(`Invalid Placeholder: ${whole}`)
}
if (id === "@") {
return shellQuote.quote(args)
}
if (id === "*") {
return shellQuote.quote([args.join(" ")])
}
const position = parseInt(id, 10)
if (position >= 1 && position <= args.length) {
return shellQuote.quote([args[position - 1]])
}
// Address default values
if (options != null) {
const prefix = options.slice(0, 2)
if (prefix === ":=") {
defaults[id] = shellQuote.quote([options.slice(2)])
async function exec (cmd, args = [], opts = {}) {
// get a quoted representation of the command for error strings
const rep = quote([cmd, ...args]);
// extend default options; we're basically re-implementing exec's options
// for use here with spawn under the hood
opts = Object.assign({
timeout: null,
encoding: 'utf8',
killSignal: 'SIGTERM',
cwd: undefined,
env: process.env,
ignoreOutput: false,
stdio: 'inherit',
isBuffer: false,
shell: undefined,
logger: undefined,
maxStdoutBufferSize: MAX_BUFFER_SIZE,
maxStderrBufferSize: MAX_BUFFER_SIZE,
tag({ name = this.options.tagName, annotation = this.options.tagAnnotation, args = this.options.tagArgs } = {}) {
const quotedMessage = quote([format(annotation, this.getContext())]);
return this.exec(`git tag --annotate --message=${quotedMessage} ${args || ''} ${name}`)
.then(() => this.setContext({ isTagged: true }))
.catch(err => {
const { latestTagName, tagName } = this.getContext();
if (/tag '.+' already exists/.test(err) && latestTagName === tagName) {
this.log.warn(`Tag "${tagName}" already exists`);
} else {
throw err;
}
});
}
exports.exec = function(url, filename, options, cb){
var key;
var stdin = ['phantomjs'];
stdin.push(options.args);
stdin.push(shq([
__dirname+'/render.js',
url,
filename,
new Buffer(JSON.stringify(options)).toString('base64')
]));
return child.exec(stdin.join(' '), function(err, stdo, stde){
cb ? cb(err) : null;
});
};
function execProcess(cmd, cb) {
exec(shellQuote(cmd), function(err, stdout, stderr) {
process.stdout.write(stdout);
process.stderr.write(stderr);
if(err) return cb(err);
cb();
});
}
module.exports.add = function(opt, cb) {
cb = cb || noop
var message = opt.message || 'first commit'
message = quote([message])
var cmd = [
'git init',
'git add .',
'git commit -m ' + message,
'git remote add origin ' + opt.url,
'git push -u origin master'
].join(' && ')
var proc = spawn(cmd, [], {
stdio: 'inherit'
})
proc.on('exit', function(code) {
if (code === 0)
cb()
else
cb(new Error("error code " + code))
cmd.push('--time-limit', timeLimit);
}
if (util.hasValue(bitRate)) {
cmd.push('--bit-rate', bitRate);
}
if (bugReport) {
cmd.push('--bugreport');
}
cmd.push(destination);
const fullCmd = [
...this.executable.defaultArgs,
'shell',
...cmd
];
log.debug(`Building screenrecord process with the command line: adb ${quote(fullCmd)}`);
return new SubProcess(this.executable.path, fullCmd);
};
quote = function (input) {
return shellQuote([input]);
}
exports.init = function(config, cimpler) {
}
let spawnArgs = { shell: true };
if (process.env.SLS_DEBUG) {
spawnArgs.stdio = 'inherit';
}
let mainCmds = [];
if (dockerCmd.length) {
dockerCmd.push(...mergeCommands(pipCmds));
mainCmds = [dockerCmd];
} else {
mainCmds = pipCmds;
}
mainCmds.push(...postCmds);
serverless.cli.log(`Running ${quote(dockerCmd)}...`);
filterCommands(mainCmds).forEach(([cmd, ...args]) => {
const res = spawnSync(cmd, args);
if (res.error) {
if (res.error.code === 'ENOENT') {
const advice =
cmd.indexOf('python') > -1
? 'Try the pythonBin option'
: 'Please install it';
throw new Error(`${cmd} not found! ${advice}`);
}
throw res.error;
}
if (res.status !== 0) {
throw new Error(`STDOUT: ${res.stdout}\n\nSTDERR: ${res.stderr}`);
}
export async function writeTextFileToVolume(
dockerComposeProjectName: string,
volume: string,
path: string,
text: string,
mode?: string,
): Promise {
if (Path.isAbsolute(path)) {
throw new Error('The provided `path` must be relative');
}
let quotedPath = ShellQuote.quote([Path.posix.join('/volume', path)]);
let commands = [`echo ${ShellQuote.quote(['-n', text])} > ${quotedPath}`];
if (mode) {
commands.push(`chmod ${ShellQuote.quote([mode])} ${quotedPath}`);
}
let subprocess = ChildProcess.spawn('docker', [
'run',
'--rm',
'--volume',
`${dockerComposeProjectName}_${volume}:/volume`,
'alpine',
'sh',
'-c',
commands.join(' && '),
]);