-
Notifications
You must be signed in to change notification settings - Fork 43
/
gulpfile.js
139 lines (116 loc) · 4.02 KB
/
gulpfile.js
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
135
136
137
138
139
var gulp = require('gulp');
var coffee = require('gulp-coffee');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var header = require('gulp-header');
var replace = require('gulp-replace');
var version = require('./src/js/version.js');
var typescript = require('gulp-typescript');
var del = require('del');
var source = require('./source.json');
var resultTag = [];
var resultFile = '';
var resultList = [];
gulp.task('config_core', [], function(){
resultFile = 'alight_core.js';
resultTag = ['core'];
});
gulp.task('config_basis', [], function(){
resultFile = 'alight_basis.js';
resultTag = ['core', 'basis'];
});
gulp.task('config_full', [], function(){
resultFile = 'alight.js';
resultTag = ['core', 'basis', 'full'];
});
gulp.task('config_compatibility', [], function(){
resultFile = 'alight.js';
resultTag = ['core', 'basis', 'full', 'compatibility'];
});
gulp.task('full', ['config_full', 'prepare', 'compress'], function(){});
gulp.task('basis', ['config_basis', 'prepare', 'compress'], function(){});
gulp.task('compatibility', ['config_compatibility', 'prepare', 'compress'], function(){});
gulp.task('core', ['config_core', 'prepare', 'compress'], function(){});
gulp.task('default', ['full'], function(){});
gulp.task('prepare', [], function(){
var tags = {};
for(var i=0; i<resultTag.length; i++)
tags[resultTag[i]] = true;
for(var i=0; i<source.length; i++) {
var f = source[i];
var skip = true;
for(var j=0; j<f.tag.length; j++) {
if(tags[f.tag[j]]) {
skip = false;
break;
}
}
var fileName = f.file;
if(skip) {
if(f.otherwise) fileName = f.otherwise;
else continue;
}
var d = fileName.match(/^(.*\.)(\w+)$/)
resultList.push('./tmp/' + d[1] + 'js');
}
});
gulp.task('clean', function () {
return del.sync(['tmp']);
});
gulp.task('compile', ['compile_coffeescript', 'compile_typescript', 'copy_js'], function() {});
gulp.task('copy_js', function () {
return gulp
.src('./src/js/*')
.pipe(gulp.dest('tmp/js/'));
});
gulp.task('compile_coffeescript', ['clean'], function() {
return gulp.src('./src/**/*.coffee')
.pipe(coffee({bare: true}).on('error', console.log))
.pipe(gulp.dest('tmp'))
});
gulp.task('compile_typescript', function() {
return gulp.src('./src/**/*.es.js')
.pipe(typescript({
allowJs: true
}))
.pipe(gulp.dest('tmp'))
});
gulp.task('assemble', ['compile'], function() {
return gulp.src(resultList)
.pipe(concat(resultFile))
.pipe(replace('{{{version}}}', version.version))
.pipe(header("/**\n * Angular Light " + version.version + "\n * (c) 2016 Oleg Nechaev\n * Released under the MIT License.\n * " + version.date + ", http://angularlight.org/ \n */"))
.pipe(gulp.dest('bin'));
});
gulp.task('compress', ['assemble'], function() {
return gulp.src('./bin/' + resultFile)
.pipe(uglify())
.pipe(rename({
extname: '.min.js'
}))
.pipe(header("/**\n * Angular Light " + version.version + "\n * (c) 2016 Oleg Nechaev\n * Released under the MIT License.\n * " + version.date + ", http://angularlight.org/ \n */"))
.pipe(gulp.dest('bin'))
});
// test
gulp.task('build_test', function() {
return gulp.src('./test/**/*.coffee')
//.pipe(coffee({bare: true}).on('error', console.log))
.pipe(coffee({}).on('error', console.log))
.pipe(gulp.dest('test'))
});
gulp.task('test', ['build_test'], function(){
var path = require('path');
var childProcess = require('child_process');
var phantomjs = require('phantomjs');
var binPath = phantomjs.path;
var childArgs = [path.join('test', 'phantom.js')];
childProcess.execFile(binPath, childArgs, function(err, stdout, stderr) {
console.log(stdout);
});
});
gulp.task('build_test_other', function() {
gulp.src('./test/benchmark/*.coffee')
.pipe(coffee({}).on('error', console.log))
.pipe(gulp.dest('test/benchmark'))
});