kirbyup 1.0.0 → 1.1.0
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 → cli.mjs} +1 -1
- package/dist/chunks/index.mjs +92 -96
- package/dist/cli.mjs +13 -11
- package/dist/index.d.ts +4 -3
- package/dist/index.mjs +5 -4
- package/dist/plugin.d.ts +2 -2
- package/package.json +21 -26
package/dist/chunks/index.mjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { existsSync as existsSync$1 } from 'node:fs';
|
|
2
|
+
import { resolve, normalize, relative, dirname, basename } from 'pathe';
|
|
3
3
|
import { build as build$1, mergeConfig } from 'vite';
|
|
4
4
|
import { createVuePlugin } from 'vite-plugin-vue2';
|
|
5
|
-
import MagicString from 'magic-string';
|
|
6
|
-
import { createConfigLoader } from 'unconfig';
|
|
7
5
|
import postcssrc from 'postcss-load-config';
|
|
8
6
|
import postcssLogical from 'postcss-logical';
|
|
9
7
|
import postcssDirPseudoClass from 'postcss-dir-pseudo-class';
|
|
@@ -13,39 +11,46 @@ import colors from 'picocolors';
|
|
|
13
11
|
import { readFile } from 'fs/promises';
|
|
14
12
|
import { gzip } from 'zlib';
|
|
15
13
|
import { promisify } from 'util';
|
|
14
|
+
import { existsSync, statSync } from 'fs';
|
|
15
|
+
import { createConfigLoader } from 'unconfig';
|
|
16
|
+
import MagicString from 'magic-string';
|
|
16
17
|
|
|
17
|
-
const
|
|
18
|
-
const
|
|
18
|
+
const name = "kirbyup";
|
|
19
|
+
const version = "1.1.0";
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
name
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
21
|
+
class PrettyError extends Error {
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = this.constructor.name;
|
|
25
|
+
if (typeof Error.captureStackTrace === "function")
|
|
26
|
+
Error.captureStackTrace(this, this.constructor);
|
|
27
|
+
else
|
|
28
|
+
this.stack = new Error(message).stack;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function handleError(error) {
|
|
32
|
+
consola.error(error.message);
|
|
33
|
+
process.exitCode = 1;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function toArray(array) {
|
|
37
|
+
array = array || [];
|
|
38
|
+
if (Array.isArray(array))
|
|
39
|
+
return array;
|
|
40
|
+
return [array];
|
|
41
|
+
}
|
|
42
|
+
const compress = promisify(gzip);
|
|
43
|
+
async function getCompressedSize(code) {
|
|
44
|
+
const size = (await compress(typeof code === "string" ? code : Buffer.from(code))).length / 1024;
|
|
45
|
+
return ` / gzip: ${size.toFixed(2)} KiB`;
|
|
46
|
+
}
|
|
47
|
+
async function printFileInfo(root, outDir, filePath, type, content) {
|
|
48
|
+
content ?? (content = await readFile(resolve(outDir, filePath), "utf8"));
|
|
49
|
+
const prettyOutDir = `${normalize(relative(root, resolve(root, outDir)))}/`;
|
|
50
|
+
const kibs = content.length / 1024;
|
|
51
|
+
const compressedSize = await getCompressedSize(content);
|
|
52
|
+
const writeColor = type === "chunk" ? colors.cyan : colors.magenta;
|
|
53
|
+
consola.log(`${colors.white(colors.dim(prettyOutDir)) + writeColor(filePath)} ${colors.dim(`${kibs.toFixed(2)} KiB${compressedSize}`)}`);
|
|
49
54
|
}
|
|
50
55
|
|
|
51
56
|
function defineConfig(config) {
|
|
@@ -90,60 +95,54 @@ async function loadConfig(cwd = process.cwd(), configOrPath = cwd, extraConfigSo
|
|
|
90
95
|
return result;
|
|
91
96
|
}
|
|
92
97
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
super(message);
|
|
96
|
-
this.name = this.constructor.name;
|
|
97
|
-
if (typeof Error.captureStackTrace === "function") {
|
|
98
|
-
Error.captureStackTrace(this, this.constructor);
|
|
99
|
-
} else {
|
|
100
|
-
this.stack = new Error(message).stack;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
function handleError(error) {
|
|
105
|
-
consola.error(error.message);
|
|
106
|
-
process.exitCode = 1;
|
|
107
|
-
}
|
|
98
|
+
const multilineCommentsRE = /\/\*(.|[\r\n])*?\*\//gm;
|
|
99
|
+
const singlelineCommentsRE = /\/\/.*/g;
|
|
108
100
|
|
|
109
|
-
function
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
async
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
101
|
+
function kirbyupAutoImportPlugin() {
|
|
102
|
+
let config;
|
|
103
|
+
return {
|
|
104
|
+
name: "kirbyup:auto-import",
|
|
105
|
+
configResolved(resolvedConfig) {
|
|
106
|
+
config = resolvedConfig;
|
|
107
|
+
},
|
|
108
|
+
async transform(code) {
|
|
109
|
+
if (code.includes("kirbyup.import")) {
|
|
110
|
+
const kirbyupImportRE = /\bkirbyup\.import\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*\)/g;
|
|
111
|
+
const noCommentsCode = code.replace(multilineCommentsRE, (m) => " ".repeat(m.length)).replace(singlelineCommentsRE, (m) => " ".repeat(m.length));
|
|
112
|
+
let s = null;
|
|
113
|
+
let match;
|
|
114
|
+
while (match = kirbyupImportRE.exec(noCommentsCode)) {
|
|
115
|
+
const { 0: exp, 1: rawPath, index } = match;
|
|
116
|
+
if (!s)
|
|
117
|
+
s = new MagicString(code);
|
|
118
|
+
s.overwrite(index, index + exp.length, `kirbyup.import(import.meta.globEager(${rawPath}))`);
|
|
119
|
+
}
|
|
120
|
+
if (s) {
|
|
121
|
+
return {
|
|
122
|
+
code: s.toString(),
|
|
123
|
+
map: config.build.sourcemap ? s.generateMap({ hires: true }) : null
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
127
130
|
}
|
|
128
131
|
|
|
129
|
-
const name = "kirbyup";
|
|
130
|
-
const version = "1.0.0";
|
|
131
|
-
|
|
132
132
|
let resolvedKirbyupConfig;
|
|
133
133
|
let resolvedPostCssConfig;
|
|
134
|
-
async function
|
|
134
|
+
async function generate(options) {
|
|
135
135
|
let result;
|
|
136
136
|
const mode = options.watch ? "development" : "production";
|
|
137
|
-
const
|
|
138
|
-
const
|
|
139
|
-
const aliasDir = resolve(root, dirname(options.entry));
|
|
137
|
+
const outDir = options.outDir || options.cwd;
|
|
138
|
+
const aliasDir = resolve(options.cwd, dirname(options.entry));
|
|
140
139
|
const { alias = {}, extendViteConfig = {} } = resolvedKirbyupConfig;
|
|
141
140
|
const defaultConfig = {
|
|
142
141
|
mode,
|
|
143
142
|
plugins: [createVuePlugin(), kirbyupAutoImportPlugin()],
|
|
144
143
|
build: {
|
|
145
144
|
lib: {
|
|
146
|
-
entry: resolve(
|
|
145
|
+
entry: resolve(options.cwd, options.entry),
|
|
147
146
|
formats: ["iife"],
|
|
148
147
|
name: "kirbyupExport",
|
|
149
148
|
fileName: () => "index.js"
|
|
@@ -178,48 +177,45 @@ async function viteBuild(options) {
|
|
|
178
177
|
result = await build$1(mergeConfig(defaultConfig, extendViteConfig));
|
|
179
178
|
} catch (error) {
|
|
180
179
|
consola.error("Build failed");
|
|
181
|
-
if (mode === "production")
|
|
180
|
+
if (mode === "production")
|
|
182
181
|
throw error;
|
|
183
|
-
}
|
|
184
182
|
}
|
|
185
183
|
if (result && !options.watch) {
|
|
186
184
|
const { output } = toArray(result)[0];
|
|
187
|
-
for (const { fileName, type, code } of output)
|
|
188
|
-
printFileInfo(
|
|
189
|
-
}
|
|
185
|
+
for (const { fileName, type, code } of output)
|
|
186
|
+
printFileInfo(options.cwd, outDir, fileName, type, code);
|
|
190
187
|
}
|
|
191
188
|
return result;
|
|
192
189
|
}
|
|
193
190
|
async function resolveOptions(options) {
|
|
191
|
+
options.cwd = options.cwd || process.cwd();
|
|
194
192
|
if (!options.entry) {
|
|
195
193
|
throw new PrettyError(`No input file, try ${colors.cyan(`${name} <path/to/file.js>`)}`);
|
|
196
194
|
}
|
|
197
|
-
if (!existsSync(options.entry))
|
|
198
|
-
throw new PrettyError(`Cannot find ${options.entry}`);
|
|
199
|
-
}
|
|
195
|
+
if (!existsSync$1(resolve(options.cwd, options.entry)))
|
|
196
|
+
throw new PrettyError(`Cannot find "${options.entry}"`);
|
|
200
197
|
return options;
|
|
201
198
|
}
|
|
202
199
|
async function build(_options) {
|
|
203
200
|
const options = await resolveOptions(_options);
|
|
204
|
-
const {
|
|
201
|
+
const { cwd } = options;
|
|
202
|
+
const { config, sources: configSources } = await loadConfig(cwd);
|
|
205
203
|
resolvedKirbyupConfig = config;
|
|
206
204
|
try {
|
|
207
205
|
resolvedPostCssConfig = await postcssrc({});
|
|
208
206
|
} catch (err) {
|
|
209
|
-
if (!/No PostCSS Config found/.test(err.message))
|
|
207
|
+
if (!/No PostCSS Config found/.test(err.message))
|
|
210
208
|
throw err;
|
|
211
|
-
}
|
|
212
209
|
resolvedPostCssConfig = {
|
|
213
210
|
plugins: [postcssLogical(), postcssDirPseudoClass()]
|
|
214
211
|
};
|
|
215
212
|
}
|
|
216
213
|
consola.log(colors.green(`${name} v${version}`));
|
|
217
214
|
consola.start(`Building ${colors.cyan(options.entry)}`);
|
|
218
|
-
if (options.watch)
|
|
215
|
+
if (options.watch)
|
|
219
216
|
consola.info("Running in watch mode");
|
|
220
|
-
}
|
|
221
217
|
const debouncedBuild = debounce(async () => {
|
|
222
|
-
|
|
218
|
+
generate(options).catch(handleError);
|
|
223
219
|
}, 100);
|
|
224
220
|
const startWatcher = async () => {
|
|
225
221
|
if (!options.watch)
|
|
@@ -230,26 +226,26 @@ async function build(_options) {
|
|
|
230
226
|
"index.{css,js}"
|
|
231
227
|
];
|
|
232
228
|
const watchPaths = typeof options.watch === "boolean" ? dirname(options.entry) : Array.isArray(options.watch) ? options.watch.filter((path) => typeof path === "string") : options.watch;
|
|
233
|
-
consola.info(
|
|
229
|
+
consola.info(`Watching for changes in ${toArray(watchPaths).map((i) => colors.cyan(i)).join(", ")}`);
|
|
234
230
|
const watcher = watch(watchPaths, {
|
|
235
231
|
ignoreInitial: true,
|
|
236
232
|
ignorePermissionErrors: true,
|
|
237
|
-
ignored
|
|
233
|
+
ignored,
|
|
234
|
+
cwd
|
|
238
235
|
});
|
|
239
|
-
if (configSources.length)
|
|
236
|
+
if (configSources.length)
|
|
240
237
|
watcher.add(configSources);
|
|
241
|
-
}
|
|
242
238
|
watcher.on("all", async (type, file) => {
|
|
243
239
|
if (configSources.includes(file)) {
|
|
244
240
|
resolvedKirbyupConfig = (await loadConfig()).config;
|
|
245
241
|
consola.info(`${colors.cyan(basename(file))} changed, setting new config`);
|
|
246
242
|
} else {
|
|
247
|
-
consola.log(colors.green(type)
|
|
243
|
+
consola.log(`${colors.green(type)} ${colors.white(colors.dim(file))}`);
|
|
248
244
|
}
|
|
249
245
|
debouncedBuild();
|
|
250
246
|
});
|
|
251
247
|
};
|
|
252
|
-
await
|
|
248
|
+
await generate(options);
|
|
253
249
|
consola.success("Build successful");
|
|
254
250
|
startWatcher();
|
|
255
251
|
}
|
package/dist/cli.mjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { cac } from 'cac';
|
|
2
|
-
import {
|
|
2
|
+
import { n as name, b as build, v as version, h as handleError } from './chunks/index.mjs';
|
|
3
|
+
import 'node:fs';
|
|
3
4
|
import 'pathe';
|
|
4
|
-
import 'fs';
|
|
5
5
|
import 'vite';
|
|
6
6
|
import 'vite-plugin-vue2';
|
|
7
|
-
import 'magic-string';
|
|
8
|
-
import 'unconfig';
|
|
9
7
|
import 'postcss-load-config';
|
|
10
8
|
import 'postcss-logical';
|
|
11
9
|
import 'postcss-dir-pseudo-class';
|
|
@@ -15,25 +13,29 @@ import 'picocolors';
|
|
|
15
13
|
import 'fs/promises';
|
|
16
14
|
import 'zlib';
|
|
17
15
|
import 'util';
|
|
16
|
+
import 'fs';
|
|
17
|
+
import 'unconfig';
|
|
18
|
+
import 'magic-string';
|
|
18
19
|
|
|
19
|
-
async function
|
|
20
|
+
async function startCli(cwd = process.cwd(), argv = process.argv, options = {}) {
|
|
20
21
|
const cli = cac(name);
|
|
21
22
|
cli.command("[file]", "Panel input file", {
|
|
22
23
|
ignoreOptionDefaultValue: true
|
|
23
24
|
}).option("-d, --out-dir <dir>", "Output directory", {
|
|
24
|
-
default:
|
|
25
|
-
}).option("-w, --watch [path]", 'Watch
|
|
25
|
+
default: cwd
|
|
26
|
+
}).option("-w, --watch [path]", 'Watch for file changes. If no path is specified, the folder of the input file will be watched. Repeat "--watch" for multiple paths.').action(async (file, flags) => {
|
|
26
27
|
Object.assign(options, {
|
|
28
|
+
cwd,
|
|
27
29
|
...flags
|
|
28
30
|
});
|
|
29
|
-
if (file)
|
|
31
|
+
if (file)
|
|
30
32
|
options.entry = file;
|
|
31
|
-
}
|
|
32
33
|
await build(options);
|
|
33
34
|
});
|
|
34
35
|
cli.help();
|
|
35
36
|
cli.version(version);
|
|
36
|
-
cli.parse(
|
|
37
|
+
cli.parse(argv, { run: false });
|
|
37
38
|
await cli.runMatchedCommand();
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
+
|
|
41
|
+
startCli().catch(handleError);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { AliasOptions, InlineConfig } from 'vite';
|
|
2
2
|
|
|
3
3
|
declare type MarkRequired<T, RK extends keyof T> = Exclude<T, RK> & Required<Pick<T, RK>>;
|
|
4
|
-
|
|
4
|
+
interface CliOptions {
|
|
5
|
+
cwd?: string;
|
|
5
6
|
entry?: string;
|
|
6
7
|
outDir?: string;
|
|
7
8
|
watch?: boolean | string | Array<boolean | string>;
|
|
8
|
-
}
|
|
9
|
-
declare type ResolvedCliOptions = MarkRequired<CliOptions, 'entry'>;
|
|
9
|
+
}
|
|
10
|
+
declare type ResolvedCliOptions = MarkRequired<CliOptions, 'cwd' | 'entry'>;
|
|
10
11
|
interface UserConfig {
|
|
11
12
|
/**
|
|
12
13
|
* Load from config files
|
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
import 'node:fs';
|
|
1
2
|
import 'pathe';
|
|
2
|
-
import 'fs';
|
|
3
3
|
import 'vite';
|
|
4
4
|
import 'vite-plugin-vue2';
|
|
5
|
-
export { b as build, d as defineConfig, r as resolveOptions } from './chunks/index.mjs';
|
|
6
5
|
import 'postcss-load-config';
|
|
7
6
|
import 'postcss-logical';
|
|
8
7
|
import 'postcss-dir-pseudo-class';
|
|
9
8
|
import 'consola';
|
|
10
9
|
import 'perfect-debounce';
|
|
11
10
|
import 'picocolors';
|
|
12
|
-
|
|
13
|
-
import 'unconfig';
|
|
11
|
+
export { b as build, d as defineConfig, r as resolveOptions } from './chunks/index.mjs';
|
|
14
12
|
import 'fs/promises';
|
|
15
13
|
import 'zlib';
|
|
16
14
|
import 'util';
|
|
15
|
+
import 'fs';
|
|
16
|
+
import 'unconfig';
|
|
17
|
+
import 'magic-string';
|
package/dist/plugin.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kirbyup",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"packageManager": "pnpm@7.3.0",
|
|
4
5
|
"description": "Zero-config bundler for Kirby Panel plugins",
|
|
5
6
|
"author": {
|
|
6
7
|
"name": "Johann Schopplich",
|
|
@@ -35,9 +36,7 @@
|
|
|
35
36
|
},
|
|
36
37
|
"module": "./dist/index.mjs",
|
|
37
38
|
"types": "./dist/index.d.ts",
|
|
38
|
-
"bin":
|
|
39
|
-
"kirbyup": "./bin/kirbyup.mjs"
|
|
40
|
-
},
|
|
39
|
+
"bin": "./cli.mjs",
|
|
41
40
|
"files": [
|
|
42
41
|
"bin",
|
|
43
42
|
"dist"
|
|
@@ -47,51 +46,47 @@
|
|
|
47
46
|
},
|
|
48
47
|
"scripts": {
|
|
49
48
|
"build": "unbuild",
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
49
|
+
"dev": "unbuild --stub",
|
|
50
|
+
"lint": "eslint .",
|
|
51
|
+
"lint:fix": "eslint . --fix",
|
|
52
|
+
"release": "bumpp --commit --push --tag",
|
|
53
|
+
"test": "vitest",
|
|
54
|
+
"typecheck": "tsc --noEmit",
|
|
56
55
|
"prepare": "pnpm exec simple-git-hooks"
|
|
57
56
|
},
|
|
58
|
-
"simple-git-hooks": {
|
|
59
|
-
"commit-msg": "node scripts/verifyCommit.mjs $1"
|
|
60
|
-
},
|
|
61
57
|
"dependencies": {
|
|
62
58
|
"cac": "^6.7.12",
|
|
63
59
|
"chokidar": "^3.5.3",
|
|
64
60
|
"consola": "^2.15.3",
|
|
65
|
-
"
|
|
66
|
-
"pathe": "^0.3.0",
|
|
61
|
+
"pathe": "^0.3.1",
|
|
67
62
|
"perfect-debounce": "^0.1.3",
|
|
68
63
|
"picocolors": "^1.0.0",
|
|
69
64
|
"postcss": "^8.4.14",
|
|
70
65
|
"postcss-dir-pseudo-class": "^6.0.4",
|
|
71
66
|
"postcss-load-config": "^4.0.1",
|
|
72
67
|
"postcss-logical": "^5.0.4",
|
|
73
|
-
"sass": "^1.
|
|
68
|
+
"sass": "^1.53.0",
|
|
74
69
|
"unconfig": "^0.3.4",
|
|
75
|
-
"vite": "
|
|
70
|
+
"vite": "2.9.9",
|
|
76
71
|
"vite-plugin-vue2": "^2.0.1",
|
|
77
72
|
"vue": "^2.6.14",
|
|
78
73
|
"vue-template-compiler": "^2.6.14"
|
|
79
74
|
},
|
|
80
75
|
"devDependencies": {
|
|
76
|
+
"@antfu/eslint-config": "^0.25.2",
|
|
81
77
|
"@types/fs-extra": "^9.0.13",
|
|
82
|
-
"@types/node": "^
|
|
78
|
+
"@types/node": "^18.0.0",
|
|
83
79
|
"@types/prompts": "^2.4.0",
|
|
84
|
-
"
|
|
85
|
-
"
|
|
80
|
+
"bumpp": "^8.2.1",
|
|
81
|
+
"eslint": "^8.18.0",
|
|
86
82
|
"fast-glob": "^3.2.11",
|
|
87
83
|
"fs-extra": "^10.1.0",
|
|
88
|
-
"minimist": "^1.2.6",
|
|
89
|
-
"prettier": "^2.6.2",
|
|
90
|
-
"prompts": "^2.4.2",
|
|
91
84
|
"simple-git-hooks": "^2.8.0",
|
|
92
|
-
"
|
|
93
|
-
"typescript": "^4.7.3",
|
|
85
|
+
"typescript": "^4.7.4",
|
|
94
86
|
"unbuild": "^0.7.4",
|
|
95
|
-
"vitest": "^0.
|
|
87
|
+
"vitest": "^0.16.0"
|
|
88
|
+
},
|
|
89
|
+
"simple-git-hooks": {
|
|
90
|
+
"commit-msg": "node scripts/verifyCommit.mjs $1"
|
|
96
91
|
}
|
|
97
92
|
}
|