Example #1
0
me.toTitleCase = function(str) {
	if (typeof str === 'undefined' || str === null || !str.length) return null;
	else {
		str = str.trim();
		str = str.replace(/^[ -]{1,}/, '');

		str = str.replace(/\bCLI\b/g, 'CLINIC');
		str = str.replace(/\bCTR\b/g, 'CENTER');
		str = str.replace(/\bLL\b/g, 'LLC');
		str = str.replace(/\bRTC\b/g, 'RESIDENTIAL TREATMENT CENTER');
		// str = str.replace(/\bTRC TEXAS\b/g, 'Treatment Research Clinic Texas');

		str = Case.title(str);

		str = str.replace(/^the\b/, 'The');
		str = str.replace(/^a\b/, 'A');

		str = str.replace(/\bBimc\b/g, 'BIMC');
		str = str.replace(/\bBma\b/g, 'BMA');
		str = str.replace(/\bCdc\b/g, 'CDC');
		str = str.replace(/\bCntr\b/g, 'Center');
		str = str.replace(/\bDsi\b/g, 'DSI');
		str = str.replace(/\bDci\b/g, 'DCI');
		str = str.replace(/\bDva\b/g, 'DVA');
		str = str.replace(/\bEsrd\b/g, 'End-Stage Renal Disease');
		str = str.replace(/\bFmc\b/g, 'FMC');
		str = str.replace(/\bFms\b/g, 'FMS');
		str = str.replace(/\bHosp\b/g, 'Hospital');
		str = str.replace(/\bIdf\b/g, 'IDF');
		str = str.replace(/\bIi\b/g, 'II');
		str = str.replace(/\bIii\b/g, 'III');
		str = str.replace(/\bLp\b/g, 'LP');
		str = str.replace(/\bNe\b/g, 'NE');
		str = str.replace(/\bNna\b/g, 'NNA');
		str = str.replace(/\bNw\b/g, 'NW');
		str = str.replace(/\bRcc\b/g, 'RCC');
		str = str.replace(/\bRtc\b/g, 'Rtc');
		str = str.replace(/\bSe\b/g, 'SE');
		str = str.replace(/\bSw\b/g, 'SW');
		str = str.replace(/\bTrc\b/g, 'TRC');
		str = str.replace(/\bUs\b/g, 'US');
		str = str.replace(/\bUsrc\b/g, 'USRC');

		str = str.replace(/\bMc$/g, 'Medical Center');
		str = str.replace(/\bDc$/g, 'Dialysis Center');

		return str;
	}
};
Example #2
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'));

      });

  }
Example #3
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, []);
        }
      });

  },