Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
const { Snippet } = require('enquirer');
const pkg = { name: 'my-awesome-lib' };
const required = ['name', 'description', 'version'];
const template = {};
for (let name of required) {
template[name] = `\${${name}}`;
}
const prompt = new Snippet({
name: 'username',
message: 'Fill out the fields in package.json',
required,
initial: pkg,
template: JSON.stringify(template, null, 2)
});
prompt.run()
.then(answer => console.log('Answer:', answer))
.catch(console.error);
'use strict';
const colors = require('ansi-colors');
const { Snippet } = require('enquirer');
const prompt = new Snippet({
name: 'username',
message: 'Fill out the fields in package.json',
values: {
name: 'awesome-lib'
},
styles: {
primary: colors.blue
},
template: `
name: "#{name}"
description: "#{description:This is a great project}"
version: "#{version}"
homepage: "https://github.com/#{username}/#{name}"
author: "#{author_name} (https://github.com/#{username})"
repository: "#{username}/#{name}"
bugs:
'use strict';
const colors = require('ansi-colors');
const semver = require('semver');
const { Snippet } = require('enquirer');
const prompt = new Snippet({
name: 'username',
message: 'Fill out the fields in package.json',
defaults: {
name: 'awesome-lib',
version: '0.1.0',
license: 'MIT'
},
required: 'description',
initial: 'version',
fields: [
{
name: 'version',
validate(value, state, field) {
if (field && field.name === 'version' && !semver.valid(value)) {
return colors.red('expected a valid semver value');
}
months: ${c.yellow`\${months}`},
years: ${c.yellow`\${years}`}
})`
const values = mode.set ? date.toObject() : {
seconds: 0,
minutes: 0,
hours: 0,
days: 0,
months: 0,
years: 0
}
Object.keys(values).forEach(key => { values[key] += '' })
const validate = v => !isNaN(v)
const fields = Object.keys(values).map(name => ({ name, validate }))
const { values: ret } = await new Snippet({
name: 'Time unit',
message,
fields,
format () { return '' },
values,
template
}).run()
return ret
}
let timeUnit
'The project dir argument is required in non-interactive mode.'
);
}
if (typeof options.name !== 'string' || options.name === '') {
throw new CommandError(
'NON_INTERACTIVE',
'--name: argument is required in non-interactive mode.'
);
}
return {
name: projectName,
displayName: options.name,
};
}
let { values } = await new Snippet({
name: 'app',
message: 'Please enter names for your project.',
required: true,
fields: [
{
name: 'name',
message: 'The name of the Android Studio and Xcode projects to be created',
initial: projectName,
filter: (name: string) => name.trim(),
validate: (name: string) => validateProjectName(name),
required: true,
},
{
name: 'displayName',
message: 'The name of your app visible on the home screen',
initial: isString(options.name) ? options.name : undefined,
'use strict';
const colors = require('ansi-colors');
const { Snippet } = require('enquirer');
const prompt = new Snippet({
name: 'username',
message: 'Fill out the fields in package.json',
values: {
name: 'awesome-lib'
},
format(value) {
return colors.blue(value);
},
items: {
name: {
format(value) {
return value ? value.toUpperCase() : '';
}
},
keywords: {
format(value) {
'use strict';
const semver = require('semver');
const { Snippet } = require('enquirer');
const prompt = new Snippet({
name: 'username',
message: 'Fill out the fields in package.json',
required: true,
fields: [
{
name: 'author_name',
message: 'Author Name'
},
{
name: 'version',
validate(value, state, item, index) {
if (item && item.name === 'version' && !semver.valid(value)) {
return prompt.styles.danger('version should be a valid semver value');
}
return true;
}
'use strict';
const { Snippet } = require('enquirer');
const prompt = new Snippet({
name: 'username',
message: 'Fill out the fields in package.json',
values: require('../../package'),
template: `{
"name": "{{name}}",
"description": "{{description}}",
"version": "{{version}}",
"homepage": "https://github.com/{{username}}/{{name}}",
"author": "{{author_name}} (https://github.com/{{username}})",
"repository": "{{username}}/{{name}}",
"bugs": {
"url": "https://github.com/{{username}}/{{name}}/issues"
},
"engines": {
"node": ">=4"
},
if (!isString(options.name) || options.name === '') {
throw new CommandError(
'NON_INTERACTIVE',
'--name: argument is required in non-interactive mode.'
);
} else {
return {
expo: {
slug: dirName,
name: options.name,
},
};
}
}
let { values } = await new Snippet({
name: 'expo',
message:
'Please enter a few initial configuration values.\n Read more: https://docs.expo.io/versions/latest/workflow/configuration/',
required: true,
fields: [
{
name: 'name',
message: 'The name of your app visible on the home screen',
initial: isString(options.name) ? options.name : undefined,
filter: (name: string) => name.trim(),
required: true,
},
{
name: 'slug',
message: 'A URL friendly name for your app',
initial: dirName,
'use strict';
const { Snippet } = require('enquirer');
const prompt = new Snippet({
name: 'username',
message: 'Fill out the fields in package.json',
defaults: {
description: 'This is a description'
},
required: ['version'],
template() {
return `{
"name": "{{name}}",
"description": "{{description}}",
"version": "{{version}}",
"homepage": "https://github.com/{{username}}/{{name}}",
"author": "{{author_name}} (https://github.com/{{username}})",
"repository": "{{username}}/{{name}}",
"bugs": {
"url": "https://github.com/{{username}}/{{name}}/issues"