Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function reset() {
console.log('Reset environment...');
// exec('npm unlink', { cwd: publicPluginRoot });
// exec('npm unlink rekit-plugin-public-test', { cwd: appRoot });
shell.rm('-rf', publicPluginRoot);
shell.rm('-rf', localPluginRoot);
_.pull(pkg.rekit.plugins, 'public-test');
shell.ShellString(JSON.stringify(pkg, null, ' ')).to(appPkgJsonPath);
}
ShellString(graph.to_dot()).to(dotFile);
const svgFile = path.join(outputDirectory, 'graph.svg');
// I was using graphviz to call dot but it didn't fail gracefully so I'm calling the command directly.
// this needs adjusted if you use a different type of graph layout (not dot)
const render = exec(`dot -Tsvg -o ${svgFile} ${dotFile}`);
if (render.code !== 0) {
error('Render failed');
process.exit(1);
}
const svg = cat(svgFile);
const svgDatauri = new DataURI();
svgDatauri.format('.svg', svg);
const htmlFile = path.join(outputDirectory, 'interactive.html');
ShellString(interactiveHtml(svgDatauri.content)).to(htmlFile);
if (argv.archiveGraphs) {
// todo if hash exists in archive, we should error if files are different, or just ignore if same
const archiveDirectory = path.join(outputDirectory, 'archive');
const hashDirectory = path.join(archiveDirectory, stats.hash);
info(`Writing archive files to ${hashDirectory}`);
mkdir('-p', hashDirectory);
cp(dotFile, path.join(hashDirectory, 'graph.dot'));
cp(svgFile, path.join(hashDirectory, 'graph.svg'));
cp(htmlFile, path.join(hashDirectory, 'interactive.html'));
cp(statsFile, path.join(hashDirectory, 'stats.json'));
// todo move more logic to archive and break out more modules
require('./archive')(stats, archiveDirectory);
}
.then(answers => {
const packageJSON = packageContents(answers);
const readme = readmeContents(answers);
const { fullName, shortName } = answers;
const componentName = upperCamelCase(fullName);
const index = indexContents(componentName);
const component = componentContents(componentName);
const story = storyContents({ componentName, fullName });
const dirName = `packages/${shortName}`;
const inactiveAuthors = answers.inactiveAuthors
? new RegExp(answers.inactiveAuthors, "i")
: null;
mkdir("-p", `${dirName}/src`);
ShellString(packageJSON).to(`${dirName}/package.json`);
ShellString(readme).to(`${dirName}/README.md`);
ShellString(index).to(`${dirName}/src/index.js`);
ShellString(component).to(`${dirName}/src/${componentName}.js`);
ShellString(story).to(`${dirName}/src/${componentName}.story.js`);
cp(["AUTHORS", "LICENSE"], `${dirName}/.`);
if (inactiveAuthors) {
grep("-v", inactiveAuthors, `${dirName}/AUTHORS`).to(
`${dirName}/AUTHORS`,
);
}
})
.catch(console.error); // eslint-disable-line no-console
.then(answers => {
const packageJSON = packageContents(answers);
const readme = readmeContents(answers);
const { fullName, shortName } = answers;
const componentName = upperCamelCase(fullName);
const index = indexContents(componentName);
const component = componentContents(componentName);
const story = storyContents({ componentName, fullName });
const dirName = `packages/${shortName}`;
const inactiveAuthors = answers.inactiveAuthors
? new RegExp(answers.inactiveAuthors, "i")
: null;
mkdir("-p", `${dirName}/src`);
ShellString(packageJSON).to(`${dirName}/package.json`);
ShellString(readme).to(`${dirName}/README.md`);
ShellString(index).to(`${dirName}/src/index.js`);
ShellString(component).to(`${dirName}/src/${componentName}.js`);
ShellString(story).to(`${dirName}/src/${componentName}.story.js`);
cp(["AUTHORS", "LICENSE"], `${dirName}/.`);
if (inactiveAuthors) {
grep("-v", inactiveAuthors, `${dirName}/AUTHORS`).to(
`${dirName}/AUTHORS`,
);
}
})
.catch(console.error); // eslint-disable-line no-console
// Always load true-false plugin
require('./plugin-true-false');
// validate command
if (typeof shell[fnName] !== 'function') {
console.error(`Error: Invalid ShellJS command: ${fnName}.`);
console.error(help());
return EXIT_CODES.SHX_ERROR;
} else if (CMD_BLACKLIST.indexOf(fnName) > -1) {
console.error(`Warning: shx ${fnName} is not supported`);
console.error('Please run `shx help` for a list of commands.');
return EXIT_CODES.SHX_ERROR;
}
const input = this !== null ? new shell.ShellString(this) : null;
// Set shell.config with parsed options
Object.assign(shell.config, parsedArgs);
// Workaround for sed syntax
let ret;
if (fnName === 'sed') {
const newArgs = convertSedRegex(args);
ret = shell[fnName].apply(input, newArgs);
} else {
ret = shell[fnName].apply(input, args);
}
if (ret === null) ret = shell.ShellString('', '', 1);
/* instanbul ignore next */
let code = Object.prototype.hasOwnProperty.call(ret, 'code') && ret.code;
runPrettier(indexPath);
if (!options.old) {
// get package content
const packagePath = computePackagePath(location);
const packageContent = `` + fs.readFileSync(packagePath);
// extract dependencies
const dependenciesRegExp = /"dependencies":\s\{([^()]+)\},\n\s+"devDependencies"/g;
const [, dependencies] = dependenciesRegExp.exec(packageContent) || ['', ''];
const dependenciesWithoutDeleted = dependencies
.split(',')
.filter(pkg => pkg.indexOf(computeModulePackageName(location, options, moduleName)) < 0);
// remove module from package list
shell
.ShellString(
packageContent.replace(
RegExp(dependenciesRegExp, 'g'),
`"dependencies": {${dependenciesWithoutDeleted}},\n "devDependencies"`
)
)
.to(packagePath);
removeSymlink(location, moduleName);
}
logger.info(chalk.green(`✔ Module for ${location} successfully deleted!`));
} else {
logger.info(chalk.red(`✘ Module ${location} location for ${modulePath} not found!`));
}
}
var jsCode = fs.readFileSync(path.join(destPath, 'tomviz.js'), { encoding: 'utf8', flag: 'r' });
var lines = htmlTemplate.split('\n');
var count = lines.length;
while (count--) {
if (lines[count].indexOf('') !== -1) {
lines[count] = [
'',
'',
].join('\n');
}
}
shell.ShellString(lines.join('\n')).to(outputFile);
}
function compileSolcContract(logger, compileSettings, allowedDirectories, callback) {
const command = `solc --standard-json --allow-paths ${allowedDirectories.join(',')}`;
shelljs.ShellString(JSON.stringify(compileSettings)).exec(command, {silent: true}, (code, stdout, stderr) => {
if (stderr) {
logger.warn(stderr);
}
if (code !== 0) {
return callback(`solc exited with error code ${code}`);
}
if (!stdout) {
return callback('solc execution returned nothing');
}
callback(null, stdout.replace(/\n/g, ''));
});
}
files.forEach(file => {
shell.ShellString(file.content).to(file.path);
});
},