forked from SoftwareBrothers/adminjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.ts
executable file
·37 lines (32 loc) · 1.29 KB
/
cli.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
#!/usr/bin/env node
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable import/no-dynamic-require */
/* eslint-disable global-require */
import fs from 'fs'
import path from 'path'
import program from 'commander'
import AdminBro from './admin-bro'
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf-8'))
program.version(pkg.version)
program
.command('bundle <configFile>')
.description([
'Bundle all custom components addde by using AdminBro.bundle(filePath).',
'method. <configFile> argument is the path to your js file where you',
'export AdminBroOptions configuration object',
].join('\n '))
.action((configFile) => {
const config = require(path.join(process.cwd(), configFile))
if (!config.databases && !config.resources) {
// eslint-disable-next-line no-console
console.log([
'Are you sure you pointed to the right configuration file?.',
`'${path.join(process.cwd(), configFile)}' does not have neither`,
'"databases" nor "resources" properties.',
].join('\n'))
return
}
const bundler = require('../lib/backend/bundler/user-components-bundler').default
bundler(new AdminBro(config), { watch: false, write: true })
})
program.parse(process.argv)