-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.js
More file actions
134 lines (110 loc) · 3.81 KB
/
gulpfile.js
File metadata and controls
134 lines (110 loc) · 3.81 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
var gulp = require('gulp');
var ts = require('gulp-typescript');
var newer = require('gulp-newer');
var jison = require('gulp-jison');
var istanbul = require('gulp-istanbul');
var runSequence = require('run-sequence');
var mocha = require('gulp-mocha');
var rename = require('gulp-rename');
var browserify = require('browserify');
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var gutil = require('gulp-util');
var assign = require('lodash.assign');
var stringify = require('stringify');
var jisonPath = 'src/parser/ast-builder/ast-builder.jison';
var tsProject = ts.createProject('tsconfig.json');
var tasks = {
typescript: 'tsc',
copyHtmlAssets: 'copyHtmlAssets',
mocha: 'mocha'
}
gulp.task(tasks.typescript, function () {
var tsResult = tsProject.src().pipe(tsProject())
return tsResult.js.pipe(gulp.dest('lib'));
});
gulp.task(tasks.copyHtmlAssets, function(){
gulp.src(['src/**/*.html']).pipe(gulp.dest('lib/'))
});
gulp.task(tasks.mocha, function() {
return gulp.src('test/test.js')
.pipe(mocha({reporter: 'spec'}))
.on('error', function (error) {
var errorText = (error.plugin) ? error : error.stack;
gutil.beep();
gutil.log(gutil.colors.yellow(errorText));
});
});
// add custom browserify options here
var customOpts = {
entries: './lib/angularjs/app.js',
debug: true
};
var b = browserify(customOpts).transform(stringify, {
appliesTo: { includeExtensions: ['.hjs', '.html', 'html', '.whatever'] },
minify: true,
minifyAppliesTo: { includeExtensions: ['.html'] },
});
gulp.task('browserify-only', function () {
return b.bundle()
.pipe(source('app.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./assets/js/'));
});
gulp.task('browserify', [tasks.typescript, tasks.copyHtmlAssets], function(){
runSequence('browserify-only')
});
gulp.task('browserify-prod', [tasks.typescript, tasks.copyHtmlAssets], function () {
return b.bundle()
.pipe(source('app.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
// Add transformation tasks to the pipeline here.
.pipe(uglify())
.on('error', gutil.log)
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./assets/js/'));
});
gulp.task('coverage', function(cb) {
gulp.src([
'api/**/*.js',
'!api/responses/*.js',
'!api/controllers/DemoController.js',
'lib/**/commands/*.js',
'lib/**/utils/*.js',
'lib/common/*.js',
'lib/parser/parser.js'
]).pipe(istanbul()) // Covering files
.on('finish', function () {
gulp.src(['test/test.js'])
.pipe(mocha({reporter: 'spec'}))
.on('error', function (error) {
var errorText = (error.plugin) ? error : error.stack;
gutil.beep();
gutil.log(gutil.colors.yellow(errorText));
})
.pipe(istanbul.writeReports()) // Creating the reports after tests runned
.on('end', cb);
});
});
gulp.task('jison', function() {
return gulp.src(jisonPath)
.pipe(jison({ moduleType: 'commonjs' }))
.pipe(gulp.dest('lib/parser/ast-builder/'));
});
gulp.task('watch', function () {
gulp.watch('src/**/*.ts',function(event) { runSequence('browserify', 'coverage') });
gulp.watch('src/**/*.ls',function(event) { runSequence('ls', 'coverage') });
gulp.watch(jisonPath, function(event) { runSequence('jison','coverage') });
gulp.watch('test/**/*.js',['coverage']);
});
gulp.task('watch-no-test', function () {
gulp.watch('src/**/*.ts',function(event) { runSequence('browserify') });
gulp.watch(jisonPath, function(event) { runSequence('jison') });
});
gulp.task('default', ['browserify','mocha','watch']);