inject.js
2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
'use strict';
var path = require('path');
var gulp = require('gulp');
var conf = require('./conf');
var map = require('map-stream');
var transform = require('vinyl-transform');
var $ = require('gulp-load-plugins')();
var wiredep = require('wiredep').stream;
var _ = require('lodash');
var browserSync = require('browser-sync');
gulp.task('inject-reload', ['inject'], function() {
browserSync.reload();
});
gulp.task('inject', ['scripts', 'styles'], function () {
var injectStyles = gulp.src([
path.join(conf.paths.tmp, '/serve/app/**/*.css'),
path.join('!' + conf.paths.tmp, '/serve/app/vendor.css')
], { read: false });
var injectScripts = gulp.src([
path.join(conf.paths.src, '/app/**/*.module.js'),
path.join(conf.paths.src, '/app/**/*.js'),
path.join('!' + conf.paths.src, '/app/**/*.spec.js'),
path.join('!' + conf.paths.src, '/app/**/*.mock.js'),
])
.pipe($.angularFilesort()).on('error', conf.errorHandler('AngularFilesort'));
var injectOptions = {
ignorePath: [conf.paths.src, path.join(conf.paths.tmp, '/serve')],
addRootSlash: false
};
return gulp.src(path.join(conf.paths.src, '/*.html'))
.pipe($.inject(injectStyles, injectOptions))
.pipe($.inject(injectScripts, injectOptions))
.pipe(wiredep(_.extend({}, conf.wiredep)))
.pipe(gulp.dest(path.join(conf.paths.tmp, '/serve')));
});
/**
* Replace the default theme skin to a npm config
*
* Uses "vinyl-transform" + "map-stream" to open the
* js file and rewrite the source file into the same
* destination
*
* @see https://www.npmjs.com/package/vinyl-transform
* @see https://www.npmjs.com/package/map-stream
*/
gulp.task('inject-skin', function () {
if(conf.paths.skin) {
var jsPaths = {
src: path.join(conf.paths.src,'./noosfero.js'),
dest: conf.paths.src,
};
$.util.log('Configuring theme skin:', conf.paths.skin, '...');
var replaceSkin = transform(function(filename) {
return map(function(file, next) {
var contents = file.toString();
contents = contents.replace('skin-whbl', conf.paths.skin);
return next(null, contents);
});
});
if (conf.isBuild()) {
jsPaths.src = path.join(conf.paths.dist, 'scripts', 'app-*.js');
jsPaths.dest = path.join(conf.paths.dist, 'scripts');
}
gulp.src(jsPaths.src)
.pipe(replaceSkin)
.pipe(gulp.dest(jsPaths.dest));
}
});