UNPKG

generator-baffled

Version:
52 lines (43 loc) 1.57 kB
'use strict'; var path = require('path'); var fs = require('fs'); var util = require('util'); var ScriptBase = require('../script-base.js'); var angularUtils = require('../util.js'); module.exports = Generator; function Generator() { ScriptBase.apply(this, arguments); this.hookFor('baffled:controller'); this.hookFor('baffled:view'); } util.inherits(Generator, ScriptBase); module.exports = Generator; Generator.prototype.rewriteAppJs = function () { var file = path.join(this.env.options.appPath, 'scripts', 'states', this._.slugify(this.name)) + '.js'; var exists = fs.existsSync(file); var stated = this.arguments.join('.').toLowerCase(); var pathed = ''; var isChild = this.arguments.length > 1; var that = this; this._.each(this.arguments, function(arg) { pathed = path.join(pathed, that._.slugify(arg)); }) if (!exists && !isChild) { this.appTemplate('state', path.join('scripts', 'states', this._.slugify(this.name))); this.addScriptToIndex(path.join('states', pathed)); } else if (!exists && isChild) { console.log('Create a parent state first; \'yo baffled:state ' + this.name + '\'.'); } else if (exists && isChild) { angularUtils.rewriteFile({ file: file, needle: '}]);', splicable: [ ' .state(\'' + stated + '\', {', ' url:\'/' + this._.last(this.arguments) + '\',', ' templateUrl: \'views/' + pathed + '.html\',', ' controller: \'' + this._.classify(this.arguments.join('-')) + 'Ctrl\'', ' })\n', ] }); } };