Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var gulp = require('gulp');
- //var browserSync = require('browser-sync');
- var sass = require('gulp-sass');
- var pug = require('gulp-pug');
- //var reload = browserSync.reload;
- //var cache = require('gulp-cached');
- var fs = require('fs');
- var path = require('path');
- var merge = require('merge-stream');
- var concat = require('gulp-concat');
- var rename = require('gulp-rename');
- var uglify = require('gulp-uglify');
- var babel = require("gulp-babel");
- var notifier = require('node-notifier');
- var scriptsPath = 'js'; // Donde estan los scripts
- var builtPath = 'jsc'; // Donde iran los compilados
- function errorHandlerSass(error) {
- notifier.notify({
- 'title': 'Error ' + error.relativePath.toString(),
- 'message': 'Line: ' + error.line.toString() + ' - ' + error.messageOriginal.toString()
- });
- this.emit('end');
- }
- function errorHandlerPug(error) {
- try {
- var filename = error.fileName.toString();
- notifier.notify({
- 'title': 'Error ' + path.relative(__dirname, filename),
- 'message': 'Line: ' + error.line.toString() + ' - ' + error.msg.toString()
- });
- } catch(e) {
- notifier.notify('Error fatal Pug');
- console.log(error);
- }
- this.emit('end');
- }
- function errorHandlerBabel(error) {
- var filename = error.fileName.toString();
- notifier.notify({
- 'title': 'Error ' + path.relative(__dirname, filename),
- 'message': 'Line: ' + error.loc.line.toString() + ' - ' + error.message.toString().substr(filename.length + 2)
- });
- this.emit('end');
- }
- function getFolders(dir) {
- return fs.readdirSync(dir)
- .filter(function(file) {
- return fs.statSync(path.join(dir, file)).isDirectory();
- });
- }
- gulp.task('scripts', function() {
- var folders = getFolders(scriptsPath);
- var tasks = folders.map(function(folder) {
- return gulp.src(path.join(scriptsPath, folder, '/**/*.js'))
- .pipe(babel({presets: ['es2015', 'react'] }).on('error', errorHandlerBabel))
- .pipe(uglify())
- .pipe(gulp.dest(path.join(builtPath, folder)))
- });
- // process all remaining files in scriptsPath root into main.js and main.min.js files
- var root = gulp.src(path.join(scriptsPath, '/*.js'))
- .pipe(babel({presets: ['es2015', 'react'] }).on('error', errorHandlerBabel))
- .pipe(uglify())
- .pipe(gulp.dest(builtPath))
- return merge(tasks, root);
- });
- gulp.task('sass-main', function () {
- return gulp.src('./assets/sass/main.sass')
- .pipe(sass({indentedSyntax: true, outputStyle: 'compressed'}).on('error', errorHandlerSass))
- .pipe(gulp.dest('./assets/css'));
- });
- gulp.task('pug-main', function() {
- return gulp.src('./pug/*.pug')
- .pipe(pug({
- pretty: true
- }).on('error', errorHandlerPug))
- .pipe(gulp.dest('./html/'))
- });
- /**
- * Crea el Servidor local y mantiene los archivos listos para cambios
- */
- // Se ejecutan los task de sass-main scripts y pug-main antes de iniciar con el task 'default'
- gulp.task('default', ['sass-main', 'scripts', 'pug-main'], function () {
- /*
- browserSync({
- server: './PUBLIC',
- ip: "0.0.0.0",
- port: 8080,//env.PORT,
- ui: { port: 8081 }
- });*/
- // Cambia cualquier archivo .sass y compila el main.sass con dependencias
- // el cwd permite hacer watching aun cuando se crean o renombran archivos
- gulp.watch('assets/sass/**/*.sass', {cwd: './'}, ['sass-main']);//sass
- gulp.watch('js/**/*.js', {cwd: './'}, ['scripts']);//js-babel
- gulp.watch('pug/**/*.pug', {cwd: './'}, ['pug-main']);//pug (ex-jade)
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement