kirbyup 0.22.0 → 0.22.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/README.md +2 -2
- package/dist/chunks/index.mjs +27 -56
- package/dist/index.d.ts +7 -11
- package/dist/index.mjs +1 -1
- package/package.json +20 -19
- package/dist/chunks/index.cjs +0 -329
- package/dist/cli.cjs +0 -40
- package/dist/index.cjs +0 -26
- package/dist/plugin.cjs +0 -15
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ The fastest and leanest way to bundle your Kirby Panel plugins. No configuration
|
|
|
13
13
|
- 🎒 [PostCSS support](#postcss)
|
|
14
14
|
- 🧭 [Path resolve aliases](#path-resolve-aliases)
|
|
15
15
|
- 🔌 [Env variables support](#env-variables)
|
|
16
|
-
- 🦔 [Extendable configuration with `kirbyup.config.js`](#extendable-configuration-with-
|
|
16
|
+
- 🦔 [Extendable configuration with `kirbyup.config.js`](#extendable-configuration-with-kirbyupconfigjs)
|
|
17
17
|
|
|
18
18
|
## Requirements
|
|
19
19
|
|
|
@@ -218,7 +218,7 @@ When aliasing to file system paths, always use absolute paths. Relative alias va
|
|
|
218
218
|
|
|
219
219
|
You can build upon the defaults kirbup uses and extend the Vite configuration with custom plugins etc.
|
|
220
220
|
|
|
221
|
-
For a complete list of options, take a look at the [Vite](https://vitejs.dev/config/).
|
|
221
|
+
For a complete list of options, take a look at the [Vite configuration options](https://vitejs.dev/config/).
|
|
222
222
|
|
|
223
223
|
## Options
|
|
224
224
|
|
package/dist/chunks/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { resolve, dirname, normalize, relative, basename } from 'pathe';
|
|
2
2
|
import { existsSync, statSync } from 'fs';
|
|
3
|
-
import { build as build$1 } from 'vite';
|
|
3
|
+
import { build as build$1, mergeConfig } from 'vite';
|
|
4
4
|
import { createVuePlugin } from 'vite-plugin-vue2';
|
|
5
5
|
import MagicString from 'magic-string';
|
|
6
6
|
import { createConfigLoader as createConfigLoader$1 } from 'unconfig';
|
|
@@ -104,16 +104,13 @@ function handleError(error) {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
const compress = promisify(gzip);
|
|
107
|
-
function arraify(target) {
|
|
108
|
-
return Array.isArray(target) ? target : [target];
|
|
109
|
-
}
|
|
110
107
|
async function getCompressedSize(code) {
|
|
111
108
|
const size = (await compress(typeof code === "string" ? code : Buffer.from(code))).length / 1024;
|
|
112
109
|
return ` / gzip: ${size.toFixed(2)} KiB`;
|
|
113
110
|
}
|
|
114
111
|
async function printFileInfo(root, outDir, filePath, type, content) {
|
|
115
|
-
content ?? (content = await readFile(
|
|
116
|
-
const prettyOutDir =
|
|
112
|
+
content ?? (content = await readFile(resolve(outDir, filePath), "utf8"));
|
|
113
|
+
const prettyOutDir = normalize(relative(root, resolve(root, outDir))) + "/";
|
|
117
114
|
const kibs = content.length / 1024;
|
|
118
115
|
const compressedSize = await getCompressedSize(content);
|
|
119
116
|
const writeColor = type === "chunk" ? cyan : magenta;
|
|
@@ -145,56 +142,20 @@ function debouncePromise(fn, delay, onError) {
|
|
|
145
142
|
}
|
|
146
143
|
|
|
147
144
|
// src/math.ts
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const source = sources.shift();
|
|
156
|
-
if (source === void 0)
|
|
157
|
-
return target;
|
|
158
|
-
if (isMergableObject(target) && isMergableObject(source)) {
|
|
159
|
-
objectKeys(source).forEach((key) => {
|
|
160
|
-
if (isMergableObject(source[key])) {
|
|
161
|
-
if (!target[key])
|
|
162
|
-
target[key] = {};
|
|
163
|
-
deepMerge(target[key], source[key]);
|
|
164
|
-
} else {
|
|
165
|
-
target[key] = source[key];
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
return deepMerge(target, ...sources);
|
|
170
|
-
}
|
|
171
|
-
function isMergableObject(item) {
|
|
172
|
-
return isObject(item) && !Array.isArray(item);
|
|
145
|
+
|
|
146
|
+
// src/array.ts
|
|
147
|
+
function toArray(array) {
|
|
148
|
+
array = array || [];
|
|
149
|
+
if (Array.isArray(array))
|
|
150
|
+
return array;
|
|
151
|
+
return [array];
|
|
173
152
|
}
|
|
174
153
|
|
|
175
154
|
const name = "kirbyup";
|
|
176
|
-
const version = "0.22.
|
|
155
|
+
const version = "0.22.1";
|
|
177
156
|
|
|
178
157
|
let resolvedKirbyupConfig;
|
|
179
158
|
let resolvedPostCssConfig;
|
|
180
|
-
async function resolvePostcssConfig(root) {
|
|
181
|
-
let result = resolvedPostCssConfig;
|
|
182
|
-
if (result) {
|
|
183
|
-
return result;
|
|
184
|
-
}
|
|
185
|
-
try {
|
|
186
|
-
result = await postcssrc({}, root);
|
|
187
|
-
} catch (err) {
|
|
188
|
-
if (!/No PostCSS Config found/.test(err.message)) {
|
|
189
|
-
throw err;
|
|
190
|
-
}
|
|
191
|
-
result = {
|
|
192
|
-
plugins: [postcssLogical(), postcssDirPseudoClass()]
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
resolvedPostCssConfig = result;
|
|
196
|
-
return result;
|
|
197
|
-
}
|
|
198
159
|
async function viteBuild(options) {
|
|
199
160
|
let result;
|
|
200
161
|
const mode = options.watch ? "development" : "production";
|
|
@@ -233,13 +194,13 @@ async function viteBuild(options) {
|
|
|
233
194
|
}
|
|
234
195
|
},
|
|
235
196
|
css: {
|
|
236
|
-
postcss:
|
|
197
|
+
postcss: resolvedPostCssConfig
|
|
237
198
|
},
|
|
238
199
|
envPrefix: ["VITE_", "KIRBYUP_"],
|
|
239
200
|
logLevel: "warn"
|
|
240
201
|
};
|
|
241
202
|
try {
|
|
242
|
-
result = await build$1(
|
|
203
|
+
result = await build$1(mergeConfig(defaultConfig, extendViteConfig));
|
|
243
204
|
} catch (error) {
|
|
244
205
|
consola.error("Build failed");
|
|
245
206
|
if (mode === "production") {
|
|
@@ -247,7 +208,7 @@ async function viteBuild(options) {
|
|
|
247
208
|
}
|
|
248
209
|
}
|
|
249
210
|
if (result && !options.watch) {
|
|
250
|
-
const { output } =
|
|
211
|
+
const { output } = toArray(result)[0];
|
|
251
212
|
for (const { fileName, type, code } of output) {
|
|
252
213
|
printFileInfo(root, outDir, fileName, type, code);
|
|
253
214
|
}
|
|
@@ -268,6 +229,16 @@ async function build(_options) {
|
|
|
268
229
|
const loadConfig = createConfigLoader();
|
|
269
230
|
const { config, sources: configSources } = await loadConfig();
|
|
270
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
|
+
}
|
|
271
242
|
consola.log(green(`${name} v${version}`));
|
|
272
243
|
consola.start("Building " + cyan(options.entry));
|
|
273
244
|
if (options.watch) {
|
|
@@ -285,7 +256,7 @@ async function build(_options) {
|
|
|
285
256
|
"index.{css,js}"
|
|
286
257
|
];
|
|
287
258
|
const watchPaths = typeof options.watch === "boolean" ? dirname(options.entry) : Array.isArray(options.watch) ? options.watch.filter((path) => typeof path === "string") : options.watch;
|
|
288
|
-
consola.info("Watching for changes in " +
|
|
259
|
+
consola.info("Watching for changes in " + toArray(watchPaths).map((i) => cyan(i)).join(", "));
|
|
289
260
|
const watcher = watch(watchPaths, {
|
|
290
261
|
ignoreInitial: true,
|
|
291
262
|
ignorePermissionErrors: true,
|
|
@@ -309,4 +280,4 @@ async function build(_options) {
|
|
|
309
280
|
startWatcher();
|
|
310
281
|
}
|
|
311
282
|
|
|
312
|
-
export {
|
|
283
|
+
export { build as b, defineConfig as d, handleError as h, name as n, resolveOptions as r, version as v };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { RollupOutput } from 'rollup';
|
|
3
|
-
import { MarkRequired } from 'ts-essentials';
|
|
4
|
-
import { InlineConfig } from 'vite';
|
|
1
|
+
import { AliasOptions, InlineConfig } from 'vite';
|
|
5
2
|
|
|
3
|
+
declare type MarkRequired<T, RK extends keyof T> = Exclude<T, RK> & Required<Pick<T, RK>>;
|
|
6
4
|
declare type CliOptions = {
|
|
7
5
|
entry?: string;
|
|
8
6
|
outDir?: string;
|
|
@@ -11,13 +9,12 @@ declare type CliOptions = {
|
|
|
11
9
|
declare type ResolvedCliOptions = MarkRequired<CliOptions, 'entry'>;
|
|
12
10
|
interface UserConfig {
|
|
13
11
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
12
|
+
* Specifies an `Object`, or an `Array` of `Object`,
|
|
13
|
+
* which defines aliases used to replace values in `import` statements.
|
|
14
|
+
* With either format, the order of the entries is important,
|
|
16
15
|
* in that the first defined rules are applied first.
|
|
17
16
|
*/
|
|
18
|
-
alias?:
|
|
19
|
-
[find: string]: string;
|
|
20
|
-
};
|
|
17
|
+
alias?: AliasOptions;
|
|
21
18
|
/**
|
|
22
19
|
* Extends Vite's configuration. Will be merged with kirbyup's
|
|
23
20
|
* default configuration. Be careful what to extend.
|
|
@@ -27,8 +24,7 @@ interface UserConfig {
|
|
|
27
24
|
|
|
28
25
|
declare function defineConfig(config: UserConfig): UserConfig;
|
|
29
26
|
|
|
30
|
-
declare function viteBuild(options: ResolvedCliOptions): Promise<RollupOutput | RollupOutput[] | rollup.RollupWatcher | undefined>;
|
|
31
27
|
declare function resolveOptions(options: CliOptions): Promise<ResolvedCliOptions>;
|
|
32
28
|
declare function build(_options: CliOptions): Promise<void>;
|
|
33
29
|
|
|
34
|
-
export { build, defineConfig, resolveOptions
|
|
30
|
+
export { build, defineConfig, resolveOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import 'pathe';
|
|
|
2
2
|
import 'fs';
|
|
3
3
|
import 'vite';
|
|
4
4
|
import 'vite-plugin-vue2';
|
|
5
|
-
export { b as build, d as defineConfig, r as resolveOptions
|
|
5
|
+
export { b as build, d as defineConfig, r as resolveOptions } from './chunks/index.mjs';
|
|
6
6
|
import 'postcss-load-config';
|
|
7
7
|
import 'postcss-logical';
|
|
8
8
|
import 'postcss-dir-pseudo-class';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kirbyup",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.1",
|
|
4
4
|
"description": "Zero-config bundler for Kirby Panel plugins",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kirby-cms",
|
|
@@ -49,7 +49,8 @@
|
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "unbuild",
|
|
51
51
|
"stub": "unbuild --stub",
|
|
52
|
-
"test": "
|
|
52
|
+
"test": "vitest",
|
|
53
|
+
"test:update": "vitest -u",
|
|
53
54
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
54
55
|
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
|
|
55
56
|
"release": "node scripts/release.js",
|
|
@@ -61,33 +62,33 @@
|
|
|
61
62
|
"colorette": "^2.0.16",
|
|
62
63
|
"consola": "^2.15.3",
|
|
63
64
|
"pathe": "^0.2.0",
|
|
64
|
-
"postcss
|
|
65
|
-
"postcss-
|
|
66
|
-
"postcss-
|
|
67
|
-
"
|
|
68
|
-
"
|
|
65
|
+
"postcss": "^8.4.5",
|
|
66
|
+
"postcss-dir-pseudo-class": "^6.0.2",
|
|
67
|
+
"postcss-load-config": "^3.1.1",
|
|
68
|
+
"postcss-logical": "^5.0.2",
|
|
69
|
+
"sass": "^1.46.0",
|
|
69
70
|
"unconfig": "^0.2.2",
|
|
70
|
-
"vite": "^2.7.
|
|
71
|
-
"vite-plugin-vue2": "^1.9.
|
|
71
|
+
"vite": "^2.7.10",
|
|
72
|
+
"vite-plugin-vue2": "^1.9.2",
|
|
72
73
|
"vue": "^2.6.14",
|
|
73
74
|
"vue-template-compiler": "^2.6.14"
|
|
74
75
|
},
|
|
75
76
|
"devDependencies": {
|
|
76
|
-
"@antfu/utils": "^0.
|
|
77
|
+
"@antfu/utils": "^0.4.0",
|
|
78
|
+
"@types/cross-spawn": "^6.0.2",
|
|
77
79
|
"@types/fs-extra": "^9.0.13",
|
|
78
|
-
"@types/
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"execa": "^5.1.1",
|
|
80
|
+
"@types/node": "^17.0.8",
|
|
81
|
+
"conventional-changelog-cli": "^2.2.2",
|
|
82
|
+
"esno": "^0.13.0",
|
|
83
|
+
"execa": "5.1.1",
|
|
83
84
|
"fast-glob": "^3.2.7",
|
|
84
85
|
"fs-extra": "^10.0.0",
|
|
85
86
|
"husky": "^7.0.4",
|
|
86
|
-
"jest": "^27.4.3",
|
|
87
87
|
"prettier": "^2.5.1",
|
|
88
88
|
"prompts": "^2.4.2",
|
|
89
|
-
"ts-
|
|
90
|
-
"typescript": "^4.5.
|
|
91
|
-
"unbuild": "^0.6.
|
|
89
|
+
"ts-essentials": "^9.1.2",
|
|
90
|
+
"typescript": "^4.5.4",
|
|
91
|
+
"unbuild": "^0.6.7",
|
|
92
|
+
"vitest": "^0.0.134"
|
|
92
93
|
}
|
|
93
94
|
}
|
package/dist/chunks/index.cjs
DELETED
|
@@ -1,329 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = 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 path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
21
|
-
const MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
|
|
22
|
-
const postcssrc__default = /*#__PURE__*/_interopDefaultLegacy(postcssrc);
|
|
23
|
-
const postcssLogical__default = /*#__PURE__*/_interopDefaultLegacy(postcssLogical);
|
|
24
|
-
const postcssDirPseudoClass__default = /*#__PURE__*/_interopDefaultLegacy(postcssDirPseudoClass);
|
|
25
|
-
const consola__default = /*#__PURE__*/_interopDefaultLegacy(consola);
|
|
26
|
-
|
|
27
|
-
const multilineCommentsRE = /\/\*(.|[\r\n])*?\*\//gm;
|
|
28
|
-
const singlelineCommentsRE = /\/\/.*/g;
|
|
29
|
-
|
|
30
|
-
function kirbyupAutoImportPlugin() {
|
|
31
|
-
let config;
|
|
32
|
-
return {
|
|
33
|
-
name: "kirbyup:auto-import",
|
|
34
|
-
configResolved(resolvedConfig) {
|
|
35
|
-
config = resolvedConfig;
|
|
36
|
-
},
|
|
37
|
-
async transform(code, id) {
|
|
38
|
-
if (code.includes("kirbyup.import")) {
|
|
39
|
-
const kirbyupImportRE = /\bkirbyup\.import\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*\)/g;
|
|
40
|
-
const noCommentsCode = code.replace(multilineCommentsRE, (m) => " ".repeat(m.length)).replace(singlelineCommentsRE, (m) => " ".repeat(m.length));
|
|
41
|
-
let s = null;
|
|
42
|
-
let match;
|
|
43
|
-
while (match = kirbyupImportRE.exec(noCommentsCode)) {
|
|
44
|
-
const { 0: exp, 1: rawPath, index } = match;
|
|
45
|
-
if (!s)
|
|
46
|
-
s = new MagicString__default(code);
|
|
47
|
-
s.overwrite(index, index + exp.length, `kirbyup.import(import.meta.globEager(${rawPath}))`);
|
|
48
|
-
}
|
|
49
|
-
if (s) {
|
|
50
|
-
return {
|
|
51
|
-
code: s.toString(),
|
|
52
|
-
map: config.build.sourcemap ? s.generateMap({ hires: true }) : null
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function defineConfig(config) {
|
|
62
|
-
return config;
|
|
63
|
-
}
|
|
64
|
-
function createConfigLoader(configOrPath = process.cwd(), extraConfigSources = []) {
|
|
65
|
-
let inlineConfig = {};
|
|
66
|
-
if (typeof configOrPath !== "string") {
|
|
67
|
-
inlineConfig = configOrPath;
|
|
68
|
-
configOrPath = process.cwd();
|
|
69
|
-
}
|
|
70
|
-
const resolved = path.resolve(configOrPath);
|
|
71
|
-
let cwd = resolved;
|
|
72
|
-
let isFile = false;
|
|
73
|
-
if (fs.existsSync(resolved) && fs.statSync(resolved).isFile()) {
|
|
74
|
-
isFile = true;
|
|
75
|
-
cwd = path.dirname(resolved);
|
|
76
|
-
}
|
|
77
|
-
const loader = unconfig.createConfigLoader({
|
|
78
|
-
sources: isFile ? [
|
|
79
|
-
{
|
|
80
|
-
files: resolved,
|
|
81
|
-
extensions: []
|
|
82
|
-
}
|
|
83
|
-
] : [
|
|
84
|
-
{
|
|
85
|
-
files: ["kirbyup.config"]
|
|
86
|
-
},
|
|
87
|
-
...extraConfigSources
|
|
88
|
-
],
|
|
89
|
-
cwd,
|
|
90
|
-
defaults: inlineConfig
|
|
91
|
-
});
|
|
92
|
-
return async () => {
|
|
93
|
-
const result = await loader.load();
|
|
94
|
-
result.config = result.config || inlineConfig;
|
|
95
|
-
return result;
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
class PrettyError extends Error {
|
|
100
|
-
constructor(message) {
|
|
101
|
-
super(message);
|
|
102
|
-
this.name = this.constructor.name;
|
|
103
|
-
if (typeof Error.captureStackTrace === "function") {
|
|
104
|
-
Error.captureStackTrace(this, this.constructor);
|
|
105
|
-
} else {
|
|
106
|
-
this.stack = new Error(message).stack;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
function handleError(error) {
|
|
111
|
-
if (error instanceof PrettyError) {
|
|
112
|
-
consola__default.error(error.message);
|
|
113
|
-
}
|
|
114
|
-
process.exitCode = 1;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const compress = util.promisify(zlib.gzip);
|
|
118
|
-
function arraify(target) {
|
|
119
|
-
return Array.isArray(target) ? target : [target];
|
|
120
|
-
}
|
|
121
|
-
async function getCompressedSize(code) {
|
|
122
|
-
const size = (await compress(typeof code === "string" ? code : Buffer.from(code))).length / 1024;
|
|
123
|
-
return ` / gzip: ${size.toFixed(2)} KiB`;
|
|
124
|
-
}
|
|
125
|
-
async function printFileInfo(root, outDir, filePath, type, content) {
|
|
126
|
-
content ?? (content = await promises.readFile(path__default.resolve(outDir, filePath), "utf8"));
|
|
127
|
-
const prettyOutDir = path__default.normalize(path__default.relative(root, path__default.resolve(root, outDir))) + "/";
|
|
128
|
-
const kibs = content.length / 1024;
|
|
129
|
-
const compressedSize = await getCompressedSize(content);
|
|
130
|
-
const writeColor = type === "chunk" ? colorette.cyan : colorette.magenta;
|
|
131
|
-
consola__default.log(colorette.white(colorette.dim(prettyOutDir)) + writeColor(filePath) + " " + colorette.dim(`${kibs.toFixed(2)} KiB${compressedSize}`));
|
|
132
|
-
}
|
|
133
|
-
function debouncePromise(fn, delay, onError) {
|
|
134
|
-
let timeout;
|
|
135
|
-
let promiseInFly;
|
|
136
|
-
let callbackPending;
|
|
137
|
-
return function debounced(...args) {
|
|
138
|
-
if (promiseInFly) {
|
|
139
|
-
callbackPending = () => {
|
|
140
|
-
debounced(...args);
|
|
141
|
-
callbackPending = void 0;
|
|
142
|
-
};
|
|
143
|
-
} else {
|
|
144
|
-
if (timeout)
|
|
145
|
-
clearTimeout(timeout);
|
|
146
|
-
timeout = setTimeout(() => {
|
|
147
|
-
timeout = void 0;
|
|
148
|
-
promiseInFly = fn(...args).catch(onError).finally(() => {
|
|
149
|
-
promiseInFly = void 0;
|
|
150
|
-
if (callbackPending)
|
|
151
|
-
callbackPending();
|
|
152
|
-
});
|
|
153
|
-
}, delay);
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// src/math.ts
|
|
159
|
-
var isObject = (val) => toString.call(val) === "[object Object]";
|
|
160
|
-
function objectKeys(obj) {
|
|
161
|
-
return Object.keys(obj);
|
|
162
|
-
}
|
|
163
|
-
function deepMerge(target, ...sources) {
|
|
164
|
-
if (!sources.length)
|
|
165
|
-
return target;
|
|
166
|
-
const source = sources.shift();
|
|
167
|
-
if (source === void 0)
|
|
168
|
-
return target;
|
|
169
|
-
if (isMergableObject(target) && isMergableObject(source)) {
|
|
170
|
-
objectKeys(source).forEach((key) => {
|
|
171
|
-
if (isMergableObject(source[key])) {
|
|
172
|
-
if (!target[key])
|
|
173
|
-
target[key] = {};
|
|
174
|
-
deepMerge(target[key], source[key]);
|
|
175
|
-
} else {
|
|
176
|
-
target[key] = source[key];
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
return deepMerge(target, ...sources);
|
|
181
|
-
}
|
|
182
|
-
function isMergableObject(item) {
|
|
183
|
-
return isObject(item) && !Array.isArray(item);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const name = "kirbyup";
|
|
187
|
-
const version = "0.22.0";
|
|
188
|
-
|
|
189
|
-
let resolvedKirbyupConfig;
|
|
190
|
-
let resolvedPostCssConfig;
|
|
191
|
-
async function resolvePostcssConfig(root) {
|
|
192
|
-
let result = resolvedPostCssConfig;
|
|
193
|
-
if (result) {
|
|
194
|
-
return result;
|
|
195
|
-
}
|
|
196
|
-
try {
|
|
197
|
-
result = await postcssrc__default({}, root);
|
|
198
|
-
} catch (err) {
|
|
199
|
-
if (!/No PostCSS Config found/.test(err.message)) {
|
|
200
|
-
throw err;
|
|
201
|
-
}
|
|
202
|
-
result = {
|
|
203
|
-
plugins: [postcssLogical__default(), postcssDirPseudoClass__default()]
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
resolvedPostCssConfig = result;
|
|
207
|
-
return result;
|
|
208
|
-
}
|
|
209
|
-
async function viteBuild(options) {
|
|
210
|
-
let result;
|
|
211
|
-
const mode = options.watch ? "development" : "production";
|
|
212
|
-
const root = process.cwd();
|
|
213
|
-
const outDir = options.outDir ?? root;
|
|
214
|
-
const aliasDir = path.resolve(root, path.dirname(options.entry));
|
|
215
|
-
const { alias = {}, extendViteConfig = {} } = resolvedKirbyupConfig;
|
|
216
|
-
const defaultConfig = {
|
|
217
|
-
mode,
|
|
218
|
-
plugins: [vitePluginVue2.createVuePlugin(), kirbyupAutoImportPlugin()],
|
|
219
|
-
build: {
|
|
220
|
-
lib: {
|
|
221
|
-
entry: path.resolve(root, options.entry),
|
|
222
|
-
formats: ["iife"],
|
|
223
|
-
name: "kirbyupExport",
|
|
224
|
-
fileName: () => "index.js"
|
|
225
|
-
},
|
|
226
|
-
minify: mode === "production",
|
|
227
|
-
outDir,
|
|
228
|
-
emptyOutDir: false,
|
|
229
|
-
rollupOptions: {
|
|
230
|
-
external: ["vue"],
|
|
231
|
-
output: {
|
|
232
|
-
assetFileNames: "index.[ext]",
|
|
233
|
-
globals: {
|
|
234
|
-
vue: "Vue"
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
resolve: {
|
|
240
|
-
alias: {
|
|
241
|
-
"~/": `${aliasDir}/`,
|
|
242
|
-
"@/": `${aliasDir}/`,
|
|
243
|
-
...alias
|
|
244
|
-
}
|
|
245
|
-
},
|
|
246
|
-
css: {
|
|
247
|
-
postcss: await resolvePostcssConfig(root)
|
|
248
|
-
},
|
|
249
|
-
envPrefix: ["VITE_", "KIRBYUP_"],
|
|
250
|
-
logLevel: "warn"
|
|
251
|
-
};
|
|
252
|
-
try {
|
|
253
|
-
result = await vite.build(deepMerge(defaultConfig, extendViteConfig));
|
|
254
|
-
} catch (error) {
|
|
255
|
-
consola__default.error("Build failed");
|
|
256
|
-
if (mode === "production") {
|
|
257
|
-
throw error;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
if (result && !options.watch) {
|
|
261
|
-
const { output } = arraify(result)[0];
|
|
262
|
-
for (const { fileName, type, code } of output) {
|
|
263
|
-
printFileInfo(root, outDir, fileName, type, code);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
return result;
|
|
267
|
-
}
|
|
268
|
-
async function resolveOptions(options) {
|
|
269
|
-
if (!options.entry) {
|
|
270
|
-
throw new PrettyError("No input file, try " + colorette.cyan(`${name} <path/to/file.js>`));
|
|
271
|
-
}
|
|
272
|
-
if (!fs.existsSync(options.entry)) {
|
|
273
|
-
throw new PrettyError(`Cannot find ${options.entry}`);
|
|
274
|
-
}
|
|
275
|
-
return options;
|
|
276
|
-
}
|
|
277
|
-
async function build(_options) {
|
|
278
|
-
const options = await resolveOptions(_options);
|
|
279
|
-
const loadConfig = createConfigLoader();
|
|
280
|
-
const { config, sources: configSources } = await loadConfig();
|
|
281
|
-
resolvedKirbyupConfig = config;
|
|
282
|
-
consola__default.log(colorette.green(`${name} v${version}`));
|
|
283
|
-
consola__default.start("Building " + colorette.cyan(options.entry));
|
|
284
|
-
if (options.watch) {
|
|
285
|
-
consola__default.info("Running in watch mode");
|
|
286
|
-
}
|
|
287
|
-
const debouncedBuild = debouncePromise(async () => {
|
|
288
|
-
viteBuild(options);
|
|
289
|
-
}, 100, handleError);
|
|
290
|
-
const startWatcher = async () => {
|
|
291
|
-
if (!options.watch)
|
|
292
|
-
return;
|
|
293
|
-
const { watch } = await import('chokidar');
|
|
294
|
-
const ignored = [
|
|
295
|
-
"**/{.git,node_modules}/**",
|
|
296
|
-
"index.{css,js}"
|
|
297
|
-
];
|
|
298
|
-
const watchPaths = typeof options.watch === "boolean" ? path.dirname(options.entry) : Array.isArray(options.watch) ? options.watch.filter((path) => typeof path === "string") : options.watch;
|
|
299
|
-
consola__default.info("Watching for changes in " + arraify(watchPaths).map((i) => colorette.cyan(i)).join(", "));
|
|
300
|
-
const watcher = watch(watchPaths, {
|
|
301
|
-
ignoreInitial: true,
|
|
302
|
-
ignorePermissionErrors: true,
|
|
303
|
-
ignored
|
|
304
|
-
});
|
|
305
|
-
if (configSources.length) {
|
|
306
|
-
watcher.add(configSources);
|
|
307
|
-
}
|
|
308
|
-
watcher.on("all", async (type, file) => {
|
|
309
|
-
if (configSources.includes(file)) {
|
|
310
|
-
resolvedKirbyupConfig = (await loadConfig()).config;
|
|
311
|
-
consola__default.info(`${colorette.cyan(path.basename(file))} changed, setting new config`);
|
|
312
|
-
} else {
|
|
313
|
-
consola__default.log(colorette.green(type) + " " + colorette.white(colorette.dim(file)));
|
|
314
|
-
}
|
|
315
|
-
debouncedBuild();
|
|
316
|
-
});
|
|
317
|
-
};
|
|
318
|
-
await viteBuild(options);
|
|
319
|
-
consola__default.success("Build successful");
|
|
320
|
-
startWatcher();
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
exports.build = build;
|
|
324
|
-
exports.defineConfig = defineConfig;
|
|
325
|
-
exports.handleError = handleError;
|
|
326
|
-
exports.name = name;
|
|
327
|
-
exports.resolveOptions = resolveOptions;
|
|
328
|
-
exports.version = version;
|
|
329
|
-
exports.viteBuild = viteBuild;
|
package/dist/cli.cjs
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
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/index.cjs
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
require('pathe');
|
|
6
|
-
require('fs');
|
|
7
|
-
require('vite');
|
|
8
|
-
require('vite-plugin-vue2');
|
|
9
|
-
const index = require('./chunks/index.cjs');
|
|
10
|
-
require('postcss-load-config');
|
|
11
|
-
require('postcss-logical');
|
|
12
|
-
require('postcss-dir-pseudo-class');
|
|
13
|
-
require('consola');
|
|
14
|
-
require('colorette');
|
|
15
|
-
require('magic-string');
|
|
16
|
-
require('unconfig');
|
|
17
|
-
require('fs/promises');
|
|
18
|
-
require('zlib');
|
|
19
|
-
require('util');
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
exports.build = index.build;
|
|
24
|
-
exports.defineConfig = index.defineConfig;
|
|
25
|
-
exports.resolveOptions = index.resolveOptions;
|
|
26
|
-
exports.viteBuild = index.viteBuild;
|
package/dist/plugin.cjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
const getComponentName = (path) => path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf(".")).toLowerCase();
|
|
6
|
-
const kirbyup = Object.freeze({
|
|
7
|
-
import(modules) {
|
|
8
|
-
return Object.entries(modules).reduce((accumulator, [path, component]) => {
|
|
9
|
-
accumulator[getComponentName(path)] = component.default;
|
|
10
|
-
return accumulator;
|
|
11
|
-
}, {});
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
exports.kirbyup = kirbyup;
|