-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathgulpfile.js
154 lines (141 loc) · 4.53 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
const fs = require("fs");
const gulp = require("gulp");
const concat = require("gulp-concat");
const strip = require("gulp-strip-comments");
const header = require("gulp-header");
const beautify = require("gulp-beautify");
const minify = require("gulp-minify");
const clean = require("gulp-clean");
const removeTest = require("gulp-strip-code");
const outputFiles = [
"lib/msrcrypto.js",
"lib/msrcrypto.min.js"
];
const subtleBuild = [
"scripts/subtle/head.js",
"scripts/subtle/syncWorker.js",
"scripts/subtle/operations.js",
"scripts/subtle/keyManager.js",
"scripts/subtle/workerManager.js",
"scripts/subtle/subtleInterface.js",
"scripts/subtle/tail.js"
];
const fullBuild = [
"scripts/bundleHead.js",
"scripts/operations.js",
"scripts/global.js",
"scripts/utilities.js",
"scripts/asn1.js",
"scripts/worker.js",
"scripts/jwk.js",
"scripts/cryptoMath.js",
"scripts/cryptoECC.js",
"scripts/curves_NIST.js",
"scripts/curves_BN.js",
"scripts/curves_NUMS.js",
"scripts/sha.js",
"scripts/sha1.js",
"scripts/sha256.js",
"scripts/sha512.js",
"scripts/hmac.js",
"scripts/aes.js",
"scripts/aes-cbc.js",
"scripts/aes-gcm.js",
"scripts/aes-kw.js",
"scripts/random.js",
"scripts/entropy.js",
"scripts/prime.js",
"scripts/rsa-base.js",
"scripts/rsa-oaep.js",
"scripts/rsa-pkcs1.js",
"scripts/rsa-pss.js",
"scripts/rsa.js",
"scripts/concat.js",
"scripts/pbkdf2.js",
"scripts/hkdf.js",
"scripts/hkdf-ctr.js",
"scripts/ecdh.js",
"scripts/ecdsa.js",
"scripts/subtle.js",
"scripts/wrapKey.js",
"scripts/bundleTail.js",
"scripts/subtle/promises.js"
];
const aesBuild = [
"scripts/bundleHead.js",
"scripts/operations.js",
"scripts/global.js",
"scripts/utilities.js",
"scripts/worker.js",
"scripts/jwk.js",
"scripts/sha.js",
"scripts/sha1.js",
"scripts/sha256.js",
"scripts/sha512.js",
"scripts/hmac.js",
"scripts/aes.js",
"scripts/aes-cbc.js",
"scripts/aes-gcm.js",
"scripts/random.js",
"scripts/entropy.js",
"scripts/subtle.js",
"scripts/wrapKey.js",
"scripts/bundleTail.js",
"scripts/subtle/promises.js"
];
const testBuild = fullBuild.concat([
"scripts/testInterface.js"
]);
// Delete the old output files before building.
function cleanBuild() {
return gulp.src(outputFiles, { read: false, allowEmpty: true })
.pipe(clean());
}
// Build the subtle.js file from a set of individual files.
function subtle() {
return gulp.src(subtleBuild)
.pipe(concat("subtle.js")) // concatenate scripts into single UMD module
.pipe(strip({ trim: true })) // strip the comments out
.pipe(beautify.js({ indent_size: 4, no_preserve_newlines: true })) // format the code
.pipe(header(fs.readFileSync("LICENSE", "utf8"))) // add a copyright/license header
.pipe(gulp.dest("scripts")); // write the file to the lib folder
}
// Concat the files into a single bundle.
function bundle() {
return gulp.src(fullBuild)
.pipe(concat("msrcrypto.js")) // concatenate scripts into single UMD module
.pipe(gulp.dest("lib")); // write the file to the lib folder
}
// Clean and format the new bundle.
function format() {
return gulp.src(
[
"lib/msrcrypto.js"
])
.pipe(removeTest({ start_comment: "debug-block", end_comment: "end-debug-block" })) // strip out test/debug code
.pipe(clean())
.pipe(strip({ trim: true })) // strip the comments out
.pipe(beautify.js({ indent_size: 4, no_preserve_newlines: true })) // format the code
.pipe(gulp.dest("lib")); // write the file to the lib folder
}
// Minify the new bundle to a .min.js file.
function minifyBundle() {
return gulp.src(
[
"lib/msrcrypto.js"
])
.pipe(minify({
ext: { min: ".min.js" },
// Fix IE8 catch issue in Promises
compress: { properties: false }
}))
.pipe(gulp.dest("lib")); // write the file to the lib folder
}
// Add the copyright/license header to output files.
function addCopyrightHeaders() {
return gulp.src(outputFiles)
.pipe(header(fs.readFileSync("LICENSE", "utf8"))) // add a copyright/license header
.pipe(gulp.dest("lib")); // write the file to the lib folder
}
gulp.task("default", gulp.series(cleanBuild, subtle, bundle, format, minifyBundle, addCopyrightHeaders));
// To run the default: >.\node_modules\.bin\gulp