-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
153 lines (132 loc) · 3.95 KB
/
gulpfile.babel.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
import del from "del";
import fs from "fs";
import gulp from "gulp";
import babel from "gulp-babel";
import eslint from "gulp-eslint";
import ext from "gulp-ext-replace";
import jscc from "gulp-jscc";
import uglify from "gulp-uglify";
import { rollup } from "rollup";
const eslintConfig = {
"parser": "babel-eslint",
"plugins": ["flowtype"],
"rules": {
"comma-dangle": [2, "always-multiline"],
"semi": 2,
"no-unexpected-multiline": 1,
"no-underscore-dangle": 0,
"space-infix-ops": 0,
"no-multi-spaces": 0,
"no-unused-vars": 1,
"comma-spacing": 1,
"no-use-before-define": 0,
"eol-last": 0,
"no-extra-semi": 0,
"curly": 0,
"dot-notation": 0,
"no-shadow": 1,
"no-proto": 0,
"flowtype/boolean-style": [2, "boolean"],
"flowtype/define-flow-type": 1,
"flowtype/delimiter-dangle": [2, "always-multiline"],
"flowtype/generic-spacing": [2, "never"],
"flowtype/no-dupe-keys": 2,
"flowtype/no-primitive-constructor-types": 2,
"flowtype/no-types-missing-file-annotation": 0,
"flowtype/no-unused-expressions": 2,
"flowtype/no-weak-types": 2,
"flowtype/object-type-delimiter": "comma",
"flowtype/require-parameter-type": 0,
"flowtype/require-return-type": 0,
"flowtype/require-valid-file-annotation": 0,
"flowtype/semi": 2,
"flowtype/space-after-type-colon": [2, "always"],
"flowtype/space-before-generic-bracket": [2, "never"],
"flowtype/space-before-type-colon": [2, "never"],
"flowtype/union-intersection-spacing": [2, "always"],
"flowtype/use-flow-type": 1, //TODO: What the hell does this do?
},
"settings": {
"flowtype": {
"onlyFilesWithFlowAnnotation": false,
},
},
};
// `clean` task
export function clean() {
return del([
"browser/",
"lib/",
], {force: true});
}
// Browser subtasks
function browserLib() {
const presets = [["@babel/preset-env", {forceAllTransforms: true, modules: false}]];
return gulp.src("src/**/*.js")
.pipe(eslint(eslintConfig))
.pipe(eslint.format())
.pipe(eslint.failAfterError())
.pipe(jscc({ values: { _DEBUG: process.env.DEBUG } }))
.pipe(babel({plugins: ["@babel/transform-flow-strip-types"], presets}))
.pipe(gulp.dest("browser/lib"));
}
function browserRollup() {
return rollup({
input: "browser/lib/index.js",
external: [
"@capnp-js/bytes",
"@capnp-js/transform",
],
}).then(bundle => {
bundle.write({
file: "browser/capnp-js-trans-packing.js",
format: "umd",
name: "capnpJsTransPacking",
sourcemap: true,
globals: {
"@capnp-js/bytes": "capnpJsBytes",
"@capnp-js/transform": "capnpJsTransform",
},
});
});
}
function browserUglify() {
return new Promise((resolve, reject) => {
fs.readFile("browser/capnp-js-trans-packing.js.map", (err, map) => {
if (err) {
reject(err);
} else {
const ugly = gulp.src("browser/capnp-js-trans-packing.js")
.pipe(uglify({
sourceMap: {
content: map.toString(),
url: "capnp-js-trans-packing.js.map",
},
}))
.pipe(gulp.dest("browser"));
resolve(ugly);
}
});
});
}
const browser = gulp.series(browserLib, browserRollup, browserUglify);
// CommonJS subtasks
function cjsLib() {
const presets = [["@babel/preset-env", {targets: {node: "8.9"}, modules: "commonjs"}]];
return gulp.src("src/**/*.js")
.pipe(eslint(eslintConfig))
.pipe(eslint.format())
.pipe(eslint.failAfterError())
.pipe(jscc({ values: { _DEBUG: process.env.DEBUG } }))
.pipe(babel({plugins: ["@babel/transform-flow-strip-types"], presets}))
.pipe(gulp.dest("lib"));
}
function cjsFlowLib() {
return gulp.src("src/**/*.js")
.pipe(jscc({ values: { _DEBUG: process.env.DEBUG } }))
.pipe(ext(".js.flow"))
.pipe(gulp.dest("lib"));
}
const cjs = gulp.parallel(cjsLib, cjsFlowLib);
// `build` task
gulp.task("build", gulp.parallel(browser, cjs));