/
Gruntfile.js
161 lines (143 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*!
* JEC JDI-MOCK Gruntfile.js
* Copyright(c) 2017 Pascal ECHEMANN
* Apache 2.0 Licensed
* This is a part of the JEC projects: <http://jecproject.org>
*/
/*
* Provides tasks for building and testing the jec-jdi-mock project.
*/
module.exports = function(grunt) {
//--> Utilities:
const INDEX_TAG = "index";
const DECLATE_TAG = /declare /g;
const IMPORT_STATEMENT = /import.*;/g;
const TRIM_BLANK_LINES = /^\s*[\r\n]/gm;
const PLACEHOLDER = /\/\*PLACEHOLDER\*\//g;
const EMPTY_STRING = "";
//--> Stores types during build process:
let typesContent = EMPTY_STRING;
//--> Grunt config initialization:
grunt.initConfig({});
//--> Compiles all ".ts" whithin the "src" folder:
grunt.config("ts", {
build : {
src: ["src/**/*.ts"],
options: {
module: "commonjs",
target: "es6",
sourceMap: false,
declaration: true,
declarationDir: "types/temp",
removeComments: true,
preserveConstEnums: true,
emitDecoratorMetadata: true,
experimentalDecorators: true,
alwaysStrict: true
}
},
test : {
src: ["test/**/*.ts", "utils/**/*.ts"],
options: {
module: "commonjs",
target: "es6",
sourceMap: false,
declaration: false,
removeComments: true,
preserveConstEnums: true,
emitDecoratorMetadata: true,
experimentalDecorators: true,
alwaysStrict: true
}
}
});
//--> Copy tasks:
grunt.config("copy", {
//--> Copies all ".js" files from the "src" to the "dist" folder:
main: {
cwd: "src",
src: "**/*.js",
dest: "dist",
expand: true
},
//--> Initializes all type files:
initTypes: {
cwd: "types/temp",
src: "**/*.ts",
dest: "types/temp2",
expand: true,
flatten: true,
filter: "isFile",
options: {
process: function (content, srcpath) {
if(srcpath.indexOf(INDEX_TAG) === -1) {
let result = content.replace(DECLATE_TAG, EMPTY_STRING);
result = result.replace(IMPORT_STATEMENT, EMPTY_STRING);
result = result.replace(TRIM_BLANK_LINES, EMPTY_STRING);
typesContent += result;
}
return content;
}
}
},
//--> Builds final type file:
buildTypesFile: {
cwd: "utils/types",
src: "**/*.ts",
dest: "types",
expand: true,
options: {
process: function (content, srcpath) {
content = content.replace(PLACEHOLDER, typesContent);
return content;
}
}
}
});
//--> Build the API documentation:
grunt.config("typedoc", {
doc: {
src: "src/",
options: {
module: "commonjs",
target: "ES6",
out: "docs/api-reference",
readme: "README.md",
name: "JEC JDI-MOCK Project",
exclude: "**/*Test*.ts"
}
}
});
//--> Removes temp folders:
grunt.config("clean", {
build: ["types/temp", "types/temp2"]
});
//--> Runs Unit Testing:
grunt.config("mochaTest", {
test: {
src: ["test/**/*.js"]
}
});
//--> Imports the TypeScript compilation task:
grunt.loadNpmTasks('grunt-ts');
//--> Imports the task used for copying all ".js" files from the "src" to the
// "dist" folder:
grunt.loadNpmTasks("grunt-contrib-copy");
//--> Imports the task used for building API documentation:
grunt.loadNpmTasks('grunt-typedoc');
//--> Imports the task used for running tests:
grunt.loadNpmTasks('grunt-mocha-test');
//--> Imports the task used for deleting temp files:
grunt.loadNpmTasks('grunt-contrib-clean');
/*!
* JEC JDI-MOCK Tasks:
*/
//--> Task: builds the "jec-jdi-mock" project:
grunt.registerTask("build", ["ts:build", "copy:main",
"copy:initTypes", "copy:buildTypesFile",
"clean:build"]);
//--> Task: builds the "jec-jdi-mock" API documentation:
grunt.registerTask("doc", ["typedoc"]);
//--> Task: builds the "jec-jdi-mock" API documentation:
grunt.registerTask("test", ["ts:test", "mochaTest"]);
}