-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_init.js
More file actions
54 lines (49 loc) · 1.63 KB
/
_init.js
File metadata and controls
54 lines (49 loc) · 1.63 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
const { execSync, execFileSync } = require('child_process');
require('dotenv').config();
function getConnectionInfo (env) {
const { URI, PROTOCOL, HOST, PORT, DATABASE, USERNAME, PASSWORD } = env;
if (URI) {
const { protocol, username, password, hostname, port, pathname } = new URL(URI);
return {
protocol: protocol.replace(':', '').trim(),
hostname,
port,
database: pathname?.substring(1),
username,
password
};
} else if (HOST && DATABASE && USERNAME && PASSWORD) {
// PROTOCOL and PORT can be undefined
return {
protocol: PROTOCOL,
hostname: HOST,
port: PORT,
database: DATABASE,
username: USERNAME,
password: PASSWORD
};
} else {
console.error('not enough configuration provided');
console.error(`URI: ${URI}, PROTOCOL: ${PROTOCOL}, HOST: ${HOST}, PORT:${PORT}, DATABASE: ${DATABASE}, USERNAME: ${USERNAME}, PASSWORD: ${PASSWORD}`);
process.exit(1);
}
}
function initiate () {
const { protocol, hostname, port, database, username, password } = getConnectionInfo(process.env);
try {
execSync('rm -rf src/models dist');
const args = ['node_modules/sequelize-auto/bin/sequelize-auto', '-o', './src/models', '-d', database, '-h', hostname, '-u', username, '-x', password, '-l', 'es6', '-a', '.sequelize-auto.config.json'];
if (port) {
args.push('-p', port);
}
if (protocol) {
args.push('-e', protocol);
}
execFileSync('node', args);
execSync('npx tsc --build');
} catch (e) {
console.error(e);
process.exit(1);
}
}
initiate();