-
Notifications
You must be signed in to change notification settings - Fork 8
/
tools.js
99 lines (81 loc) · 1.9 KB
/
tools.js
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
const fs = require('fs');
const path = require('path');
const {program} = require('commander');
const pLimit = require('p-limit');
program
.name(' ')
.usage(
`
Force sync database schema (drop tables then create).
node tools.js sync
Remove database file.
node tools.js rmdb
Build electron app.
node tools.js build`);
program
.command('sync')
.description('sync database schema');
program
.command('rmdb')
.description('remove database');
program
.command('build')
.description('build electron app');
program.parse(process.argv);
function removeDatabase() {
const {DATABASE_PATH} = require('./src/main-process/common/database');
console.log(`remove ${DATABASE_PATH}`);
fs.rmSync(DATABASE_PATH, {force: true});
return Promise.resolve();
}
async function sync() {
const {connectDatabase, DATABASE_PATH} = require('./src/main-process/common/database');
const limit = pLimit(1);
fs.rmSync(DATABASE_PATH, {force: true});
connectDatabase({isLogSQL: true});
const models = require('./src/main-process/models/data');
await Promise.all(
Object.values(models.sequelize.models).map(model => limit(() => model.sync({force: true}))),
);
}
function build() {
return require('electron-builder')
.build({
x64: true,
projectDir: path.resolve(__dirname),
win: ['portable'],
mac: ['dmg'],
config: {
copyright: 'Copyright © 2022 kelp404',
directories: {
output: 'dist',
},
files: [
'package.json',
'dist/main-process/**/*',
'dist/renderer-process/**/*',
'dist/shared/**/*',
],
extends: null,
},
});
}
async function execute() {
const {args} = program;
if (args[0] === 'sync') {
return sync();
}
if (args[0] === 'rmdb') {
return removeDatabase();
}
if (args[0] === 'build') {
return build();
}
return program.help();
}
execute()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});