Created
December 3, 2015 10:10
-
-
Save kitze/4e656b405215e6b8617e to your computer and use it in GitHub Desktop.
gulpfile for generating a react component with style.js file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
import gulp from 'gulp'; | |
import webpack from 'webpack-stream'; | |
import path from 'path'; | |
import sync from 'run-sequence'; | |
import serve from 'browser-sync'; | |
import rename from 'gulp-rename'; | |
import template from 'gulp-template'; | |
import fs from 'fs'; | |
import yargs from 'yargs'; | |
import lodash from 'lodash'; | |
let root = 'src'; | |
let jsWithoutTests = '**/*!(.spec.js).js'; | |
let platform = ''; | |
let indexFile = 'index.html'; | |
let resolveToApp = (glob) => { | |
glob = glob || ''; | |
return path.join(root, glob); | |
}; | |
let resolveToComponents = (glob) => { | |
glob = glob || ''; | |
return path.join(root, `${platform}/components`, glob); | |
}; | |
let resolveToCommon = (glob) => { | |
glob = glob || ''; | |
return path.join(root, `common/${glob}`) | |
}; | |
let paths = { | |
js: [resolveToComponents(jsWithoutTests)], // exclude spec files | |
styles: resolveToApp('**/*.scss'), // stylesheets | |
html: [ | |
resolveToApp('**/*.html'), | |
path.join(root, indexFile) | |
], | |
output: root, | |
blankTemplates: path.join(__dirname, 'generator', 'component/**/*.**') | |
}; | |
gulp.task('component', () => { | |
let cap = (val) => { | |
return val.charAt(0).toUpperCase() + val.slice(1); | |
}; | |
let name = yargs.argv.name; | |
let parentPath = yargs.argv.parent || ''; | |
let destPath = path.join(yargs.argv.common ? resolveToCommon() : resolveToComponents(), parentPath, name); | |
return gulp.src(paths.blankTemplates) | |
.pipe(template({ | |
name: name, | |
upCaseName: cap(name) | |
})) | |
.pipe(rename((path) => { | |
path.basename = path.basename.replace('temp', cap(name)); | |
})) | |
.pipe(gulp.dest(destPath)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment