generator-levi-9-angularjs-2
Version:
Yeoman generator for levi9 angularjs2 projects
65 lines (54 loc) • 2.32 kB
JavaScript
'use strict';
var yeoman = require('yeoman-generator');
var _ = require('lodash');
var pathPrefix = require('../config').paths.app;
var generatorUtils = require('../generatorUtils');
module.exports = yeoman.Base.extend({
constructor: function () {
yeoman.Base.apply(this, arguments);
this.argument('componentName',
{
type: String,
required: true,
desc: 'Use kebab-case, camelCase or snake_case'
});
this.argument('path',
{
type: String,
defaults: pathPrefix,
desc: 'Supports paths relative to /$root/src/app, defaults to \'' + pathPrefix + '\''
});
this.componentNameCamel = _.camelCase(this.componentName);
this.componentNameClass = _.upperFirst(this.componentNameCamel);
},
writing: function () {
if (generatorUtils.invalidInput('component', this.componentName, this.path)) {
return;
}
this.path = generatorUtils.addPrefixAndSuffixToPath(pathPrefix, this.path, '/');
this.style = this.config.get('useSass') ? 'scss' : 'css';
if (this.config.get('useSass')) {
this.fs.copyTpl(
this.templatePath('_component.scss'),
this.destinationPath(this.path + this.componentName + '.component.scss'), {name: this.componentName, nameCamel: this.componentNameCamel}
);
} else {
this.fs.copyTpl(
this.templatePath('_component.css'),
this.destinationPath(this.path + this.componentName + '.component.css'), {name: this.componentName, nameCamel: this.componentNameCamel}
);
}
this.fs.copyTpl(
this.templatePath('_component.html'),
this.destinationPath(this.path + this.componentName + '.component.html'), {name: this.componentName, nameCamel: this.componentNameCamel}
);
this.fs.copyTpl(
this.templatePath('_component.ts'),
this.destinationPath(this.path + this.componentName + '.component.ts'), {name: this.componentName, nameClass: this.componentNameClass, style: this.style}
);
this.fs.copyTpl(
this.templatePath('_spec.ts'),
this.destinationPath(this.path + this.componentName + '.component.spec.ts'), {name: this.componentName, nameCamel: this.componentNameCamel, nameClass: this.componentNameClass}
);
}
});