https://github.com/lencx/l3x-generate-file
Generate File
https://github.com/lencx/l3x-generate-file
file generate json template
Last synced: 2 months ago
JSON representation
Generate File
- Host: GitHub
- URL: https://github.com/lencx/l3x-generate-file
- Owner: lencx
- License: mit
- Created: 2018-09-07T03:54:19.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-08T16:54:10.000Z (almost 8 years ago)
- Last Synced: 2026-03-22T03:21:47.468Z (4 months ago)
- Topics: file, generate, json, template
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# l3x-generate-file
> Generate File
## Installation
```bash
npm install l3x-generate-file
```
## Usage
```js
const {genTpl, genJSON} = require('l3x-generate-file')
genTpl(data)
genJSON(data [, outputPath|options])
```
## Methods
* [genTpl](./doc/gentpl.md)
* [genJSON](./doc/genjson.md)
## Example
```js
const {genTpl, genJSON} = require('l3x-generate-file')
// genTpl
genTpl(require('./tpl'))
// or
genTpl({
css: {
tpl: `body {background: pink;}`,
output: 'tpl/css/main.css'
},
// ...
})
// ------------------------------------------
genJSON({a: 1, b: 2}) // ouputFile: default.json
genJSON({a: 1, b: 2}, 'a/b.json') // ouputFile: rootPath/a/b.json
genJSON(require('./test.json')) // ouputFile: default.json
genJSON(require('./test.json'), 'a/b.json') // ouputFile: rootPath/a/b.json
// ouputFile: default.json
genJSON(require('./test.json'), {
key: 'c',
val: 3
})
// ouputFile: rootPath/a/b.json
genJSON(require('./test.json'), {
key: 'c',
val: 3,
output: 'a/b.json'
})
// ouputFile: rootPath/a/b.json
// Override the value of the source file property
genJSON(require('a/b.json'), {
key: 'c',
val: 3,
output: 'a/b.json', // default: default.json
cover: true // default: false
})
```
> require('tpl')
```js
/** tpl.js **/
let pugTpl = `h1 Hello
`
let jsTpl = `let str = 'JS Template'
console.log(str)
`
// ...
module.exports = {
pug: {
tpl: pugTpl,
output: 'tpl/view/test.pug'
},
js: {
tpl: jsTpl,
output: 'tpl/js/test.js'
},
// ...
}
```