-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.js
More file actions
71 lines (57 loc) · 2.02 KB
/
run.js
File metadata and controls
71 lines (57 loc) · 2.02 KB
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
const process= require('process');
process.removeAllListeners('warning');
const path = require('path');
const fse = require('fs-extra');
const argsMinimist = require('minimist')(process.argv);
const pathToDist = path.join(process.cwd(), 'dist');
const pathToDistApp = path.join(pathToDist, 'app.js');
try {
fse.ensureDirSync(path.join(process.cwd(), 'databases'));
} catch (error) {
}
try {
fse.ensureDirSync(path.join(process.cwd(), 'routes'));
} catch (error) {
}
const encoding = 'utf8';
var secondsWaitAfterDistDetected = 5;
function emptyDistFolder() {
return !(
fse.existsSync(pathToDist) &&
fse.lstatSync(pathToDist).isDirectory() &&
fse.existsSync(pathToDistApp) &&
fse.readFileSync(pathToDistApp, { encoding }).toString().search('default') !== -1
);
}
var messageWasShown = false;
while (emptyDistFolder()) {
var seconds = 2;
if (!messageWasShown) {
messageWasShown = true;
console.log(`Waiting for build process...`);
}
var waitTill = new Date(new Date().getTime() + seconds * 1000);
while (waitTill > new Date()) { }
}
if (messageWasShown) {
var waitTill = new Date(new Date().getTime() + secondsWaitAfterDistDetected * 1000);
while (waitTill > new Date()) { }
}
const PROJECT_NPM_NAME = require('./dist/lib/build-info._auto-generated_.js').PROJECT_NPM_NAME;
console.log({PROJECT_NPM_NAME});
var app = require('./dist/app').default;
var ContextsEndpointStorageInstance = globalThis['$$$ContextsEndpointStorage$$$'];
app({
onlyMigrationRun: argsMinimist.onlyMigrationRun,
onlyMigrationRevertToTimestamp: argsMinimist.onlyMigrationRevertToTimestamp,
args: [process.argv.slice(2).map(c => `"${c}"`).join(',')]
}).then(async () => {
const endpoints = ContextsEndpointStorageInstance.arr || [];
await Promise.all(endpoints.map(c => c.initControllersHook(ContextsEndpointStorageInstance)));
console.log(ContextsEndpointStorageInstance.SPECIAL_APP_READY_MESSAGE);
}).catch(err => {
console.error(err);
console.error('App Start Error');
process.exit(1);
});
process.stdin.resume();