Comparing version 0.1.0 to 0.2.0
{ | ||
"name": "vue-gue", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Vue component generator", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -9,2 +9,7 @@ | ||
<p align="center"> | ||
<img width="430" src="./logo.png"> | ||
</p> | ||
## Demo | ||
<p align="center"> | ||
<img src="./preview.gif"> | ||
@@ -38,3 +43,3 @@ </p> | ||
This will generate `tab` component in `./menu/tab.vue` | ||
> Consider behavior of directory parameter when you have a config file and you don't. [details](#usage) | ||
> Consider behavior of directory parameter when you have a config file and you don't. [details](#usage) | ||
> For a consistent way to change root directory of components see [config](#config-file). | ||
@@ -52,3 +57,11 @@ | ||
``` | ||
gue <componentName> [directory] [options] | ||
$ gue --help | ||
Usage: gue <componentName> [direcroty] [options] | ||
Options: | ||
-u, --unit create unit test of the component too | ||
-t, --template <name> define which template to use | ||
-h, --help output usage information | ||
``` | ||
@@ -59,3 +72,3 @@ * <componentName> is mandatory. | ||
If you don't, then this will lead to generation of component in exact `direcroty` | ||
* [options] are optional, only available option is `-u` which will generate test file. | ||
* [options] are optional, available options are `-u` which will generate test file, and `-t` which is used to define which template for components to use. | ||
@@ -67,3 +80,3 @@ ## Config file | ||
* `componentRoot`: root directory which components will be generated in. should be relative path. | ||
* `componentSource`: path to custom component template. | ||
* `componentSource`: path to custom component template. Or an object to define [multiple templates](#using-multiple-custom-templates). | ||
* `unitRoot`: directory which test will be generated in. should be a relative path. | ||
@@ -73,3 +86,3 @@ * `unitSource`: path to custom test file template. | ||
An example of a config file with all options: | ||
``` | ||
```json | ||
{ | ||
@@ -113,1 +126,30 @@ "componentRoot":"./front-end/src/components", | ||
To see other examples look at [templates folder](https://github.com/hosein2398/gue/tree/master/src/templates). | ||
##### Using multiple custom templates | ||
You can use multiple custom templates. So `componentSource` can be object (multiple templates) or a string (single template). Multiple templates can be created like: | ||
```json | ||
{ | ||
"componentSource": { | ||
"component" : "./tmps/component.vue", | ||
"page" : "./tmps/page.vue" | ||
} | ||
} | ||
``` | ||
And when using Gue you have to tell it which component template to use: | ||
``` | ||
gue menu -t component | ||
gue setting ./pages -t page | ||
``` | ||
You can define one of your templates as `default` one, so that you don't have to type `-t` every time. Default component can be specified with `:default` postfix: | ||
```json | ||
{ | ||
"componentSource": { | ||
"component:default" : "./tmps/component.vue", | ||
"page" : "./tmps/page.vue" | ||
} | ||
} | ||
``` | ||
Now if you type any command without `-t`, component template will be used. | ||
``` | ||
gue foo | ||
``` | ||
Will use `component` template to generate foo component. No need of `-t component` |
@@ -8,3 +8,4 @@ #!/usr/bin/env node | ||
.arguments('<componentName> [direcroty]') | ||
.option('-u, --unit', 'create unit test of the component too'); | ||
.option('-u, --unit', 'create unit test of the component too') | ||
.option('-t, --template <name>', 'define which template to use'); | ||
@@ -11,0 +12,0 @@ const params = program.parse(process.argv); |
@@ -8,2 +8,3 @@ const path = require('path'); | ||
const unitTemplate = require('./templates/sample-unit'); | ||
const {isObject, findDefault, isObjectEmpty} = require('./utils'); | ||
@@ -51,5 +52,29 @@ class Gue { | ||
formatComponent() { | ||
const data = this.componentSource ? | ||
fs.readFileSync(this.componentSource, {encoding: 'utf8'}) : | ||
cmpTemplate; | ||
let data; | ||
if (this.options.template) { | ||
this.checkConfigExist(); | ||
if (!isObject(this.componentSource)) { | ||
logger.fatal('When using -t your componentSource must be an object'); | ||
} | ||
if (isObject(this.componentSource)) { | ||
if (!(this.options.template in this.componentSource)) { | ||
logger.fatal(`There is no "${this.options.template}" template in componentSource in gue config file`); | ||
} | ||
data = fs.readFileSync(this.componentSource[this.options.template], {encoding: 'utf8'}); | ||
} | ||
} else if (isObject(this.componentSource)) { | ||
const defaultTemplate = findDefault(this.componentSource); | ||
if (!defaultTemplate) { | ||
logger.fatal('No default component defined in componentSource object'); | ||
} | ||
data = fs.readFileSync(this.componentSource[defaultTemplate], {encoding: 'utf8'}); | ||
} else { | ||
data = this.componentSource ? | ||
fs.readFileSync(this.componentSource, {encoding: 'utf8'}) : | ||
cmpTemplate; | ||
} | ||
const rex = /<%NAME%>/g; | ||
@@ -103,2 +128,8 @@ return data.replace(rex, this.componentName); | ||
checkConfigExist() { | ||
if (isObjectEmpty(configFile)) { | ||
logger.fatal('Could not find any config file in root directory'); | ||
} | ||
} | ||
run() { | ||
@@ -105,0 +136,0 @@ this.generate(); |
@@ -43,4 +43,11 @@ const box = require('boxen'); | ||
} | ||
fatal(e) { | ||
console.log( | ||
box(`⚠️ ${chalk.red(e)}`, {padding: 1}) | ||
); | ||
throw new Error(e); | ||
} | ||
} | ||
module.exports = new Logger(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14798
10
232
148