Example #1
0
function Generator() {
  generator.NamedBase.apply(this, arguments);
  var dirPath = this.options.coffee ? '../templates/coffeescript/' : '../templates/javascript';
  this.sourceRoot(path.join(__dirname, dirPath));
  this.argument('model', { type: String, required: false });
  this.option('coffee', { desc: 'CoffeeScript instead standard JavaScript' });
}
Example #2
0
function Generator() {
  generator.NamedBase.apply(this, arguments);
  var dirPath = '../templates/javascript';
  this.sourceRoot(path.join(__dirname, dirPath));

  this.argument('inherit', { type: String, required: false });
}
function Generator() {
  generator.NamedBase.apply(this, arguments);
  var dirPath = '../templates/javascript';
  this.sourceRoot(path.join(__dirname, dirPath));

  this.argument('inherit', { type: String, required: false });

  this.option('create-all', { desc: 'Create a new model for this collection' });
  

  /* set the template name which is auto created */
  this.tmplOrig = this.name;
  this.tmpl = this.name + '_tmpl';
  this.tmplLocation = 'layout';

  if ( this.tmplOrig && this.options['create-all'] ) {
    this.hookFor('marionette', { as: 'tmpl', args: [this.tmplOrig, this.tmplLocation], options: this.options });
  }

  // invoke  mocha
  this.hookFor('mocha-amd2', {
    as: 'unitTest', 
    args: [this.name, 'layout', 'views/layout']
  });
}
Example #4
0
  constructor: function() {
    generator.NamedBase.apply(this, arguments);

    // this.option('stateless', {
    //   desc: 'Create a stateless component instead of a full one',
    //   defaults: false
    // });
  },
Example #5
0
 constructor: function () {
     generators.NamedBase.apply(this, arguments);
     console.log('inside ngc sub-generator', this.name);
     
     this.option('view', {
         desc: 'Determines if view is created along with controller',
         type: Boolean,
         default: false
     });
 },
Example #6
0
var Generator = module.exports = function Generator () {
	generator.NamedBase.apply( this, arguments );

	this.sourceRoot( path.join( __dirname, '../../', 'templates' ) );

	this.argument( 'specType', { 'type' : String, 'required' : false } );
	this.argument( 'location', { 'type' : String, 'required' : false } );

	this.inflector = inflector;
};
/**
 * Module Generator
 *
 * @param args
 * @param options
 * @param config
 */
