-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
backend.ts
111 lines (106 loc) · 3.71 KB
/
backend.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
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
import { ChildProcess } from '@bcms/selfhosted-utils/child-process';
import path from 'path';
import { FS } from '@bcms/selfhosted-utils/fs';
import { packageJsonExport } from './utils/package-json';
import { replaceStringInFile } from './utils/file';
import { buildCjs, buildMjs } from './utils/build';
import { getUtilsVersion } from './utils/versions';
export async function buildUtils() {
const basePath = path.join(process.cwd(), 'backend');
const localFs = new FS(basePath);
if (await localFs.exist(['dist-utils'])) {
await localFs.deleteDir(['dist-utils']);
}
await buildMjs(localFs, basePath, 'build:utils:mjs', 'dist-utils');
await buildCjs(localFs, basePath, 'build:utils:cjs', 'dist-utils');
const packageJson = JSON.parse(
await localFs.readString('utils.package.json'),
);
packageJson.devDependencies = undefined;
packageJson.scripts = undefined;
let files = await localFs.fileTree(['dist-utils'], '');
packageJsonExport(files, packageJson);
await localFs.save(
['dist-utils', 'package.json'],
JSON.stringify(packageJson, null, 4),
);
}
export async function packUtils() {
await ChildProcess.advancedExec('npm pack', {
cwd: path.join(process.cwd(), 'backend', 'dist-utils'),
onChunk(type, chunk) {
process[type].write(chunk);
},
}).awaiter;
}
export async function buildBackendPackage() {
const basePath = path.join(process.cwd(), 'backend');
const localFs = new FS(basePath);
if (await localFs.exist(['dist'])) {
await localFs.deleteDir(['dist']);
}
await ChildProcess.advancedExec('npm run build', {
cwd: basePath,
onChunk(type, chunk) {
process[type].write(chunk);
},
}).awaiter;
await localFs.deleteDir(['dist', '_utils']);
await replaceStringInFile({
endsWith: ['.js', '.d.ts'],
basePath: '',
dirPath: ['backend', 'dist'],
regex: [/@bcms\/selfhosted-backend/g],
});
const packageJson = JSON.parse(await localFs.readString('package.json'));
const utilsVersion = await getUtilsVersion();
packageJson.dependencies[utilsVersion[0]] = '^' + utilsVersion[1];
packageJson.devDependencies = undefined;
packageJson.scripts = undefined;
packageJson.nodemonConfig = undefined;
await localFs.save(
['dist', 'package.json'],
JSON.stringify(packageJson, null, 4),
);
}
export async function buildBackend() {
const basePath = path.join(process.cwd(), 'backend');
const localFs = new FS(basePath);
if (await localFs.exist(['dist'])) {
await localFs.deleteDir(['dist']);
}
await ChildProcess.advancedExec('npm run build', {
cwd: basePath,
onChunk(type, chunk) {
process[type].write(chunk);
},
}).awaiter;
await replaceStringInFile({
endsWith: ['.js', '.d.ts'],
basePath: '/_utils',
dirPath: ['backend', 'dist'],
regex: [/@bcms\/selfhosted-utils/g],
});
await replaceStringInFile({
endsWith: ['.js', '.d.ts'],
basePath: '',
dirPath: ['backend', 'dist'],
regex: [/@bcms\/selfhosted-backend/g],
});
const packageJson = JSON.parse(await localFs.readString('package.json'));
packageJson.devDependencies = undefined;
packageJson.scripts = undefined;
packageJson.nodemonConfig = undefined;
await localFs.save(
['dist', 'package.json'],
JSON.stringify(packageJson, null, 4),
);
}
export async function packBackend() {
await ChildProcess.advancedExec('npm pack', {
cwd: path.join(process.cwd(), 'backend', 'dist'),
onChunk(type, chunk) {
process[type].write(chunk);
},
}).awaiter;
}