kirbyup 3.4.0 → 3.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kirbyup",
3
3
  "type": "module",
4
- "version": "3.4.0",
4
+ "version": "3.4.1",
5
5
  "packageManager": "pnpm@10.15.1",
6
6
  "description": "Zero-config bundler for Kirby Panel plugins",
7
7
  "author": {
@@ -10,7 +10,7 @@
10
10
  "url": "https://johannschopplich.com"
11
11
  },
12
12
  "license": "MIT",
13
- "homepage": "https://github.com/johannschopplich/kirbyup#readme",
13
+ "homepage": "https://kirbyup.getkirby.com",
14
14
  "repository": {
15
15
  "type": "git",
16
16
  "url": "git+https://github.com/johannschopplich/kirbyup.git"
@@ -26,19 +26,19 @@
26
26
  ],
27
27
  "exports": {
28
28
  ".": {
29
- "types": "./dist/node/index.d.mts",
30
- "default": "./dist/node/index.mjs"
29
+ "types": "./dist/node/index.d.ts",
30
+ "default": "./dist/node/index.js"
31
31
  },
32
32
  "./config": {
33
- "types": "./dist/client/config.d.mts",
34
- "default": "./dist/client/config.mjs"
33
+ "types": "./dist/client/config.d.ts",
34
+ "default": "./dist/client/config.js"
35
35
  },
36
36
  "./plugin": {
37
- "types": "./dist/client/plugin.d.mts",
38
- "default": "./dist/client/plugin.mjs"
37
+ "types": "./dist/client/plugin.d.ts",
38
+ "default": "./dist/client/plugin.js"
39
39
  }
40
40
  },