function ModuleGenerator(args) {

    // check to see if we were given a name
    if (args.length !== 1) {
        // if not, lets just set a temp one, so we can move on
        args[0] = 'TEMP';
        this.fakeName = true;
    }

    yeoman.NamedBase.apply(this, arguments);
}
function Generator() {
  generator.NamedBase.apply(this, arguments);
  var dirPath = '../templates/javascript';
  this.sourceRoot(path.join(__dirname, dirPath));

  // invoke  mocha
  this.hookFor('mocha-amd', {
    as: 'unitTest',
    args: [this.name, 'module', 'modules']
  });
}
Example #9
0
function Generator() {
  generator.NamedBase.apply(this, arguments);
  var dirPath = '../templates/javascript';
  this.sourceRoot(path.join(__dirname, dirPath));

  this.argument('tmplLocation', { type: String, required: false });
  

  this.tmplLocation = this.tmplLocation ? this.tmplLocation : '';

  this.name = this.name + "_tmpl";
}
Example #10
0
function Generator() {
  generator.NamedBase.apply(this, arguments);
  var dirPath = this.options.coffee ? '../templates/coffeescript/' : '../templates/javascript';
  this.sourceRoot(path.join(__dirname, dirPath));
  this.argument('model', { type: String, required: false });
  this.option('create-model', { desc: 'Create a new model for this collection' });
  this.option('coffee', { desc: 'CoffeeScript instead standard JavaScript' });

  if (this.model && this.options['create-model']) {
    // TODO: pass --coffee option to model if coffee was enabled
    this.hookFor('backbone-amd', { as: 'model', args: [this.model], options: this.options })
  }
}
Example #11
0
function Generator() {
  generator.NamedBase.apply(this, arguments);
  var dirPath = '../templates/javascript';
  this.sourceRoot(path.join(__dirname, dirPath));

  this.argument('inherit', { type: String, required: false });

  // invoke  mocha
  this.hookFor('mocha-amd', { 
    as: 'unitTest', 
    args: [this.name, 'controller', 'controllers']
  });
}
Example #12
0
function Generator() {
  generator.NamedBase.apply(this, arguments);

  // inspect package.json for appname
  try {
    this.pkg = JSON.parse(this.readFileAsString(path.join(process.cwd(), 'package.json')));
    this.appname = this.pkg.name;
  }
  catch (err) {
    console.log('ERROR::',err);
    // pass
  }

  var dirPath = this.options.coffee ? '../templates/coffeescript/' : '../templates/javascript';
  this.sourceRoot(path.join(__dirname, dirPath));
  this.argument('model', { type: String, required: false });
  this.option('coffee', { desc: 'CoffeeScript instead standard JavaScript' });
}
  constructor: function() {

    generators.NamedBase.apply(this, arguments);

    this.writeScriptTag = function(src) {

      var tag = '<script src="' + src + '"></script>';
      var file = this.dest.read('index.html');
      var i = file.lastIndexOf('</script>') + 9;

      if (file.indexOf(tag) === -1) {
        this.conflicter.force = true;
        file = file.substring(0, i) + '\n  ' + tag + file.substring(i);
        this.dest.write('index.html', file);
      }

    }.bind(this);

  }
function Generator() {
  generator.NamedBase.apply(this, arguments);
  this.sourceRoot(path.join(__dirname, '../templates/coffeescript/'));

  this.prompt({
    type: 'list',
    name: 'viewType',
    message: 'What kind of view do you want?',
    choices: [
      {'name':'HumanView', value:'human'},
      {'name':'Backbone.View', value:'backbone'}
    ],
    default: 'backbone'

  }, function (answers) {

    this.viewType = answers.viewType;

  });
}
Example #15
0
function Generator() {
  generator.NamedBase.apply(this, arguments);
  var dirPath = '../templates/javascript';
  this.sourceRoot(path.join(__dirname, dirPath));

  this.argument('model', { type: String, required: false });
  this.argument('inherit', { type: String, required: false });

  this.option('create-all', { desc: 'Create a new model for this collection' });

  if (this.model && this.options['create-all']) {
    this.hookFor('marionette', { as: 'model', args: [this.model, this.inherit], options: this.options });
  }

  // invoke  mocha
  this.hookFor('mocha-amd', { 
    as: 'unitTest', 
    args: [this.name, 'collection', 'collections']
  });
}
  constructor: function () {
    // Calling the super constructor is important so our generator is correctly set up
    generators.NamedBase.apply(this, arguments);

    this.option('dest', {
      desc: 'Set a destination where to save the file',
      type: String,
      required: 'false'
    }); // This method adds support for a `--dest` flag
    this.option('component', {
      desc: 'Set the destination to be under the component library'
    }); // This method adds support for a `--component` flag
    this.option('bundle', {
      desc: 'Create the task\'s file under a specific bundle instead of the file name',
      type: String,
      required: 'false'
    }); // This method adds support for a `--bundle` flag
    this.option('skip-test', {
      desc: 'Create the task\'s file without a spec file',
      type: Boolean,
      defaults: false,
      required: 'false'
    }); // This method adds support for a `--bundle` flag
  },
