kirbyup 0.22.3 → 0.24.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/bin/kirbyup.mjs +3 -0
- package/dist/chunks/index.mjs +35 -58
- package/dist/cli.mjs +2 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.mjs +1 -0
- package/package.json +38 -38
- package/bin/kirbyup.cjs +0 -2
- package/dist/chunks/index.cjs +0 -295
- package/dist/cli.cjs +0 -40
- package/dist/index.cjs +0 -25
- package/dist/plugin.cjs +0 -15
package/bin/kirbyup.mjs
ADDED
package/dist/chunks/index.mjs
CHANGED
|
@@ -3,12 +3,13 @@ import { existsSync, statSync } from 'fs';
|
|
|
3
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
|
-
import { createConfigLoader
|
|
6
|
+
import { createConfigLoader } from 'unconfig';
|
|
7
7
|
import postcssrc from 'postcss-load-config';
|
|
8
8
|
import postcssLogical from 'postcss-logical';
|
|
9
9
|
import postcssDirPseudoClass from 'postcss-dir-pseudo-class';
|
|
10
10
|
import consola from 'consola';
|
|
11
|
-
import {
|
|
11
|
+
import { debounce } from 'perfect-debounce';
|
|
12
|
+
import colors from 'picocolors';
|
|
12
13
|
import { readFile } from 'fs/promises';
|
|
13
14
|
import { gzip } from 'zlib';
|
|
14
15
|
import { promisify } from 'util';
|
|
@@ -50,20 +51,26 @@ function kirbyupAutoImportPlugin() {
|
|
|
50
51
|
function defineConfig(config) {
|
|
51
52
|
return config;
|
|
52
53
|
}
|
|
53
|
-
function
|
|
54
|
+
async function loadConfig(cwd = process.cwd(), configOrPath = cwd, extraConfigSources = []) {
|
|
54
55
|
let inlineConfig = {};
|
|
55
56
|
if (typeof configOrPath !== "string") {
|
|
56
57
|
inlineConfig = configOrPath;
|
|
57
|
-
|
|
58
|
+
if (inlineConfig.configFile === false) {
|
|
59
|
+
return {
|
|
60
|
+
config: inlineConfig,
|
|
61
|
+
sources: []
|
|
62
|
+
};
|
|
63
|
+
} else {
|
|
64
|
+
configOrPath = inlineConfig.configFile || process.cwd();
|
|
65
|
+
}
|
|
58
66
|
}
|
|
59
67
|
const resolved = resolve(configOrPath);
|
|
60
|
-
let cwd = resolved;
|
|
61
68
|
let isFile = false;
|
|
62
69
|
if (existsSync(resolved) && statSync(resolved).isFile()) {
|
|
63
70
|
isFile = true;
|
|
64
71
|
cwd = dirname(resolved);
|
|
65
72
|
}
|
|
66
|
-
const loader = createConfigLoader
|
|
73
|
+
const loader = createConfigLoader({
|
|
67
74
|
sources: isFile ? [
|
|
68
75
|
{
|
|
69
76
|
files: resolved,
|
|
@@ -78,11 +85,9 @@ function createConfigLoader(configOrPath = process.cwd(), extraConfigSources = [
|
|
|
78
85
|
cwd,
|
|
79
86
|
defaults: inlineConfig
|
|
80
87
|
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return result;
|
|
85
|
-
};
|
|
88
|
+
const result = await loader.load();
|
|
89
|
+
result.config = result.config || inlineConfig;
|
|
90
|
+
return result;
|
|
86
91
|
}
|
|
87
92
|
|
|
88
93
|
class PrettyError extends Error {
|
|
@@ -97,12 +102,16 @@ class PrettyError extends Error {
|
|
|
97
102
|
}
|
|
98
103
|
}
|
|
99
104
|
function handleError(error) {
|
|
100
|
-
|
|
101
|
-
consola.error(error.message);
|
|
102
|
-
}
|
|
105
|
+
consola.error(error.message);
|
|
103
106
|
process.exitCode = 1;
|
|
104
107
|
}
|
|
105
108
|
|
|
109
|
+
function toArray(array) {
|
|
110
|
+
array = array || [];
|
|
111
|
+
if (Array.isArray(array))
|
|
112
|
+
return array;
|
|
113
|
+
return [array];
|
|
114
|
+
}
|
|
106
115
|
const compress = promisify(gzip);
|
|
107
116
|
async function getCompressedSize(code) {
|
|
108
117
|
const size = (await compress(typeof code === "string" ? code : Buffer.from(code))).length / 1024;
|
|
@@ -113,43 +122,12 @@ async function printFileInfo(root, outDir, filePath, type, content) {
|
|
|
113
122
|
const prettyOutDir = normalize(relative(root, resolve(root, outDir))) + "/";
|
|
114
123
|
const kibs = content.length / 1024;
|
|
115
124
|
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
|
-
function toArray(array) {
|
|
145
|
-
array = array || [];
|
|
146
|
-
if (Array.isArray(array))
|
|
147
|
-
return array;
|
|
148
|
-
return [array];
|
|
125
|
+
const writeColor = type === "chunk" ? colors.cyan : colors.magenta;
|
|
126
|
+
consola.log(colors.white(colors.dim(prettyOutDir)) + writeColor(filePath) + " " + colors.dim(`${kibs.toFixed(2)} KiB${compressedSize}`));
|
|
149
127
|
}
|
|
150
128
|
|
|
151
129
|
const name = "kirbyup";
|
|
152
|
-
const version = "0.
|
|
130
|
+
const version = "0.24.1";
|
|
153
131
|
|
|
154
132
|
let resolvedKirbyupConfig;
|
|
155
133
|
let resolvedPostCssConfig;
|
|
@@ -214,7 +192,7 @@ async function viteBuild(options) {
|
|
|
214
192
|
}
|
|
215
193
|
async function resolveOptions(options) {
|
|
216
194
|
if (!options.entry) {
|
|
217
|
-
throw new PrettyError(`No input file, try ${cyan(`${name} <path/to/file.js>`)}`);
|
|
195
|
+
throw new PrettyError(`No input file, try ${colors.cyan(`${name} <path/to/file.js>`)}`);
|
|
218
196
|
}
|
|
219
197
|
if (!existsSync(options.entry)) {
|
|
220
198
|
throw new PrettyError(`Cannot find ${options.entry}`);
|
|
@@ -223,7 +201,6 @@ async function resolveOptions(options) {
|
|
|
223
201
|
}
|
|
224
202
|
async function build(_options) {
|
|
225
203
|
const options = await resolveOptions(_options);
|
|
226
|
-
const loadConfig = createConfigLoader();
|
|
227
204
|
const { config, sources: configSources } = await loadConfig();
|
|
228
205
|
resolvedKirbyupConfig = config;
|
|
229
206
|
try {
|
|
@@ -236,14 +213,14 @@ async function build(_options) {
|
|
|
236
213
|
plugins: [postcssLogical(), postcssDirPseudoClass()]
|
|
237
214
|
};
|
|
238
215
|
}
|
|
239
|
-
consola.log(green(`${name} v${version}`));
|
|
240
|
-
consola.start(`Building ${cyan(options.entry)}`);
|
|
216
|
+
consola.log(colors.green(`${name} v${version}`));
|
|
217
|
+
consola.start(`Building ${colors.cyan(options.entry)}`);
|
|
241
218
|
if (options.watch) {
|
|
242
219
|
consola.info("Running in watch mode");
|
|
243
220
|
}
|
|
244
|
-
const debouncedBuild =
|
|
245
|
-
viteBuild(options);
|
|
246
|
-
}, 100
|
|
221
|
+
const debouncedBuild = debounce(async () => {
|
|
222
|
+
viteBuild(options).catch(handleError);
|
|
223
|
+
}, 100);
|
|
247
224
|
const startWatcher = async () => {
|
|
248
225
|
if (!options.watch)
|
|
249
226
|
return;
|
|
@@ -253,7 +230,7 @@ async function build(_options) {
|
|
|
253
230
|
"index.{css,js}"
|
|
254
231
|
];
|
|
255
232
|
const watchPaths = typeof options.watch === "boolean" ? dirname(options.entry) : Array.isArray(options.watch) ? options.watch.filter((path) => typeof path === "string") : options.watch;
|
|
256
|
-
consola.info("Watching for changes in " + toArray(watchPaths).map((i) => cyan(i)).join(", "));
|
|
233
|
+
consola.info("Watching for changes in " + toArray(watchPaths).map((i) => colors.cyan(i)).join(", "));
|
|
257
234
|
const watcher = watch(watchPaths, {
|
|
258
235
|
ignoreInitial: true,
|
|
259
236
|
ignorePermissionErrors: true,
|
|
@@ -265,9 +242,9 @@ async function build(_options) {
|
|
|
265
242
|
watcher.on("all", async (type, file) => {
|
|
266
243
|
if (configSources.includes(file)) {
|
|
267
244
|
resolvedKirbyupConfig = (await loadConfig()).config;
|
|
268
|
-
consola.info(`${cyan(basename(file))} changed, setting new config`);
|
|
245
|
+
consola.info(`${colors.cyan(basename(file))} changed, setting new config`);
|
|
269
246
|
} else {
|
|
270
|
-
consola.log(green(type) + " " + white(dim(file)));
|
|
247
|
+
consola.log(colors.green(type) + " " + colors.white(colors.dim(file)));
|
|
271
248
|
}
|
|
272
249
|
debouncedBuild();
|
|
273
250
|
});
|
package/dist/cli.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import 'postcss-load-config';
|
|
|
10
10
|
import 'postcss-logical';
|
|
11
11
|
import 'postcss-dir-pseudo-class';
|
|
12
12
|
import 'consola';
|
|
13
|
+
import 'perfect-debounce';
|
|
13
14
|
import 'picocolors';
|
|
14
15
|
import 'fs/promises';
|
|
15
16
|
import 'zlib';
|
|
@@ -21,7 +22,7 @@ async function main(options = {}) {
|
|
|
21
22
|
ignoreOptionDefaultValue: true
|
|
22
23
|
}).option("-d, --out-dir <dir>", "Output directory", {
|
|
23
24
|
default: process.cwd()
|
|
24
|
-
}).option("--watch [path]", 'Watch mode
|
|
25
|
+
}).option("-w, --watch [path]", 'Watch mode. If no path is specified, the folder of the input file will be watched. Repeat "--watch" for multiple paths.').action(async (file, flags) => {
|
|
25
26
|
Object.assign(options, {
|
|
26
27
|
...flags
|
|
27
28
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,11 @@ declare type CliOptions = {
|
|
|
8
8
|
};
|
|
9
9
|
declare type ResolvedCliOptions = MarkRequired<CliOptions, 'entry'>;
|
|
10
10
|
interface UserConfig {
|
|
11
|
+
/**
|
|
12
|
+
* Load from config files
|
|
13
|
+
* Set to `false` to disable
|
|
14
|
+
*/
|
|
15
|
+
configFile?: string | false;
|
|
11
16
|
/**
|
|
12
17
|
* Specifies an `Object`, or an `Array` of `Object`,
|
|
13
18
|
* which defines aliases used to replace values in `import` statements.
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kirbyup",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.1",
|
|
4
4
|
"description": "Zero-config bundler for Kirby Panel plugins",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Johann Schopplich",
|
|
7
|
+
"email": "pkg@johannschopplich.com",
|
|
8
|
+
"url": "https://johannschopplich.com"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"homepage": "https://github.com/johannschopplich/kirbyup#readme",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/johannschopplich/kirbyup.git"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/johannschopplich/kirbyup/issues"
|
|
18
|
+
},
|
|
5
19
|
"keywords": [
|
|
6
20
|
"kirby-cms",
|
|
7
21
|
"kirby-plugin",
|
|
@@ -9,35 +23,21 @@
|
|
|
9
23
|
"panel",
|
|
10
24
|
"bundle"
|
|
11
25
|
],
|
|
12
|
-
"homepage": "https://github.com/johannschopplich/kirbyup#readme",
|
|
13
|
-
"bugs": {
|
|
14
|
-
"url": "https://github.com/johannschopplich/kirbyup/issues"
|
|
15
|
-
},
|
|
16
|
-
"repository": {
|
|
17
|
-
"type": "git",
|
|
18
|
-
"url": "git+https://github.com/johannschopplich/kirbyup.git"
|
|
19
|
-
},
|
|
20
|
-
"license": "MIT",
|
|
21
|
-
"author": {
|
|
22
|
-
"name": "Johann Schopplich",
|
|
23
|
-
"email": "pkg@johannschopplich.com",
|
|
24
|
-
"url": "https://johannschopplich.com"
|
|
25
|
-
},
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|
|
28
|
-
"require": "./dist/index.cjs",
|
|
29
28
|
"import": "./dist/index.mjs",
|
|
30
29
|
"types": "./dist/index.d.ts"
|
|
31
30
|
},
|
|
32
31
|
"./plugin": {
|
|
33
|
-
"require": "./dist/plugin.cjs",
|
|
34
32
|
"import": "./dist/plugin.mjs",
|
|
35
33
|
"types": "./dist/plugin.d.ts"
|
|
36
34
|
}
|
|
37
35
|
},
|
|
36
|
+
"main": "./dist/index.mjs",
|
|
37
|
+
"module": "./dist/index.mjs",
|
|
38
38
|
"types": "./dist/index.d.ts",
|
|
39
39
|
"bin": {
|
|
40
|
-
"kirbyup": "./bin/kirbyup.
|
|
40
|
+
"kirbyup": "./bin/kirbyup.mjs"
|
|
41
41
|
},
|
|
42
42
|
"files": [
|
|
43
43
|
"bin",
|
|
@@ -53,46 +53,46 @@
|
|
|
53
53
|
"test:update": "vitest --update",
|
|
54
54
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
55
55
|
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
|
|
56
|
-
"release": "vitest --run &&
|
|
56
|
+
"release": "vitest --run && tsx scripts/release.ts",
|
|
57
57
|
"prepare": "pnpm exec simple-git-hooks"
|
|
58
58
|
},
|
|
59
59
|
"simple-git-hooks": {
|
|
60
|
-
"commit-msg": "
|
|
60
|
+
"commit-msg": "node scripts/verifyCommit.mjs $1"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"cac": "^6.7.12",
|
|
64
64
|
"chokidar": "^3.5.3",
|
|
65
65
|
"consola": "^2.15.3",
|
|
66
|
-
"execa": "
|
|
67
|
-
"pathe": "^0.
|
|
66
|
+
"execa": "6.1.0",
|
|
67
|
+
"pathe": "^0.3.0",
|
|
68
|
+
"perfect-debounce": "^0.1.3",
|
|
68
69
|
"picocolors": "^1.0.0",
|
|
69
|
-
"postcss": "^8.4.
|
|
70
|
+
"postcss": "^8.4.14",
|
|
70
71
|
"postcss-dir-pseudo-class": "^6.0.4",
|
|
71
|
-
"postcss-load-config": "^
|
|
72
|
+
"postcss-load-config": "^4.0.1",
|
|
72
73
|
"postcss-logical": "^5.0.4",
|
|
73
|
-
"sass": "^1.
|
|
74
|
-
"unconfig": "^0.3.
|
|
75
|
-
"vite": "^2.
|
|
76
|
-
"vite-plugin-vue2": "^
|
|
74
|
+
"sass": "^1.52.1",
|
|
75
|
+
"unconfig": "^0.3.4",
|
|
76
|
+
"vite": "^2.9.9",
|
|
77
|
+
"vite-plugin-vue2": "^2.0.1",
|
|
77
78
|
"vue": "^2.6.14",
|
|
78
79
|
"vue-template-compiler": "^2.6.14"
|
|
79
80
|
},
|
|
80
81
|
"devDependencies": {
|
|
81
|
-
"@antfu/utils": "^0.5.0",
|
|
82
82
|
"@types/fs-extra": "^9.0.13",
|
|
83
|
-
"@types/node": "^17.0.
|
|
83
|
+
"@types/node": "^17.0.38",
|
|
84
84
|
"@types/prompts": "^2.4.0",
|
|
85
85
|
"@types/semver": "^7.3.9",
|
|
86
86
|
"conventional-changelog-cli": "^2.2.2",
|
|
87
|
-
"esno": "^0.14.1",
|
|
88
87
|
"fast-glob": "^3.2.11",
|
|
89
|
-
"fs-extra": "^10.
|
|
90
|
-
"minimist": "^1.2.
|
|
91
|
-
"prettier": "^2.
|
|
88
|
+
"fs-extra": "^10.1.0",
|
|
89
|
+
"minimist": "^1.2.6",
|
|
90
|
+
"prettier": "^2.6.2",
|
|
92
91
|
"prompts": "^2.4.2",
|
|
93
|
-
"simple-git-hooks": "^2.
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
"
|
|
92
|
+
"simple-git-hooks": "^2.8.0",
|
|
93
|
+
"tsx": "^3.4.2",
|
|
94
|
+
"typescript": "^4.7.2",
|
|
95
|
+
"unbuild": "^0.7.4",
|
|
96
|
+
"vitest": "^0.13.1"
|
|
97
97
|
}
|
|
98
98
|
}
|
package/bin/kirbyup.cjs
DELETED
package/dist/chunks/index.cjs
DELETED
|
@@ -1,295 +0,0 @@
|
|
|
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 picocolors = require('picocolors');
|
|
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" ? picocolors.cyan : picocolors.magenta;
|
|
127
|
-
consola__default.log(picocolors.white(picocolors.dim(prettyOutDir)) + writeColor(filePath) + " " + picocolors.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
|
-
function toArray(array) {
|
|
155
|
-
array = array || [];
|
|
156
|
-
if (Array.isArray(array))
|
|
157
|
-
return array;
|
|
158
|
-
return [array];
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const name = "kirbyup";
|
|
162
|
-
const version = "0.22.3";
|
|
163
|
-
|
|
164
|
-
let resolvedKirbyupConfig;
|
|
165
|
-
let resolvedPostCssConfig;
|
|
166
|
-
async function viteBuild(options) {
|
|
167
|
-
let result;
|
|
168
|
-
const mode = options.watch ? "development" : "production";
|
|
169
|
-
const root = process.cwd();
|
|
170
|
-
const outDir = options.outDir ?? root;
|
|
171
|
-
const aliasDir = pathe.resolve(root, pathe.dirname(options.entry));
|
|
172
|
-
const { alias = {}, extendViteConfig = {} } = resolvedKirbyupConfig;
|
|
173
|
-
const defaultConfig = {
|
|
174
|
-
mode,
|
|
175
|
-
plugins: [vitePluginVue2.createVuePlugin(), kirbyupAutoImportPlugin()],
|
|
176
|
-
build: {
|
|
177
|
-
lib: {
|
|
178
|
-
entry: pathe.resolve(root, options.entry),
|
|
179
|
-
formats: ["iife"],
|
|
180
|
-
name: "kirbyupExport",
|
|
181
|
-
fileName: () => "index.js"
|
|
182
|
-
},
|
|
183
|
-
minify: mode === "production",
|
|
184
|
-
outDir,
|
|
185
|
-
emptyOutDir: false,
|
|
186
|
-
rollupOptions: {
|
|
187
|
-
external: ["vue"],
|
|
188
|
-
output: {
|
|
189
|
-
assetFileNames: "index.[ext]",
|
|
190
|
-
globals: {
|
|
191
|
-
vue: "Vue"
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
},
|
|
196
|
-
resolve: {
|
|
197
|
-
alias: {
|
|
198
|
-
"~/": `${aliasDir}/`,
|
|
199
|
-
"@/": `${aliasDir}/`,
|
|
200
|
-
...alias
|
|
201
|
-
}
|
|
202
|
-
},
|
|
203
|
-
css: {
|
|
204
|
-
postcss: resolvedPostCssConfig
|
|
205
|
-
},
|
|
206
|
-
envPrefix: ["VITE_", "KIRBYUP_"],
|
|
207
|
-
logLevel: "warn"
|
|
208
|
-
};
|
|
209
|
-
try {
|
|
210
|
-
result = await vite.build(vite.mergeConfig(defaultConfig, extendViteConfig));
|
|
211
|
-
} catch (error) {
|
|
212
|
-
consola__default.error("Build failed");
|
|
213
|
-
if (mode === "production") {
|
|
214
|
-
throw error;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
if (result && !options.watch) {
|
|
218
|
-
const { output } = toArray(result)[0];
|
|
219
|
-
for (const { fileName, type, code } of output) {
|
|
220
|
-
printFileInfo(root, outDir, fileName, type, code);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return result;
|
|
224
|
-
}
|
|
225
|
-
async function resolveOptions(options) {
|
|
226
|
-
if (!options.entry) {
|
|
227
|
-
throw new PrettyError(`No input file, try ${picocolors.cyan(`${name} <path/to/file.js>`)}`);
|
|
228
|
-
}
|
|
229
|
-
if (!fs.existsSync(options.entry)) {
|
|
230
|
-
throw new PrettyError(`Cannot find ${options.entry}`);
|
|
231
|
-
}
|
|
232
|
-
return options;
|
|
233
|
-
}
|
|
234
|
-
async function build(_options) {
|
|
235
|
-
const options = await resolveOptions(_options);
|
|
236
|
-
const loadConfig = createConfigLoader();
|
|
237
|
-
const { config, sources: configSources } = await loadConfig();
|
|
238
|
-
resolvedKirbyupConfig = config;
|
|
239
|
-
try {
|
|
240
|
-
resolvedPostCssConfig = await postcssrc__default({});
|
|
241
|
-
} catch (err) {
|
|
242
|
-
if (!/No PostCSS Config found/.test(err.message)) {
|
|
243
|
-
throw err;
|
|
244
|
-
}
|
|
245
|
-
resolvedPostCssConfig = {
|
|
246
|
-
plugins: [postcssLogical__default(), postcssDirPseudoClass__default()]
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
consola__default.log(picocolors.green(`${name} v${version}`));
|
|
250
|
-
consola__default.start(`Building ${picocolors.cyan(options.entry)}`);
|
|
251
|
-
if (options.watch) {
|
|
252
|
-
consola__default.info("Running in watch mode");
|
|
253
|
-
}
|
|
254
|
-
const debouncedBuild = debouncePromise(async () => {
|
|
255
|
-
viteBuild(options);
|
|
256
|
-
}, 100, handleError);
|
|
257
|
-
const startWatcher = async () => {
|
|
258
|
-
if (!options.watch)
|
|
259
|
-
return;
|
|
260
|
-
const { watch } = await import('chokidar');
|
|
261
|
-
const ignored = [
|
|
262
|
-
"**/{.git,node_modules}/**",
|
|
263
|
-
"index.{css,js}"
|
|
264
|
-
];
|
|
265
|
-
const watchPaths = typeof options.watch === "boolean" ? pathe.dirname(options.entry) : Array.isArray(options.watch) ? options.watch.filter((path) => typeof path === "string") : options.watch;
|
|
266
|
-
consola__default.info("Watching for changes in " + toArray(watchPaths).map((i) => picocolors.cyan(i)).join(", "));
|
|
267
|
-
const watcher = watch(watchPaths, {
|
|
268
|
-
ignoreInitial: true,
|
|
269
|
-
ignorePermissionErrors: true,
|
|
270
|
-
ignored
|
|
271
|
-
});
|
|
272
|
-
if (configSources.length) {
|
|
273
|
-
watcher.add(configSources);
|
|
274
|
-
}
|
|
275
|
-
watcher.on("all", async (type, file) => {
|
|
276
|
-
if (configSources.includes(file)) {
|
|
277
|
-
resolvedKirbyupConfig = (await loadConfig()).config;
|
|
278
|
-
consola__default.info(`${picocolors.cyan(pathe.basename(file))} changed, setting new config`);
|
|
279
|
-
} else {
|
|
280
|
-
consola__default.log(picocolors.green(type) + " " + picocolors.white(picocolors.dim(file)));
|
|
281
|
-
}
|
|
282
|
-
debouncedBuild();
|
|
283
|
-
});
|
|
284
|
-
};
|
|
285
|
-
await viteBuild(options);
|
|
286
|
-
consola__default.success("Build successful");
|
|
287
|
-
startWatcher();
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
exports.build = build;
|
|
291
|
-
exports.defineConfig = defineConfig;
|
|
292
|
-
exports.handleError = handleError;
|
|
293
|
-
exports.name = name;
|
|
294
|
-
exports.resolveOptions = resolveOptions;
|
|
295
|
-
exports.version = version;
|
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('picocolors');
|
|
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,25 +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('picocolors');
|
|
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;
|
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;
|