-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
135 lines (118 loc) · 4.21 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
/**
* sffjs
* https://github.com/dmester/sffjs
* Copyright © Daniel Mester Pirttijärvi
*/
"use strict";
const gulp = require("gulp"),
del = require("del"),
fs = require("fs"),
rename = require("gulp-rename"),
closure = require('google-closure-compiler').gulp(),
zip = require("gulp-zip"),
merge = require("merge-stream"),
replace = require("gulp-replace"),
exec = require("child_process").exec,
pack = require("./package.json"),
sourcemaps = require('gulp-sourcemaps');
function getWrapper(source, placeholder) {
return fs.readFileSync(source)
.toString()
.replace(/<%=contents%>/, placeholder)
.replace(/\{version\}/g, pack.version)
.replace(/\{year\}/g, new Date().getFullYear())
.replace(/\{date\}/g, new Date().toISOString());
}
gulp.task("clean", function () {
return del(["./obj/**/*.*", "./dist/**/*.*"]);
});
gulp.task("compile", function () {
var src = gulp.src("./src/stringformat.js")
// Replace variables
.pipe(replace(/\{version\}/g, pack.version))
.pipe(replace(/\{year\}/g, new Date().getFullYear()))
.pipe(replace(/\{date\}/g, new Date().toISOString()))
.pipe(rename(function (path) { path.basename = "stringformat"; path.extname = ".js" }))
.pipe(gulp.dest("dist"))
.pipe(rename(function (path) { path.basename = "stringformat-" + pack.version; path.extname = ".js" }))
.pipe(gulp.dest("obj"))
// Prepare for minification
.pipe(sourcemaps.init())
// Minified file
.pipe(closure({
compilation_level: "SIMPLE",
rewritePolyfills: false,
createSourceMap: true,
outputWrapper: getWrapper("./src/template.min.js", "%output%"),
externs: [
{ src: "var module; function define(deps, cb) { }" }
],
}, {
platform: ['javascript']
}));
return merge(
src
.pipe(rename(function (path) { path.basename = "stringformat"; path.extname = ".min.js" }))
.pipe(sourcemaps.write('.', {
mapSources: (path) => "stringformat.js"
}))
.pipe(gulp.dest("dist")),
src
.pipe(rename(function (path) { path.basename = "stringformat-" + pack.version; path.extname = ".min.js" }))
.pipe(sourcemaps.write('.', {
mapSources: (path) => `stringformat-${pack.version}.js`
}))
.pipe(gulp.dest("obj"))
);
});
gulp.task("preparerelease", function () {
return gulp.src([
"./src/license.txt",
"./src/readme.txt",
"./src/tests.html",
"./src/stringformat.d.ts",
"./src/stringformat.tests.js"
])
.pipe(replace(/\{version\}/g, pack.version))
.pipe(replace(/\{year\}/g, new Date().getFullYear()))
.pipe(replace(/\{date\}/g, new Date().toISOString()))
.pipe(gulp.dest("dist"))
.pipe(gulp.dest("obj"));
});
gulp.task("cultures", function () {
return gulp.src([ "./src/cultures/*.*" ])
.pipe(gulp.dest("dist/cultures"))
.pipe(gulp.dest("obj/cultures"));
});
gulp.task("preparenuget", function () {
return gulp.src(["./src/stringformat.nuspec"])
.pipe(replace(/\{version\}/g, pack.version))
.pipe(replace(/\{year\}/g, new Date().getFullYear()))
.pipe(replace(/\{date\}/g, new Date().toISOString()))
.pipe(rename(function (path) { path.basename = "~" + path.basename }))
.pipe(gulp.dest("./"));
});
gulp.task("nuget", function (cb) {
exec("\"./utils/nuget/nuget.exe\" pack ~stringformat.nuspec -OutputDirectory releases", function (error, stdout, stderr) {
if (error) {
cb(error);
} else {
del(["./~stringformat.nuspec"]);
cb();
}
});
});
gulp.task("createpackage", function () {
return gulp.src(["./obj/**"])
.pipe(zip("sffjs-" + pack.version + ".zip"))
.pipe(gulp.dest("releases"));
});
gulp.task("build", gulp.series(
"clean",
"compile",
"cultures",
"preparerelease",
"preparenuget",
"nuget",
"createpackage"
));