-
Notifications
You must be signed in to change notification settings - Fork 2
/
Gruntfile.js
138 lines (119 loc) · 4.09 KB
/
Gruntfile.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
"use strict";
module.exports = function (grunt) {
// Load grunt tasks automatically
require("jit-grunt")(grunt, {
buildcontrol: "grunt-build-control"
});
require("time-grunt")(grunt); // Time how long tasks take. Can help when optimizing build times
var
pkg = grunt.file.readJSON("package.json"),
paths = {
src: "src",
build: "dist",
temp: ".temp",
test: "test"
},
options = {
dev: grunt.option("dev")
};
// Define the configuration for all the tasks
grunt.initConfig({
// Configurable paths
paths: paths,
ts: {
options: {
fast: "never",
target: "es3",
module: "umd",
sourceMap: false,
declaration: false,
comments: true
},
dev: {
src: "<%= paths.src %>/**/*.ts",
options: {
sourceMap: true
}
},
test: {
src: "<%= paths.test %>/**/*.ts"
},
dist: {
src: "<%= paths.src %>/**/*.ts",
outDir: "<%= paths.build %>",
options: {
declaration: true,
rootDir: "<%= paths.src %>"
}
},
distes: {
src: "<%= paths.src %>/**/*.ts",
outDir: "<%= paths.build %>/es",
options: {
target: "es6",
module: "es6",
declaration: false,
rootDir: "<%= paths.src %>"
}
}
},
tslint: {
options: {
configuration: grunt.file.readJSON("tslint.json")
},
dev: {
src: "<%= paths.src %>/**/*.ts"
},
test: {
src: "<%= paths.test %>/**/*.ts"
}
},
buildcontrol: {
options: {
dir: "<%= paths.build %>",
commit: true,
push: true,
branch: "release"
},
publish: {
options: {
tag: pkg.version,
remote: pkg.repository.url,
message: "Publish %sourceName% '" + pkg.version + "' from commit %sourceCommit% on branch %sourceBranch%"
}
}
},
clean: {
dev: [
"<%= paths.src %>/**/*.d.ts",
"!<%= paths.src %>/math.d.ts",
"<%= paths.src %>/**/*.js",
"<%= paths.src %>/**/*.js.map"
],
dist: "<%= paths.build %>",
build: "<%= paths.build %>/.baseDir.*"
}
});
grunt.registerTask("packages", function() {
var pkg = grunt.file.readJSON("package.json");
delete pkg.devDependencies;
delete pkg.scripts;
grunt.file.write(paths.build + "/package.json", JSON.stringify(pkg, null, 2));
var bower = grunt.file.readJSON("bower.json");
grunt.file.write(paths.build + "/bower.json", JSON.stringify(bower, null, 2));
});
grunt.registerTask("npmpublish", "Publish NPM package", function () {
const
npmBin = /^win/.test(process.platform) ? "npm.cmd" : "npm",
res = require("child_process").spawnSync(npmBin, ["publish"], { cwd: paths.build });
if (res.status !== 0) {
return grunt.fail.warn("An error occured while trying to publish NPM package", res.status);
}
grunt.verbose.writeln(res.stdout);
grunt.log.ok("NPM package successfully published!");
});
grunt.registerTask("build", ["clean:dev", "clean:dist", "tslint:dev", "ts:dist", "ts:distes", "packages"]);
grunt.registerTask("dev", ["clean:dev", "tslint:dev", "ts:dev"]);
grunt.registerTask("publish", ["build", "clean:build", "buildcontrol:publish", "npmpublish"]);
grunt.registerTask("default", ["build"]);
};