Skip to content

Instantly share code, notes, and snippets.

@NateJLewis
Created May 8, 2017 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NateJLewis/a88a5bca6625ea3ee73cab45fcef9293 to your computer and use it in GitHub Desktop.
Save NateJLewis/a88a5bca6625ea3ee73cab45fcef9293 to your computer and use it in GitHub Desktop.
let root = 'src';
let resolveToComponents = ( glob = '' ) => {
return $.path.join( root, 'components', glob ); // app/components/{glob}
};
gulp.task( 'component', () => {
const cap = ( val ) => {
return val.charAt( 0 ).toUpperCase() + val.slice( 1 );
};
const name = $.yargs.argv.name;
const parentPath = $.yargs.argv.parent || '';
const templatePath = $.path.join( 'components', parentPath, name );
const destPath = $.path.join( resolveToComponents(), parentPath, name );
const nameArray = name.split( '.' );
const newNameArray = nameArray.map( function( name, index ) {
if ( index === 0 ) {
return name;
} else {
return name.charAt( 0 ).toUpperCase() + name.slice( 1 );
}
} );
const htmlClass = newNameArray.join( '-' );
const htmlId = newNameArray.join( '_' );
const component = newNameArray.join( '' );
const componentName = component + 'Component';
const componentControllerName = component.charAt( 0 ).toUpperCase() + component.slice( 1 ) + 'Controller';
return gulp.src( paths.componentTemplates )
.pipe( $.template( {
htmlClass: htmlClass.toLowerCase(),
htmlId: htmlId.toLowerCase(),
name: name,
component: component,
templatePath: templatePath,
componentName: componentName,
componentControllerName: componentControllerName,
upCaseName: cap( componentName )
} ) )
.pipe( $.rename( ( path ) => {
path.basename = path.basename.replace( 'temp', name );
} ) )
.pipe( gulp.dest( destPath ) );
} );
let resolveToControllers = ( glob = '' ) => {
return $.path.join( root, 'controllers', glob );
};
gulp.task( 'controller', () => {
const cap = ( val ) => {
return val.charAt( 0 ).toUpperCase() + val.slice( 1 );
};
const name = $.yargs.argv.name;
const parentPath = $.yargs.argv.parent || '';
const templatePath = $.path.join( 'controllers', parentPath, name );
const destPath = $.path.join( resolveToControllers(), parentPath, name );
const nameArray = name.split( '.' );
const newNameArray = nameArray.map( function( name, index ) {
if ( index === 0 ) {
return name;
} else {
return name.charAt( 0 ).toUpperCase() + name.slice( 1 );
}
} );
const htmlClass = newNameArray.join( '-' );
const htmlId = newNameArray.join( '_' );
const controller = newNameArray.join( '' );
const controllerFunction = controller.charAt( 0 ).toUpperCase() + controller.slice( 1 ) + 'Function';
return gulp.src( paths.controllerTemplates )
.pipe( $.template( {
htmlClass: htmlClass.toLowerCase(),
htmlId: htmlId.toLowerCase(),
name: name,
controller: controller,
templatePath: templatePath,
controllerFunction: controllerFunction,
upCaseName: cap( controllerFunction )
} ) )
.pipe( $.rename( ( path ) => {
path.basename = path.basename.replace( 'temp', name );
} ) )
.pipe( gulp.dest( destPath ) );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment