Skip to content

Commit e13509c

Browse files
committed
feat: live-reload via CLI arg, CLI help, refactor
1 parent bd709ad commit e13509c

File tree

6 files changed

+132
-183
lines changed

6 files changed

+132
-183
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"sass": "^1.54.1",
7373
"unconfig": "^0.3.5",
7474
"vite": "^3.0.4",
75-
"vite-plugin-live-reload": "^3.0.0",
75+
"vite-plugin-full-reload": "^1.0.3",
7676
"vue": "^2.7.8"
7777
},
7878
"devDependencies": {

pnpm-lock.yaml

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/node/cli-start.ts

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,45 @@
11
import { cac } from 'cac'
22
import { name, version } from '../../package.json'
3-
import type { CliOptions } from './types'
43
import { build, serve } from './index'
54

6-
export async function startCli(
7-
cwd = process.cwd(),
8-
argv = process.argv,
9-
options: CliOptions = {},
10-
) {
5+
export async function startCli(cwd = process.cwd(), argv = process.argv) {
116
const cli = cac(name)
127

138
cli
14-
.command('serve [file]', 'Panel input file', {
15-
ignoreOptionDefaultValue: true,
16-
})
17-
.action(async (file, flags) => {
18-
Object.assign(options, {
19-
cwd,
20-
...flags,
21-
})
22-
23-
if (file)
24-
options.entry = file
25-
26-
const server = await serve(options)
27-
process.on('SIGINT', () => server.close())
28-
})
29-
30-
cli
31-
.command('[file]', 'Panel input file', {
32-
ignoreOptionDefaultValue: true,
33-
})
34-
.option('-d, --out-dir <dir>', 'Output directory', {
35-
default: cwd,
36-
})
9+
.command('<file>', 'Compile the panel plugin to index.js and index.css')
10+
.option('-d, --out-dir <dir>', 'Output directory', { default: cwd })
3711
.option(
3812
'-w, --watch [path]',
39-
'Watch for file changes. If no path is specified, the folder of the input file will be watched. Repeat "--watch" for multiple paths.',
13+
'Watch for file changes. If no path is specified, the folder of the input file will be watched',
14+
{ default: false },
4015
)
41-
.action(async (file: string, flags) => {
42-
Object.assign(options, {
43-
cwd,
44-
...flags,
45-
})
16+
.example('kirbyup src/index.js')
17+
.example('kirbyup src/index.js --out-dir ~/kirby-site/site/plugins/demo')
18+
.example('kirbyup src/index.js --watch src/**/*.{js,css} --watch assets/*\n')
19+
.action(async (file: string, options: { outDir: string; watch: boolean | string | string[] }) => {
20+
await build({ cwd, entry: file, ...options })
21+
})
4622

47-
if (file)
48-
options.entry = file
23+
cli
24+
.command('serve <file>', 'Start development server with live reload')
25+
.option('--no-watch', 'Don\'t watch .php files for changes', { default: '\0' })
26+
.option('-w, --watch <path>', 'Watch additional files', { default: './**/*.php' })
27+
.example('kirbyup serve src/index.js')
28+
.example('kirbyup serve src/index.js --no-watch')
29+
.example('kirbyup serve src/index.js --watch snippets/*.php --watch templates/*.php\n')
30+
.action(async (file: string, options: { watch: false | string | string[] }) => {
31+
const server = await serve({ cwd, entry: file, ...options })
4932

50-
await build(options)
33+
process.on('SIGINT', () => server.close())
34+
process.on('exit', () => server.close())
35+
process.on('uncaughtException', () => {
36+
process.exitCode = 1
37+
server.close()
38+
})
5139
})
5240

53-
cli.help()
41+
// Filter out unnecessary "default" output for negated options (zerobyte acts as marker)
42+
cli.help(s => s.map(msg => ({ ...msg, body: msg.body.replace(' (default: \0)', '') })))
5443
cli.version(version)
5544

5645
// Parse CLI args without running the command to

0 commit comments

Comments
 (0)