How to use the enquirer.Snippet function in enquirer

To help you get started, we’ve selected a few enquirer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github enquirer / enquirer / examples / snippet / json-fillin.js View on Github external
'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);
github enquirer / enquirer / examples / snippet / yaml-template.js View on Github external
'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:
github enquirer / enquirer / examples / snippet / option-validate.js View on Github external
'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');
        }
github Elevista / git-amend / index.js View on Github external
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
github expo / expo-cli / packages / expo-cli / src / commands / init.ts View on Github external
'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,
github enquirer / enquirer / examples / snippet / option-items.js View on Github external
'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) {
github enquirer / enquirer / examples / snippet / prompt.js View on Github external
'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;
      }
github enquirer / enquirer / examples / snippet / option-values.js View on Github external
'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"
  },
github expo / expo-cli / packages / expo-cli / src / commands / init.ts View on Github external
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,
github enquirer / enquirer / examples / snippet / option-template-fn.js View on Github external
'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"