-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
gulpfile.mjs
848 lines (777 loc) · 23.8 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
// All other imports are lazy so that single tasks start up fast.
import {basename, dirname, join, resolve} from 'path';
import {existsSync, promises, readdirSync} from 'fs';
import gulp from 'gulp';
import {gzipSync} from 'zlib';
const UTF8 = 'utf-8';
const TEST_MODULES = [
'',
'ui-react',
'ui-react-dom',
'ui-react-inspector',
'tools',
'persisters',
'persisters/persister-automerge',
'persisters/persister-browser',
'persisters/persister-cr-sqlite-wasm',
'persisters/persister-durable-object-storage',
'persisters/persister-electric-sql',
'persisters/persister-expo-sqlite',
'persisters/persister-file',
'persisters/persister-indexed-db',
'persisters/persister-libsql',
'persisters/persister-partykit-client',
'persisters/persister-partykit-server',
'persisters/persister-pglite',
'persisters/persister-postgres',
'persisters/persister-powersync',
'persisters/persister-remote',
'persisters/persister-sqlite-wasm',
'persisters/persister-sqlite3',
'persisters/persister-yjs',
'synchronizers',
'synchronizers/synchronizer-local',
'synchronizers/synchronizer-ws-client',
'synchronizers/synchronizer-ws-server',
'synchronizers/synchronizer-ws-server-simple',
'synchronizers/synchronizer-ws-server-durable-object',
'synchronizers/synchronizer-broadcast-channel',
];
const ALL_MODULES = [
...TEST_MODULES,
'store',
'metrics',
'indexes',
'relationships',
'queries',
'checkpoints',
'mergeable-store',
'common',
];
const ALL_DEFINITIONS = [
...ALL_MODULES,
'_internal/store',
'_internal/queries',
'_internal/ui-react',
];
const DIST_DIR = 'dist';
const DOCS_DIR = 'docs';
const TMP_DIR = 'tmp';
const LINT_BLOCKS = /```[jt]sx?( [^\n]+)?(\n.*?)```/gms;
const TYPES_DOC_CODE_BLOCKS = /\/\/\/\s*(\S*)(.*?)(?=(\s*\/\/)|(\n\n)|(\n$))/gs;
const TYPES_DOC_BLOCKS = /(\/\*\*.*?\*\/)\s*\/\/\/\s*(\S*)/gs;
const getGlobalName = (module) =>
'TinyBase' +
(module == ''
? ''
: basename(module)
.split('-')
.map((part) => part[0].toUpperCase() + part.slice(1).toLowerCase())
.join('')
.replace('Partykit', 'PartyKit')); // lol
const getPrettierConfig = async () => ({
...JSON.parse(await promises.readFile('.prettierrc', UTF8)),
parser: 'typescript',
});
const allOf = async (array, cb) => await Promise.all(array.map(cb));
const testModules = async (cb) => await allOf(TEST_MODULES, cb);
const allModules = async (cb) => await allOf(ALL_MODULES, cb);
const allDefinitions = async (cb) => await allOf(ALL_DEFINITIONS, cb);
const clearDir = async (dir = DIST_DIR) => {
try {
await removeDir(dir);
} catch {}
await makeDir(dir);
};
const makeDir = async (dir) => {
try {
await promises.mkdir(dir);
} catch {}
};
const ensureDir = async (fileOrDirectory) => {
await promises.mkdir(dirname(fileOrDirectory), {recursive: true});
return fileOrDirectory;
};
const removeDir = async (dir) => {
await promises.rm(dir, {recursive: true});
};
const forEachDeepFile = (dir, callback, extension = '') =>
forEachDirAndFile(
dir,
(dir) => forEachDeepFile(dir, callback, extension),
(file) => callback(file),
extension,
);
const forEachDirAndFile = (dir, dirCallback, fileCallback, extension = '') =>
readdirSync(dir, {withFileTypes: true}).forEach((entry) => {
const path = resolve(join(dir, entry.name));
if (entry.isDirectory()) {
dirCallback?.(path);
} else if (path.endsWith(extension)) {
fileCallback?.(path);
}
});
const copyWithReplace = async (src, [from, to], dst = src) => {
const file = await promises.readFile(src, UTF8);
await promises.writeFile(dst, file.replace(from, to), UTF8);
};
const gzipFile = async (fileName) =>
await promises.writeFile(
`${fileName}.gz`,
gzipSync(await promises.readFile(fileName, UTF8), {level: 9}),
);
const copyPackageFiles = async (forProd = false) => {
const targets = forProd ? [null, 'es6'] : [null];
const mins = forProd ? [null, 'min'] : [null];
const modules = forProd ? ALL_MODULES : TEST_MODULES;
const schemas = [null, 'with-schemas'];
const json = JSON.parse(await promises.readFile('package.json', UTF8));
delete json.private;
delete json.scripts;
delete json.devDependencies;
json.bin = {tinybase: './cli/index.js'};
json.main = './index.js';
json.types = './@types/index.d.ts';
json.typesVersions = {'*': {}};
json.exports = {};
targets.forEach((target) => {
mins.forEach((min) => {
modules.forEach((module) => {
schemas.forEach((withSchemas) => {
const path = [target, min, module, withSchemas]
.filter((part) => part)
.join('/');
const typesPath = ['.', '@types', module, withSchemas, 'index.d.']
.filter((part) => part)
.join('/');
const codePath = (path ? '/' : '') + path;
json.typesVersions['*'][path ? path : '.'] = [typesPath + 'ts'];
json.exports['.' + codePath] = {
...(forProd
? {
require: {
types: typesPath + 'cts',
default: './cjs' + codePath + '/index.cjs',
},
}
: {}),
default: {
types: typesPath + 'ts',
default: '.' + codePath + '/index.js',
},
};
});
});
});
});
await promises.writeFile(
join(DIST_DIR, 'package.json'),
JSON.stringify(json, undefined, 2),
UTF8,
);
await promises.copyFile('LICENSE', join(DIST_DIR, 'LICENSE'));
await promises.copyFile('readme.md', join(DIST_DIR, 'readme.md'));
await promises.copyFile('releases.md', join(DIST_DIR, 'releases.md'));
};
let labelBlocks;
const getLabelBlocks = async () => {
if (labelBlocks == null) {
labelBlocks = new Map();
await allModules(async (module) => {
[
...(
await promises.readFile(`src/@types/${module}/docs.js`, UTF8)
).matchAll(TYPES_DOC_BLOCKS),
].forEach(([_, block, label]) => {
if (labelBlocks.has(label)) {
throw new Error(`Duplicate label '${label}' in ${module}`);
}
labelBlocks.set(label, block);
});
});
}
return labelBlocks;
};
const copyDefinition = async (dir, module) => {
const labelBlocks = await getLabelBlocks();
// Add easier-to-read with-schemas blocks
const codeBlocks = new Map();
[
...(
await promises.readFile(`src/@types/${module}/index.d.ts`, UTF8)
).matchAll(TYPES_DOC_CODE_BLOCKS),
].forEach(([_, label, code]) => {
const prefix = code.match(/^\n\s*/m)?.[0];
if (prefix) {
codeBlocks.set(
label,
code
.replace(/export type \S+ =\s/, '')
.replace(/export function /, '')
.replaceAll(prefix, prefix + ' * '),
);
}
});
const fileRewrite = (block, addOverrideSnippet) =>
block.replace(TYPES_DOC_CODE_BLOCKS, (_, label, code) => {
if (labelBlocks.has(label)) {
const codeOverride = codeBlocks.get(label);
let block = labelBlocks.get(label);
if (
addOverrideSnippet &&
codeBlocks.has(label) &&
code.includes('<') &&
code.includes('Schema') &&
!codeOverride.endsWith('{')
) {
const prefix = block.match(/^\s+\*$/m)?.[0];
if (prefix) {
const line = '\n' + prefix;
block = block.replace(
/^\s+\*$/m,
`${prefix}${line}` +
' This has schema-based typing.' +
' The following is a simplified representation:' +
`${line}${line} \`\`\`ts override` +
codeOverride.trimEnd() +
`${line} \`\`\`${line}`,
);
}
code = code.replace(/^\s*?\/\/\/.*?\n/gm, '');
}
return block + code;
}
throw `Missing docs label ${label} in ${module}`;
});
await allOf(['', '/with-schemas'], async (extraDir) => {
const definitionFile = await ensureDir(
`${dir}/@types/${module}${extraDir}/index.d.ts`,
);
await promises.writeFile(
definitionFile,
fileRewrite(
await promises.readFile(
`src/@types/${module}${extraDir}/index.d.ts`,
UTF8,
),
extraDir != '',
),
UTF8,
);
await copyWithReplace(
definitionFile,
[/\.d\.ts/g, '.d.cts'],
definitionFile.replace(/index.d.ts$/, 'index.d.cts'),
);
});
};
const copyDefinitions = async (dir) => {
await allDefinitions((module) => copyDefinition(dir, module));
};
const execute = async (cmd) => {
const {exec} = await import('child_process');
const {promisify} = await import('util');
try {
await promisify(exec)(cmd);
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
throw e.stdout;
}
};
const lintCheckFiles = async (dir) => {
const {
default: {ESLint},
} = await import('eslint');
const esLint = new ESLint({
extensions: ['.js', '.jsx', '.ts', '.tsx'],
});
const results = await esLint.lintFiles([dir]);
if (
results.filter((result) => result.errorCount > 0 || result.warningCount > 0)
.length > 0
) {
const formatter = await esLint.loadFormatter();
const errors = await formatter.format(results);
throw errors;
}
};
const lintCheckDocs = async (dir) => {
const {
default: {ESLint},
} = await import('eslint');
const esLint = new ESLint({
extensions: [],
overrideConfig: {
rules: {
'no-console': 0,
'react/prop-types': 0,
'react-hooks/rules-of-hooks': 0,
'@typescript-eslint/no-unused-expressions': 0,
'max-len': [
2,
{code: 80, ignorePattern: '^(\\s+\\* )?((im|ex)ports?|// ->)\\W.*'},
],
},
},
});
const {default: prettier} = await import('prettier');
const prettierConfig = await getPrettierConfig();
const docConfig = {...prettierConfig, printWidth: 75};
const filePaths = [];
['.js', '.d.ts'].forEach((extension) =>
forEachDeepFile(dir, (filePath) => filePaths.push(filePath), extension),
);
await allOf(filePaths, async (filePath) => {
const code = await promises.readFile(filePath, UTF8);
if (
!(await prettier.check(code, {...prettierConfig, filepath: filePath}))
) {
throw `${filePath} not pretty`;
}
await allOf(
[...(code.matchAll(LINT_BLOCKS) ?? [])],
async ([_, hint, docBlock]) => {
if (hint?.trim() == 'override') {
return; // can't lint orphaned TS methods
}
const code = docBlock.replace(/\n +\* ?/g, '\n').trimStart();
if (!(await prettier.check(code, docConfig))) {
const pretty = (await prettier.format(code, docConfig))
.trim()
.replace(/^|\n/g, '\n * ');
throw `${filePath} not pretty:\n${code}\n\nShould be:\n${pretty}\n`;
}
const results = await esLint.lintText(code);
if (
results.filter(
(result) => result.errorCount > 0 || result.warningCount > 0,
).length > 0
) {
const formatter = await esLint.loadFormatter();
const errors = await formatter.format(results);
throw `${filePath} does not lint:\n${code}\n\n${errors}`;
}
},
);
});
};
const spellCheck = async (dir, deep = false) =>
await execute(`cspell "${dir}/*${deep ? '*' : ''}"`);
const getTsOptions = async (dir) => {
const {default: tsc} = await import('typescript');
return tsc.parseJsonSourceFileConfigFileContent(
tsc.readJsonConfigFile(`${dir}/tsconfig.json`, tsc.sys.readFile),
tsc.sys,
dir,
);
};
const tsCheck = async (dir) => {
const path = await import('path');
const {default: tsc} = await import('typescript');
const {analyzeTsConfig} = await import('ts-unused-exports');
const {fileNames, options} = await getTsOptions(dir);
const results = tsc
.getPreEmitDiagnostics(
tsc.createProgram(
fileNames.filter(
(fileName) => !fileName.startsWith('test/unit/core/types'),
),
options,
),
)
.filter((result) => !result.file?.fileName.includes('/node_modules/'));
if (results.length > 0) {
const resultText = results
.map((result) => {
const {file, messageText, start} = result;
const {line, character} = file.getLineAndCharacterOfPosition(start);
return `${file.fileName}:${line}:${character}\n${JSON.stringify(
messageText,
)}`;
})
.join('\n\n');
throw resultText;
}
const unusedResults = Object.entries(
analyzeTsConfig(`${path.resolve(dir)}/tsconfig.json`, [
'--excludeDeclarationFiles',
'--excludePathsFromReport=' +
'build.ts;ui-react/common.ts;' +
TEST_MODULES.map((module) => `${module}.ts`).join(';'),
]).unusedExports,
)
.map(
([file, exps]) =>
`${file}: ${exps.map((exp) => exp.exportName).join(', ')}`,
)
.join('\n');
if (unusedResults != '') {
throw `Unused exports for ${dir} in: \n${unusedResults}`;
}
};
const compileModule = async (
module,
dir = DIST_DIR,
format = 'esm',
target = 'esnext',
min = '',
cli = false,
) => {
const path = await import('path');
const {default: esbuild} = await import('rollup-plugin-esbuild');
const {rollup} = await import('rollup');
const {default: replace} = await import('@rollup/plugin-replace');
const {default: prettierPlugin} = await import('rollup-plugin-prettier');
const {default: shebang} = await import('rollup-plugin-preserve-shebang');
const {default: image} = await import('@rollup/plugin-image');
const {default: terser} = await import('@rollup/plugin-terser');
let inputFile = `src/${module}/index.ts`;
if (!existsSync(inputFile)) {
inputFile += 'x';
}
const inputConfig = {
external: [
'cloudflare:workers',
'expo-sqlite',
'fs',
'fs/promises',
'path',
'prettier/standalone',
'prettier/plugins/estree',
'prettier/plugins/typescript',
'react',
'react-dom',
'url',
'yjs',
'tinybase/store',
'tinybase/tools',
'../ui-react',
],
input: inputFile,
plugins: [
esbuild({
target,
legalComments: 'inline',
}),
replace({
'/*!': '\n/*',
delimiters: ['', ''],
preventAssignment: true,
...(cli
? {
'../store/index.ts': 'tinybase/store',
'../tools/index.ts': 'tinybase/tools',
}
: {}),
'../ui-react/index.ts': '../ui-react',
}),
shebang(),
image(),
min
? [
terser({
toplevel: true,
compress: {
unsafe: true,
passes: 3,
...(module == 'tools'
? {reduce_vars: false, reduce_funcs: false}
: {}),
},
}),
]
: prettierPlugin(await getPrettierConfig()),
],
onwarn: (warning, warn) => {
if (warning.code !== 'MISSING_NODE_BUILTINS') {
warn(warning);
}
},
};
const moduleDir = dirname(await ensureDir(dir + '/' + module + '/-'));
const index = 'index.' + (format == 'cjs' ? 'c' : '') + 'js';
const outputConfig = {
dir: moduleDir,
entryFileNames: index,
format,
globals: {
'expo-sqlite': 'expo-sqlite',
'fs/promises': 'fs/promises',
'react-dom': 'ReactDOM',
'cloudflare:workers': 'cloudflare:workers',
fs: 'fs',
react: 'React',
yjs: 'yjs',
[path.resolve('src/ui-react')]: getGlobalName('ui-react'),
},
interop: 'default',
name: getGlobalName(module),
};
await (await rollup(inputConfig)).write(outputConfig);
// kill me now
const outputFile = join(moduleDir, index);
const outputFiles = [outputFile];
if (!cli) {
const outputFileWithSchemas = await ensureDir(
join(moduleDir, 'with-schemas', index),
);
outputFiles.push(outputFileWithSchemas);
await copyWithReplace(
outputFile,
['../ui-react', '../../ui-react/with-schemas/' + index],
outputFileWithSchemas,
);
}
await copyWithReplace(
outputFile,
['../ui-react', '../ui-react/' + index],
outputFile,
);
if (min) {
allOf(outputFiles, async (outputFile) => await gzipFile(outputFile));
}
};
// coverageMode = 0: none; 1: screen; 2: json; 3: html
const test = async (
dirs,
{coverageMode, countAsserts, puppeteer, serialTests} = {},
) => {
const {default: jest} = await import('jest');
await makeDir(TMP_DIR);
const {
results: {success},
} = await jest.runCLI(
{
roots: dirs,
setupFilesAfterEnv: ['./test/jest/setup'],
...(puppeteer
? {
setupFilesAfterEnv: ['expect-puppeteer'],
preset: 'jest-puppeteer',
detectOpenHandles: true,
maxWorkers: 2,
}
: {testEnvironment: './test/jest/environment'}),
...(coverageMode > 0
? {
collectCoverage: true,
coverageProvider: 'babel',
collectCoverageFrom: [
`${DIST_DIR}/index.js`,
`${DIST_DIR}/ui-react/index.js`,
// Other modules cannot be fully exercised in isolation.
],
coverageReporters: ['text-summary']
.concat(coverageMode > 1 ? ['json-summary'] : [])
.concat(coverageMode > 2 ? ['lcov'] : []),
coverageDirectory: 'tmp',
}
: {}),
...(countAsserts
? {
testEnvironment: './test/jest/environment',
reporters: ['default', './test/jest/reporter'],
runInBand: true,
}
: {}),
...(serialTests ? {runInBand: true} : {}),
},
[''],
);
if (!success) {
await removeDir(TMP_DIR);
throw 'Test failed';
}
if (coverageMode == 2) {
await promises.writeFile(
'coverage.json',
JSON.stringify({
...(countAsserts
? JSON.parse(await promises.readFile('./tmp/assertion-summary.json'))
: {}),
...JSON.parse(await promises.readFile('./tmp/coverage-summary.json'))
.total,
}),
UTF8,
);
}
if (coverageMode < 3) {
await removeDir(TMP_DIR);
}
};
const compileModulesForProd = async (fast = false) => {
await clearDir(DIST_DIR);
await copyPackageFiles(true);
await copyDefinitions(DIST_DIR);
await allOf(
[undefined, ...(fast ? [] : ['umd', 'cjs'])],
async (format) =>
await allOf(
[undefined, ...(fast ? [] : ['es6'])],
async (target) =>
await allModules(
async (module) =>
await allOf(
[undefined, ...(fast ? [] : ['min'])],
async (min) =>
await compileModule(
module,
`${DIST_DIR}/` +
[format, target, min]
.filter((part) => part != null)
.join('/'),
format,
target,
min,
),
),
),
),
);
await compileModule('cli', DIST_DIR, undefined, undefined, undefined, true);
await execute(`chmod +x ${DIST_DIR}/cli/index.js`);
};
const compileDocsAndAssets = async (api = true, pages = true) => {
const {default: esbuild} = await import('esbuild');
const {default: esbuildPlugin} = await import('rollup-plugin-esbuild');
const {default: terser} = await import('@rollup/plugin-terser');
const {rollup} = await import('rollup');
await makeDir(TMP_DIR);
await esbuild.build({
entryPoints: ['site/build.ts'],
external: ['tinydocs', 'react', '@prettier/sync'],
target: 'esnext',
bundle: true,
outfile: './tmp/build.js',
format: 'esm',
platform: 'node',
});
await (
await rollup({
input: 'node_modules/partysocket/dist/index.mjs',
plugins: [esbuildPlugin(), terser({toplevel: true, compress: true})],
})
).write({
dir: 'tmp',
entryFileNames: 'partysocket.js',
format: 'umd',
interop: 'default',
name: 'PartySocketModule',
exports: 'named',
});
// eslint-disable-next-line import/no-unresolved
const {build} = await import('./tmp/build.js');
await build(DOCS_DIR, api, pages);
await removeDir(TMP_DIR);
};
const npmInstall = async () => {
const {exec} = await import('child_process');
const {promisify} = await import('util');
return await promisify(exec)('npm install --legacy-peer-deps');
};
const npmPublish = async () => {
const {exec} = await import('child_process');
const {promisify} = await import('util');
return await promisify(exec)('npm publish');
};
const {parallel, series} = gulp;
// --
export const preparePackage = copyPackageFiles;
export const compileForTest = async () => {
await clearDir(DIST_DIR);
await copyPackageFiles();
await copyDefinitions(DIST_DIR);
await testModules(async (module) => {
await compileModule(module, DIST_DIR);
});
};
export const lintFiles = async () => await lintCheckFiles('.');
export const lintDocs = async () => await lintCheckDocs('src');
export const lint = parallel(lintFiles, lintDocs);
export const spell = async () => {
await spellCheck('.');
await spellCheck('src', true);
await spellCheck('test', true);
await spellCheck('site', true);
};
export const ts = async () => {
await tsCheck('src');
await tsCheck('test');
await tsCheck('site');
};
export const compileForProd = async () => await compileModulesForProd();
export const compileForProdFast = async () => await compileModulesForProd(true);
export const testUnit = async () => {
await test(['test/unit'], {coverageMode: 1, serialTests: true});
};
export const testUnitFast = async () => {
await test(['test/unit/core'], {coverageMode: 1});
};
export const testUnitCountAsserts = async () => {
await test(['test/unit'], {coverageMode: 2, countAsserts: true});
};
export const testUnitSaveCoverage = async () => {
await test(['test/unit/core'], {coverageMode: 3});
};
export const compileAndTestUnit = series(compileForTest, testUnit);
export const compileAndTestUnitFast = series(compileForTest, testUnitFast);
export const compileAndTestUnitSaveCoverage = series(
compileForTest,
testUnitSaveCoverage,
);
export const testPerf = async () => {
await test(['test/perf'], {serialTests: true});
};
export const compileAndTestPerf = series(compileForTest, testPerf);
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 testE2e = async () => {
await test(['test/e2e'], {puppeteer: true});
};
export const compileAndTestE2e = series(compileForProdAndDocs, testE2e);
export const testProd = async () => {
await execute('attw --pack dist --format table-flipped');
await test(['test/prod']);
};
export const compileAndTestProd = series(compileForProdAndDocs, testProd);
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,
compileForTest,
parallel(lint, spell, ts),
testUnitCountAsserts,
testPerf,
compileForProd,
testProd,
compileDocs,
testE2e,
);
export const publishPackage = series(prePublishPackage, npmPublish);