0.0.8 • Published 4 years ago

@dking/hasaki-cli v0.0.8

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

At present, the template project has not been fully developed, and will be added in succession。

hasaki-cli

It can automatically build React, Vue, jQuery, JS library, Koa / Express / Egg project, Plugin and other project structure initialization. It can also generate single or multiple plug-in configurations that can be used directly for existing projects.

Install

$ npm i @dking/hasaki-cli -g 

Usage

$ hasaki-cli init -d ./react-demo

$ hasaki-cli install https://github.com/JohnApache/hasaki-template/tree/master/react -d ./react-demo

$ hasaki-cli gen readme,eslint,babel,webpack --installed react

$ hasaki-cli template --list

CommandIntroduction

  • init | i Quickly initialize the project by selecting a suitable template. The optional configuration is as follows

    • -d, --out-dir Specifies the output directory, which is the current execution environment directory by default.
    • --ignore <pattern,...,parttern> Specify files to ignore.
    • --exclude <pattern,...,parttern> Specify files that do not require EJS rendering.
    • --include <pattern,...,parttern> Specifies the files that need to be rendered with EJS, generally used in conjunction with exclude.
    • -c, --config Specify the template project configuration file name to read, Default: .hasakirc.js.
    • -h, --help Output help documents
      $ hasaki-cli init -d ./react-demo
  • install It has the same effect as "init". The remote address is used instead of the built-in template option. The optional configuration is as follows

    • -d, --out-dir Specifies the output directory, which is the current execution environment directory by default.
    • --ignore <pattern,...,parttern> Specify files to ignore.
    • --exclude <pattern,...,parttern> Specify files that do not require EJS rendering.
    • --include <pattern,...,parttern> Specifies the files that need to be rendered with EJS, generally used in conjunction with exclude.
    • -c, --config Specify the template project configuration file name to read, Default: .hasakirc.js.
    • -h, --help Output help documents
      $ hasaki-cli init -d ./react-demo
  • template | t The command is used to customize the template list with CRUD. The optional configurations are as follows

    • --list Show current template list.
    • --add Add template.
    • --update Update template.
    • --delete Delete template.
    • --clear Clear template.
    • --reset Reset template.
    • -h, --help Output help documents

      $ hasaki-cli template --list
      
      $ hasaki-cli template --add
      
      $ hasaki-cli template --reset
  • gen | generate plugin,...,plugin Quickly add configuration files or other related files for existing projects

    • -d, --out-dir Specify output directory, default to current directory.
    • --installed <plugin,...,plugin> Specify the plug-in environment that the current project has installed.
    • -f, --force-cover Force overwrite file.
    • -h, --help Output help documents

      The list of supported plug-in configurations is as follows: readme, eslint, mocha, jest, babel, webpack, rollup, gulp, lerna, typescript.

      Additional configurable installed configuration: react, vue....

      $ hasaki-cli gen eslint,readme,mocha,babel,rollup,typepscript -d ./config --installed react

.hasakirc.js

.hasakirc.js file is a configuration file that exists in the root directory of the template project, hasaki-cli will attempt to dynamically read and load the file. And load the filter file according to the configuration file, read files according to ejs rules, If there is no such file, the target project will be output in full,Such a configuration file gives hasaki-cli the ability to customize template projects, allows users to customize template projects, output different contents in different situations, and it is applicable to any GitHub project, very flexible!.

// .hasakirc.js
module.exports = {
    parseExclude: [],
    parseInclude: [],
    ignore: [],
    question: [{
        type: 'confirm',
        message: 'use ts?',
        name: 'useTs',
        default: true
    }],
    screener(answers) {
        const { useTs } = answers;
        const include = [];
        const exclude = [];
    
        if(useTs) {
            exclude.push({
                path: './src/index.js'
            })
        }else {
            exclude.push({
                path: './src/index.ts'
            }, {
                path: './tsconfig.json'
            })
        }
        return { include, exclude }
    }
}
  • parseExclude

    • Meaning: Specify files that do not require EJS rendering, Prevent EJS template file in the project.
    • Type: Array<Rule | RegExp>
  • parseInclude

    • Meaning: Specify files that require EJS rendering,Use with parseExclude.
    • Type: Array<Rule | RegExp>
  • ignore

    • Meaning: Specify files to ignore
    • Type: Array<Rule | RegExp>
  • question

    • Meaning: Specify the interaction problem of inquirer to be used
    • Type: Array For specific configuration, see inquirer.
  • screener

    • Meaning: Screener is a function, it takes "answer" of "question" as a parameter, return type is {exclude: Array<Rule | RegExp>, include: Array<Rule | RegExp>}, you can filter files according to different "answers".
    • Type: Function(answer: Answer): {

        exclude: Array<Rule | RegExp>; // Specify files to exclude
      
        include: Array<Rule | RegExp>; // Specifies the files to be included for use with "exclude"

      };

TIPS

  1. Multiple choices split multiple options with "," by default
  2. pattern can be a relative path of the target project or a RegExp, or a Rule, Rule is a object like this { path?: string; match?: RegExp; }, path is a relative path, match is RegExp, path and match only need one
  3. The .hasakirc.js file must be exported in commonjs.
  4. .hasakirc.js write question must same rules as inquirer Question. Otherwise, it will parse the error

Questions

Please open an issue here.

License

MIT