kirbyup 0.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/LICENSE +21 -0
- package/README.md +32 -0
- package/dist/cli-default.d.ts +1 -0
- package/dist/cli-default.js +275 -0
- package/dist/cli-main.d.ts +6 -0
- package/dist/cli-main.js +274 -0
- package/dist/index.d.ts +812 -0
- package/dist/index.js +197 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Johann Schopplich
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# kirbyup
|
|
2
|
+
|
|
3
|
+
The fastest and leanest way to bundle your Kirby Panel plugins. No configuration necessary.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Install it locally in your project folder:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm i kirbyup --save-dev
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
You can also install it globally but it's not recommended.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Bundle files
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
kirbyup src/index.js
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The final panel plugin will be written into the current directory as `./index.js`.
|
|
24
|
+
|
|
25
|
+
## Credits
|
|
26
|
+
|
|
27
|
+
- [EGOIST](https://github.com/egoist) for his work on [tsup](https://github.com/egoist/tsup), on which the CLI was built.
|
|
28
|
+
- [Vite](https://vitejs.dev) by Evan You and all of its contributors.
|
|
29
|
+
|
|
30
|
+
## License
|
|
31
|
+
|
|
32
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
23
|
+
var __require = typeof require !== "undefined" ? require : (x) => {
|
|
24
|
+
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
25
|
+
};
|
|
26
|
+
var __esm = (fn, res) => function __init() {
|
|
27
|
+
return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
|
|
28
|
+
};
|
|
29
|
+
var __export = (target, all) => {
|
|
30
|
+
__markAsModule(target);
|
|
31
|
+
for (var name in all)
|
|
32
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
33
|
+
};
|
|
34
|
+
var __reExport = (target, module2, desc) => {
|
|
35
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
36
|
+
for (let key of __getOwnPropNames(module2))
|
|
37
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
38
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
39
|
+
}
|
|
40
|
+
return target;
|
|
41
|
+
};
|
|
42
|
+
var __toModule = (module2) => {
|
|
43
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// node_modules/tsup/assets/cjs_shims.js
|
|
47
|
+
var importMetaUrlShim;
|
|
48
|
+
var init_cjs_shims = __esm({
|
|
49
|
+
"node_modules/tsup/assets/cjs_shims.js"() {
|
|
50
|
+
importMetaUrlShim = typeof document === "undefined" ? new (require("url")).URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// src/errors.ts
|
|
55
|
+
function handleError(error) {
|
|
56
|
+
if (error.loc) {
|
|
57
|
+
console.error(import_chalk.default.bold(import_chalk.default.red(`Error parsing: ${error.loc.file}:${error.loc.line}:${error.loc.column}`)));
|
|
58
|
+
}
|
|
59
|
+
if (error.frame) {
|
|
60
|
+
console.error(import_chalk.default.red(error.message));
|
|
61
|
+
console.error(import_chalk.default.dim(error.frame));
|
|
62
|
+
} else {
|
|
63
|
+
if (error instanceof PrettyError) {
|
|
64
|
+
console.error(import_chalk.default.red(error.message));
|
|
65
|
+
} else {
|
|
66
|
+
console.error(import_chalk.default.red(error.stack));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
process.exitCode = 1;
|
|
70
|
+
if (!import_worker_threads.isMainThread && import_worker_threads.parentPort) {
|
|
71
|
+
import_worker_threads.parentPort.postMessage("has-error");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
var import_worker_threads, import_chalk, PrettyError;
|
|
75
|
+
var init_errors = __esm({
|
|
76
|
+
"src/errors.ts"() {
|
|
77
|
+
init_cjs_shims();
|
|
78
|
+
import_worker_threads = __toModule(require("worker_threads"));
|
|
79
|
+
import_chalk = __toModule(require("chalk"));
|
|
80
|
+
PrettyError = class extends Error {
|
|
81
|
+
constructor(message) {
|
|
82
|
+
super(message);
|
|
83
|
+
this.name = this.constructor.name;
|
|
84
|
+
if (typeof Error.captureStackTrace === "function") {
|
|
85
|
+
Error.captureStackTrace(this, this.constructor);
|
|
86
|
+
} else {
|
|
87
|
+
this.stack = new Error(message).stack;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// src/utils.ts
|
|
95
|
+
function debouncePromise(fn, delay, onError) {
|
|
96
|
+
let timeout;
|
|
97
|
+
let promiseInFly;
|
|
98
|
+
let callbackPending;
|
|
99
|
+
return function debounced(...args) {
|
|
100
|
+
if (promiseInFly) {
|
|
101
|
+
callbackPending = () => {
|
|
102
|
+
debounced(...args);
|
|
103
|
+
callbackPending = void 0;
|
|
104
|
+
};
|
|
105
|
+
} else {
|
|
106
|
+
if (timeout != null)
|
|
107
|
+
clearTimeout(timeout);
|
|
108
|
+
timeout = setTimeout(() => {
|
|
109
|
+
timeout = void 0;
|
|
110
|
+
promiseInFly = fn(...args).catch(onError).finally(() => {
|
|
111
|
+
promiseInFly = void 0;
|
|
112
|
+
if (callbackPending)
|
|
113
|
+
callbackPending();
|
|
114
|
+
});
|
|
115
|
+
}, delay);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
var init_utils = __esm({
|
|
120
|
+
"src/utils.ts"() {
|
|
121
|
+
init_cjs_shims();
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// src/log.ts
|
|
126
|
+
function log(type, message) {
|
|
127
|
+
switch (type) {
|
|
128
|
+
case "error": {
|
|
129
|
+
return console.error(label, makeMessage(message, type));
|
|
130
|
+
}
|
|
131
|
+
default:
|
|
132
|
+
console.log(label, makeMessage(message, type));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
var import_chalk2, label, makeMessage;
|
|
136
|
+
var init_log = __esm({
|
|
137
|
+
"src/log.ts"() {
|
|
138
|
+
init_cjs_shims();
|
|
139
|
+
import_chalk2 = __toModule(require("chalk"));
|
|
140
|
+
label = import_chalk2.default.gray("[kirbyup]");
|
|
141
|
+
makeMessage = (input, type) => import_chalk2.default[type === "info" ? "yellow" : type === "error" ? "red" : "green"](input);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// package.json
|
|
146
|
+
var version;
|
|
147
|
+
var init_package = __esm({
|
|
148
|
+
"package.json"() {
|
|
149
|
+
version = "0.1.0";
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// src/index.ts
|
|
154
|
+
var src_exports = {};
|
|
155
|
+
__export(src_exports, {
|
|
156
|
+
build: () => build,
|
|
157
|
+
runViteBuild: () => runViteBuild
|
|
158
|
+
});
|
|
159
|
+
async function runViteBuild(options) {
|
|
160
|
+
let result;
|
|
161
|
+
try {
|
|
162
|
+
result = await (0, import_vite.build)({
|
|
163
|
+
plugins: [(0, import_vite_plugin_vue2.createVuePlugin)()],
|
|
164
|
+
build: {
|
|
165
|
+
lib: {
|
|
166
|
+
entry: import_path.default.resolve(__dirname, options.entry),
|
|
167
|
+
formats: ["es"]
|
|
168
|
+
},
|
|
169
|
+
outDir: ".",
|
|
170
|
+
rollupOptions: {
|
|
171
|
+
external: ["vue"],
|
|
172
|
+
output: {
|
|
173
|
+
entryFileNames: `[name].js`,
|
|
174
|
+
assetFileNames: `index.[ext]`,
|
|
175
|
+
globals: {
|
|
176
|
+
vue: "Vue"
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
logLevel: "error"
|
|
182
|
+
});
|
|
183
|
+
} catch (error) {
|
|
184
|
+
log("error", "Build failed");
|
|
185
|
+
throw error;
|
|
186
|
+
}
|
|
187
|
+
if (result) {
|
|
188
|
+
log("success", `Build success`);
|
|
189
|
+
}
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
async function build(_options) {
|
|
193
|
+
const options = await normalizeOptions(_options);
|
|
194
|
+
log("info", `kirbyup v${version}`);
|
|
195
|
+
log("info", `Building: ${options.entry}`);
|
|
196
|
+
if (options.watch) {
|
|
197
|
+
log("info", "Running in watch mode");
|
|
198
|
+
}
|
|
199
|
+
const debouncedBuildAll = debouncePromise(async () => {
|
|
200
|
+
runViteBuild(options);
|
|
201
|
+
}, 100, handleError);
|
|
202
|
+
const startWatcher = async () => {
|
|
203
|
+
if (!options.watch)
|
|
204
|
+
return;
|
|
205
|
+
const { watch } = await import("chokidar");
|
|
206
|
+
const ignored = ["**/{.git,node_modules}/**"];
|
|
207
|
+
const watchPaths = typeof options.watch === "boolean" ? import_path.default.dirname(options.entry) : Array.isArray(options.watch) ? options.watch.filter((path2) => typeof path2 === "string") : options.watch;
|
|
208
|
+
log("info", `Watching for changes in ${Array.isArray(watchPaths) ? watchPaths.map((v) => '"' + v + '"').join(" | ") : '"' + watchPaths + '"'}`);
|
|
209
|
+
const watcher = watch(watchPaths, {
|
|
210
|
+
ignoreInitial: true,
|
|
211
|
+
ignorePermissionErrors: true,
|
|
212
|
+
ignored
|
|
213
|
+
});
|
|
214
|
+
watcher.on("all", async (type, file) => {
|
|
215
|
+
log("info", `Change detected: ${type} ${file}`);
|
|
216
|
+
debouncedBuildAll();
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
await runViteBuild(options);
|
|
220
|
+
startWatcher();
|
|
221
|
+
}
|
|
222
|
+
var import_fs, import_path, import_vite, import_vite_plugin_vue2, normalizeOptions;
|
|
223
|
+
var init_src = __esm({
|
|
224
|
+
"src/index.ts"() {
|
|
225
|
+
init_cjs_shims();
|
|
226
|
+
import_fs = __toModule(require("fs"));
|
|
227
|
+
import_path = __toModule(require("path"));
|
|
228
|
+
import_vite = __toModule(require("vite"));
|
|
229
|
+
import_vite_plugin_vue2 = __toModule(require("vite-plugin-vue2"));
|
|
230
|
+
init_errors();
|
|
231
|
+
init_utils();
|
|
232
|
+
init_log();
|
|
233
|
+
init_package();
|
|
234
|
+
normalizeOptions = async (options) => {
|
|
235
|
+
if (!options.entry) {
|
|
236
|
+
throw new PrettyError(`No input file, try "kirbyup <path/to/file.js>"`);
|
|
237
|
+
}
|
|
238
|
+
if (!import_fs.default.existsSync(options.entry)) {
|
|
239
|
+
throw new PrettyError(`Cannot find ${options.entry}`);
|
|
240
|
+
}
|
|
241
|
+
return options;
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
// src/cli-default.ts
|
|
247
|
+
init_cjs_shims();
|
|
248
|
+
init_errors();
|
|
249
|
+
|
|
250
|
+
// src/cli-main.ts
|
|
251
|
+
init_cjs_shims();
|
|
252
|
+
var import_fs2 = __toModule(require("fs"));
|
|
253
|
+
var import_path2 = __toModule(require("path"));
|
|
254
|
+
var import_cac = __toModule(require("cac"));
|
|
255
|
+
async function main(options = {}) {
|
|
256
|
+
const cli = (0, import_cac.cac)("kirbyup");
|
|
257
|
+
cli.command("[file]", "Panel input file", {
|
|
258
|
+
ignoreOptionDefaultValue: true
|
|
259
|
+
}).option("--watch [path]", 'Watch mode, if path is not specified, it watches the current folder ".". Repeat "--watch" for more than one path').action(async (file, flags) => {
|
|
260
|
+
const { build: build2 } = await Promise.resolve().then(() => (init_src(), src_exports));
|
|
261
|
+
Object.assign(options, __spreadValues({}, flags));
|
|
262
|
+
if (file) {
|
|
263
|
+
options.entry = file;
|
|
264
|
+
}
|
|
265
|
+
await build2(options);
|
|
266
|
+
});
|
|
267
|
+
cli.help();
|
|
268
|
+
const pkgPath = (0, import_path2.join)(__dirname, "../package.json");
|
|
269
|
+
cli.version(JSON.parse((0, import_fs2.readFileSync)(pkgPath, "utf8")).version);
|
|
270
|
+
cli.parse(process.argv, { run: false });
|
|
271
|
+
await cli.runMatchedCommand();
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// src/cli-default.ts
|
|
275
|
+
main().catch(handleError);
|
package/dist/cli-main.js
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
22
|
+
var __require = typeof require !== "undefined" ? require : (x) => {
|
|
23
|
+
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
24
|
+
};
|
|
25
|
+
var __esm = (fn, res) => function __init() {
|
|
26
|
+
return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
|
|
27
|
+
};
|
|
28
|
+
var __export = (target, all) => {
|
|
29
|
+
__markAsModule(target);
|
|
30
|
+
for (var name in all)
|
|
31
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
32
|
+
};
|
|
33
|
+
var __reExport = (target, module2, desc) => {
|
|
34
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
35
|
+
for (let key of __getOwnPropNames(module2))
|
|
36
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
37
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
38
|
+
}
|
|
39
|
+
return target;
|
|
40
|
+
};
|
|
41
|
+
var __toModule = (module2) => {
|
|
42
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// node_modules/tsup/assets/cjs_shims.js
|
|
46
|
+
var importMetaUrlShim;
|
|
47
|
+
var init_cjs_shims = __esm({
|
|
48
|
+
"node_modules/tsup/assets/cjs_shims.js"() {
|
|
49
|
+
importMetaUrlShim = typeof document === "undefined" ? new (require("url")).URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// src/errors.ts
|
|
54
|
+
function handleError(error) {
|
|
55
|
+
if (error.loc) {
|
|
56
|
+
console.error(import_chalk.default.bold(import_chalk.default.red(`Error parsing: ${error.loc.file}:${error.loc.line}:${error.loc.column}`)));
|
|
57
|
+
}
|
|
58
|
+
if (error.frame) {
|
|
59
|
+
console.error(import_chalk.default.red(error.message));
|
|
60
|
+
console.error(import_chalk.default.dim(error.frame));
|
|
61
|
+
} else {
|
|
62
|
+
if (error instanceof PrettyError) {
|
|
63
|
+
console.error(import_chalk.default.red(error.message));
|
|
64
|
+
} else {
|
|
65
|
+
console.error(import_chalk.default.red(error.stack));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
process.exitCode = 1;
|
|
69
|
+
if (!import_worker_threads.isMainThread && import_worker_threads.parentPort) {
|
|
70
|
+
import_worker_threads.parentPort.postMessage("has-error");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
var import_worker_threads, import_chalk, PrettyError;
|
|
74
|
+
var init_errors = __esm({
|
|
75
|
+
"src/errors.ts"() {
|
|
76
|
+
init_cjs_shims();
|
|
77
|
+
import_worker_threads = __toModule(require("worker_threads"));
|
|
78
|
+
import_chalk = __toModule(require("chalk"));
|
|
79
|
+
PrettyError = class extends Error {
|
|
80
|
+
constructor(message) {
|
|
81
|
+
super(message);
|
|
82
|
+
this.name = this.constructor.name;
|
|
83
|
+
if (typeof Error.captureStackTrace === "function") {
|
|
84
|
+
Error.captureStackTrace(this, this.constructor);
|
|
85
|
+
} else {
|
|
86
|
+
this.stack = new Error(message).stack;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// src/utils.ts
|
|
94
|
+
function debouncePromise(fn, delay, onError) {
|
|
95
|
+
let timeout;
|
|
96
|
+
let promiseInFly;
|
|
97
|
+
let callbackPending;
|
|
98
|
+
return function debounced(...args) {
|
|
99
|
+
if (promiseInFly) {
|
|
100
|
+
callbackPending = () => {
|
|
101
|
+
debounced(...args);
|
|
102
|
+
callbackPending = void 0;
|
|
103
|
+
};
|
|
104
|
+
} else {
|
|
105
|
+
if (timeout != null)
|
|
106
|
+
clearTimeout(timeout);
|
|
107
|
+
timeout = setTimeout(() => {
|
|
108
|
+
timeout = void 0;
|
|
109
|
+
promiseInFly = fn(...args).catch(onError).finally(() => {
|
|
110
|
+
promiseInFly = void 0;
|
|
111
|
+
if (callbackPending)
|
|
112
|
+
callbackPending();
|
|
113
|
+
});
|
|
114
|
+
}, delay);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
var init_utils = __esm({
|
|
119
|
+
"src/utils.ts"() {
|
|
120
|
+
init_cjs_shims();
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// src/log.ts
|
|
125
|
+
function log(type, message) {
|
|
126
|
+
switch (type) {
|
|
127
|
+
case "error": {
|
|
128
|
+
return console.error(label, makeMessage(message, type));
|
|
129
|
+
}
|
|
130
|
+
default:
|
|
131
|
+
console.log(label, makeMessage(message, type));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
var import_chalk2, label, makeMessage;
|
|
135
|
+
var init_log = __esm({
|
|
136
|
+
"src/log.ts"() {
|
|
137
|
+
init_cjs_shims();
|
|
138
|
+
import_chalk2 = __toModule(require("chalk"));
|
|
139
|
+
label = import_chalk2.default.gray("[kirbyup]");
|
|
140
|
+
makeMessage = (input, type) => import_chalk2.default[type === "info" ? "yellow" : type === "error" ? "red" : "green"](input);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// package.json
|
|
145
|
+
var version;
|
|
146
|
+
var init_package = __esm({
|
|
147
|
+
"package.json"() {
|
|
148
|
+
version = "0.1.0";
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// src/index.ts
|
|
153
|
+
var src_exports = {};
|
|
154
|
+
__export(src_exports, {
|
|
155
|
+
build: () => build,
|
|
156
|
+
runViteBuild: () => runViteBuild
|
|
157
|
+
});
|
|
158
|
+
async function runViteBuild(options) {
|
|
159
|
+
let result;
|
|
160
|
+
try {
|
|
161
|
+
result = await (0, import_vite.build)({
|
|
162
|
+
plugins: [(0, import_vite_plugin_vue2.createVuePlugin)()],
|
|
163
|
+
build: {
|
|
164
|
+
lib: {
|
|
165
|
+
entry: import_path.default.resolve(__dirname, options.entry),
|
|
166
|
+
formats: ["es"]
|
|
167
|
+
},
|
|
168
|
+
outDir: ".",
|
|
169
|
+
rollupOptions: {
|
|
170
|
+
external: ["vue"],
|
|
171
|
+
output: {
|
|
172
|
+
entryFileNames: `[name].js`,
|
|
173
|
+
assetFileNames: `index.[ext]`,
|
|
174
|
+
globals: {
|
|
175
|
+
vue: "Vue"
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
logLevel: "error"
|
|
181
|
+
});
|
|
182
|
+
} catch (error) {
|
|
183
|
+
log("error", "Build failed");
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
186
|
+
if (result) {
|
|
187
|
+
log("success", `Build success`);
|
|
188
|
+
}
|
|
189
|
+
return result;
|
|
190
|
+
}
|
|
191
|
+
async function build(_options) {
|
|
192
|
+
const options = await normalizeOptions(_options);
|
|
193
|
+
log("info", `kirbyup v${version}`);
|
|
194
|
+
log("info", `Building: ${options.entry}`);
|
|
195
|
+
if (options.watch) {
|
|
196
|
+
log("info", "Running in watch mode");
|
|
197
|
+
}
|
|
198
|
+
const debouncedBuildAll = debouncePromise(async () => {
|
|
199
|
+
runViteBuild(options);
|
|
200
|
+
}, 100, handleError);
|
|
201
|
+
const startWatcher = async () => {
|
|
202
|
+
if (!options.watch)
|
|
203
|
+
return;
|
|
204
|
+
const { watch } = await import("chokidar");
|
|
205
|
+
const ignored = ["**/{.git,node_modules}/**"];
|
|
206
|
+
const watchPaths = typeof options.watch === "boolean" ? import_path.default.dirname(options.entry) : Array.isArray(options.watch) ? options.watch.filter((path2) => typeof path2 === "string") : options.watch;
|
|
207
|
+
log("info", `Watching for changes in ${Array.isArray(watchPaths) ? watchPaths.map((v) => '"' + v + '"').join(" | ") : '"' + watchPaths + '"'}`);
|
|
208
|
+
const watcher = watch(watchPaths, {
|
|
209
|
+
ignoreInitial: true,
|
|
210
|
+
ignorePermissionErrors: true,
|
|
211
|
+
ignored
|
|
212
|
+
});
|
|
213
|
+
watcher.on("all", async (type, file) => {
|
|
214
|
+
log("info", `Change detected: ${type} ${file}`);
|
|
215
|
+
debouncedBuildAll();
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
await runViteBuild(options);
|
|
219
|
+
startWatcher();
|
|
220
|
+
}
|
|
221
|
+
var import_fs, import_path, import_vite, import_vite_plugin_vue2, normalizeOptions;
|
|
222
|
+
var init_src = __esm({
|
|
223
|
+
"src/index.ts"() {
|
|
224
|
+
init_cjs_shims();
|
|
225
|
+
import_fs = __toModule(require("fs"));
|
|
226
|
+
import_path = __toModule(require("path"));
|
|
227
|
+
import_vite = __toModule(require("vite"));
|
|
228
|
+
import_vite_plugin_vue2 = __toModule(require("vite-plugin-vue2"));
|
|
229
|
+
init_errors();
|
|
230
|
+
init_utils();
|
|
231
|
+
init_log();
|
|
232
|
+
init_package();
|
|
233
|
+
normalizeOptions = async (options) => {
|
|
234
|
+
if (!options.entry) {
|
|
235
|
+
throw new PrettyError(`No input file, try "kirbyup <path/to/file.js>"`);
|
|
236
|
+
}
|
|
237
|
+
if (!import_fs.default.existsSync(options.entry)) {
|
|
238
|
+
throw new PrettyError(`Cannot find ${options.entry}`);
|
|
239
|
+
}
|
|
240
|
+
return options;
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// src/cli-main.ts
|
|
246
|
+
__export(exports, {
|
|
247
|
+
main: () => main
|
|
248
|
+
});
|
|
249
|
+
init_cjs_shims();
|
|
250
|
+
var import_fs2 = __toModule(require("fs"));
|
|
251
|
+
var import_path2 = __toModule(require("path"));
|
|
252
|
+
var import_cac = __toModule(require("cac"));
|
|
253
|
+
async function main(options = {}) {
|
|
254
|
+
const cli = (0, import_cac.cac)("kirbyup");
|
|
255
|
+
cli.command("[file]", "Panel input file", {
|
|
256
|
+
ignoreOptionDefaultValue: true
|
|
257
|
+
}).option("--watch [path]", 'Watch mode, if path is not specified, it watches the current folder ".". Repeat "--watch" for more than one path').action(async (file, flags) => {
|
|
258
|
+
const { build: build2 } = await Promise.resolve().then(() => (init_src(), src_exports));
|
|
259
|
+
Object.assign(options, __spreadValues({}, flags));
|
|
260
|
+
if (file) {
|
|
261
|
+
options.entry = file;
|
|
262
|
+
}
|
|
263
|
+
await build2(options);
|
|
264
|
+
});
|
|
265
|
+
cli.help();
|
|
266
|
+
const pkgPath = (0, import_path2.join)(__dirname, "../package.json");
|
|
267
|
+
cli.version(JSON.parse((0, import_fs2.readFileSync)(pkgPath, "utf8")).version);
|
|
268
|
+
cli.parse(process.argv, { run: false });
|
|
269
|
+
await cli.runMatchedCommand();
|
|
270
|
+
}
|
|
271
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
272
|
+
0 && (module.exports = {
|
|
273
|
+
main
|
|
274
|
+
});
|