UNPKG

gulp-crometrics

Version:

Predefined Gulp Tasks for CROmetrics (fork of gulp-clearhead)

152 lines (103 loc) 5.23 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = clearbuild; var _gulpHelp = require('gulp-help'); var _gulpHelp2 = _interopRequireDefault(_gulpHelp); var _bundlify = require('./transforms/bundlify'); var _bundlify2 = _interopRequireDefault(_bundlify); var _gulpSequence = require('gulp-sequence'); var _gulpSequence2 = _interopRequireDefault(_gulpSequence); var _gulpShell = require('gulp-shell'); var _gulpShell2 = _interopRequireDefault(_gulpShell); var _del = require('del'); var _del2 = _interopRequireDefault(_del); var _gulpSass = require('gulp-sass'); var _gulpSass2 = _interopRequireDefault(_gulpSass); var _gulpEslint = require('gulp-eslint'); var _gulpEslint2 = _interopRequireDefault(_gulpEslint); var _eslintconfig = require('./config/eslintconfig'); var _eslintconfig2 = _interopRequireDefault(_eslintconfig); var _gulpCsslint = require('gulp-csslint'); var _gulpCsslint2 = _interopRequireDefault(_gulpCsslint); var _csslintconfig = require('./config/csslintconfig'); var _csslintconfig2 = _interopRequireDefault(_csslintconfig); var _processFinder = require('process-finder'); var _processFinder2 = _interopRequireDefault(_processFinder); var _path = require('path'); var _path2 = _interopRequireDefault(_path); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var paths = { src: { html: 'src/**/*.html', scripts: 'src/**/*.js', stylesheets: ['src/**/*.css', 'src/**/*.scss', 'src/**/*.sass'], all: 'src/**/*.+(html|js|css|scss|sass)' }, html: 'src/*.html', scripts: 'src/*.js', stylesheets: ['src/*.css', 'src/*.scss', 'src/*.sass'], dest: '' }; var sassOptions = { outputStyle: 'compressed', sourceMapEmbed: false }; function clearbuild(_gulp, basePath) { var _ref = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; var _ref$lintCss = _ref.lintCss; var lintCss = _ref$lintCss === undefined ? false : _ref$lintCss; var gulp = (0, _gulpHelp2.default)(_gulp); var sequence = _gulpSequence2.default.use(gulp); var globalPath = _path2.default.join(basePath, '..'); // Executable Dev function to compile and watch for further file changes this.dev = function () { return sequence(['lint:scripts', 'lint:stylesheets'], 'build:stylesheets', 'build:scripts', 'watch')(); }; // Compile all relevant files but don't watch for further changes. this.compile = function () { return sequence(['lint:scripts', 'lint:stylesheets'], 'build:stylesheets', 'build:scripts')(); }; gulp.task('default', 'Run the dev task.', ['dev']); // -- Live Development ---------- gulp.task('dev', 'Build and preview your experiment.', this.dev); gulp.task('watch', 'Rebuild when experiment files change.', function () { gulp.watch(basePath + '/' + paths.src.all, ['build']); // Watch global gulp.watch(globalPath + '/' + paths.src.all, ['build']); }); // -- Build Experiment ---------- gulp.task('build', 'Build experiment scripts and stylesheets.', function () { console.log('Change detected. Compiling...'); return sequence('lint', 'build:clean', 'build:stylesheets', 'build:scripts')(); }); gulp.task('build:clean', 'Clean build.', function (cb) { return (0, _del2.default)([basePath + '/*.js', basePath + '/*.css', globalPath + '/*.js', globalPath + '/*.css'], cb); }); gulp.task('build:scripts', 'Transpile and browserify scripts.', ['build:scripts:global', 'build:scripts:variation']); gulp.task('build:scripts:global', function () { return gulp.src(globalPath + '/' + paths.scripts).pipe((0, _bundlify2.default)()).pipe(gulp.dest(globalPath)); }); gulp.task('build:scripts:variation', function () { return gulp.src(basePath + '/' + paths.scripts).pipe((0, _bundlify2.default)()).pipe(gulp.dest(basePath)); }); gulp.task('build:stylesheets', 'Compile stylesheets.', ['build:stylesheets:global', 'build:stylesheets:variation']); gulp.task('build:stylesheets:global', 'Compile stylesheets.', function () { return gulp.src(globalPath + '/src/global.scss').pipe((0, _gulpSass2.default)(sassOptions).on('error', _gulpSass2.default.logError)).pipe(gulp.dest(globalPath)); }); gulp.task('build:stylesheets:variation', 'Compile stylesheets.', function () { return gulp.src(basePath + '/' + paths.stylesheets).pipe((0, _gulpSass2.default)(sassOptions).on('error', _gulpSass2.default.logError)).pipe(gulp.dest(basePath)); }); // -- Lint Experiment ---------- gulp.task('lint', 'Lint scripts and stylesheets', ['lint:scripts', 'lint:stylesheets']); gulp.task('lint:scripts', 'Lint scripts.', function () { return gulp.src(basePath + '/' + paths.scripts).pipe((0, _gulpEslint2.default)(_eslintconfig2.default)).pipe(_gulpEslint2.default.format()); }); gulp.task('lint:stylesheets', 'Compile and lint stylesheets.', function () { var task = gulp.src(basePath + '/' + paths.stylesheets).pipe((0, _gulpSass2.default)({ sourceMapEmbed: false }).on('error', _gulpSass2.default.logError)).pipe((0, _gulpCsslint2.default)(_csslintconfig2.default)); if (lintCss) { task.pipe(_gulpCsslint2.default.reporter()); } }); }