0.2.0 • Published 7 years ago

fisx-command-init v0.2.0

Weekly downloads
2
License
ISC
Repository
github
Last release
7 years ago

fisx-command-init

Dependency Status devDependency Status NPM Version

Init project or files using the given tempalte.

How to use

Init project

fisx init # using the default project template to init project
fisx init spa # init spa project template
fisx init spa --force # force init the not empty project directory
fisx init gitlab:xx/xx # init project using the template from gitlab
fisx init github:xx/xx # init project using the template from github
fisx init ./xx/xx # init project from local template
fisx init npm:xx@1.0.0 # specify the scaffold version

The init source syntax is the same as fisx package install

If using gitlab, some custom options you can configure:

fis.set('scaffold.gitlabDomain', 'http://<your gitlab domain>');
fis.set('scaffold.gitlabToken', '<private token>');

Init file

fisx init html index.html # create html file
fisx init js app.js # create js file

View help information

fisx init -h

Force use the latest scaffold

If your scaffold is from remote, and you want to disable the local cache and fetch the latest to init, you can use --latest options.

fisx init --latest

Custom builtin template

Default builtin template is fisx-scaffold. You can custom the builtin template type:

  • Custom project template

    fis.set('scaffold.project', {
        spa: {
            uri: 'yourscaffold/xxx', // by default source is github, you can use like github:xx to specify the source type
            description: 'the template descripion, you can see this in help information'
        }
    });
  • Custom file template

    fis.set('scaffold.file', {
        html: {
            uri: 'yourscaffold/xxx.html',
            description: 'the template descripion, you can see this in help information'
        }
    });
  • Custom the deafult template source owner:

    fisx init abc is equivalent to fisx init myrepos/abc, and is also equivalent to fisx init github:myrepos/abc.

    fis.set('scaffold.namespace', 'myrepos');
  • Custom the scaffold source type

    By default, the default source type is GitHub, using the following setting to change:

    fis.set('scaffold.source', {
        value: 'gitlab',
        options: function () {
            token: 'xx',
            domain: 'http://xx.gitlab.com'
        }
    });

Template syntax

Syntax of variable

  • ${#variableName#}: the variable value will be inited in the form of command interaction

  • ${#variableName=variable default value#}: with default value

  • ${#varName:boolean=true#}: specify the type of the variable

  • The template is rendered by template engine etpl, so it supports the syntax like conditional expression defined in etpl.

  • The command open and close syntax: <!#-- and --#> .

  • You can use the template variable in file name or file content.

Builtin template variable

  • author: by default using the author information from package.json, if not found, will try to use the system use name.

  • date: the date format is like YYYY/m/d

  • name: the project name, by default using the project director name

  • custom your template variable

    • using the config

      fis.set('template.xxx', function () {
          return 'xxx';
      });
      fis.set('template.xxx', 'xxx');
    • using the command args

      fisx init xx --author xxx@xx.com