A cozy place for your shell scripts
npm install gulp-shelterGulp-shelter brings the best of both worlds and makes everyone in the team happy.
This is the recommended installation for a fresh new project with Node v4+ installed locally.
See legacy config below if you're in a different situation.
npm install --save-dev gulp-shelter gulpjs/gulp#4.0
(Having Gulp v3 installed globally should not be a problem.)
``js
const gulp = require('gulp');
const shelter = require('gulp-shelter')(gulp);
const BRANCH = process.env.TRAVIS_BRANCH;
// project config
const project = 'projectName';
const main = src/main.js;dist/${project}.js
const dest = ;
const domain = (
BRANCH === 'master' ? 'www.domain.com' :
BRANCH === 'develop' ? 'dev.domain.com' :
false
);
// commands and fragments
const browserifyOpts =
--standalone ${project}
--transform [ babelify --presets [ es2015 react ] ]
--debug; // --debug enables source-mapbrowserify ${main} ${browserifyOpts}
const browserify = ;exorcist ${dest}.map > ${dest}
const exorcist = ;watchify ${main} ${browserifyOpts} -o ${dest}
const watchify = ;browser-sync start --server --files "${dest}, index.html"
const browsersync = ;surge --project ./dist --domain ${domain}
const surge = domain ? : ':'; // ':' is noop in bash
// tasks definitions
shelter({
build: {
dsc: generate ${project} lib and external source-map,${browserify} | ${exorcist}
cmd: ${watchify} & ${browsersync}
},
serve: {
dsc: 'Open index.html and live-reload on changes',
cmd: ${browserify} | ${exorcist} && ${surge}
},
deploy: {
dsc: 'Run by Travis to automatically deploy on Surge',
cmd: `
}
});
Note that it's not required that your command consist of { dsc: …, cmd: … } objects.gulp --tasks
A string will do as well, but adding a description will make your tasks discoverable and explicit using ;
One of the advantages of npm scripts is that they do not require any other command line tools to be installed.
You can get the same benefit by adding the following lines to your package.json:`json`
"scripts": {
"gulp": "gulp",
"help": "gulp --tasks"
},
Now tasks can be discovered by running npm run help, and individual tasks can be run with npm run gulp --
Versions of Node prior to v4 did not support template strings out of the box.
Thankfully, Gulp v3.9+ is able to read special gulpfiles that contain ES6 syntax.
Install the following additional dependencies:
npm install --save-dev babel-core babel-register babel-preset-es2015
Setup Babel to use es2015, if you haven't already:
echo '{ "presets": ["es2015"] }' > .babelrc
And finally name or rename your gulpfile to gulpfile.babel.js.
If you plan on using the npm run help task described above with Gulp 3.X,
you will need a local version of gulp-cli for task descriptions to be displayed in the console.
npm install --save-dev gulp-cli`
## License
MIT