-
-
Notifications
You must be signed in to change notification settings - Fork 247
Expand file tree
/
Copy pathapi-generate.js
More file actions
35 lines (31 loc) · 1 KB
/
api-generate.js
File metadata and controls
35 lines (31 loc) · 1 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
const child_process = require('node:child_process')
const os = require('node:os')
const path = require('node:path')
const { styleText } = require('node:util')
const Store = require('electron-store')
// When running outside Electron, electron-store can't resolve app data path.
// Provide it explicitly via the `cwd` option.
const appDataDir = path.join(
os.homedir(),
'Library',
'Application Support',
'massCode',
'v2',
)
const store = new Store({ name: 'preferences', cwd: appDataDir })
const apiPort = store.get('apiPort', 4321)
const url = `http://localhost:${apiPort}/swagger/json`
async function generateApi() {
try {
console.log(styleText('blue', 'Generating API...'))
child_process.execSync(
`npx swagger-typescript-api@13.0.23 -p ${url} -o ./src/renderer/services/api/generated -n index.ts`,
)
console.log(styleText('green', 'API is successfully generated'))
}
catch (err) {
console.log(styleText('red', 'Error generating API'))
console.log(err)
}
}
generateApi()