@bryanadamss/generate-file

1.1.7 • Public • Published

generate-file

read ejs template then generate a file

English | 中文

Install

npm install @bryanadamss/generate-file

or

yarn add @bryanadamss/generate-file

Config

  • cosmiconfig style config
    • so you can put a generate-file.config.js in the project root to modify default config just like below
// generate-file.config.js
module.exports = {
  case: 'snakeCase', // default to 'paramCase'(kebab-case)
  output: 'src/views', // default to '.',its process.cwd()
  template: '.generate-file-vue-template', // default to '.generate-file-template',relative to process.cwd()
}
  • case
    • generated file name case
    • support camelCase, capitalCase,constantCase,dotCase,headerCase,noCase,paramCase,pascalCase,pathCase,sentenceCase,snakeCase;
    • You can visit https://www.npmjs.com/package/change-case for a detail
  • output
    • output directory
    • relative to process.cwd()
  • template
    • ejs template file name

Ejs template vars

  • you can get all merged config variable and an additional variable fileName

Examples

// generate-file.config.js
module.exports = {
  case: 'pascalCase',
  output: 'src/views',
  template: '.generate-file-vue-template',
}

// .generate-file-vue-template
<template>
  <div class="c-<%=fileName%>"></div>
</template>

<script>
/**
 * * <%=fileName%>
 */

export default {
  name: '<%=fileName%>',
  components: {},
  mixins: [],
  props: {},
  data() {
    return {}
  },
  computed: {},
  watch: {},
  beforeCreate() {},
  created() {},
  mounted() {},
  methods: {}
}
</script>

<style lang="scss" scoped>
.c-<%=fileName%> {

}
</style>

// npm script
"scripts":{
  "new:comp":"node node_modules/@bryanadamss/generate-file"
}

// run script
npm run new:comp

// stdin
test-generate-file.vue


// ------------------------------------
// output
// ------------------------------------

// dir tree
|-src
|--views
|---TestGenFile.vue


// src/views/TestGenFile.vue
<template>
  <div class="c-TestGenFile"></div>
</template>

<script>
/**
 * * TestGenFile
 */

export default {
  name: 'TestGenFile',
  components: {},
  mixins: [],
  props: {},
  data() {
    return {}
  },
  computed: {},
  watch: {},
  beforeCreate() {},
  created() {},
  mounted() {},
  methods: {}
}
</script>

<style lang="scss" scoped>
.c-TestGenFile {

}
</style>

NPM

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2020 BryanAdamss@foxmail.com.
This project is MIT licensed.

Contributors

Thanks goes to these wonderful people (emoji key):


GuangHui

📆

This project follows the all-contributors specification. Contributions of any kind welcome!

Readme

Keywords

Package Sidebar

Install

npm i @bryanadamss/generate-file

Weekly Downloads

2

Version

1.1.7

License

MIT

Unpacked Size

15.7 kB

Total Files

13

Last publish

Collaborators

  • bryanadamss