give-me-file
generate files like vue-cli
Last updated 2 years ago by tinkgu .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install give-me-file 
SYNC missed versions from official npm registry.

give-me-file

generate files by generators, inspired of vue-cli

NOTE

just copy some code from vue-cli@2, thanks for their work

Install

npm i give-me-file -g

Usage

you can use this cli tool as vue-cli@2.x, you can see the basic usage at its docs: vuejs/vue-cli: ????️ CLI for rapid Vue.js development

give-me-file just add some convient features, such as

use template in repo subdir

--dir <dirname> : run gmfile with a specified directory at the repo

Look at the files tree of TinkGu/my-templates

- package.json
- meta.js
- template/a.js
- sub
  - meta.js
  - template/b.js

run this cmd, you may get a.js

gmfile TinkGu/my-templates my-project

run this cmd, you may get b.js

gmfile TinkGu/my-templates my-project --dir sub

task

task will run before/after generating files

// meta.js

module.exports = {
  // ...
  task: {
    // run before ask
    before: api => {
      // print sth
      api.helpers.logger.log('using gmfile')
    },

    // run after ask
    afterAsk: api => {
      // modify your renderData here!
      const renderData = api.metalsmith.metadata()
      if (renderData.a === true) {
        api.extraRenderData.merge({
          b: true,
        })
      }
    },

    // run after generate
    complete: api => {
      // update package.json
      api.pkg.update(pkg => ({
        ...pkg,
        scripts: {
          ...(pkg.scripts || {}),
          lint: 'eslint src'
        }
      }))
    }
  }
}

install deps for meta.js

gmfile TinkGu/my-templates my-project --install

then gmfile will install the deps at package.json for this repo, only after downloading.

partial

you can add partial dir to your repo, then you can use these partials render your templates.

- meta.js
- partial/
  - p.js
  - .rc
- template
  a.js
# partial/p.js

this is a partial, pass name to here : {{ name }}
# template/a.js

{{> p_js name="a" }}
# output

this is a partial, pass name to here : a

NOTE

dot . in filename will be translate to _

example:

  • .a.js -> _a_js
  • .rc -> _rc

api

task-api

interface Task {
  (api: TaskApi) => void
}

interface TaskApi {
  metalsmith: Metalsmith,
  meta: Meta, // the meta obj you defined in meta.js
  helpers: {
    chalk: Chalk, // see npm package called chalk
    logger: Logger,
  },
  pkg: {
    read: (path?: string) => Promise,
    write: (obj: Object, path?: string) => Promise,
    update: (setter: object => object, path?: string) => Promise,
    merge: (v: Object, path?: string) => Promise
  },
  install: (deps: string | string[]) => void, // install deps
  installDev: (deps: string | string[]) => void, // install dev deps
  extraRenderData: {
    get: () => Object,
    set: (v: Object) => void, // reassign extraRenderData
    merge: (v: Object) => void, // merge v to extraRenderData
  }
}

interface Logger {
  log: string => void,
  success: string => void,
  fatal: string => void,
}

you can see the api for Metalsmith at segmentio/metalsmith

Current Tags

  • 1.3.1                                ...           latest (2 years ago)

6 Versions

  • 1.3.1                                ...           2 years ago
  • 1.3.0                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (20)
Dev Dependencies (7)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |