-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServeCommand.ts
More file actions
98 lines (83 loc) 路 2.17 KB
/
Copy pathServeCommand.ts
File metadata and controls
98 lines (83 loc) 路 2.17 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
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
/**
* @athenna/core
*
* (c) Jo茫o Lenon <lenon@athenna.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { Log } from '@athenna/logger'
import { Config } from '@athenna/config'
import { Path, Module } from '@athenna/common'
import { BaseCommand, Option } from '@athenna/artisan'
export class ServeCommand extends BaseCommand {
@Option({
signature: '-w, --watch',
description: 'Use nodemon to watch the application and restart on changes.',
default: false
})
public watch: boolean
public static signature(): string {
return 'serve'
}
public static description(): string {
return 'Serve your application.'
}
public async handle(): Promise<void> {
const entrypoint = Config.get(
'rc.commands.serve.entrypoint',
Path.bin(`main.${Path.ext()}`)
)
if (this.watch) {
const nodemon = this.getNodemon()
nodemon({
script: entrypoint.replace('.ts', '.js'),
ignore: [
'.git',
'.github',
'.idea',
'.vscode',
'.fleet',
'public',
'resources',
'*.{png,jpg,jpeg,csv,pdf}',
'vite.config.{js,ts,mjs}',
'node_modules/**/node_modules'
],
watch: [
'./',
'package.json',
'.athennarc.json',
'tsconfig.json',
'.env',
'.env.dev',
'.env.test',
'.env.testing',
'.env.example'
],
ext: '*.*',
...Config.get('rc.commands.serve.nodemon', {})
})
let isFirstRestart = true
nodemon
.on('start', async () => {
if (isFirstRestart) {
return
}
console.clear()
Log.channelOrVanilla('application').success(
'Application successfully restarted'
)
})
.on('restart', () => {
isFirstRestart = false
})
return
}
await Module.resolve(entrypoint, Config.get('rc.parentURL'))
}
public getNodemon() {
const require = Module.createRequire(import.meta.url)
return require('nodemon')
}
}