Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
log.warn(`No path given!`);
process.exit(1);
return;
}
// Get absolute path
const path = resolve(await fs.realpath(process.cwd()), name);
// Check if exist
if (await fs.exists(path)) {
log.warn(`Path exists!`);
process.exit(1);
return;
}
log.start(`Copying...`);
// Copy from template
try {
await fs.copy(resolve(__dirname, "..", "template"), path);
} catch (error) {
error(`Error copying.`, error);
process.exit(1);
return;
}
log.info(`Setting up...`);
// Set the "name" field in package.json
try {
const childPackagePath = resolve(path, "package.json");
// Read
async fixMissingDependencies(api) {
if (!this.options.silent) consola.start('Checking missing dependencies...');
const hasDependency = name => {
const packageJson = require(api.resolve('package.json'));
return packageJson.dependencies[name] ? true : false;
};
const isYarn = () => {
return fs.existsSync(api.resolve('yarn.lock'));
};
// Missing Apollo deps
if (api.hasPlugin('apollo') && !hasDependency('isomorphic-fetch')) {
if (!this.options.silent) consola.info('Installing isomorphic-fetch for Apollo...');
if (isYarn()) {
await execa('yarn', ['add', 'isomorphic-fetch'], {
// PWA
if (api.hasPlugin('pwa')) {
await fixPlugin('PWA', ['code:register-service-worker'], 'fixPwa');
}
// Apollo
if (api.hasPlugin('apollo')) {
await fixPlugin('Apollo', ['code:createApolloClient'], 'fixApollo');
}
// TypeScript
await this.fixTsConfig(api);
// Main
{
if (!this.options.silent) consola.start(`Checking main file...`);
if (fs.existsSync(mainPath + '.ts')) {
mainPath += '.ts';
} else {
mainPath += '.js';
}
const code = await fs.readFile(mainPath, 'utf-8');
let result = this.fixNewVue(code);
result = this.fixPluginVueOption(result, 'router');
if (api.hasPlugin('vuex')) {
result = this.fixPluginVueOption(result, 'store');
}
if (api.hasPlugin('i18n')) {
};
const wait = time => new Promise(resolve => setTimeout(resolve, time));
if (!scenario.steps) {
scenario.steps = [
{
path: '/',
},
];
}
const repeat = scenario.repeat || 1;
for (let i = 0; i < repeat; i++) {
consola.start(`Run ${i + 1}/${repeat}`);
for (const stepIndex in scenario.steps) {
const step = scenario.steps[stepIndex];
await httpBenchmark(autocannonConfig, step.path);
if (step.wait) {
await wait(step.wait);
}
}
}
};
async argv => {
consola.start('Starting benchmark...');
const startPath = require.resolve('@uvue/server/start');
const server = execa('node', [startPath, ...buildServerArgs(argv)], {
stdio: 'inherit',
});
await executeScenario(argv.scenario, argv);
server.kill('SIGINT');
},
];
argv => {
consola.start('Starting server with ndb...');
let args = ['node', require.resolve('@vue/cli-service/bin/vue-cli-service'), 'ssr:serve'];
if (argv.prod) {
args = ['node', require.resolve('@uvue/server/start')];
}
const ndbPath = require.resolve('ndb/ndb');
return execa(ndbPath, [...args, ...buildServerArgs(argv)]);
},
];
argv => {
consola.start('Starting Node Clinic: BubbleProf...');
const ClinicBubbleprof = require('@nearform/bubbleprof');
const bubbleprof = new ClinicBubbleprof();
return clinicRun(argv, bubbleprof);
},
];
argv => {
consola.start('Starting Node Clinic: Doctor...');
const ClinicDoctor = require('@nearform/doctor');
const doctor = new ClinicDoctor();
return clinicRun(argv, doctor);
},
];
return async function () {
consola.start(isStdin ? 'stdin' : inputFile)
await mkdirp(path.resolve(outputFile, '..'))
try {
await new Promise(async function (resolve) {
if (hasFilters) {
await mkdirp(path.resolve(temporaryFile, '..'))
}
const flagCommand = createFFmpegCommand(
ffmpegBinaryPath,
inputFile,
hasFilters ? temporaryFile : outputFile,
ffmpegOptions.flags
)
const childProcess = runCommand(flagCommand, isDebug)
if (isStdin) {
childProcess.on('exit', function () {
resolve()
async fixTsConfig(api) {
const filepath = api.resolve('tsconfig.json');
if (api.hasPlugin('typescript') && fs.existsSync(filepath)) {
if (!this.options.silent) consola.start('Checking tsconfig...');
try {
const tsConfig = JSON.parse((await fs.readFile(filepath, 'utf-8')) || '{}');
tsConfig.compilerOptions = tsConfig.compilerOptions || {};
tsConfig.compilerOptions.types = tsConfig.compilerOptions.types || [];
if (!tsConfig.compilerOptions.types.includes('@uvue/core')) {
tsConfig.compilerOptions.types.push('@uvue/core');
await fs.writeFile(filepath, JSON.stringify(tsConfig, null, ' '));
}
if (!this.options.silent) consola.success('Types OK');
} catch (err) {
if (!this.options.silent) consola.error('Unable to check or fix tsconfig.json');
}
}