41
- "types": "./dist/node/index.d.mts",
41
+ "types": "./dist/node/index.d.ts",
42
42
  "typesVersions": {
43
43
  "*": {
44
44
  "config": [
@@ -60,8 +60,7 @@
60
60
  "node": ">=18"
61
61
  },
62
62
  "scripts": {
63
- "build": "unbuild",
64
- "dev": "UNBUILD_STUB=true unbuild",
63
+ "build": "tsdown",
65
64
  "docs:dev": "vitepress dev docs",
66
65
  "docs:build": "vitepress build docs",
67
66
  "docs:preview": "vitepress preview docs",
@@ -75,7 +74,7 @@
75
74
  "@vitejs/plugin-vue2": "2.2.0",
76
75
  "@vitejs/plugin-vue2-jsx": "1.1.0",
77
76
  "@vue/compiler-sfc": "^2.7.16",
78
- "c12": "^3.2.0",
77
+ "c12": "~3.2.0",
79
78
  "cac": "^6.7.14",
80
79
  "chokidar": "^4.0.3",
81
80
  "consola": "^3.4.2",
@@ -87,22 +86,24 @@
87
86
  "postcss-load-config": "^6.0.1",
88
87
  "rollup-plugin-external-globals": "^0.13.0",
89
88
  "sass": "^1.92.1",
90
- "vite": "~6.3.6",
89
+ "vite": "^6.3.6",
91
90
  "vite-plugin-full-reload": "^1.2.0",
92
91
  "vue": "^2.7.16"
93
92
  },
94
93
  "devDependencies": {
95
94
  "@antfu/eslint-config": "^5.3.0",
96
95
  "@types/node": "^24.3.1",
97
- "@types/prompts": "^2.4.9",
98
96
  "bumpp": "^10.2.3",
99
97
  "eslint": "^9.35.0",
100
- "fast-glob": "^3.3.3",
98
+ "tinyglobby": "^0.2.15",
99
+ "tsdown": "^0.15.0",
101
100
  "typescript": "^5.9.2",
102
- "unbuild": "^3.6.1",
103
101
  "vitest": "^3.2.4"
104
102
  },
105
103
  "pnpm": {
104
+ "overrides": {
105
+ "vite": "^6.3.6"
106
+ },
106
107
  "onlyBuiltDependencies": [
107
108
  "@parcel/watcher",
108
109
  "esbuild"
@@ -1,6 +0,0 @@
1
- import { U as UserConfig } from '../shared/kirbyup.DNMktHWN.mjs';
2
- import 'vite';
3
-
4
- declare function defineConfig(config: UserConfig): UserConfig;
5
-
6
- export { defineConfig };
@@ -1,5 +0,0 @@
1
- function defineConfig(config) {
2
- return config;
3
- }
4
-
5
- export { defineConfig };
@@ -1,12 +0,0 @@
1
- declare const kirbyup: Readonly<{
2
- /**
3
- * Auto-import Kirby Panel components, transformed by
4
- * kirbyup's glob-import plugin for Vite.
5
- *
6
- * @example
7
- * kirbyup.import('./components/blocks/*.vue')
8
- */
9
- import(glob: string): Record<string, any>;
10
- }>;
11
-
12
- export { kirbyup };
@@ -1,24 +0,0 @@
1
- const kirbyup = Object.freeze({
2
- /**
3
- * Auto-import Kirby Panel components, transformed by
4
- * kirbyup's glob-import plugin for Vite.
5
- *
6
- * @example
7
- * kirbyup.import('./components/blocks/*.vue')
8
- */
9
- import(glob) {
10
- const modules = glob;
11
- return Object.entries(modules).reduce(
12
- (accumulator, [path, component]) => {
13
- accumulator[getComponentName(path)] = component.default;
14
- return accumulator;
15
- },
16
- {}
17
- );
18
- }
19
- });
20
- function getComponentName(path) {
21
- return path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf(".")).toLowerCase();
22
- }
23
-
24
- export { kirbyup };
@@ -1,2 +0,0 @@
1
-
2
- export { };
package/dist/node/cli.mjs DELETED
@@ -1,53 +0,0 @@
1
- import { cac } from 'cac';
2
- import { n as name, b as build, s as serve, v as version, h as handleError } from '../shared/kirbyup.Bxmi3UeO.mjs';
3
- import 'node:fs';
4
- import 'node:fs/promises';
5
- import '@vitejs/plugin-vue2';
6
- import '@vitejs/plugin-vue2-jsx';
7
- import 'consola';
8
- import 'consola/utils';
9
- import 'pathe';
10
- import 'perfect-debounce';
11
- import 'rollup-plugin-external-globals';
12
- import 'vite';
13
- import 'vite-plugin-full-reload';
14
- import 'vue/compiler-sfc';
15
- import 'c12';
16
- import 'postcss-load-config';
17
- import 'magic-string';
18
- import 'nypm';
19
- import 'node:buffer';
20
- import 'node:util';
21
- import 'node:zlib';
22
-
23
- async function startCli(cwd = process.cwd(), argv = process.argv) {
24
- const cli = cac(name);
25
- cli.command("<file>", "Compile the Kirby Panel plugin to index.js and index.css").option("-d, --out-dir <dir>", "Output directory", { default: cwd }).option(
26
- "-w, --watch [path]",
27
- "Watch for file changes. If no path is specified, the folder of the input file will be watched",
28
- { default: false }
29
- ).example("kirbyup src/index.js").example("kirbyup src/index.js --out-dir ~/kirby-site/site/plugins/demo").example("kirbyup src/index.js --watch src/**/*.{js,css} --watch assets/*\n").action(async (file, options) => {
30
- process.env.NODE_ENV ||= options.watch ? "development" : "production";
31
- await build({ cwd, entry: file, ...options });
32
- });
33
- cli.command("serve <file>", "Start development server with live reload").option("--no-watch", "Don't watch .php files for changes", { default: "\0" }).option("-w, --watch <path>", "Watch additional files", { default: "./**/*.php" }).option("-p, --port <number>", "Port for the development server", { default: 5177 }).option("-d, --out-dir <dir>", "Output directory").example("kirbyup serve src/index.js").example("kirbyup serve src/index.js --no-watch --port 3003").example("kirbyup serve src/index.js --watch snippets/*.php --watch templates/*.php\n").action(async (file, options) => {
34
- process.env.NODE_ENV ||= "development";
35
- const server = await serve({ cwd, entry: file, ...options });
36
- const exitProcess = async () => {
37
- try {
38
- await server.close();
39
- } finally {
40
- process.exit();
41
- }
42
- };
43
- process.once("SIGINT", exitProcess);
44
- });
45
- cli.help(
46
- (s) => s.map((msg) => ({ ...msg, body: msg.body.replace(" (default: \0)", "") }))
47
- );
48
- cli.version(version);
49
- cli.parse(argv, { run: false });
50
- await cli.runMatchedCommand();
51
- }
52
-
53
- startCli().catch(handleError);
@@ -1,7 +0,0 @@
1
- import * as vite from 'vite';
2
- import { B as BuildOptions, S as ServeOptions } from '../shared/kirbyup.DNMktHWN.mjs';
3
-
4
- declare function build(options: BuildOptions): Promise<void>;
5
- declare function serve(options: ServeOptions): Promise<vite.ViteDevServer>;
6
-
7
- export { build, serve };
@@ -1,20 +0,0 @@
1
- import 'node:fs';
2
- import 'node:fs/promises';
3
- import '@vitejs/plugin-vue2';
4
- import '@vitejs/plugin-vue2-jsx';
5
- import 'consola';
6
- import 'consola/utils';
7
- import 'pathe';
8
- import 'perfect-debounce';
9
- import 'rollup-plugin-external-globals';
10
- import 'vite';
11
- import 'vite-plugin-full-reload';
12
- import 'vue/compiler-sfc';
13
- export { b as build, s as serve } from '../shared/kirbyup.Bxmi3UeO.mjs';
14
- import 'c12';
15
- import 'postcss-load-config';
16
- import 'magic-string';
17
- import 'nypm';
18
- import 'node:buffer';
19
- import 'node:util';
20
- import 'node:zlib';
@@ -1,449 +0,0 @@
1
- import * as fs from 'node:fs';
2
- import * as fsp from 'node:fs/promises';
3
- import vuePlugin from '@vitejs/plugin-vue2';
4
- import vueJsxPlugin from '@vitejs/plugin-vue2-jsx';
5
- import { consola } from 'consola';
6
- import { colors } from 'consola/utils';
7
- import { resolve, normalize, relative, dirname, basename } from 'pathe';
8
- import { debounce } from 'perfect-debounce';
9
- import externalGlobals from 'rollup-plugin-external-globals';
10
- import { createLogger, createServer, build as build$1, mergeConfig } from 'vite';
11
- import fullReloadPlugin from 'vite-plugin-full-reload';
12
- import * as vueCompilerSfc from 'vue/compiler-sfc';
13
- import { loadConfig as loadConfig$1 } from 'c12';
14
- import postcssrc from 'postcss-load-config';
15
- import MagicString from 'magic-string';
16
- import { detectPackageManager } from 'nypm';
17
- import { Buffer } from 'node:buffer';
18
- import { promisify } from 'node:util';
19
- import { gzip } from 'node:zlib';
20
-
21
- const name = "kirbyup";
22
- const version = "3.4.0";
23
-
24
- function loadConfig(cwd = process.cwd()) {
25
- return loadConfig$1({
26
- cwd,
27
- name: "kirbyup",
28
- rcFile: false,
29
- packageJson: false
30
- });
31
- }
32
- async function resolvePostCSSConfig(cwd) {
33
- try {
34
- return await postcssrc(void 0, void 0, { stopDir: cwd });
35
- } catch (error) {
36
- if (!error.message.includes("No PostCSS Config found"))
37
- throw error;
38
- }
39
- }
40
-
41
- class PrettyError extends Error {
42
- constructor(message) {
43
- super(message);
44
- this.name = this.constructor.name;
45
- if (typeof Error.captureStackTrace === "function")
46
- Error.captureStackTrace(this, this.constructor);
47
- else
48
- this.stack = new Error(message).stack;
49
- }
50
- }
51
- function handleError(error) {
52
- consola.error(error.message);
53
- process.exitCode = 1;
54
- }
55
-
56
- function kirbyupBuildCleanupPlugin(options) {
57
- let config;
58
- let devIndexPath;
59
- return {
60
- name: "kirbyup:build-cleanup",
61
- configResolved(resolvedConfig) {
62
- config = resolvedConfig;
63
- devIndexPath = resolve(config.root, options.outDir, "index.dev.mjs");
64
- },
65
- writeBundle() {
66
- if (fs.existsSync(devIndexPath))
67
- fs.unlinkSync(devIndexPath);
68
- }
69
- };
70
- }
71
-
72
- const multilineCommentsRE = /\/\*(.|[\r\n])*?\*\//g;
73
- const singlelineCommentsRE = /\/\/.*/g;
74
- const HMR_RUNTIME_ID = "\0plugin-vue2:hmr-runtime";
75
- const JSX_HMR_RUNTIME_ID = "plugin-vue2-jsx:hmr-runtime";
76
- function isHmrRuntimeId(id) {
77
- return id === HMR_RUNTIME_ID || id === JSX_HMR_RUNTIME_ID;
78
- }
79
- const __INJECTED_HMR_CODE__ = `
80
- /** - injected by kirbyup - */
81
- for (const methodName of ['rerender', 'reload']) {
82
- const original = __VUE_HMR_RUNTIME__[methodName]
83
-
84
- __VUE_HMR_RUNTIME__[methodName] = function (id, updatedDef) {
85
- const key = updatedDef?.__file ? '__file' : updatedDef?.__hmrId ? '__hmrId' : null
86
-
87
- if (key) {
88
- const pluginComponents = window.panel.plugins.components
89
- // const usedComponentDefs = window.panel.app.$options.components
90
- const usedComponentDefs = window.panel.app._vnode.componentInstance.$options.components // #33
91
-
92
- for (const componentName in pluginComponents) {
93
- if (updatedDef[key] === pluginComponents[componentName][key]) {
94
- const usedDefinition = usedComponentDefs[componentName].options
95
-
96
- if (map[id].options !== usedDefinition)
97
- map[id].options = usedDefinition
98
-
99
- if (typeof map[id].options.$_isSection !== 'boolean')
100
- map[id].options.$_isSection = /^k-.*-section$/.test(componentName)
101
-
102
- break
103
- }
104
- }
105
- }
106
-
107
- return original.apply(this, arguments)
108
- }
109
- }
110
-
111
- function $_applyKirbyModifications(activeDef, newDef) {
112
- const usedComponentDefs = window.panel.app.$options.components
113
-
114
- if (newDef.template)
115
- newDef.render = null
116
-
117
- if (activeDef.$_isSection)
118
- newDef.$_isSection = true
119
- if (newDef.$_isSection && !newDef.mixins?.[0]?.methods?.load)
120
- newDef.mixins = [activeDef.mixins[0], ...(newDef.mixins || [])]
121
-
122
- if (typeof newDef.extends === 'string') {
123
- if (newDef.extends === activeDef.extends?.options?.name) {
124
- newDef.extends = activeDef.extends
125
- }
126
- else if (usedComponentDefs[newDef.extends]) {
127
- newDef.extends = usedComponentDefs[newDef.extends].extend({
128
- options: newDef,
129
- components: { ...usedComponentDefs, ...(newDef.components || {}) },
130
- })
131
- }
132
- else { newDef.extends = null }
133
- }
134
- }
135
- /** -- */
136
- `;
137
-
138
- function kirbyupGlobImportPlugin() {
139
- let config;
140
- return {
141
- name: "kirbyup:glob-import",
142
- configResolved(resolvedConfig) {
143
- config = resolvedConfig;
144
- },
145
- async transform(code) {
146
- if (!code.includes("kirbyup.import"))
147
- return;
148
- const kirbyupImportRE = /\bkirbyup\.import\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*\)/g;
149
- const noCommentsCode = code.replace(multilineCommentsRE, (m) => " ".repeat(m.length)).replace(singlelineCommentsRE, (m) => " ".repeat(m.length));
150
- let s;
151
- let match;
152
- while (match = kirbyupImportRE.exec(noCommentsCode)) {
153
- const { 0: exp, 1: rawPath, index } = match;
154
- if (!s)
155
- s = new MagicString(code);
156
- s.overwrite(
157
- index,
158
- index + exp.length,
159
- `kirbyup.import(import.meta.glob(${rawPath}, { eager: true }))`
160
- );
161
- }
162
- if (s) {
163
- return {
164
- code: s.toString(),
165
- map: config.build.sourcemap ? s.generateMap({ hires: true }) : void 0
166
- };
167
- }
168
- }
169
- };
170
- }
171
-
172
- function kirbyupHmrPlugin(options) {
173
- let config;
174
- let entry;
175
- let devIndexPath;
176
- return {
177
- name: "kirbyup:hmr",
178
- apply: "serve",
179
- configResolved(resolvedConfig) {
180
- config = resolvedConfig;
181
- entry = resolve(config.root, options.entry);
182
- devIndexPath = resolve(config.root, options.outDir || "", "index.dev.mjs");
183
- },
184
- transform(code, id) {
185
- if (isHmrRuntimeId(id)) {
186
- return code.replace(
187
- // https://github.com/vitejs/vite-plugin-vue2/blob/8de73ea6b8a1df4c14308da2885db195dacc2b14/src/utils/hmrRuntime.ts#L173
188
- /^.*=\s*record\.Ctor\.super\.extend\(options\)/m,
189
- "$_applyKirbyModifications(record.Ctor.options, options) // injected by kirbyup\n$&"
190
- ) + __INJECTED_HMR_CODE__;
191
- }
192
- },
193
- configureServer(server) {
194
- if (!server.httpServer)
195
- return;
196
- server.httpServer.once("listening", async () => {
197
- const entryPath = entry.replace(`${config.root}/`, "");
198
- const { address, family, port } = server.httpServer.address();
199
- const hostname = family === "IPv6" ? `[${address}]` : address;
200
- const baseUrl = `http://${hostname}:${port}${config.base}`;
201
- const entryUrl = new URL(entryPath, baseUrl).href;
202
- const pm = await detectPackageManager(config.root);
203
- await fsp.writeFile(devIndexPath, getViteProxyModule(entryUrl, pm));
204
- });
205
- },
206
- closeBundle() {
207
- if (fs.existsSync(devIndexPath))
208
- fs.unlinkSync(devIndexPath);
209
- }
210
- };
211
- }
212
- function getViteProxyModule(entryUrl, packageManager) {
213
- const pm = packageManager?.name || "npm";
214
- return `
215
- try {
216
- await import("${entryUrl}");
217
- } catch (err) {
218
- console.error(
219
- "[kirbyup] Couldn't connect to the development server. Run \`${pm} run serve\` to start Vite or build the plugin with \`${pm} run build\` so Kirby uses the production version."
220
- );
221
- throw err;
222
- }
223
- `.trimStart();
224
- }
225
-
226
- function toArray(array) {
227
- array ??= [];
228
- return Array.isArray(array) ? array : [array];
229
- }
230
- const compress = promisify(gzip);
231
- async function getCompressedSize(code) {
232
- const size = (await compress(typeof code === "string" ? code : Buffer.from(code))).length / 1024;
233
- return ` / gzip: ${size.toFixed(2)} KiB`;
234
- }
235
- async function printFileInfo({
236
- root,
237
- outDir,
238
- filePath,
239
- content,
240
- type,
241
- maxLength
242
- }) {
243
- const prettyOutDir = `${normalize(relative(root, resolve(root, outDir)))}/`;
244
- const kibs = content.length / 1024;
245
- const compressedSize = await getCompressedSize(content);
246
- const writeColor = type === "chunk" ? colors.cyan : colors.magenta;
247
- consola.log(
248
- colors.white(colors.dim(prettyOutDir)) + writeColor(filePath.padEnd(maxLength + 2)) + colors.dim(`${kibs.toFixed(2)} kB${compressedSize}`)
249
- );
250
- }
251
-
252
- let resolvedKirbyupConfig;
253
- let resolvedPostCssConfig;
254
- const logLevel = "warn";
255
- const logger = createLogger(logLevel);
256
- const loggerWarn = logger.warn;
257
- logger.warn = (msg, options) => {
258
- if (msg.includes("(!) build.outDir"))
259
- return;
260
- loggerWarn(msg, options);
261
- };
262
- function getViteConfig(command, options) {
263
- const aliasDir = resolve(options.cwd, dirname(options.entry));
264
- const { alias = {}, vite, extendViteConfig } = resolvedKirbyupConfig;
265
- const userConfig = vite ?? extendViteConfig ?? {};
266
- const sharedConfig = {
267
- resolve: {
268
- alias: {
269
- "~/": `${aliasDir}/`,
270
- "@/": `${aliasDir}/`,
271
- ...alias
272
- }
273
- },
274
- plugins: [
275
- // Explicitly pass the compiler, since the plugin's resolving of the compiler
276
- // looks in the current directory and breaks `npx kirbyup`
277
- vuePlugin({ compiler: vueCompilerSfc }),
278
- vueJsxPlugin(),
279
- kirbyupGlobImportPlugin(),
280
- { ...externalGlobals({ vue: "Vue" }), enforce: "post" }
281
- ],
282
- build: {
283
- copyPublicDir: false
284
- },
285
- ...resolvedPostCssConfig && {
286
- css: {
287
- postcss: resolvedPostCssConfig
288
- }
289
- },
290
- envDir: options.cwd,
291
- envPrefix: ["VITE_", "KIRBYUP_"],
292
- customLogger: logger,
293
- logLevel
294
- };
295
- if (command === "serve") {
296
- const { port, watch } = options;
297
- const serveConfig = mergeConfig(sharedConfig, {
298
- plugins: [
299
- kirbyupHmrPlugin(options),
300
- watch && fullReloadPlugin(watch)
301
- ].filter(Boolean),
302
- // Input needs to be specified so dependency pre-bundling works
303
- build: {
304
- rollupOptions: {
305
- input: resolve(options.cwd, options.entry)
306
- }
307
- },
308
- // Specify origin so asset URLs include Vite server host
309
- server: {
310
- port,
311
- strictPort: true,
312
- origin: `http://localhost:${port}`
313
- }
314
- });
315
- return mergeConfig(serveConfig, userConfig);
316
- }
317
- const mode = options.watch ? "development" : "production";
318
- const buildConfig = mergeConfig(sharedConfig, {
319
- mode,
320
- plugins: [kirbyupBuildCleanupPlugin(options)],
321
- build: {
322
- lib: {
323
- entry: resolve(options.cwd, options.entry),
324
- formats: ["iife"],
325
- name: "kirbyupExport",
326
- fileName: () => "index.js"
327
- },
328
- minify: mode === "production",
329
- outDir: options.outDir,
330
- emptyOutDir: false,
331
- rollupOptions: {
332
- output: {
333
- assetFileNames: "index.[ext]"
334
- }
335
- }
336
- }
337
- });
338
- return mergeConfig(buildConfig, userConfig);
339
- }
340
- async function generate(options) {
341
- const config = getViteConfig("build", options);
342
- let result;
343
- try {
344
- result = await build$1(config);
345
- } catch (error) {
346
- consola.error("Build failed");
347
- if (config.mode === "production")
348
- throw error;
349
- }
350
- if (result && !options.watch) {
351
- const { output } = toArray(result)[0];
352
- let maxLength = 0;
353
- for (const chunkFile in output) {
354
- const fileNameLength = output[chunkFile].fileName.length;
355
- if (fileNameLength > maxLength)
356
- maxLength = fileNameLength;
357
- }
358
- for (const { fileName, type, code } of output) {
359
- const content = code || await fsp.readFile(resolve(options.outDir, fileName), "utf8");
360
- await printFileInfo(
361
- {
362
- root: options.cwd,
363
- outDir: options.outDir,
364
- filePath: fileName,
365
- content,
366
- type,
367
- maxLength
368
- }
369
- );
370
- }
371
- }
372
- return result;
373
- }
374
- async function build(options) {
375
- assertEntryExists(options);
376
- const { cwd } = options;
377
- const { config, configFile } = await loadConfig(cwd);
378
- resolvedKirbyupConfig = config ?? {};
379
- resolvedPostCssConfig = await resolvePostCSSConfig(cwd);
380
- {
381
- consola.log(colors.green(`${name} v${version}`));
382
- consola.start(`Building ${colors.cyan(options.entry)}`);
383
- }
384
- if (options.watch)
385
- consola.info("Running in watch mode");
386
- const debouncedBuild = debounce(async () => {
387
- generate(options).catch(handleError);
388
- }, 100);
389
- const startWatcher = async () => {
390
- if (!options.watch)
391
- return;
392
- const { watch } = await import('chokidar');
393
- const ignored = [
394
- "**/{.git,node_modules}/**",
395
- // Always ignore dist files
396
- "index.{css,js}"
397
- ];
398
- const watchPaths = typeof options.watch === "boolean" ? dirname(options.entry) : Array.isArray(options.watch) ? options.watch.filter(
399
- (path) => typeof path === "string"
400
- ) : options.watch;
401
- consola.info(
402
- `Watching for changes in ${toArray(watchPaths).map((i) => colors.cyan(i)).join(", ")}`
403
- );
404
- const watcher = watch(watchPaths, {
405
- ignoreInitial: true,
406
- ignorePermissionErrors: true,
407
- ignored,
408
- cwd
409
- });
410
- if (configFile)
411
- watcher.add(configFile);
412
- watcher.on("all", async (type, file) => {
413
- const absolutePath = resolve(cwd, file);
414
- if (configFile === absolutePath) {
415
- resolvedKirbyupConfig = (await loadConfig(cwd)).config ?? {};
416
- consola.info(
417
- `${colors.cyan(basename(file))} changed, setting new config`
418
- );
419
- } else {
420
- consola.log(`${colors.green(type)} ${colors.white(colors.dim(file))}`);
421
- }
422
- debouncedBuild();
423
- });
424
- };
425
- await generate(options);
426
- consola.success("Build successful");
427
- startWatcher();
428
- }
429
- async function serve(options) {
430
- assertEntryExists(options);
431
- const { cwd } = options;
432
- const { config } = await loadConfig(cwd);
433
- resolvedKirbyupConfig = config ?? {};
434
- resolvedPostCssConfig = await resolvePostCSSConfig(cwd);
435
- {
436
- consola.log(colors.green(`${name} v${version}`));
437
- consola.info("Starting development server...");
438
- }
439
- const server = await createServer(getViteConfig("serve", options));
440
- await server.listen();
441
- consola.success(`Server is listening on :${server.config.server.port}`);
442
- return server;
443
- }
444
- function assertEntryExists(options) {
445
- if (!fs.existsSync(resolve(options.cwd, options.entry)))
446
- throw new PrettyError(`Cannot find "${options.entry}"`);
447
- }
448
-
449
- export { build as b, handleError as h, name as n, serve as s, version as v };