generator-levi-9-angularjs-2
Version:
Yeoman generator for levi9 angularjs2 projects
91 lines (80 loc) • 2.93 kB
JavaScript
'use strict';
var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var pathPrefix = require('../config').paths.app;
var _ = require('lodash');
var generatorUtils = require('../generatorUtils');
var allowedTypes = ['component', 'entity', 'module'];
module.exports = yeoman.Base.extend({
constructor: function () {
yeoman.Base.apply(this, arguments);
this.argument('renameType',
{
type: String,
required: true,
desc: 'What should we rename? Allowed: ' + allowedTypes.toString()
});
this.argument('renameOld',
{
type: String,
required: true,
desc: 'What is old name?'
});
this.argument('renameNew',
{
type: String,
required: true,
desc: 'What is new name?'
});
this.argument('path',
{
type: String,
defaults: '',
desc: 'Supports paths relative to /$root/src/app, defaults to \'' + pathPrefix + '\''
});
},
initializing: function () {
if (allowedTypes.indexOf(this.renameType) === -1) {
this.log(chalk.red(this.renameType + ' is not available for renaming') +
' Please run \'yo levi-9-angularjs-2:rename --help\' to check for available options.');
return;
}
if (this.renameType === 'component') {
this.composeWith('levi-9-angularjs-2:component', {
arguments: [this.renameNew, this.path]
}, {
local: require.resolve('../component')
});
}
if (this.renameType === 'entity') {
this.composeWith('levi-9-angularjs-2:entity', {
arguments: [this.renameNew, this.path]
}, {
local: require.resolve('../entity')
});
}
if (this.renameType === 'module') {
this.composeWith('levi-9-angularjs-2:module', {
arguments: [this.renameNew, this.path]
}, {
local: require.resolve('../module')
});
}
this._removeFiles(this.path, this.renameOld);
},
_removeFiles: function (path, fileName) {
var style = this.config.get('useSass') ? 'scss' : 'css';
path = generatorUtils.addPrefixAndSuffixToPath(pathPrefix, this.path, this.renameOld + '/');
this.fs.delete(pathPrefix + fileName + '.component.html');
this.fs.delete(pathPrefix + fileName + '.component.' + style);
this.fs.delete(pathPrefix + fileName + '.component.ts');
this.fs.delete(pathPrefix + fileName + '.component.spec.ts');
this.fs.delete(path + fileName + '.component.html');
this.fs.delete(path + fileName + '.component.' + style);
this.fs.delete(path + fileName + '.component.ts');
this.fs.delete(path + fileName + '.component.spec.ts');
this.fs.delete(path + fileName + '.service.ts');
this.fs.delete(path + fileName + '.ts');
this.fs.delete(path + fileName + '.service.spec.ts');
}
});