1

Parts of my gulp file are not doing anything, I get no errors, but the needed file is not showing up (or being modified).

The full gulpFile is below; and while gulp task 'vendor' does what it's supposed to do - (creates files in 'build' dir)... the gulp tasks 'js' and 'build' DO NOT create the expected 'app.js' in 'build' dir.

Since 'js' and 'build' use 'event-stream' and function getTemplateStream(), I suspect the issue is there

to confirm; if I remove those elements, this works:

gulp.task( 'x', function() {
    gulp.src( source.js.src )
        .pipe( concat( 'app.js' ) )
        .pipe( gulp.dest( 'build' ) )
}); 

I cannot seem to console.log() or get an error - so I am at a loss Any help - greatly appreciated

/*
    GULP BUILD SYSTEM
    -Will watch and compress files, as needed, restart server on change in dev mode
    -Will create a single "vendor.js" uglified file for any JS files specified in the "app.scripts.json" file
    -will move condensed files to "build"
*/
var es = require( 'event-stream' );
var gulp = require( 'gulp' );
var concat = require( 'gulp-concat' );
var connect = require( 'gulp-connect' );
var templateCache = require( 'gulp-angular-templatecache' );
var ngAnnotate = require( 'gulp-ng-annotate' );
var uglify = require( 'gulp-uglify' );
var gutil = require( 'gulp-util' );
var fs = require( 'fs' );
var _ = require( 'lodash' );

var scripts = require( './app.scripts.json' ); // for vendor.js
var source = {
    js: {
        main: 'app/main.js',
        src: [  'app.config.js',
                'app/main.js',
                'app/app.js',
                'app/**/module.js',
                'app/**/!(module)*.js' ],
        tpl: 'app/**/*.tpl.html'
    }
};

var destinations = {
    js: 'build'
};



// FUNCTIONS
var swallowError = function( error ) {

    console.error.bind( error.toString() );
    this.emit( 'end' );

};

var getTemplateStream = function () {

    return
    gulp.src( source.js.tpl )
        .pipe( templateCache( {
            root: 'app/',
            module: 'app'
        } ) )

};


// GULP TASKS
gulp.task( 'build', function() {
    return
    es.merge( gulp.src( source.js.src ) , getTemplateStream() )
        .pipe( ngAnnotate() )
        .pipe( uglify() )
        .pipe( concat( 'app.js' ) )
        .on( 'error', swallowError )
        .pipe( gulp.dest( destinations.js ) );
});


gulp.task( 'js', function() {
    return
    es.merge( gulp.src( source.js.src ) , getTemplateStream() )
        .pipe( concat( 'app.js' ) )
        .on( 'error', swallowError )
        .pipe( gulp.dest( destinations.js ) );

});


gulp.task( 'vendor', function() {

    _.forIn( scripts.chunks, function( chunkScripts, chunkName ) {

        var paths = [];

        chunkScripts.forEach( function( script ) {

            var scriptFileName = scripts.paths[script];

            if ( !fs.existsSync( __dirname + '/' + scriptFileName ) ) {

                throw console.error( 'Required path doesn\'t exist: ' + __dirname + '/' + scriptFileName, script );

            }

            paths.push( scriptFileName );
            //console.log( 'vendor file ' + scriptFileName + ' added to vendor.js.' );

        });

        gulp.src( paths )
            .pipe( concat( chunkName + '.js' ) )
            .on( 'error', swallowError )
            .pipe( gulp.dest( destinations.js ) )

    });

});


gulp.task( 'watch', function() {

    gulp.watch( source.js.src, ['js'] );
    gulp.watch( source.js.tpl, ['js'] );

});


gulp.task( 'connect', function() {

    connect.server({
        port: 8888
    });

});

gulp.task( 'prod', ['vendor', 'build'] );
gulp.task( 'dev', ['vendor', 'js', 'watch', 'connect'] );
gulp.task( 'default', ['dev'] );
// END GULP TASKS
j-p
  • 3,410
  • 7
  • 45
  • 79
  • Possible duplicate of [What are the rules for JavaScript's automatic semicolon insertion (ASI)?](http://stackoverflow.com/questions/2846283/what-are-the-rules-for-javascripts-automatic-semicolon-insertion-asi) – Sven Schoenung Aug 25 '16 at 05:49

1 Answers1

1

Sven (in a very passive aggressive way) pointed to the answer.

The issue was javascript automatically inserting semicolons..., with The classic example of the Return Statement: (found about 1/2 down the referred page)

return 
  "something";
// is transformed to
return;
  "something";

so making those adjustment - fixed my issue.

Sven, I disagree that this was a duplicate question, although the answer was the same. There is no way I would know to 'look' for the original post. You could have simply directed me to the post as an answer.

Please keep in mind that people who post, looking for answers, don't always have the depth or breadth, that's WHY we ask.

j-p
  • 3,410
  • 7
  • 45
  • 79