Пример #1
0
module.exports = function(name) {
    let cwd = process.cwd();

    return parse(fs.readFileSync(
        `${cwd}/blocks/${Case.kebab(name)}.comb`
    ).toString());
};
Пример #2
0
      .then(function() {

        var parentModulePath = self.cli.reflect.findParentModule(dest);

        self.cli.refactor.addModuleImport({
          identifier: Case.camel(moduleName),
          child: path.resolve(dest + '/' + Case.kebab(moduleName) +'.module.js'),
          parent: parentModulePath
        });

        self.cli.refactor.addAngularDependency({
          identifier: Case.kebab(moduleName),
          module: parentModulePath
        });

        console.log(chalk.yellow('\nPlease carefully examine all changes before you commit!\n'));

      });
Пример #3
0
  getNewArtifactPath: function(type, template, name, destination) {

    var self = this;
    var cwd = process.cwd();

    //path names should all be kebab-cased
    name = Case.kebab(name);

    var projectRoot = this.cli.reflect.projectRoot();
    if (!projectRoot) {
      console.log(chalk.white("Make sure you are inside a project before creating a new " + type + "!"));
      console.log("");
      return;
    }

    if( cwd === path.resolve(projectRoot + '/shared_modules') ) {
      console.log(chalk.white("You cannot create an artifact directly in the shared modules folder."));
      console.log("");
      return;
    }

    //determine the destination
    if (!destination) {
      if (projectRoot !== cwd && (cwd.indexOf(path.resolve(projectRoot + '/components')) !== -1 || cwd.indexOf(path.resolve(projectRoot + '/shared_modules')) !== -1) ) {
        if (path.basename(cwd) !== type+'s') {
          destination = path.resolve(cwd + '/' + type + 's/' + name);
        } else {
          destination = path.resolve(cwd + '/' + name);
        }
      } else {
        destination = path.resolve(projectRoot + '/' + type + 's/' + name);
      }
    }

    return destination;

  },
Пример #4
0
  run: function(source, dest) {

    var self = this;

    //make sure we're passing in both the source and destination
    if( !source || !dest ) {
      console.log(chalk.white('\nYou must provide both a source and destination to copy a module.\n'));
      process.exit(1);
    }

    //resolve provided paths
    source = path.resolve(source);
    dest = path.resolve(dest);

    //make sure we have a valid source module
    this.validateSource(source);

    //make sure we have a valid dest module
    this.validateDest(dest);

    console.log(chalk.cyan(':: copying module from: ' + chalk.white(source) + ' to ' + chalk.white(dest)));
    //console.log(chalk.cyan(':: source module file: ' + chalk.white(this.moduleFilePath(source))));

    var oldModuleName = path.basename(source);
    var moduleName = path.basename(dest);

    var options = {};

    //setup file names to change
    options.rename = { startsWith: {}};
    options.rename.startsWith[oldModuleName] = moduleName;

    //setup words to replace in source
    options.replace = [];
    options.replace.push([Case.camel(oldModuleName), Case.camel(moduleName)]);
    options.replace.push([Case.title(oldModuleName), Case.title(moduleName)]);
    options.replace.push([Case.kebab(oldModuleName), Case.kebab(moduleName)]);

    //use source as a template and generate new files
    this.cli.generate
      .source(source + '/**/*')
      .options(options)
      .dest(dest)
      .then(function() {

        var parentModulePath = self.cli.reflect.findParentModule(dest);

        self.cli.refactor.addModuleImport({
          identifier: Case.camel(moduleName),
          child: path.resolve(dest + '/' + Case.kebab(moduleName) +'.module.js'),
          parent: parentModulePath
        });

        self.cli.refactor.addAngularDependency({
          identifier: Case.kebab(moduleName),
          module: parentModulePath
        });

        console.log(chalk.yellow('\nPlease carefully examine all changes before you commit!\n'));

      });

  }
