kirbyup 0.21.0 → 0.22.2

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/README.md CHANGED
@@ -11,8 +11,9 @@ The fastest and leanest way to bundle your Kirby Panel plugins. No configuration
11
11
  - 🔍 Watch mode
12
12
  - \*️⃣ `kirbyup.import` to [auto-import blocks & fields](#auto-import-blocks-and-fields)
13
13
  - 🎒 [PostCSS support](#postcss)
14
- - 🧭 [`~/` path resolve alias](#path-resolve-alias)
14
+ - 🧭 [Path resolve aliases](#path-resolve-aliases)
15
15
  - 🔌 [Env variables support](#env-variables)
16
+ - 🦔 [Extendable configuration with `kirbyup.config.js`](#extendable-configuration-with-kirbyupconfigjs)
16
17
 
17
18
  ## Requirements
18
19
 
@@ -58,7 +59,7 @@ Example package configuration:
58
59
  "build": "kirbyup src/index.js"
59
60
  },
60
61
  "devDependencies": {
61
- "kirbyup": "^0.20.1"
62
+ "kirbyup": "latest"
62
63
  }
63
64
  }
64
65
  ```
@@ -106,7 +107,7 @@ If no configuration file is found, kirbyup will apply two PostCSS plugins which
106
107
  - [postcss-logical](https://github.com/csstools/postcss-logical) lets you use logical, rather than physical, direction and dimension mappings in CSS, following the [CSS Logical Properties and Values](https://drafts.csswg.org/css-logical/) specification.
107
108
  - [postcss-dir-pseudo-class](https://github.com/csstools/postcss-dir-pseudo-class) lets you style by directionality using the `:dir()` pseudo-class in CSS, following the [Selectors](https://www.w3.org/TR/selectors-4/#the-dir-pseudo) specification. It gives you the same syntax Kirby uses for full compatibility with RTL localizations of the Panel.
108
109
 
109
- ### Path Resolve Alias
110
+ ### Path Resolve Aliases
110
111
 
111
112
  Import certain modules more easily by using the `~/` path alias. It will resolve to the directory of your input file, for example `src` when building `kirbyup src/index.js`.
112
113
 
@@ -187,6 +188,38 @@ KIRBYUP_SOME_KEY=123
187
188
 
188
189
  Only `KIRBYUP_SOME_KEY` will be exposed as `import.meta.env.VITE_SOME_KEY` to your plugin's source code, but `DB_PASSWORD` will not.
189
190
 
191
+ ### Extendable Configuration With `kirbyup.config.js`
192
+
193
+ Create a `kirbyup.config.js` or `kirbyup.config.ts` configuration file the root-level of your project to customize kirbyup.
194
+
195
+ ```js
196
+ import { resolve } from 'path'
197
+ import { defineConfig } from 'kirbyup'
198
+
199
+ export default defineConfig({
200
+ alias: {
201
+ '#deep/': `${resolve(__dirname, 'src/deep')}/`
202
+ },
203
+ extendViteConfig: {
204
+ build: {
205
+ lib: {
206
+ name: 'myPlugin'
207
+ }
208
+ }
209
+ }
210
+ })
211
+ ```
212
+
213
+ #### `alias`
214
+
215
+ When aliasing to file system paths, always use absolute paths. Relative alias values will be used as-is and will not be resolved into file system paths.
216
+
217
+ #### `extendViteConfig`
218
+
219
+ You can build upon the defaults kirbup uses and extend the Vite configuration with custom plugins etc.
220
+
221
+ For a complete list of options, take a look at the [Vite configuration options](https://vitejs.dev/config/).
222
+
190
223
  ## Options
191
224
 
192
225
  > Inspect all available options with `kirbyup --help`.
@@ -206,4 +239,4 @@ Sets the watch mode. If no path is specified, kirbyup watches the folder of the
206
239
 
207
240
  ## License
208
241
 
209
- MIT
242
+ [MIT](./LICENSE) License © 2021 [Johann Schopplich](https://github.com/johannschopplich)
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require('../dist/cli.cjs')
@@ -0,0 +1,298 @@
1
+ 'use strict';
2
+
3
+ const pathe = require('pathe');
4
+ const fs = require('fs');
5
+ const vite = require('vite');
6
+ const vitePluginVue2 = require('vite-plugin-vue2');
7
+ const MagicString = require('magic-string');
8
+ const unconfig = require('unconfig');
9
+ const postcssrc = require('postcss-load-config');
10
+ const postcssLogical = require('postcss-logical');
11
+ const postcssDirPseudoClass = require('postcss-dir-pseudo-class');
12
+ const consola = require('consola');
13
+ const colorette = require('colorette');
14
+ const promises = require('fs/promises');
15
+ const zlib = require('zlib');
16
+ const util = require('util');
17
+
18
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
19
+
20
+ const MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
21
+ const postcssrc__default = /*#__PURE__*/_interopDefaultLegacy(postcssrc);
22
+ const postcssLogical__default = /*#__PURE__*/_interopDefaultLegacy(postcssLogical);
23
+ const postcssDirPseudoClass__default = /*#__PURE__*/_interopDefaultLegacy(postcssDirPseudoClass);
24
+ const consola__default = /*#__PURE__*/_interopDefaultLegacy(consola);
25
+
26
+ const multilineCommentsRE = /\/\*(.|[\r\n])*?\*\//gm;
27
+ const singlelineCommentsRE = /\/\/.*/g;
28
+
29
+ function kirbyupAutoImportPlugin() {
30
+ let config;
31
+ return {
32
+ name: "kirbyup:auto-import",
33
+ configResolved(resolvedConfig) {
34
+ config = resolvedConfig;
35
+ },
36
+ async transform(code, id) {
37
+ if (code.includes("kirbyup.import")) {
38
+ const kirbyupImportRE = /\bkirbyup\.import\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*\)/g;
39
+ const noCommentsCode = code.replace(multilineCommentsRE, (m) => " ".repeat(m.length)).replace(singlelineCommentsRE, (m) => " ".repeat(m.length));
40
+ let s = null;
41
+ let match;
42
+ while (match = kirbyupImportRE.exec(noCommentsCode)) {
43
+ const { 0: exp, 1: rawPath, index } = match;
44
+ if (!s)
45
+ s = new MagicString__default(code);
46
+ s.overwrite(index, index + exp.length, `kirbyup.import(import.meta.globEager(${rawPath}))`);
47
+ }
48
+ if (s) {
49
+ return {
50
+ code: s.toString(),
51
+ map: config.build.sourcemap ? s.generateMap({ hires: true }) : null
52
+ };
53
+ }
54
+ }
55
+ return null;
56
+ }
57
+ };
58
+ }
59
+
60
+ function defineConfig(config) {
61
+ return config;
62
+ }
63
+ function createConfigLoader(configOrPath = process.cwd(), extraConfigSources = []) {
64
+ let inlineConfig = {};
65
+ if (typeof configOrPath !== "string") {
66
+ inlineConfig = configOrPath;
67
+ configOrPath = process.cwd();
68
+ }
69
+ const resolved = pathe.resolve(configOrPath);
70
+ let cwd = resolved;
71
+ let isFile = false;
72
+ if (fs.existsSync(resolved) && fs.statSync(resolved).isFile()) {
73
+ isFile = true;
74
+ cwd = pathe.dirname(resolved);
75
+ }
76
+ const loader = unconfig.createConfigLoader({
77
+ sources: isFile ? [
78
+ {
79
+ files: resolved,
80
+ extensions: []
81
+ }
82
+ ] : [
83
+ {
84
+ files: ["kirbyup.config"]
85
+ },
86
+ ...extraConfigSources
87
+ ],
88
+ cwd,
89
+ defaults: inlineConfig
90
+ });
91
+ return async () => {
92
+ const result = await loader.load();
93
+ result.config = result.config || inlineConfig;
94
+ return result;
95
+ };
96
+ }
97
+
98
+ class PrettyError extends Error {
99
+ constructor(message) {
100
+ super(message);
101
+ this.name = this.constructor.name;
102
+ if (typeof Error.captureStackTrace === "function") {
103
+ Error.captureStackTrace(this, this.constructor);
104
+ } else {
105
+ this.stack = new Error(message).stack;
106
+ }
107
+ }
108
+ }
109
+ function handleError(error) {
110
+ if (error instanceof PrettyError) {
111
+ consola__default.error(error.message);
112
+ }
113
+ process.exitCode = 1;
114
+ }
115
+
116
+ const compress = util.promisify(zlib.gzip);
117
+ async function getCompressedSize(code) {
118
+ const size = (await compress(typeof code === "string" ? code : Buffer.from(code))).length / 1024;
119
+ return ` / gzip: ${size.toFixed(2)} KiB`;
120
+ }
121
+ async function printFileInfo(root, outDir, filePath, type, content) {
122
+ content ?? (content = await promises.readFile(pathe.resolve(outDir, filePath), "utf8"));
123
+ const prettyOutDir = pathe.normalize(pathe.relative(root, pathe.resolve(root, outDir))) + "/";
124
+ const kibs = content.length / 1024;
125
+ const compressedSize = await getCompressedSize(content);
126
+ const writeColor = type === "chunk" ? colorette.cyan : colorette.magenta;
127
+ consola__default.log(colorette.white(colorette.dim(prettyOutDir)) + writeColor(filePath) + " " + colorette.dim(`${kibs.toFixed(2)} KiB${compressedSize}`));
128
+ }
129
+ function debouncePromise(fn, delay, onError) {
130
+ let timeout;
131
+ let promiseInFly;
132
+ let callbackPending;
133
+ return function debounced(...args) {
134
+ if (promiseInFly) {
135
+ callbackPending = () => {
136
+ debounced(...args);
137
+ callbackPending = void 0;
138
+ };
139
+ } else {
140
+ if (timeout)
141
+ clearTimeout(timeout);
142
+ timeout = setTimeout(() => {
143
+ timeout = void 0;
144
+ promiseInFly = fn(...args).catch(onError).finally(() => {
145
+ promiseInFly = void 0;
146
+ if (callbackPending)
147
+ callbackPending();
148
+ });
149
+ }, delay);
150
+ }
151
+ };
152
+ }
153
+
154
+ // src/math.ts
155
+
156
+ // src/array.ts
157
+ function toArray(array) {
158
+ array = array || [];
159
+ if (Array.isArray(array))
160
+ return array;
161
+ return [array];
162
+ }
163
+
164
+ const name = "kirbyup";
165
+ const version = "0.22.2";
166
+
167
+ let resolvedKirbyupConfig;
168
+ let resolvedPostCssConfig;
169
+ async function viteBuild(options) {
170
+ let result;
171
+ const mode = options.watch ? "development" : "production";
172
+ const root = process.cwd();
173
+ const outDir = options.outDir ?? root;
174
+ const aliasDir = pathe.resolve(root, pathe.dirname(options.entry));
175
+ const { alias = {}, extendViteConfig = {} } = resolvedKirbyupConfig;
176
+ const defaultConfig = {
177
+ mode,
178
+ plugins: [vitePluginVue2.createVuePlugin(), kirbyupAutoImportPlugin()],
179
+ build: {
180
+ lib: {
181
+ entry: pathe.resolve(root, options.entry),
182
+ formats: ["iife"],
183
+ name: "kirbyupExport",
184
+ fileName: () => "index.js"
185
+ },
186
+ minify: mode === "production",
187
+ outDir,
188
+ emptyOutDir: false,
189
+ rollupOptions: {
190
+ external: ["vue"],
191
+ output: {
192
+ assetFileNames: "index.[ext]",
193
+ globals: {
194
+ vue: "Vue"
195
+ }
196
+ }
197
+ }
198
+ },
199
+ resolve: {
200
+ alias: {
201
+ "~/": `${aliasDir}/`,
202
+ "@/": `${aliasDir}/`,
203
+ ...alias
204
+ }
205
+ },
206
+ css: {
207
+ postcss: resolvedPostCssConfig
208
+ },
209
+ envPrefix: ["VITE_", "KIRBYUP_"],
210
+ logLevel: "warn"
211
+ };
212
+ try {
213
+ result = await vite.build(vite.mergeConfig(defaultConfig, extendViteConfig));
214
+ } catch (error) {
215
+ consola__default.error("Build failed");
216
+ if (mode === "production") {
217
+ throw error;
218
+ }
219
+ }
220
+ if (result && !options.watch) {
221
+ const { output } = toArray(result)[0];
222
+ for (const { fileName, type, code } of output) {
223
+ printFileInfo(root, outDir, fileName, type, code);
224
+ }
225
+ }
226
+ return result;
227
+ }
228
+ async function resolveOptions(options) {
229
+ if (!options.entry) {
230
+ throw new PrettyError("No input file, try " + colorette.cyan(`${name} <path/to/file.js>`));
231
+ }
232
+ if (!fs.existsSync(options.entry)) {
233
+ throw new PrettyError(`Cannot find ${options.entry}`);
234
+ }
235
+ return options;
236
+ }
237
+ async function build(_options) {
238
+ const options = await resolveOptions(_options);
239
+ const loadConfig = createConfigLoader();
240
+ const { config, sources: configSources } = await loadConfig();
241
+ resolvedKirbyupConfig = config;
242
+ try {
243
+ resolvedPostCssConfig = await postcssrc__default({});
244
+ } catch (err) {
245
+ if (!/No PostCSS Config found/.test(err.message)) {
246
+ throw err;
247
+ }
248
+ resolvedPostCssConfig = {
249
+ plugins: [postcssLogical__default(), postcssDirPseudoClass__default()]
250
+ };
251
+ }
252
+ consola__default.log(colorette.green(`${name} v${version}`));
253
+ consola__default.start("Building " + colorette.cyan(options.entry));
254
+ if (options.watch) {
255
+ consola__default.info("Running in watch mode");
256
+ }
257
+ const debouncedBuild = debouncePromise(async () => {
258
+ viteBuild(options);
259
+ }, 100, handleError);
260
+ const startWatcher = async () => {
261
+ if (!options.watch)
262
+ return;
263
+ const { watch } = await import('chokidar');
264
+ const ignored = [
265
+ "**/{.git,node_modules}/**",
266
+ "index.{css,js}"
267
+ ];
268
+ const watchPaths = typeof options.watch === "boolean" ? pathe.dirname(options.entry) : Array.isArray(options.watch) ? options.watch.filter((path) => typeof path === "string") : options.watch;
269
+ consola__default.info("Watching for changes in " + toArray(watchPaths).map((i) => colorette.cyan(i)).join(", "));
270
+ const watcher = watch(watchPaths, {
271
+ ignoreInitial: true,
272
+ ignorePermissionErrors: true,
273
+ ignored
274
+ });
275
+ if (configSources.length) {
276
+ watcher.add(configSources);
277
+ }
278
+ watcher.on("all", async (type, file) => {
279
+ if (configSources.includes(file)) {
280
+ resolvedKirbyupConfig = (await loadConfig()).config;
281
+ consola__default.info(`${colorette.cyan(pathe.basename(file))} changed, setting new config`);
282
+ } else {
283
+ consola__default.log(colorette.green(type) + " " + colorette.white(colorette.dim(file)));
284
+ }
285
+ debouncedBuild();
286
+ });
287
+ };
288
+ await viteBuild(options);
289
+ consola__default.success("Build successful");
290
+ startWatcher();
291
+ }
292
+
293
+ exports.build = build;
294
+ exports.defineConfig = defineConfig;
295
+ exports.handleError = handleError;
296
+ exports.name = name;
297
+ exports.resolveOptions = resolveOptions;
298
+ exports.version = version;
@@ -0,0 +1,283 @@
1
+ import { resolve, dirname, normalize, relative, basename } from 'pathe';
2
+ import { existsSync, statSync } from 'fs';
3
+ import { build as build$1, mergeConfig } from 'vite';
4
+ import { createVuePlugin } from 'vite-plugin-vue2';
5
+ import MagicString from 'magic-string';
6
+ import { createConfigLoader as createConfigLoader$1 } from 'unconfig';
7
+ import postcssrc from 'postcss-load-config';
8
+ import postcssLogical from 'postcss-logical';
9
+ import postcssDirPseudoClass from 'postcss-dir-pseudo-class';
10
+ import consola from 'consola';
11
+ import { white, dim, cyan, magenta, green } from 'colorette';
12
+ import { readFile } from 'fs/promises';
13
+ import { gzip } from 'zlib';
14
+ import { promisify } from 'util';
15
+
16
+ const multilineCommentsRE = /\/\*(.|[\r\n])*?\*\//gm;
17
+ const singlelineCommentsRE = /\/\/.*/g;
18
+
19
+ function kirbyupAutoImportPlugin() {
20
+ let config;
21
+ return {
22
+ name: "kirbyup:auto-import",
23
+ configResolved(resolvedConfig) {
24
+ config = resolvedConfig;
25
+ },
26
+ async transform(code, id) {
27
+ if (code.includes("kirbyup.import")) {
28
+ const kirbyupImportRE = /\bkirbyup\.import\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*\)/g;
29
+ const noCommentsCode = code.replace(multilineCommentsRE, (m) => " ".repeat(m.length)).replace(singlelineCommentsRE, (m) => " ".repeat(m.length));
30
+ let s = null;
31
+ let match;
32
+ while (match = kirbyupImportRE.exec(noCommentsCode)) {
33
+ const { 0: exp, 1: rawPath, index } = match;
34
+ if (!s)
35
+ s = new MagicString(code);
36
+ s.overwrite(index, index + exp.length, `kirbyup.import(import.meta.globEager(${rawPath}))`);
37
+ }
38
+ if (s) {
39
+ return {
40
+ code: s.toString(),
41
+ map: config.build.sourcemap ? s.generateMap({ hires: true }) : null
42
+ };
43
+ }
44
+ }
45
+ return null;
46
+ }
47
+ };
48
+ }
49
+
50
+ function defineConfig(config) {
51
+ return config;
52
+ }
53
+ function createConfigLoader(configOrPath = process.cwd(), extraConfigSources = []) {
54
+ let inlineConfig = {};
55
+ if (typeof configOrPath !== "string") {
56
+ inlineConfig = configOrPath;
57
+ configOrPath = process.cwd();
58
+ }
59
+ const resolved = resolve(configOrPath);
60
+ let cwd = resolved;
61
+ let isFile = false;
62
+ if (existsSync(resolved) && statSync(resolved).isFile()) {
63
+ isFile = true;
64
+ cwd = dirname(resolved);
65
+ }
66
+ const loader = createConfigLoader$1({
67
+ sources: isFile ? [
68
+ {
69
+ files: resolved,
70
+ extensions: []
71
+ }
72
+ ] : [
73
+ {
74
+ files: ["kirbyup.config"]
75
+ },
76
+ ...extraConfigSources
77
+ ],
78
+ cwd,
79
+ defaults: inlineConfig
80
+ });
81
+ return async () => {
82
+ const result = await loader.load();
83
+ result.config = result.config || inlineConfig;
84
+ return result;
85
+ };
86
+ }
87
+
88
+ class PrettyError extends Error {
89
+ constructor(message) {
90
+ super(message);
91
+ this.name = this.constructor.name;
92
+ if (typeof Error.captureStackTrace === "function") {
93
+ Error.captureStackTrace(this, this.constructor);
94
+ } else {
95
+ this.stack = new Error(message).stack;
96
+ }
97
+ }
98
+ }
99
+ function handleError(error) {
100
+ if (error instanceof PrettyError) {
101
+ consola.error(error.message);
102
+ }
103
+ process.exitCode = 1;
104
+ }
105
+
106
+ const compress = promisify(gzip);
107
+ async function getCompressedSize(code) {
108
+ const size = (await compress(typeof code === "string" ? code : Buffer.from(code))).length / 1024;
109
+ return ` / gzip: ${size.toFixed(2)} KiB`;
110
+ }
111
+ async function printFileInfo(root, outDir, filePath, type, content) {
112
+ content ?? (content = await readFile(resolve(outDir, filePath), "utf8"));
113
+ const prettyOutDir = normalize(relative(root, resolve(root, outDir))) + "/";
114
+ const kibs = content.length / 1024;
115
+ const compressedSize = await getCompressedSize(content);
116
+ const writeColor = type === "chunk" ? cyan : magenta;
117
+ consola.log(white(dim(prettyOutDir)) + writeColor(filePath) + " " + dim(`${kibs.toFixed(2)} KiB${compressedSize}`));
118
+ }
119
+ function debouncePromise(fn, delay, onError) {
120
+ let timeout;
121
+ let promiseInFly;
122
+ let callbackPending;
123
+ return function debounced(...args) {
124
+ if (promiseInFly) {
125
+ callbackPending = () => {
126
+ debounced(...args);
127
+ callbackPending = void 0;
128
+ };
129
+ } else {
130
+ if (timeout)
131
+ clearTimeout(timeout);
132
+ timeout = setTimeout(() => {
133
+ timeout = void 0;
134
+ promiseInFly = fn(...args).catch(onError).finally(() => {
135
+ promiseInFly = void 0;
136
+ if (callbackPending)
137
+ callbackPending();
138
+ });
139
+ }, delay);
140
+ }
141
+ };
142
+ }
143
+
144
+ // src/math.ts
145
+
146
+ // src/array.ts
147
+ function toArray(array) {
148
+ array = array || [];
149
+ if (Array.isArray(array))
150
+ return array;
151
+ return [array];
152
+ }
153
+
154
+ const name = "kirbyup";
155
+ const version = "0.22.2";
156
+
157
+ let resolvedKirbyupConfig;
158
+ let resolvedPostCssConfig;
159
+ async function viteBuild(options) {
160
+ let result;
161
+ const mode = options.watch ? "development" : "production";
162
+ const root = process.cwd();
163
+ const outDir = options.outDir ?? root;
164
+ const aliasDir = resolve(root, dirname(options.entry));
165
+ const { alias = {}, extendViteConfig = {} } = resolvedKirbyupConfig;
166
+ const defaultConfig = {
167
+ mode,
168
+ plugins: [createVuePlugin(), kirbyupAutoImportPlugin()],
169
+ build: {
170
+ lib: {
171
+ entry: resolve(root, options.entry),
172
+ formats: ["iife"],
173
+ name: "kirbyupExport",
174
+ fileName: () => "index.js"
175
+ },
176
+ minify: mode === "production",
177
+ outDir,
178
+ emptyOutDir: false,
179
+ rollupOptions: {
180
+ external: ["vue"],
181
+ output: {
182
+ assetFileNames: "index.[ext]",
183
+ globals: {
184
+ vue: "Vue"
185
+ }
186
+ }
187
+ }
188
+ },
189
+ resolve: {
190
+ alias: {
191
+ "~/": `${aliasDir}/`,
192
+ "@/": `${aliasDir}/`,
193
+ ...alias
194
+ }
195
+ },
196
+ css: {
197
+ postcss: resolvedPostCssConfig
198
+ },
199
+ envPrefix: ["VITE_", "KIRBYUP_"],
200
+ logLevel: "warn"
201
+ };
202
+ try {
203
+ result = await build$1(mergeConfig(defaultConfig, extendViteConfig));
204
+ } catch (error) {
205
+ consola.error("Build failed");
206
+ if (mode === "production") {
207
+ throw error;
208
+ }
209
+ }
210
+ if (result && !options.watch) {
211
+ const { output } = toArray(result)[0];
212
+ for (const { fileName, type, code } of output) {
213
+ printFileInfo(root, outDir, fileName, type, code);
214
+ }
215
+ }
216
+ return result;
217
+ }
218
+ async function resolveOptions(options) {
219
+ if (!options.entry) {
220
+ throw new PrettyError("No input file, try " + cyan(`${name} <path/to/file.js>`));
221
+ }
222
+ if (!existsSync(options.entry)) {
223
+ throw new PrettyError(`Cannot find ${options.entry}`);
224
+ }
225
+ return options;
226
+ }
227
+ async function build(_options) {
228
+ const options = await resolveOptions(_options);
229
+ const loadConfig = createConfigLoader();
230
+ const { config, sources: configSources } = await loadConfig();
231
+ resolvedKirbyupConfig = config;
232
+ try {
233
+ resolvedPostCssConfig = await postcssrc({});
234
+ } catch (err) {
235
+ if (!/No PostCSS Config found/.test(err.message)) {
236
+ throw err;
237
+ }
238
+ resolvedPostCssConfig = {
239
+ plugins: [postcssLogical(), postcssDirPseudoClass()]
240
+ };
241
+ }
242
+ consola.log(green(`${name} v${version}`));
243
+ consola.start("Building " + cyan(options.entry));
244
+ if (options.watch) {
245
+ consola.info("Running in watch mode");
246
+ }
247
+ const debouncedBuild = debouncePromise(async () => {
248
+ viteBuild(options);
249
+ }, 100, handleError);
250
+ const startWatcher = async () => {
251
+ if (!options.watch)
252
+ return;
253
+ const { watch } = await import('chokidar');
254
+ const ignored = [
255
+ "**/{.git,node_modules}/**",
256
+ "index.{css,js}"
257
+ ];
258
+ const watchPaths = typeof options.watch === "boolean" ? dirname(options.entry) : Array.isArray(options.watch) ? options.watch.filter((path) => typeof path === "string") : options.watch;
259
+ consola.info("Watching for changes in " + toArray(watchPaths).map((i) => cyan(i)).join(", "));
260
+ const watcher = watch(watchPaths, {
261
+ ignoreInitial: true,
262
+ ignorePermissionErrors: true,
263
+ ignored
264
+ });
265
+ if (configSources.length) {
266
+ watcher.add(configSources);
267
+ }
268
+ watcher.on("all", async (type, file) => {
269
+ if (configSources.includes(file)) {
270
+ resolvedKirbyupConfig = (await loadConfig()).config;
271
+ consola.info(`${cyan(basename(file))} changed, setting new config`);
272
+ } else {
273
+ consola.log(green(type) + " " + white(dim(file)));
274
+ }
275
+ debouncedBuild();
276
+ });
277
+ };
278
+ await viteBuild(options);
279
+ consola.success("Build successful");
280
+ startWatcher();
281
+ }
282
+
283
+ export { build as b, defineConfig as d, handleError as h, name as n, resolveOptions as r, version as v };
package/dist/cli.cjs ADDED
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ const cac = require('cac');
4
+ const index = require('./chunks/index.cjs');
5
+ require('pathe');
6
+ require('fs');
7
+ require('vite');
8
+ require('vite-plugin-vue2');
9
+ require('magic-string');
10
+ require('unconfig');
11
+ require('postcss-load-config');
12
+ require('postcss-logical');
13
+ require('postcss-dir-pseudo-class');
14
+ require('consola');
15
+ require('colorette');
16
+ require('fs/promises');
17
+ require('zlib');
18
+ require('util');
19
+
20
+ async function main(options = {}) {
21
+ const cli = cac.cac(index.name);
22
+ cli.command("[file]", "Panel input file", {
23
+ ignoreOptionDefaultValue: true
24
+ }).option("-d, --out-dir <dir>", "Output directory", {
25
+ default: process.cwd()
26
+ }).option("--watch [path]", 'Watch mode, if path is not specified, it watches the folder of the input file. Repeat "--watch" for multiple paths').action(async (file, flags) => {
27
+ Object.assign(options, {
28
+ ...flags
29
+ });
30
+ if (file) {
31
+ options.entry = file;
32
+ }
33
+ await index.build(options);
34
+ });
35
+ cli.help();
36
+ cli.version(index.version);
37
+ cli.parse(process.argv, { run: false });
38
+ await cli.runMatchedCommand();
39
+ }
40
+ main().catch(index.handleError);
package/dist/cli.d.ts CHANGED
@@ -1 +1 @@
1
- #!/usr/bin/env node
1
+