Example #17
0
module.exports = generator.NamedBase.extend({

  constructor: function() {
    generator.NamedBase.apply(this, arguments);

    // this.option('stateless', {
    //   desc: 'Create a stateless component instead of a full one',
    //   defaults: false
    // });
  },

  writing: function() {
    var styleSetting = this.config.get('style');
    this.args.forEach(name=>{     
      let settings = utils.yeoman.getAllSettingsFromComponentName(name, styleSetting);
      // let componentType = this.options.stateless ? 'Stateless' : 'Base';

      // Create the style template
      this.fs.copyTpl(
        this.templatePath(`style${settings.style.suffix}`),
        this.destinationPath(settings.style.destinationPath),
        settings
      );

      // Create the component
      this.fs.copyTpl(
        this.templatePath('component.js'),
        this.destinationPath(settings.component.destinationPath),
        settings
      );  
    });
    
  }
});
Example #18
0
 constructor: function() {
   generators.NamedBase.apply(this, arguments);
 },
Example #19
0
module.exports = generators.NamedBase.extend({
  paths: function() {
    this.destinationRoot();
    // returns '~/projects'

    this.destinationPath('index.js');
    // returns '~/projects/index.js'

    this.sourceRoot();
    // returns './templates'

    this.templatePath('index.js');
    // returns './templates/index.js'
  },
  configuring: {
    setupFolders: function() {

    }
  },
  writing: {
    components: function(name) {
      this.fs.copyTpl(
        this.templatePath('index.html'),
        this.destinationPath('App/' + name + '/' + name + '.html'), {
          title: name
        }
      );

      this.fs.copyTpl(
        this.templatePath('index.js'),
        this.destinationPath('App/' + name + '/' + name + '.js'), {
          title: name
        }
      );

      this.fs.copyTpl(
        this.templatePath('index.test.js'),
        this.destinationPath('App/' + name + '/' + name + '.test.js'), {
          title: name
        }
      );
    },
    services: function(name) {

    },
    styles: function(name) {

    }
  },
  install: {
    updateConfigs: function(name) {
      var path = "./App/require-setup.js",
      file = this.readFileAsString(path);
      var hook = '// << Yeoman ViewModels Hook >>';
      var insertionContent = '\n\t\t\t' + name + ': ' + "'./app/" + name + "/" + name +  "',";

      /* make modifications to the file string here */
      this.write(path, file.replace(hook, hook + insertionContent));
    },
    updateRoutes: function(name) {
      var path = "./App/router.js",
      file = this.readFileAsString(path);
      var hook = '// << Yeoman Router Hook >>';
      var insertionContent = '\n\t\t\t\t' + "{ url: '/"+ name +"',     params: { page: '"+ name +"' } },";

      /* make modifications to the file string here */
      this.write(path, file.replace(hook, hook + insertionContent));
    },
    updateRegisters: function(name) {

      var path = "./App/app.js",
      file = this.readFileAsString(path);
      var hook = '// << Yeoman Register Hook >>';
      var insertionContent = '\n\t\t\t' + "  ko.components.register('"+ name +"', {  require: '"+name+"' });";

      /* make modifications to the file string here */
      this.write(path, file.replace(hook, hook + insertionContent));
    }
  },
  end: {
    finalMessage: function(name) {
      console.log(name + ' component has just been created.');
    }
  }
});
var MyBase = module.exports = generators.NamedBase.extend({

  constructor: function () {
    // Calling the super constructor is important so our generator is correctly set up
    generators.NamedBase.apply(this, arguments);

    this.option('dest', {
      desc: 'Set a destination where to save the file',
      type: String,
      required: 'false'
    }); // This method adds support for a `--dest` flag
    this.option('component', {
      desc: 'Set the destination to be under the component library'
    }); // This method adds support for a `--component` flag
    this.option('bundle', {
      desc: 'Create the task\'s file under a specific bundle instead of the file name',
      type: String,
      required: 'false'
    }); // This method adds support for a `--bundle` flag
    this.option('skip-test', {
      desc: 'Create the task\'s file without a spec file',
      type: Boolean,
      defaults: false,
      required: 'false'
    }); // This method adds support for a `--bundle` flag
  },
  // Copy the right template based on the type
  appTemplate: function(options) {

    // Validate options
    var valid = this._checkOptions();
    if (!valid) {
      return false;
    }

    var fileType = this._getFileType('language'),
      templateSrc = fileType + '/' + options['type'] + '.' + fileType,
      testSrc = /*fileType +*/ 'js/spec/' + options['type'] + '.js',
      templateData = {
        scriptAppName: this.appname,
        scriptClassName: camelCase(this.name),
        serviceValue : (typeof this.options['service-value'] !== 'undefined') ? this.options['service-value'] : ''
      },
      fullPath = 'src/index.html',
      templateDest = this._makeDestination(options['type']), // Create the destination path
      testDest = 'src/' + this._makeDestination(options['type'], true) + '.spec.js', // + fileType,
      typedTemplateDest = 'src/' + templateDest + '.' + fileType; // Add to the destination path the file type

    this.template(templateSrc, typedTemplateDest, templateData); // Create file
    //console.log(this.options['skip-test']);
    if ((typeof options['skipTest'] === 'undefined' || !options['skipTest']) && !this.options['skip-test']) {
      this.template(testSrc,  testDest, templateData); // Create test
    }
  },
  // Add styles
  _addStyles: function() {

    // Validate options
    var valid = this._checkOptions();
    if (!valid) {
      return false;
    }
    var fileType = this._getFileType('style'),
      templateSrc = 'style.' + fileType,
      fullPath = 'src/index.html',
      templateDest = this._makeDestination('style'), // Create the destination path
      typedTemplateDest = 'src/' + templateDest + '.' + fileType; // Add to the destination path the file type

    this.template(templateSrc, typedTemplateDest); // Create file

  },
  // Adds partials
  _addPartials: function() {

    var valid = this._checkOptions();
    if (!valid) {
      return false;
    }

    var fileType = this._getFileType('html'),
      templateDest = this._makeDestination('partial'), // Create the destination path
      templateSrc = 'partial.' + fileType,
      typedTemplateDest = 'src/' + templateDest + '.' + fileType; // Add to the destination path the file type

    this.template(templateSrc, typedTemplateDest); // Create file
   },
  // Create the file path to copy the template to and to insert in the index.html file
  _makeDestination: function(taskType, testFile) {
    testFile = testFile || false;
    var destType = (typeof this.options['component'] !== 'undefined') ? 'app/components' : 'app',
      filename = this._getFilename(taskType),
      bundle = (typeof this.options['bundle'] !== 'undefined') ? this.options['bundle'] : this.name,
      templateDest = destType + '/' + bundle + '/' + filename;

    if (typeof this.options['dest'] !== 'undefined') {
      templateDest = this._prepareDestination(this.options['dest']) + '/' + filename;
    }

    return templateDest;
  },
  // Get file type from settings or from options
  _getFileType: function(type) {

    if (type == 'language') { // coffee or js
      return this._getFileTypeCheck(type, 'js', 'script-type');
    }
    else if (type == 'style') {
      return this._getFileTypeCheck(type, 'css', 'style-type');
    }
    else {
      return this._getFileTypeCheck(type, 'html', 'html-type');
    }
  },
  //Checks the file type
  _getFileTypeCheck: function(type, defaultType, optionType) {
    var config = this.config.get('props');
    var fileType = defaultType;
    if (typeof this.options[optionType] !== 'undefined') {
      fileType = this.options[optionType];
    }
    else {
      fileType = config[type];
    }
    return fileType;
  },
  // Do not include task type to partial and styles
  _getFilename: function(taskType) {
    switch (taskType) {
      case 'partial':
      case 'style':
        return this.name;
      default:
        return this.name + '.' + taskType;
    }
  },
  // Validate options
  _checkOptions: function() {
    var valid = true;
    if (typeof this.options['bundle'] !== 'undefined') {
      if (typeof this.options['bundle'] === 'boolean') {
        this.log(chalk.red('Bundle cannot be empty!'));
        valid = false;
      }
    }
    if (typeof this.options['dest'] !== 'undefined') {
      if (typeof this.options['dest'] === 'boolean') {
        this.log(chalk.red('Destination cannot be empty!'));
        valid = false;
      }
    }

    if (typeof this.options['script-type'] !== 'undefined') {
      if (typeof this.options['script-type'] === 'boolean') {
        this.log(chalk.red('Script type cannot be empty!'));
        valid = false;
      }
      else if (this.options['script-type'] != 'js' && this.options['script-type'] != 'coffee') {
        this.log(chalk.red('Script type can be "js" or "coffee" only!'));
        valid = false;
      }
    }

    if (typeof this.options['style-type'] !== 'undefined') {
      if (typeof this.options['style-type'] === 'boolean') {
        this.log(chalk.red('Style type cannot be empty! Please choose from {css, scss, sass, less, styl} options'));
        valid = false;
      }
    }

    if (typeof this.options['html-type'] !== 'undefined') {
      if (typeof this.options['html-type'] === 'boolean') {
        this.log(chalk.red('HTML type cannot be empty! Please choose from {html, jade} options'));
        valid = false;
      }
    }

    return valid;
  },
  // Prepare the destination string so we can control it.
  _prepareDestination: function(dest) {
    if (dest.charAt(dest.length - 1) == '/') {
      dest = dest.slice(0, -1);
    } // Removes / from the end of the destination

    var src = dest.slice(0, 3);
    if (src == 'src') {
      dest = dest.replace('src/', '');
    } // Removes 'src/' from the beginning

    return dest;
  },
  _getTaskPluralDirectory: function(taskType) {
    switch (taskType) {
      case 'factory':
        return 'factories';
      default:
        return taskType + 's'

    }
  },
  _addMoreOptions: function() {
    this.option('script-type', {
      desc: 'Choose script language type for file [js, coffee]',
      type: String
    }); // This method adds support for a `--coffee` flag
  }
});
Example #21
0
function Generator() {
  generator.NamedBase.apply(this, arguments);
  var dirPath = '../templates/javascript';
  this.sourceRoot(path.join(__dirname, dirPath));
  
}
Example #22
0
var AutoGenerator =  generators.NamedBase.extend({
  // The name `constructor` is important here
  constructor: function () {
    // Calling the super constructor is important so our generator is correctly set up
    generators.Base.apply(this, arguments);

    // Next, add your custom code
    this.option('coffee'); // This method adds support for a `--coffee` flag

    this.option('skip-welcome-message', {
      desc: 'Skips the welcome message',
      type: Boolean
    });


    // And you can then access it later on this way; e.g.
    this.scriptSuffix = (this.options.coffee ? ".coffee": ".js");
    // This makes `appname` a required argument.
    // this.argument('appname', { type: String, required: true });
    // And you can then access it later on this way; e.g. CamelCased
    //  this.appname = _.camelCase(this.appname);
  },
  /* method1: function () {
   this.log(chalk.red('this method 1') + ' generator!');
   },*/

  init: function () {
    this.helperMethod = function () {
      this.log(chalk.blue('won\'t be called automatically'));
    }
  },
  initializing : function () {
    this.log(chalk.black('initializing'));
    var baseFileName = this.baseFileName;
    this.viewJsTemplate = handlebars.compile(this.read("template_view_js.txt"));
    this.modelJsTemplate = handlebars.compile(this.read("template_model_js.txt"));
    this.htmlTemplate = handlebars.compile(this.read("template_html.html"));
  },


  prompting: function () {
    // Have Yeoman greet the user.
    this.log(yosay(
      'Welcome to the shining ' + chalk.red('generator-auto') + ' generator!'
    ));

    var prompts = [{
      type: 'input',
      name: 'resourcesPath',
      message: 'The resources path that you place javascript and html template files.',
      store: true,
      default: 'resources/app/'
    },
      {
        type    : 'input',
        name    : 'fileName',
        message : 'The app parent folder name which is the next level folder of resourcesPath.',
        default : 'test'  // Default to current folder name
      },
      {
        type: 'confirm',
        name: 'isCreateDir',
        message: 'Would you want to create dir?',
        default: false
      },
      {
        type    : 'list',
        name    : 'moduleType',
        message: 'The type of  module',
        choices: ['ItemView', 'CompositeView', 'LayoutView'],
        default : 'ItemView' // Default to current folder name
      }];

    return this.prompt(prompts).then(function (props) {
      // To access props later use this.props.someAnswer;
   //   this.props = props;
      this.fileName = props.fileName;
      this.resourcesPath = props.resourcesPath;
      this.isCreateDir = props.isCreateDir;
      this.moduleType = props.moduleType;
    }.bind(this));
  },
  writing: function () {
    if (!MATCH_TEPLATE_NAMES.test(this.fileName)) {
      this.log(chalk.red('The fileName argument is illegal! please pass the argument like this: [a-zA-Z0-9_-],[a-zA-Z0-9_-]'));
      return;
    }

    this.templateData = {
      isLayoutView: this.moduleType === 'LayoutView',
      isCompositeView: this.moduleType === 'CompositeView',
      isItemView: this.moduleType === 'ItemView',
      modelName: this.fileName+"Model",
      fileName: this.fileName,
      modelUrl: this.templateFilePath,
      author: author,
      time: new Date(),
      modelUrl: 'models/'+ this.fileName
    };

    var viewJsFileContent = this.viewJsTemplate(this.templateData);
    var modelJsFileContent = this.modelJsTemplate(this.templateData);
    var htmlFileContent = this.htmlTemplate(this.templateData);

    this.absoluteViewJsFilePath = this.resourcesPath + 'views/'+ this.fileName + '.js';
    this.absoluteModelJsFilePath = this.resourcesPath + 'models/'+ this.fileName + '.js';
    this.absolutehtmlFilePath = this.resourcesPath + 'templates/'+ this.fileName + '.html';

    // this.log(chalk.red(this.absoluteViewJsFilePath));

    this.write(this.absoluteViewJsFilePath, viewJsFileContent);
    this.write(this.absoluteModelJsFilePath, modelJsFileContent);
    this.write(this.absolutehtmlFilePath, htmlFileContent);

    /* this.fs.copyTpl(
     this.templatePath('index.html'),
     this.destinationPath('public/index.html'),
     {title: 'Templating with Yeoman'}
     );*/

/*    this.template('common.js', 'app/common/common.js');
    this.copy('index.js', 'app/views/index.js');
    this.copy('index.js', 'app/main.js');*/

/*    this.fs.copy(
      this.templatePath('dummyfile.txt'),
      this.destinationPath('dummyfile.txt')
    );*/
  },
  conflicts: function () {
    //  this.log(chalk.black('conflicts'));
  },
  install : function () {
   // this.installDependencies();
     this.log(chalk.black('install'));
  },
  end: function () {
    this.log(chalk.black('end'));
  }


});
module.exports  = generators.NamedBase.extend({
  promptUser: function () {
    var done = this.async();

    var prompts = [
    {
      name: 'includeRun',
      message: "Should your directive have a run function?",
      default: false
    },
    {
      name: 'includeConfig',
      message: "Should your directive have a config function?",
      default: false
    },
    {
      name: 'bindToElement',
      message: "Should your directive be restricted to Element?",
      default: true
    },
    {
      name: 'bindToAttribute',
      message: "Should your directive be restricted to Attribute?",
      default: true
    }
  ];

    this.prompt(prompts, function(props){
      this.includeRun = props.includeRun
      this.includeConfig = props.includeConfig
      this.bindToElement = props.bindToElement
      this.bindToAttribute = props.bindToAttribute

      done();
    }.bind(this))
  },
  copyMainFiles: function(){
    this.destinationRoot(path.join('client/app/components', this.name));
    var context = {
      directiveName: this.name,
      includeRun : this.includeRun,
      includeConfig : this.includeConfig,
      bindToElement : this.bindToElement,
      bindToAttribute : this.bindToAttribute
    }

    if(this.includeRun){
      this.template("_run.js", this.name +".run.js", context);
    }
    if(this.includeConfig){
      this.template("_config.js", this.name +".config.js", context);
    }
      this.template("_tpl.html", this.name +".tpl.html", context);
      this.template("_directive.js", this.name +".directive.js", context);
      this.template("_controller.js", this.name +".controller.js", context);
      this.template("_index.js", "index.js", context);
      this.template("_.scss", this.name+".scss", context);
  }
});
Example #24
0
 constructor: function () {
   yeomen.NamedBase.apply(this, arguments)
   this.name = changeCase.camelCase(this.name)
 },