Пример #5
0
 }, {
   name: 'email',
   message: 'Ⓐ your email:',
   validate: ifEmpty('You have to provide email'),
 }, {
   name: 'appVersion',
   message: 'Ⓐ preferred version to start:',
   default: '0.0.0',
 }, {
   name: 'appLicense',
   message: 'Ⓐ preferred license:',
   default: 'MIT',
 }, {
   name: 'appName',
   message: 'Ⓐ application name:',
   default: Case.kebab(this.name || this.appname),
   filter: Case.kebab,
 }, {
   name: 'prefix',
   message: 'Ⓐ prefix for directives:',
   default: '',
 }, {
   name: 'appDesc',
   message: 'Ⓐ description:',
 }, {
   name: 'appKeywords',
   message: 'Ⓐ keywords:',
   filter: splitKeywords,
 }, {
   name: 'withRouting',
   message: 'Ⓐ Include routing library?:',
Пример #6
0
        .pipe(rename(function (path) {

          //rename exact file name
          var dir = self.config.rename[path.dirname];

          if( dir ) {

            var file = dir[path.basename + path.extname];
            if( file ) {

              if( typeof file === 'object' ) {

                if (file.basename) {
                  path.basename = file.basename;
                }

                if (file.extname) {
                  path.extname = file.extname;
                }

              } else {

                file = file.split('.');
                path.basename = file[0];
                if( file[1] ) {
                  path.extname = '.' + file[1];
                }

              }
            }
          }

          //replace the keyword 'name.' at the beginning of a file with the artifact name
          if( path.basename.split('.')[0] === 'name' ) {

            var basename = path.basename.split('.');

            var newName = Case.kebab(self.data.name);

            basename.shift();
            basename.unshift(newName);

            if (self.cli.isEnabled('debug')) {
              console.log(chalk.gray(':: renaming file:'), chalk.white(basename.join('.') + path.extname));
            }

            path.basename = basename.join('.');

          }

          //replace first segment name...
          if( self.config.rename.startsWith ) {
            for( var startsWith in self.config.rename.startsWith ) {

              if( path.basename.split('.')[0] === startsWith ) {

                var basename1 = path.basename.split('.');

                var newName1 = Case.kebab(self.config.rename.startsWith[startsWith]);

                basename1.shift();
                basename1.unshift(newName1);

                if (self.cli.isEnabled('debug')) {
                  console.log(chalk.gray(':: renaming file:'), chalk.white(basename1.join('.') + path.extname));
                }

                path.basename = basename1.join('.');

              }

            }
          }

        }))
Пример #7
0
  createArtifact: function(type, template, name, destination, callback) {

    var self = this;

    var artifactName = Case.camel(name);
    var pathName = Case.kebab(name);

    this.template(type, template)
      .options({rename: {name: pathName}})
      .context({moduleName: this.cli.reflect.getModuleName(destination), name: pathName, 'name_camel': Case.camel(name), 'name_title': Case.title(name)})
      .dest(destination)
      .then(function () {

        var identifier = artifactName;
        var parentModulePath = self.cli.reflect.findParentModule(path.resolve(destination));

        //determine whether importing module or specific artifact
        var importType = type;
        if( type === 'component' ) {
          importType = 'module';
        } else if( type === 'directive' && template === 'element' ) {
          importType = 'module';
        }

        //add service suffix if not set
        if( type === 'service' ) {
          identifier = Case.pascal(identifier);
          if( identifier.substr(identifier.length-'service'.length, identifier.length) !== 'Service' ) {
            identifier += 'Service';
          }
        }

        var modulePath = path.normalize(path.relative(self.cli.reflect.projectRoot(), destination) + '/' + pathName +'.' + importType+'.js');
        console.log(chalk.cyan(':: creating new ' + type + ': '), chalk.white(identifier) + chalk.gray(' (' + modulePath + ')'));

        self.cli.refactor.addModuleImport({
          identifier: identifier,
          child: path.resolve(destination + '/' + pathName + '.' + importType + '.js'),
          parent: parentModulePath
        });

        if( importType === 'module' ) {

          self.cli.refactor.addAngularDependency({
            identifier: name,
            module: parentModulePath
          });

        } else {

          self.cli.refactor.addAngularDefinition({
            name: identifier,
            type: type,
            module: parentModulePath
          });

        }

        if(self.templates.get(type, template).done ) {
          self.templates.get(type, template).done(name, destination);
        }

        if( callback ) {
          callback.apply(self, []);
        }
      });

  },