Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return prompts(BULLETS, { onCancel }).then(argv => {
if (!ok) {
log.info(`Received ${colors.cyan().underline('CTRL+C')} command`);
return log.log(`Exited ${colors.dim('$ pwa init')} setup`);
}
// console.log(argv);
if (argv.exists && !argv.force) {
return log.error(`Refusing to overwrite existing directory.\nPlease specify a different destination or use the ${colors.cyan('--force')} flag.`);
}
let dest = argv.dir;
// Construct `package.json` file
// ---
let pkg = { private:true };
let deps = ['sirv-cli', 'ganalytics'];
let devdeps = ['@pwa/cli']
copyDir(template, dest, data);
copyDir(styleDir, dest, data);
}
// Sign off message
// ---
let dir = parse(argv.dir).base;
let txt = argv.preset ? (colors.magenta().underline(argv.preset) + ' ') : '';
let msg = `Created a new ${txt}project within ${ colors.green().bold(dir) } 🎉\n`;
msg += '\nInside this directory, you may:\n';
msg += '\n – Develop within a live-reload server:';
msg += `\n ${colors.dim('$ pwa watch')}\n`;
msg += '\n – Build your application for production:';
msg += `\n ${colors.dim('$ pwa build')}\n`;
msg += '\n – Export routes\' HTML for static hosting:';
msg += `\n ${colors.dim('$ pwa export')}\n`;
msg += '\n – Start a production HTTP file server:';
msg += `\n ${colors.dim('$ npm start')}\n`;
msg += `\nThese commands have been added to your ${colors.white().underline('package.json')} already.`;
msg += '\nWe suggest you begin by typing:\n';
msg += '\n ' + colors.dim(`$ cd ${dir}`);
msg += `\n ${colors.dim('$ npm install')}`;
msg += `\n ${colors.dim('$ npm run watch')}`;
msg += `\n\nDocumentation can be found at ${colors.white().bold().underline('https://pwa.cafe/docs')}`;
log.success(msg);
log.success('Enjoy! 😍');
});
type: x => x === false && 'text',
message: 'OK. Please provide another directory.'
}, {
name: 'force',
message: 'Force destination overwrite?',
type: (_, all) => fs.existsSync(all.dir) && 'confirm',
format: (x, all) => (all.exists=1,x) // bcuz it ran
}
];
dir = dir || '.';
setValue('dir', dir);
if (type=toLower(type)) {
let idx = presets.map(toLower).indexOf(type);
if (idx === -1) return log.error(`Unknown preset "${colors.red(type)}" provided!\nPlease run ${colors.dim('$ pwa init --help')} for info`);
setValue('preset', ++idx);
}
if (opts.force) {
log.warn(`Detected ${colors.cyan('--force')} flag; target directory will be overwritten!`);
prompts.inject({ force:true });
}
let ok = true;
let onCancel = () => ok=false;
return prompts(BULLETS, { onCancel }).then(argv => {
if (!ok) {
log.info(`Received ${colors.cyan().underline('CTRL+C')} command`);
return log.log(`Exited ${colors.dim('$ pwa init')} setup`);
}
// Sign off message
// ---
let dir = parse(argv.dir).base;
let txt = argv.preset ? (colors.magenta().underline(argv.preset) + ' ') : '';
let msg = `Created a new ${txt}project within ${ colors.green().bold(dir) } 🎉\n`;
msg += '\nInside this directory, you may:\n';
msg += '\n – Develop within a live-reload server:';
msg += `\n ${colors.dim('$ pwa watch')}\n`;
msg += '\n – Build your application for production:';
msg += `\n ${colors.dim('$ pwa build')}\n`;
msg += '\n – Export routes\' HTML for static hosting:';
msg += `\n ${colors.dim('$ pwa export')}\n`;
msg += '\n – Start a production HTTP file server:';
msg += `\n ${colors.dim('$ npm start')}\n`;
msg += `\nThese commands have been added to your ${colors.white().underline('package.json')} already.`;
msg += '\nWe suggest you begin by typing:\n';
msg += '\n ' + colors.dim(`$ cd ${dir}`);
msg += `\n ${colors.dim('$ npm install')}`;
msg += `\n ${colors.dim('$ npm run watch')}`;
msg += `\n\nDocumentation can be found at ${colors.white().bold().underline('https://pwa.cafe/docs')}`;
log.success(msg);
log.success('Enjoy! 😍');
});
}
}
// Sign off message
// ---
let dir = parse(argv.dir).base;
let txt = argv.preset ? (colors.magenta().underline(argv.preset) + ' ') : '';
let msg = `Created a new ${txt}project within ${ colors.green().bold(dir) } 🎉\n`;
msg += '\nInside this directory, you may:\n';
msg += '\n – Develop within a live-reload server:';
msg += `\n ${colors.dim('$ pwa watch')}\n`;
msg += '\n – Build your application for production:';
msg += `\n ${colors.dim('$ pwa build')}\n`;
msg += '\n – Export routes\' HTML for static hosting:';
msg += `\n ${colors.dim('$ pwa export')}\n`;
msg += '\n – Start a production HTTP file server:';
msg += `\n ${colors.dim('$ npm start')}\n`;
msg += `\nThese commands have been added to your ${colors.white().underline('package.json')} already.`;
msg += '\nWe suggest you begin by typing:\n';
msg += '\n ' + colors.dim(`$ cd ${dir}`);
msg += `\n ${colors.dim('$ npm install')}`;
msg += `\n ${colors.dim('$ npm run watch')}`;
msg += `\n\nDocumentation can be found at ${colors.white().bold().underline('https://pwa.cafe/docs')}`;
log.success(msg);
log.success('Enjoy! 😍');
});
}
reasons.map(reason => {
const versionTag = kleur.dim('@' + reason[0].version)
return reason.reverse().map(rs => {
return kleur.blue(rs.name || dirName)
}).join(' > ') + versionTag
}).sort().forEach(x => console.log(' ' + x))
}
export function printHelpFor (command: SerializedCommandContract): void {
if (command.description) {
console.log('')
console.log(command.description)
}
console.log('')
console.log(`${yellow('Usage:')} ${command.commandName} ${dim(command.args.map(wrapArg).join(' '))}`)
const flags = getFlagsForDisplay(command.flags)
const args = getArgsForDisplay(command.args)
/**
* Getting max width to keep flags and args symmetric
*/
const maxWidth = Math.max.apply(Math, flags.concat(args as any).map(({ width }) => width))
if (args.length) {
console.log('')
console.log(bold(yellow('Arguments')))
args.forEach(({ displayName, description = '', width }) => {
const whiteSpace = padRight('', maxWidth - width, ' ')
console.log(` ${green(displayName)} ${whiteSpace} ${dim(description)}`)
flags.forEach(({ displayName, displayType, description = '', width }) => {
const whiteSpace = padRight('', maxWidth - width, ' ')
console.log(` ${green(displayName)} ${dim(displayType)} ${whiteSpace} ${dim(description)}`)
})
}
const description = `${error.name ? error.name + ': ' : ''}${error.message ||
error}`;
const message = error.plugin
? `(${error.plugin} plugin) ${description}`
: description;
stderr(red().bold(message));
if (error.loc) {
stderr();
stderr(`at ${error.loc.file}:${error.loc.line}:${error.loc.column}`);
}
if (error.frame) {
stderr();
stderr(dim(error.frame));
} else if (err.stack) {
const headlessStack = error.stack.replace(message, '');
stderr(dim(headlessStack));
}
stderr();
}
let txt = argv.preset ? (colors.magenta().underline(argv.preset) + ' ') : '';
let msg = `Created a new ${txt}project within ${ colors.green().bold(dir) } 🎉\n`;
msg += '\nInside this directory, you may:\n';
msg += '\n – Develop within a live-reload server:';
msg += `\n ${colors.dim('$ pwa watch')}\n`;
msg += '\n – Build your application for production:';
msg += `\n ${colors.dim('$ pwa build')}\n`;
msg += '\n – Export routes\' HTML for static hosting:';
msg += `\n ${colors.dim('$ pwa export')}\n`;
msg += '\n – Start a production HTTP file server:';
msg += `\n ${colors.dim('$ npm start')}\n`;
msg += `\nThese commands have been added to your ${colors.white().underline('package.json')} already.`;
msg += '\nWe suggest you begin by typing:\n';
msg += '\n ' + colors.dim(`$ cd ${dir}`);
msg += `\n ${colors.dim('$ npm install')}`;
msg += `\n ${colors.dim('$ npm run watch')}`;
msg += `\n\nDocumentation can be found at ${colors.white().bold().underline('https://pwa.cafe/docs')}`;
log.success(msg);
log.success('Enjoy! 😍');
});
}