# lazy-creator

> A custom file generator based on node.js, which can realize the standardized development of project structure through custom file generation, eliminate unnecessary repetitive work and improve efficiency.

Latest version **1.0.1** (published 2019-05-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install lazy-creator
pnpm add lazy-creator
yarn add lazy-creator
bun add lazy-creator
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-05-19 |
| First published | 2019-05-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 16.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | yongtian.hong |
| Maintainers | smartjk |
| Keywords | lazy, creator, lazy-creator |

## Links

- npm: https://www.npmjs.com/package/lazy-creator
- Repository: https://github.com/gikhub-HYT/lazy-creator
- Homepage: https://github.com/gikhub-HYT/lazy-creator#readme
- Issues: https://github.com/gikhub-HYT/lazy-creator/issues
- npm.io page: https://npm.io/package/lazy-creator

## Dependencies (1)

- [chalk](https://npm.io/package/chalk.md) ^2.4.2

## Recent versions

- 1.0.1 (latest) — 2019-05-19
- 1.0.0 — 2019-05-14

## README

# lazy-creator
一个基于node.js的自定义文件生成器，可以根据预设的项目规范自定义文件模板生成文件，消除不必要的重复性劳动，提升效率，
同时可以实现团队规范与项目结构的一致性

 ![display](https://images.gitee.com/uploads/images/2019/0519/132819_9f71d979_1384885.gif "gitee.gif")

### 1.安装

```
npm install --save lazy-creator 或 yarn add lazy-creator
```

### 2.用法

```
const lazyCreator = require('lazy-creator');

lazyCreator
    .log()
    .onInput((inputName, ctx) => {
      
    })

其中inputName为用户输入的内容，ctx提供以下几个方法：

ctx.log.warn(msg:String) 

ctx.log.success(msg:String) 

ctx.log.error(msg:String) 

ctx.resolve(path:String) //获取目标路径

ctx.generateFile(targetPath:String, fileName:String, fileContent:String)

ctx.generateFiles(targetPath:String, templateObj:Object)

```
### 3.用例
```
const storeTemplate={
      state: "export default {}",
      mutations: "export default {}",
      actions: "export default {}",
      getter: "export default {}",
      index: `import state from './state'
      import mutations from './mutations
      import actions from './actions
      import getter from './getter
      exports default {
         state: state,
         mutations: mutations,
         actions: actions,
         getter: getter
      }`
  };

const i18nTemplate={
    'en_US.js': "export default {}",
    'zh_CN.js': "export default {}",
    'zh_TW.js': "export default {}",
    'index.js': `import en_us from './en_US';
    import zh_cn from './zh_CN';
    import zh_tw from './zh_TW';
    export default{
        en_US:en_us,
        zh_CN:zh_cn,
        zh_TW:zh_tw
    }`
};


const VueTemplate = function(compoenntName) {

    return ` <style lang="scss" scoped>
            </style>
            <template>
              <div class="${compoenntName}-wrap">
                ${compoenntName}组件
              </div>
            </template>
            <script>
            import components from './components'
                export default {
                    name: '${compoenntName}',
                    components:components
                };
            </script>`;
};


lazyCreator
    .log(`请输入要创建的页面名称`)
    .onInput((inputName, ctx) => {
        const targetPath = ctx.resolve(`src/pages/${inputName}`);
        const storePath = ctx.resolve(`${targetPath}/store`);
        const i18nPath = ctx.resolve(`${targetPath}/i18n`);

        ctx.generateFile(targetPath, "page.vue", VueTemplate(inputName));
        ctx.log.success(`page.vue创建成功！`)

        ctx.generateFiles(storePath, storeTemplate);
        ctx.log.success(`store创建成功！`)
            
        ctx.generateFiles(i18nPath, i18nTemplate);
        ctx.log.success(`i18n创建成功！`)        

    })
```

---
_Source: https://npm.io/package/lazy-creator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
