forked from tinyplex/tinybase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.mjs
185 lines (162 loc) · 4.3 KB
/
gulpfile.mjs
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
eslint-disable
jest/no-identical-title,
jest/no-disabled-tests,
jest/expect-expect,
jest/no-export,
@typescript-eslint/explicit-module-boundary-types
*/
import {
BIN_DIR,
DOCS_DIR,
LIB_DIR,
allModules,
allOf,
clearDir,
compileDocsAndAssets,
compileModule,
copyDefinitions,
execute,
lintCheck,
npmInstall,
npmPublish,
spellCheck,
test,
testModules,
tsCheck,
} from './build/common.mjs';
import gulp from 'gulp';
const {parallel, series} = gulp;
export const lint = async () => await lintCheck('.');
export const spell = async () => {
await spellCheck('.');
await spellCheck('src', true);
await spellCheck('test', true);
await spellCheck('site', true);
};
export const ts = async () => {
await copyDefinitions();
await tsCheck('src');
await tsCheck('test');
await tsCheck('site');
};
export const compileForTest = async () => {
await clearDir(LIB_DIR);
await testModules(async (module) => {
await compileModule(module, true, `${LIB_DIR}/debug`);
});
await copyDefinitions();
await compileForCli();
};
export const compileForProd = async () => {
await clearDir(LIB_DIR);
await allOf(
[undefined, 'umd', 'cjs'],
async (format) =>
await allOf([undefined, 'es6'], async (target) => {
const folder = `${LIB_DIR}/${[format, target]
.filter((token) => token)
.join('-')}`;
await allModules(
async (module) =>
await compileModule(module, false, folder, format, target),
);
if (format || target) {
await compileModule(
'ui-react-dom',
true,
folder,
format,
target,
false,
true,
'-debug',
);
}
}),
);
await allModules(
async (module) => await compileModule(module, true, `${LIB_DIR}/debug`),
);
await copyDefinitions();
await compileForCli();
};
export const compileForCli = async () => {
await clearDir(BIN_DIR);
await compileModule('cli', false, BIN_DIR, undefined, undefined, true);
await execute(`chmod +x ${BIN_DIR}/cli.js`);
};
export const compileUmdReactDomDebug = async () =>
await compileModule(
'ui-react-dom',
true,
`${LIB_DIR}/umd`,
'umd',
undefined,
false,
true,
'-debug',
);
export const testUnit = async () => {
await test('test/unit', {coverageMode: 1});
};
export const testUnitCountAsserts = async () => {
await test('test/unit', {coverageMode: 2, countAsserts: true});
};
export const testUnitSaveCoverage = async () => {
await test('test/unit', {coverageMode: 3});
};
export const compileAndTestUnit = series(compileForTest, testUnit);
export const compileAndTestUnitSaveCoverage = series(
compileForTest,
testUnitSaveCoverage,
);
export const testPerf = async () => {
await test('test/perf', {serialTests: true});
};
export const compileAndTestPerf = series(compileForTest, testPerf);
export const testE2e = async () => {
await test('test/e2e', {puppeteer: true});
};
export const compileAndTestE2e = series(compileForTest, testE2e);
export const compileDocsPagesOnly = async () =>
await compileDocsAndAssets(false);
export const compileDocsAssetsOnly = async () =>
await compileDocsAndAssets(false, false);
export const compileDocs = async () => await compileDocsAndAssets();
export const compileForProdAndDocs = series(compileForProd, compileDocs);
export const serveDocs = async () => {
const {createServer} = await import('http-server');
const {default: replace} = await import('buffer-replace');
const removeDomain = (_, res) => {
res._write = res.write;
res.write = (buffer) =>
res._write(replace(buffer, 'https://tinybase.org/', '/'.padStart(21)));
res.emit('next');
};
createServer({
root: DOCS_DIR,
cache: -1,
gzip: true,
// eslint-disable-next-line no-console
logFn: (req) => console.log(req.url),
before: [removeDomain],
}).listen('8080', '0.0.0.0');
};
export const preCommit = series(
parallel(lint, spell, ts),
compileForTest,
testUnit,
compileForProd,
);
export const prePublishPackage = series(
npmInstall,
parallel(lint, spell, ts),
compileForTest,
testUnitCountAsserts,
testPerf,
compileForProd,
compileDocs,
testE2e,
);
export const publishPackage = series(prePublishPackage, npmPublish);