Skip to content

Commit

Permalink
Merge pull request #1 from justgeek/development
Browse files Browse the repository at this point in the history
 release v1.1.0
  • Loading branch information
justgeek authored Apr 4, 2020
2 parents 41baeb8 + 814f393 commit 69ce257
Show file tree
Hide file tree
Showing 26 changed files with 1,286 additions and 1,039 deletions.
358 changes: 224 additions & 134 deletions README.md

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Change Log
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Release] 1.1.0
### Added
- Specify destination folder is now possible with `--dest <destination path>` option
- Added showroom to easily test tool functionality (test with `npm link`)

### Changed
- Updated docs
- Changed bin command to `vgcx` instead of `vgc` [Breaking]
- Test files are now generated inside `__tests__` folder [To be optionated later]
- Store,Action,Mutation,Getter files are now generated inside `store` folder

## [Release] 1.0.0
### Added
- Working MVP for basic vue project page generation

37 changes: 28 additions & 9 deletions lib/TemplateGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class TemplateGenerator {
*/
_create(options = {}) {
const { name, type, actions, postfix } = options;
const filesType = config.getConfigFile().filesType;
const { filesType, dest } = config.getConfigFile()

if (options.isDir) {
this._createDirectory(this._getDirPath(type), { name, actions, filesType, postfix }, filesType);
this._createDirectory(this._getDirPath(type), { name, actions, filesType, postfix, dest }, filesType);
} else {
const tpl = this._compileTpl(this._getSingleTpl(type), { name, postfix, actions, filesType });
this._createFile(name, type, filesType.script, tpl);
Expand Down Expand Up @@ -54,7 +54,7 @@ class TemplateGenerator {
* @private
*/
_createFile(name, type, fileType, tpl) {
fs.outputFile(this._createFilePath(name, type, fileType), tpl, function(err) {
fs.outputFile(this._createFilePath(name, type, fileType), tpl, function (err) {
if (err) console.error(err);
});
}
Expand All @@ -69,8 +69,9 @@ class TemplateGenerator {
_createDirectory(dirPath, data, fileTypes) {
fs.readdir(dirPath, (err, dir) => {
let name = data.name;
let dest = data.dest;

let folder = path.join(process.cwd(), name);
let folder = path.join(process.cwd(), dest, name);
let splitIdx = folder.lastIndexOf('/');
if (splitIdx > -1) {
name = folder.slice(splitIdx + 1);
Expand All @@ -82,8 +83,21 @@ class TemplateGenerator {
dir.forEach(tempFile => {
const compiled = this._compileTpl(`${dirPath}/${tempFile}`, data);
let fileName = this._createFileName(tempFile, name, fileTypes, data.postfix);
filePath = path.join(folder, fileName);
fs.outputFile(filePath, compiled, function(err) {
let innerFileName = this._createFileName(tempFile, name, fileTypes); // for file inside folders ignore postfix to avoid long names
const isTestFile = tempFile.includes('test')
const isStoreFile = tempFile.includes('actions') || tempFile.includes('mutations') || tempFile.includes('getters') || tempFile.includes('store')

if (isTestFile) {
filePath = path.join(folder, '__tests__', innerFileName)
}
else if (isStoreFile) {
filePath = path.join(folder, 'store', innerFileName)
}
else {
filePath = path.join(folder, fileName)
}

fs.outputFile(filePath, compiled, function (err) {
if (err) console.error(err);
});
});
Expand All @@ -99,7 +113,7 @@ class TemplateGenerator {
* @private
*/
_createFileName(tempFile, name, fileTypes, postfix) {
let newName = tempFile.replace(/temp/, name + '.' + postfix);
let newName = postfix ? tempFile.replace(/temp/, name + '.' + postfix) : tempFile.replace(/temp/, name)

if (newName.indexOf('tpl') > -1) {
newName = newName.replace(/tpl./, '');
Expand All @@ -116,8 +130,8 @@ class TemplateGenerator {
newName = newName.replace(/extension/, fileTypes.script);
}

if (newName.indexOf('spec') > -1) {
newName = newName.replace(/extension/, fileTypes.spec);
if (newName.indexOf('test') > -1) {
newName = newName.replace(/extension/, fileTypes.test);
}

if (newName.indexOf('store') > -1) {
Expand All @@ -132,6 +146,11 @@ class TemplateGenerator {
newName = newName.replace(/extension/, fileTypes.actions);
}

if (newName.indexOf('getter') > -1) {
newName = newName.replace(/extension/, fileTypes.getters);
}


return newName;
}

Expand Down
12 changes: 11 additions & 1 deletion lib/blueprints/component/temp.actions.extension
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
export const {{name | camelCase}}Actions={
import { Commit } from 'vuex';
import { {{name | camelCase}}Mutations } from './{{name}}.mutations';
import { {{name | camelCase}}Store } from './{{name}}.store';

export const namespace = '{{name | camelCase}}Store';

export const {{name | camelCase}}Actions = {

}

export const {{name | camelCase}}ActionsMap = {

}
5 changes: 5 additions & 0 deletions lib/blueprints/component/temp.getters.extension
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { {{name | PascalCase}}State } from './{{ name }}.store.{{ filesType.script }}';

export const {{name | camelCase}}Getters = {

};
16 changes: 10 additions & 6 deletions lib/blueprints/component/temp.mutations.extension
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { MutationTree } from 'vuex';
export const {{name | camelCase}}Mutations: MutationTree<any> = {
// DO__SOME_ACTION(state: any, payload: entity[]) {
// state.entity = payload;
// },
};
import { {{name | camelCase}}State } from './{{name}}.store';

export const namespace = '{{name | camelCase}}Store';

export const {{name | camelCase}}Mutations = {

}

export const {{name | camelCase}}MutationsMap = {

}
10 changes: 4 additions & 6 deletions lib/blueprints/component/temp.script.extension
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { Component, Vue } from 'vue-property-decorator';
import Vue from 'vue';
import Component from 'vue-class-component';

@Component({
components: {
},
name: '{{name | kebabCase}}',
})

export default class {{name | camelCase}}{{postfix | camelCase}} extends Vue {

created(){

}
export default class {{name | PascalCase}}{{postfix | PascalCase}} extends Vue {

}

Expand Down
29 changes: 0 additions & 29 deletions lib/blueprints/component/temp.spec.extension

This file was deleted.

25 changes: 15 additions & 10 deletions lib/blueprints/component/temp.store.extension
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { Module } from 'vuex';
import { {{name | camelCase}}Mutations } from 'from "./{{ name }}.mutations.{{ filesType.script }}";'
import { {{name | camelCase}}Actions} from 'from "./{{ name }}.actions.{{ filesType.script }}";'
class {{name | camelCase}}Store implements Module<any, any> {
public state = {
};
actions = { ...{{name | camelCase}}Actions}

mutations = {...{{name | camelCase}}Mutations}
import { {{name | camelCase}}Getters } from './{{ name }}.getters';
import { {{name | camelCase}}MutationsMap } from './{{ name }}.mutations';
import { {{name | camelCase}}ActionsMap } from './{{ name }}.actions';

export interface {{name | PascalCase}}State {

}

export default new {{name | camelCase}}Store();
export const {{name | camelCase}}State: {{name | PascalCase}}State = {

};

export const {{name | camelCase}}Store = {
state: {{name | camelCase}}State,
getters: {...{{name | camelCase}}Getters},
actions: { ...{{name | camelCase}}ActionsMap },
mutations: { ...{{name | camelCase}}MutationsMap },
}

10 changes: 10 additions & 0 deletions lib/blueprints/component/temp.test.extension
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Vue from 'vue';
import { mount } from '@vue/test-utils'
import {{name | PascalCase}}{{postfix | PascalCase}} from './{{name}}{% if postfix %}.{{postfix}}{% endif %}.{{ filesType.script }}';

describe('{{name | PascalCase}}{{postfix | PascalCase}}', () => {
test('is a Vue instance', () => {
const wrapper = mount({{name | PascalCase}}{{postfix | PascalCase}})
expect(wrapper.isVueInstance()).toBeTruthy()
})
})
6 changes: 6 additions & 0 deletions lib/config/cli-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,11 @@ export default [
type: String,
group: 'options',
description: 'create postfix in file name'
},
{
name: 'dest',
type: String,
group: 'options',
description: 'destination path to move genrated folder inside'
}
];
6 changes: 4 additions & 2 deletions lib/config/config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"dest": "",
"filesType": {
"spec": "js",
"test": "js",
"script": "js",
"actions": "js",
"store": "js",
"mutations": "js",
"getters": "js",
"html": "html",
"style": "scss"
}
}
}
22 changes: 15 additions & 7 deletions lib/config/swig-filters.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
import _ from 'lodash';

export default ( swig ) => {
export default (swig) => {
/* ===============
Swig filters
=============== */
swig.setFilter('kebabCase', function( input ) {
swig.setFilter('kebabCase', function (input) {
return _.kebabCase(input);
});

swig.setFilter('camelCase', function( input ) {
return _.capitalize(_.camelCase(input));
swig.setFilter('camelCase', function (input) {
return _.camelCase(input);
});

swig.setFilter('camelCaseOnly', function( input ) {
return _.camelCase(input);
swig.setFilter('PascalCase', function (input) {
return _.capitalize(_.camelCase(input));
});

swig.setFilter('upperCase', function( input ) {
swig.setFilter('upperCase', function (input) {
return input.toUpperCase();
});

}

/* CASES */
/*
camelCase
PascalCase
snake_case
kebab-case
*/
7 changes: 5 additions & 2 deletions lib/vgc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@ const options = cli.parse().options;
Ask for help
=============== */
if (options.help) {
console.warn('\x1b[33m%s\x1b[0m','cli help documents are still in progress, meanwhile please refer to readme file');
}

/* ===============
Set the file extensions
=============== */
if (options.html || options.style || options.all || options.script || options.spec) {
if (options.html || options.style || options.all || options.script || options.test || options.path) {
let configData = config.getConfigFile();
configData.filesType.html = options.html ? options.html : configData.filesType.html;
configData.filesType.style = options.style ? options.style : configData.filesType.style;
configData.filesType.script = options.script ? options.script : configData.filesType.script;
configData.filesType.actions = options.script ? options.script : configData.filesType.actions;
configData.filesType.mutations = options.script ? options.script : configData.filesType.mutations;
configData.filesType.getters = options.script ? options.script : configData.filesType.getters;
configData.filesType.store = options.script ? options.script : configData.filesType.store;
configData.filesType.spec = options.script ? options.script : configData.filesType.spec;
configData.filesType.test = options.script ? options.script : configData.filesType.test;
configData.dest=options.dest? options.dest : configData.dest

config.updateConfigFile(configData);
}
Expand Down
Loading

0 comments on commit 69ce257

Please sign in to comment.