-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
142 lines (142 loc) · 4.14 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
// Imports
import gulp from 'gulp';
import * as rollup from 'rollup';
import swc from './rollup-plugins/swc/index.js';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import { wasm } from '@rollup/plugin-wasm';
import fs from 'fs';
import path from 'path';
// Configs
const compileTypeScriptFile = async (name, input, output, debug) => {
// Read Configuration
const config = JSON.parse(await fs.promises.readFile('./package.json', 'utf8'));
// Compile
const bundle = await rollup.rollup({
input: input,
external: ['commander', 'chevrotain', 'fs', '@jest/globals', 'wasi'],
plugins: [
wasm({
targetEnv: 'auto-inline',
}),
swc({
jsc: {
minify: {
mangle: true,
},
parser: {
syntax: 'typescript',
},
target: 'es2022',
transform: {
constModules: {
globals: {
'@brisk/config': {
__DEBUG__: `${debug}`,
__VERSION__: `'${config.version}'`,
},
},
},
},
},
minify: true,
sourceMaps: true,
}),
nodeResolve({
extensions: ['.js', '.ts', '.mjs', '.json'],
preferBuilitns: true,
modulesOnly: true,
}),
],
});
await bundle.write({
file: output,
format: 'es',
name: name,
compact: false,
indent: ' ',
generatedCode: {
constBindings: true,
objectShorthand: true,
},
sourcemap: true,
});
};
// Gulp Tasks
gulp.task('build', async () => {
// Get the size of the original bundle
const oldCode = fs.existsSync('./dist/brisk.js')
? await fs.promises.readFile('./dist/brisk.js', 'utf-8')
: '';
const previousStats = {
chars: oldCode.length,
lines: oldCode.split('\n').length,
blanks: oldCode.split('\n').filter((n) => n.trim() == '').length,
comments: oldCode.split('\n').filter((n) => n.trim().startsWith('//')).length,
};
// Clean the original
const folder = './dist';
if (fs.existsSync(folder)) await fs.promises.rm(folder, { recursive: true });
await fs.promises.mkdir(folder);
// Build the Compiler
await compileTypeScriptFile('brisk', './src/cli/index.ts', './dist/brisk.js', true);
// Get new size
const newCode = fs.existsSync('./dist/brisk.js')
? await fs.promises.readFile('./dist/brisk.js', 'utf-8')
: '';
const stats = {
chars: newCode.length,
lines: newCode.split('\n').length,
blanks: newCode.split('\n').filter((n) => n.trim() == '').length,
comments: newCode.split('\n').filter((n) => n.trim().startsWith('//')).length,
};
console.table({
previous: {
...previousStats,
code: previousStats.lines - previousStats.blanks - previousStats.comments,
},
current: {
...stats,
code: stats.lines - stats.blanks - stats.comments,
},
reduction: {
chars: previousStats.chars - newCode.length,
lines: previousStats.lines - newCode.split('\n').length,
blanks: previousStats.blanks - newCode.split('\n').filter((n) => n.trim() == '').length,
comments:
previousStats.comments -
newCode.split('\n').filter((n) => n.trim().startsWith('//')).length,
code:
previousStats.lines -
previousStats.blanks -
previousStats.comments -
(stats.lines - stats.blanks - stats.comments),
},
});
});
gulp.task('mock', async () => {
// Clean the original
const folder = './__tests__/dist';
if (fs.existsSync(folder)) await fs.promises.rm(folder, { recursive: true });
await fs.promises.mkdir(folder);
// Build the Compiler
await compileTypeScriptFile(
'Brisk-Test-Data',
'./__tests__/Data.ts',
'./__tests__/dist/Data.js',
false
);
});
gulp.task('injectExtension', async () => {
const extPath = path.join(
process.env[process.platform == 'win32' ? 'USERPROFILE' : 'HOME'],
'/.vscode/extensions/briskSupport'
);
// Move Extension To Extension Land
if (fs.existsSync(extPath)) {
await fs.promises.rm(extPath, { recursive: true });
}
await fs.promises.cp('./extension/', extPath, {
recursive: true,
force: true,
});
});