5.5.0 • Published 4 years ago

create-whatever v5.5.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

✨ Create Whatever

npm-badge workflow-badge

The smartest create- app template generator.

screencast

Why?

  • ⚖️ Built-in License chooser No need to care about license things.
  • 🎩 Template engine Just put files with template strings and we will do the rest.
  • 💄 Highly customizable Can change caveat text, and add extra cli options.

Table of contents

Quick Start

Let's create create-greet package in four steps.

1. yarn create whatever

yarn create whatever create-greet --template typescript

or if you use npm, then run npm create create-greet

2. Edit templates

cd create-greet and edit files inside templates/default.

TypeScript

Run yarn build or npm run build to transpile TypeScript into JavaScript.

3. Publish package to npm

Run yarn publish or npm publish to publish your create- app to npm.

4. PROFIT!

yarn create greet ohayo

Template

Edit files inside templates/default. File names, directory names, and text files will be processed through Handlebars template engine to replace all template strings with respective value.

  • {{name}} package name
  • {{description}} package description
  • {{author}} author name
  • {{email}} author email
  • {{contact}} author name formatted with {{name}} <{{email}}> if email given, otherwise {{name}}
  • {{license}} package license (e.g. MIT)
  • {{year}} current year (e.g. 2020)

Helper functions

upper

Output text in UPPERCASE.

{{upper name}} becomes CREATE-REACT-APP.

lower

Output text in lowercase.

{{lower name}} becomes create-react-app.

camel

Output text in camelCase.

{{camel name}} becomes createReactApp.

capital

Output text in CapitalCase.

{{capital name}} becomes CreateReactApp, and {{capital name space=true}} becomes Create React App.

snake

Output text in snake_case.

{{snake name}} becomes create_react_app.

kebab

Output text in kebab-case.

{{kebab name}} becomes create-react-app.

uuid

Generates unique UUID string.

{{uuid}}
{{upper (uuid)}}

Config

You can find the app config in src/cli.ts.

import {resolve} from 'path';
import {create} from 'create-whatever';

create('create-greet', {
  templateRoot: resolve(__dirname, '../templates'),
  extra: {
    language: {
      type: 'input',
      describe: 'greeting language',
      default: 'en',
      prompt: 'if-no-arg',
    },
  },
  caveat: `Your app has been created successfuly!`,
});

templateRoot set to path.resolve(__dirname, '../templates'). You can change it to whereever you want.

extra

object | undefined

Extra options passed to the app. These options will be accessible as a cli option, interactive question, and template string. In this case, --language cli option and {{language}} template string will be available.

You can find all possible options in yargs-interactive documentation.

caveat

string | ((options: AfterHookOptions) => string | void) | undefined

The caveat message will be shown after the entire process completed.

create('create-greet', {
  caveat: 'Happy coding!',
});
create('create-greet', {
  caveat: ({ answers }) => `Run -> cd ${answers.name} && make`,
});
create('create-greet', {
  caveat: async ({ answers }) => {
    const pkg = answers.plugin;
    await execa('yarn', ['add', plugin]);
    console.log(`${plugin} has been added`);
  },
});

AfterHookOptions

{
  // variables
  packageDir: string;
  templateDir: string;
  year: number; // 2020
  answers: {
    name: string; // package name
    description: string; // description
    author: string; // John Doe
    email: string; // john@example.com
    contact: string; // John Doe <john@example.com>
    license: string; // MIT
    [key: string]: string | number | boolean | any[]; // any values defined in the `extra` field.
  };
  // functions
  run: (command: string, options?: CommonOptions<string>) => ExecaChildProcess<string>; // run shell command in the package dir
  installNpmPackage: (packageName: string) => Promise<void>; // use yarn if available
}

after

(options: AfterHookOptions) => void

After hook script that runs after the initialization.

Contribution

PRs are always welcome!

5.5.0

4 years ago

5.4.0

4 years ago

5.3.0

4 years ago

5.2.1

4 years ago

5.2.0

4 years ago

5.1.1

4 years ago

5.1.0

4 years ago

5.0.1

4 years ago

5.0.0

5 years ago

4.1.0

5 years ago

4.0.4

5 years ago

4.0.3

5 years ago

4.0.2

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

3.1.0

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.0.0

5 years ago

1.4.0

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago