Skip to content
Snippets Groups Projects
Select Git revision
  • master default protected
  • homologa protected
  • development protected
  • enrollment_rate
  • hotfix-enrollment-aggregate
  • es23-superior-enrollment
  • instruction_level_fixes
  • docentes-ies-ente-federativo
  • receita-potencial
  • #974-receita-potencial
  • db-conn
  • years-of-study-mean
  • teachers-ies
  • new-indicators
  • issue_935
  • instruction_number
  • issue_958
  • issue_953
  • issues_indicadores_agregados
  • courseAggregate
  • v1.16.0
  • v1.15.1
  • v1.14.2
  • v1.14.1
  • v1.14.0
  • v1.14
  • v1.9.0
  • v1.8.3
  • v1.8.2
  • v1.8.1
  • v1.8.0
  • v1.7.0
  • v1.6.1
  • v1.6.0
  • v1.5.0
  • v1.4.2
  • v1.4.1
  • v1.4.0
  • v1.3.3
  • v1.3.2
40 results

gulpfile.babel.js

Blame
  • gulpfile.babel.js 2.34 KiB
    const fs = require('fs');
    
    const gulp = require('gulp');
    
    const babel = require('gulp-babel');
    
    const eslint = require('gulp-eslint');
    
    const mocha = require('gulp-mocha');
    
    const nodemon = require('gulp-nodemon');
    
    const Cache = require('gulp-file-cache');
    
    const docco = require('gulp-docco');
    
    const cache = new Cache();
    
    function createLogDir() {
        const logDirPath = 'build/logs';
        fs.access(logDirPath, fs.F_OK, (err) => {
            if (err) {
                console.info(`Logs directory not found, creating it.`);
                fs.mkdir(logDirPath, 0o700, (dirErr) => {
                    console.error(`Failed to create logs directory.\n\tError: ${dirErr}`);
                });
            }
        });
    }
    
    /**
     * Compile source files
     */
    gulp.task('compile', () => {
        createLogDir();
        // run ESLint
        gulp.src('src/**/*.js')
            .pipe(eslint())
            .pipe(eslint.format());
    
        // compile source to ES5
        gulp.src('src/**/*.js')
            .pipe(cache.filter())       // cache source files
            .pipe(babel())      // compile only modified files
            .pipe(cache.cache())        // cache compiled files
            .pipe(gulp.dest('build'));  // move compiled files to build directory
    
        // copy configuration file to build directory
        gulp.src('config.json')
            .pipe(gulp.dest('build'));
        gulp.src('test_config.json')
            .pipe(gulp.dest('build'));
    });
    
    gulp.task('build', ['compile']);
    
    gulp.task('docco', () => {
        gulp.src('./src/**/*.js')
            .pipe(docco())
            .pipe(gulp.dest('./docs'));
    });
    
    gulp.task('doc', ['docco']);
    
    gulp.task('test', ['build'], () => {
        gulp.src('test/test.js', {read: false})
            .pipe(mocha())
            .once('error', () => {
                process.exit(1);
            })
            .once('end', () => {
                process.exit();
            });
    });
    
    gulp.task('watch', ['compile'], () => {
        console.log('Watching source directory for changes');
        gulp.watch('src/**/*.js').on('change', () => {
            console.log('Recompiling source');
            gulp.start('compile');
            console.log('Source recompilation done');
        });
    });
    
    gulp.task('run', () => {
        process.chdir('build');
        nodemon({
            script: 'server.js',
            tasks: ['watch'],
            ignore: ["test/test.js", "gulpfile.babel.js"],
            ext: 'js html json',
            env: { 'NODE_ENV': 'development' }
        });
    });
    
    gulp.task('default', ['run']);