Example #25
0
module.exports = generators.NamedBase.extend({
    constructor: function () {
        generators.NamedBase.apply(this, arguments);
        console.log('inside ngc sub-generator', this.name);
        
        this.option('view', {
            desc: 'Determines if view is created along with controller',
            type: Boolean,
            default: false
        });
    },
    
    writing: function(){
        var fileNameFragment = getFileNameFragment(this.name);
        
        this.fs.copyTpl(
            this.templatePath('ng-controller.js'),
            this.destinationPath('src/app/' + fileNameFragment + '/' + fileNameFragment + '.controller.js'),
            {
                ctrlName: this.name,
                appName: this.config.get('ngappname')
            }
        );
        
        if (this.options.view) {
            this.fs.copyTpl(
                this.templatePath('ng-view.html'),
                this.destinationPath('src/app/' + fileNameFragment + '/' + fileNameFragment + '.html'),
                {
                    name: this.name
                });
        }
        
        function getFileNameFragment(ctrlName) {
            var ctrlIndex = ctrlName.indexOf('Ctrl');
            if (ctrlIndex === (ctrlName.length - 4)) {
                ctrlName = ctrlName.substring(0, ctrlIndex);
            }
            return _.kebabCase(ctrlName);
        }
    }
});
Example #26
0
'use strict';

var generators = require('yeoman-generator');
var mkdirp = require('mkdirp');

module.exports = generators.NamedBase.extend({
    _createFileSystem: function () {
        var sourceRoot = this.sourceRoot();
        var destPath = this.destinationPath();
        var appDir = destPath + '/public/';
        var templateContext = {
            appname: this.appname,
            name: this.name
        };
        mkdirp(destPath + '/src/app/components/' + this.name);

        var currentPath = destPath + '/src/app/components/' + this.name + '/';
        this.fs.copyTpl(sourceRoot + '/src/app/components/sample.controller.js', currentPath + this.name + '.controller.js', templateContext);
        this.fs.copyTpl(sourceRoot + '/src/app/components/sample.spec.js', currentPath + this.name + '.spec.js', templateContext);
    },
    initializing: function () {
    },
    configuring: function () {
    },
    writing: function () {
        this._createFileSystem();
    },
    end: function () {
     this.spawnCommand('gulp', ['app']);
    }
});
Example #27
0
var generators = require('yeoman-generator');
module.exports = generators.NamedBase.extend({

    generateAureliaVM: function() {
        this.fs.copyTpl(
            this.templatePath('vm.js'),
            this.destinationPath('src/components/' + this.name + '/' + this.name + '.js'),
            { ComponentName: this.name }
        );
    },
    generateAureliaView: function() {
        this.fs.copyTpl(
            this.templatePath('view.html'),
            this.destinationPath('src/components/' + this.name + '/' + this.name + '.html'),
            {
                ComponentName: this.name,
                Hello: '${hello}'
            }
        );
    }
});
Example #28
0
module.exports = generators.NamedBase.extend({

  writing: function() {
    var templateName = this.name + '-template.hbs',
        viewName = this.name + 'View.js',
        sassName = '_' + this.name + '.scss';

    console.log('building view');
    this.fs.copyTpl(
        this.templatePath('view.js'),
        this.destinationPath(this.name + '/' + viewName),
        {template: templateName}
    );
    console.log('building template');
    this.fs.copyTpl(
        this.templatePath('template.hbs'),
        this.destinationPath(this.name + '/' + templateName),
        {}
    );
    console.log('building sass file');
    this.fs.copyTpl(
        this.templatePath('_styles.scss'),
        this.destinationPath(this.name + '/' + sassName),
        {}
    );
  },

  writeToAppScss: function() {
    try {
      var appPath = this.env.options.appPath || '.';
      var fullPath = appPath + '/app.scss';

      util.rewriteFile({
        file: fullPath,
        addLineAtEnd: true,
        splicable: [
          "@import '" + this.name + '/' + this.name + "';"
        ]
      });
    } catch (e) {
      this.log('\n Unable to find ' + fullPath + '. Reference to _' + this.name + '.scss ' + 'not added.\n');
    }
  }
});
Example #29
0
module.exports = generators.NamedBase.extend({

  prompting: function() {
    var done = this.async();
    this.prompt({
      type: 'confirm',
      name: 'singleton',
      message: 'Is the view a singleton?',
      default: false
    }, function(answers) {
      this.singleton = answers.singleton;
      done();
    }.bind(this));
  },

  writing: function() {
    var templateName = this.name + '-template.hbs',
        viewName = (this.singleton ? this.name : capitalizeFirstLetter(this.name)) + 'View.js',
        sassName = '_' + this.name + '.scss';
    console.log('building view');
    this.fs.copyTpl(
        this.templatePath('view.js'),
        this.destinationPath(this.name + '/' + viewName),
        {
          template: templateName,
          singleton: this.singleton
        }
    );
    console.log('building template');
    this.fs.copyTpl(
        this.templatePath('template.hbs'),
        this.destinationPath(this.name + '/' + templateName),
        {}
    );
    console.log('building sass file');
    this.fs.copyTpl(
        this.templatePath('_styles.scss'),
        this.destinationPath(this.name + '/' + sassName),
        {}
    );
    this.log('\nCreated new pod.');
  },

  writeToAppScss: function() {
    try {
      var appPath = this.env.options.appPath || '.';
      var fullPath = appPath + '/app.scss';

      util.rewriteFile({
        file: fullPath,
        addLineAtEnd: true,
        splicable: [
          "@import '" + this.name + '/' + this.name + "';"
        ]
      });
      this.log('\nAdded _' + this.name + '.scss reference to ' + fullPath + '\n');
    } catch (e) {
      this.log('\nUnable to find ' + fullPath + '. Reference to _' + this.name + '.scss ' + 'not added.\n');
    }
  }
});
Example #30
0
module.exports = yeomen.NamedBase.extend({
  constructor: function () {
    yeomen.NamedBase.apply(this, arguments)
    this.name = changeCase.camelCase(this.name)
  },
  promptName: function () {
    var done = this.async()

    var prompts = [
      {
        type: 'input',
        name: 'parent',
        message: 'Enter path (relative to src/app)?',
        default: 'components'
      }
    ]

    this.prompt(prompts, props => {
      this.parent = props.parent
      done()
    })
  },

  copy: function () {
    const appPath = 'src/app'

    const files = [
      '.component.js',
      '.controller.js',
      '.css',
      '.html', '.js', '.spec.js'
    ]

    files.forEach(file => {
      this.fs.copyTpl(
       this.templatePath(file),
       this.destinationPath(path.join(appPath, this.parent, this.name, this.name + file)),
        {
          name: this.name,
          pascalCase: changeCase.pascalCase(this.name),
          camelCase: changeCase.camelCase(this.name)
        }
     )
    })
  }
})