-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
client.ts
50 lines (48 loc) · 1.98 KB
/
client.ts
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
import path from 'path';
import { ChildProcess } from '@bcms/selfhosted-utils/child-process';
import { FS } from '@bcms/selfhosted-utils/fs';
import { buildCjs, buildMjs } from './utils/build';
import { packageJsonExport } from './utils/package-json';
import { getBackendVersion, getUtilsVersion } from './utils/versions';
export async function packClient() {
await ChildProcess.advancedExec('npm pack', {
cwd: path.join(process.cwd(), 'client', 'dist'),
onChunk(type, chunk) {
process[type].write(chunk);
},
}).awaiter;
}
export async function buildClient() {
const basePath = path.join(process.cwd(), 'client');
const localFs = new FS(basePath);
if (await localFs.exist(['dist'])) {
await localFs.deleteDir(['dist']);
}
await buildMjs(localFs, basePath, 'build:ts:mjs', 'dist');
await buildCjs(localFs, basePath, 'build:ts:cjs', 'dist');
const fileNames = await localFs.readdir(['dist', 'client', 'src']);
for (let i = 0; i < fileNames.length; i++) {
const fileName = fileNames[i];
await localFs.move(
['dist', 'client', 'src', fileName],
['dist', fileName],
);
}
await localFs.deleteDir(['dist', 'backend']);
await localFs.deleteDir(['dist', 'client']);
await localFs.copy('README.md', ['dist', 'README.md']);
await localFs.copy('LICENSE', ['dist', 'LICENSE']);
const packageJson = JSON.parse(await localFs.readString('package.json'));
packageJson.devDependencies = undefined;
packageJson.scripts = {};
const backendVersion = await getBackendVersion();
const utilsVersion = await getUtilsVersion();
packageJson.dependencies[backendVersion[0]] = '^' + backendVersion[1];
packageJson.dependencies[utilsVersion[0]] = '^' + utilsVersion[1];
let files = await localFs.fileTree(['dist'], '');
packageJsonExport(files, packageJson);
await localFs.save(
['dist', 'package.json'],
JSON.stringify(packageJson, null, 4),
);
}