forked from xtemplate/xtemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
158 lines (151 loc) · 4.56 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
var gulp = require('gulp');
var filter = require('gulp-filter');
var kclean = require('gulp-kclean');
var modulex = require('gulp-modulex');
var path = require('path');
var rename = require('gulp-rename');
var packageInfo = require('./package.json');
var src = path.resolve(process.cwd(), 'lib');
var build = path.resolve(process.cwd(), 'build');
var uglify = require('gulp-uglify');
var replace = require('gulp-replace');
var wrapper = require('gulp-wrapper');
var date = new Date();
var header = ['/*',
'Copyright ' + date.getFullYear() + ', ' + packageInfo.name + '@' + packageInfo.version,
packageInfo.license + ' Licensed',
'build time: ' + (date.toGMTString()),
'*/', ''].join('\n');
gulp.task('xtemplate', function () {
var CombinedStream = require('combined-stream');
var combinedStream = CombinedStream.create();
var packages = {};
var fullName = 'xtemplate/' + packageInfo.version;
packages[fullName] = {
base: path.resolve(src)
};
['index', 'runtime'].forEach(function (mod) {
var js = mod + '.js';
var debugJs = mod + '-debug.js';
var excludeModules;
if (mod === 'index') {
excludeModules = [fullName + '/runtime'];
}
combinedStream.append(gulp.src(path.resolve(src, js))
.pipe(modulex({
modulex: {
packages: packages
},
genDeps: false,
excludeModules: excludeModules
}))
.pipe(kclean({
files: [
{
src: path.resolve(src, debugJs),
outputModule: fullName + '/' + mod
}
]
}))
.pipe(replace(/@VERSION@/g, packageInfo.version))
.pipe(wrapper({
header: header
}))
.pipe(gulp.dest(build))
.pipe(filter(debugJs))
.pipe(replace(/@DEBUG@/g, ''))
.pipe(uglify())
.pipe(rename(js))
.pipe(gulp.dest(build)));
});
return combinedStream;
});
gulp.task('precompile-test', function () {
var gulpXTemplate = require('gulp-xtemplate');
return gulp.src('tests/browser/fixture/*.xtpl').pipe(gulpXTemplate({
runtime: '../../../lib/runtime',
truncatePrefixLen: process.cwd().length,
wrap: false,
XTemplate: require('./')
})).pipe(gulp.dest('tests/browser/fixture/'));
});
gulp.task('default', ['xtemplate', 'xtemplate-standalone', 'precompile-test']);
gulp.task('xtemplate-standalone', function () {
var CombinedStream = require('combined-stream');
var combinedStream = CombinedStream.create();
var packages = {};
var fullName = 'xtemplate/' + packageInfo.version;
packages[fullName] = {
base: path.resolve(src)
};
var wrap = {
index: {
start: 'var XTemplate = (function(){ var module = {};\n',
end: '\nreturn xtemplate403Index;\n})();'
},
runtime: {
start: 'var XTemplateRuntime = (function(){ var module = {};\n',
end: '\nreturn xtemplate403Runtime;\n})();'
}
};
['index', 'runtime'].forEach(function (mod) {
var js = mod + '.js';
var debugJs = mod + '-debug.js';
var standaloneJs = mod + '-standalone.js';
var standaloneDebugJs = mod + '-standalone-debug.js';
var modWrap = wrap[mod];
combinedStream.append(gulp.src(path.resolve(src, js))
.pipe(modulex({
modulex: {
packages: packages
}
}))
.pipe(kclean({
files: [
{
src: path.resolve(src, debugJs),
wrap: modWrap
}
]
}))
.pipe(replace(/@VERSION@/g, packageInfo.version))
.pipe(wrapper({
header: header
}))
.pipe(rename(standaloneDebugJs))
.pipe(gulp.dest(build))
.pipe(replace(/@DEBUG@/g, ''))
.pipe(uglify())
.pipe(rename(standaloneJs))
.pipe(gulp.dest(build)));
});
return combinedStream;
});
gulp.task('parser', function (callback) {
require('child_process').exec('node node_modules/kison/bin/kison -g lib/compiler/parser-grammar.kison',
function (error, stdout, stderr) {
if (stdout) {
console.log('stdout: ' + stdout);
}
if (stderr) {
console.log('stderr: ' + stderr);
}
if (error) {
console.log('exec error: ' + error);
}
}).on('exit', callback);
});
gulp.task('parser-dev', function (callback) {
require('child_process').exec('node node_modules/kison/bin/kison -g lib/compiler/parser-grammar.kison --no-compressSymbol',
function (error, stdout, stderr) {
if (stdout) {
console.log('stdout: ' + stdout);
}
if (stderr) {
console.log('stderr: ' + stderr);
}
if (error) {
console.log('exec error: ' + error);
}
}).on('exit', callback);
});