Skip to content

Commit

Permalink
Merge pull request #7 from justgeek/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
justgeek authored Jul 10, 2020
2 parents 107b0ad + dc3d907 commit bbc2c8a
Show file tree
Hide file tree
Showing 22 changed files with 2,549 additions and 1,395 deletions.
10 changes: 5 additions & 5 deletions Gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
var gulp = require('gulp');
var babel = require('gulp-babel');
var del = require('del');
var runSequence = require('run-sequence');
const runSequence = require('gulp4-run-sequence');

gulp.task('dev', function() {
gulp.task('dev', async function() {
return gulp.src(['./lib/**/*.js', '!./lib/blueprints/**/*.js'])
.pipe(babel({
presets: ['es2015']
}))
.pipe(gulp.dest('dist'));
});

gulp.task('copy', function() {
gulp.task('copy', async function() {
gulp.src('./lib/blueprints/**/**', {
base: "./lib"
})
Expand All @@ -21,14 +21,14 @@ gulp.task('copy', function() {
.pipe(gulp.dest('./dist/config'));
});

gulp.task('clean', function() {
gulp.task('clean', async function() {
return del([
'dist/**'
]);
});


gulp.task('build', function(callback) {
gulp.task('build', async function(callback) {
runSequence('clean',
'dev',
'copy',
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ vgcx <OPTIONS> <NAME>
[
{
name: 'help',
type: Boolean,escription: 'help'
type: Boolean,
description: 'help'
},
{
name: 'html',
Expand Down Expand Up @@ -74,6 +75,11 @@ vgcx <OPTIONS> <NAME>
type: String,
description: 'create postfix in file name'
},
{
name: 'classExtension',
type: String,
description: 'if provided will replace default extension for pages with whatever name provided to this option'
},
{
name: 'dest',
type: String,
Expand Down
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ 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.2.0
### Added
- Add support for custom class extension for pages (MyPage extends MyCustomComponent)
### Fixed
- Upgrade gulp to v4
- Fixed some typos

## [Hotfix] 1.1.4
### Changed
- Remove namespace from mutations file
Expand Down
3 changes: 2 additions & 1 deletion lib/TemplateFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class TemplateFactory {
* Generate Vue 2 component
*/
if (cli.component) {
return new TemplateGenerator(new ComponentTpl(cli.component, cli.postfix));
const { component, postfix, classExtension } = cli
return new TemplateGenerator(new ComponentTpl(component, { postfix, classExtension }));
}

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

if (options.isDir) {
this._createDirectory(this._getDirPath(type), { name, actions, filesType, postfix, dest }, filesType);
this._createDirectory(this._getDirPath(type), { name, actions, filesType, postfix, dest, classExtension }, filesType);
} else {
const tpl = this._compileTpl(this._getSingleTpl(type), { name, postfix, actions, filesType });
const tpl = this._compileTpl(this._getSingleTpl(type), { name, postfix, actions, filesType, classExtension });
this._createFile(name, type, filesType.script, tpl);
}
}
Expand All @@ -40,9 +40,9 @@ class TemplateGenerator {
* @returns {*}
* @private
*/
_compileTpl(file, { name, actions, filesType, postfix }) {
_compileTpl(file, { name, actions, filesType, postfix, classExtension }) {
const compiled = swig.compileFile(file);
return compiled({ name, actions, filesType, postfix });
return compiled({ name, actions, filesType, postfix, classExtension });
}

/**
Expand Down
3 changes: 1 addition & 2 deletions lib/blueprints/component/temp.script.extension
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import Component from 'vue-class-component';
name: '{{name | kebabCase}}',
})

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

export default class {{name | PascalCase}}{{postfix | PascalCase}} extends {% if classExtension %}{{classExtension}}{% else %}Vue{% endif %} {
}


2 changes: 1 addition & 1 deletion lib/blueprints/component/temp.tpl.extension
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
section(id="{{name | kebabCase}}" class="page")
h1 {{name | kebabCase}} Component
{% else %}
<section id="{{name | kebabCase}}">
<section id="{{name | kebabCase}}" class="page">
<h1>{{name | kebabCase}} Component</h1>
</section>
{% endif %}
6 changes: 6 additions & 0 deletions lib/config/cli-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ export default [
group: 'options',
description: 'create postfix in file name'
},
{
name: 'classExtension',
type: String,
group: 'options',
description: 'if provided will replace default extension for pages with whatever name provided to this option'
},
{
name: 'dest',
type: String,
Expand Down
3 changes: 2 additions & 1 deletion lib/templates/ComponentTpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ class ComponentTpl {
*
* @param name - the component name
*/
constructor(name, postfix) {
constructor(name, { postfix, classExtension }) {
this.type = 'component';
this.isDir = true;
this.name = name;
this.postfix = postfix;
this.classExtension = classExtension;
}
}

Expand Down
9 changes: 4 additions & 5 deletions lib/vgc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#! /usr/bin/env node
import commandLineArgs from 'command-line-args';
import swig from 'swig';
import path from 'path';
import TemplateFactory from './TemplateFactory';
import fs from 'fs';
import config from './config/config';
import cliOptions from './config/cli-options';
import swigFilters from './config/swig-filters';
Expand All @@ -16,13 +14,13 @@ 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');
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.test || options.path) {
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;
Expand All @@ -32,7 +30,8 @@ if (options.html || options.style || options.all || options.script || options.te
configData.filesType.getters = options.script ? options.script : configData.filesType.getters;
configData.filesType.store = options.script ? options.script : configData.filesType.store;
configData.filesType.test = options.script ? options.script : configData.filesType.test;
configData.dest=options.dest? options.dest : configData.dest
configData.dest = options.dest ? options.dest : configData.dest
configData.classExtension = options.classExtension ? options.classExtension : configData.classExtension

config.updateConfigFile(configData);
}
Expand Down
Loading

0 comments on commit bbc2c8a

Please sign in to comment.