Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { dim, green, red, yellow } = require('ansi-colors');
const { Input } = require('enquirer');
const color = t => t >= 7 ? green(t) : t > 3 ? yellow(t) : red(t);
let time = 5;
let int;
/**
* This example shows how to create a "countdown" effect. You can
* put the countdown timer in the prefix, footer, header, separator,
* or whatever prompt position makes sense for your goal.
*/
const prompt = new Input({
name: 'name',
header() {
return `${dim('You have')} ${color(time)} ${dim('seconds left to answer!')}`;
},
separator() {
return ''; // hide separator
},
message(state) {
if (state.submitted && !state.input) return 'Really? Your own name?';
return state.submitted ? 'Well done,' : 'What is your full name!!!';
}
});
prompt.once('close', () => clearInterval(int));
prompt.once('run', () => {
int = setInterval(() => {
);
// update license year and author
let license: string = await fs.readFile(
path.resolve(projectPath, 'LICENSE'),
{ encoding: 'utf-8' }
);
license = license.replace(//, `${new Date().getFullYear()}`);
// attempt to automatically derive author name
let author = getAuthorName();
if (!author) {
bootSpinner.stop();
const licenseInput = new Input({
name: 'author',
message: 'Who is the package author?',
});
author = await licenseInput.run();
setAuthorName(author);
bootSpinner.start();
}
license = license.replace(//, author.trim());
await fs.writeFile(path.resolve(projectPath, 'LICENSE'), license, {
encoding: 'utf-8',
});
const templateConfig = templates[template as keyof typeof templates];
const generatePackageJson = composePackageJson(templateConfig);
'use strict';
const colors = require('ansi-colors');
const { Input } = require('enquirer');
const prompt = new Input({
message: 'What is your username?',
initial: 'jonschlinkert',
symbols: { prefix: '$' },
styles: {
primary: colors.yellow,
get submitted() {
return this.complement;
}
}
});
prompt.run()
.then(answer => console.log('ANSWER', answer))
.catch(console.log);
'use strict';
const { Input } = require('enquirer');
const colors = require('ansi-colors');
const prompt = new Input({
message: 'What is your username?',
initial: 'jonschlinkert',
styles: {
primary: colors.blue,
get submitted() {
return this.complement;
}
}
});
prompt.run()
.then(answer => console.log('ANSWER', answer))
.catch(console.log);
'use strict';
const yosay = require('yosay');
const { Input } = require('enquirer');
const prompt = new Input({
message: 'What is your username?',
header: yosay('Welcome to my awesome generator!'),
footer: 'This is a footer\nwith a\nfew\nextra\nlines'
});
prompt.run()
.then(answer => console.log('ANSWER', answer))
.catch(console.log);
throw new Error(
`Invalid project identifier [${identifier}]. Publishing requires a full deployment identifier with version hash.`
)
}
const { projectId, deploymentId } = parsedFaas
const project = await spinner(
client.getProject(projectId),
`Fetching project [${projectId}]`
)
const lastPublishedVersion = project.lastPublishedVersion || '0.0.0'
console.log(`Current version ${lastPublishedVersion}`)
const prompt = new Input({
message: 'Enter semver version to publish.',
validate: (value) => {
return semver.valid(value) && semver.gt(value, lastPublishedVersion)
},
result: (value) => {
return semver.clean(value)
}
})
const version = await prompt.run()
const deployment = await spinner(
client.publishDeployment(deploymentId, { version }),
`Publishing deployment [${deploymentId}] as version "${version}"`
)
'use strict';
const colors = require('ansi-colors');
const yosay = require('yosay');
const { Input } = require('enquirer');
const prompt = new Input({
message: 'What is your username?',
header: yosay('Welcome to my awesome generator!'),
footer: colors.yellow('This is a footer\nwith a\nfew\nextra\nlines'),
initial: 'jonschlinkert'
});
prompt.run()
.then(answer => console.log('ANSWER', answer))
.catch(console.log);
export default async (type, initialValue = "") => {
const prompt = new Input({
message: `Please enter the ${type}`,
initial: initialValue
});
return prompt.run();
};
'use strict';
const yosay = require('yosay');
const { Input } = require('enquirer');
const prompt = new Input({
message: 'What is your username?',
header: yosay('Welcome to my awesome generator!'),
footer: 'This is \na footer\nwith a\nfew\nlines\n',
initial: 'jonschlinkert'
});
prompt.footer = () => {
let state = { ...prompt.state };
delete state.prompt;
delete state.styles;
delete state.keypress;
delete state.symbols;
delete state.header;
delete state.footer;
delete state.buffer;
return '\n' + prompt.options.footer + '\n' + JSON.stringify(state, null, 2);
export default async DEVICE_NAME => {
const prompt = new Input({
message: "Please enter a device name",
initial: DEVICE_NAME ? DEVICE_NAME : "My device"
});
return prompt.run();
};