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/dist/index.js ADDED
@@ -0,0 +1,197 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
+ var __require = typeof require !== "undefined" ? require : (x) => {
9
+ throw new Error('Dynamic require of "' + x + '" is not supported');
10
+ };
11
+ var __export = (target, all) => {
12
+ __markAsModule(target);
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __reExport = (target, module2, desc) => {
17
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
18
+ for (let key of __getOwnPropNames(module2))
19
+ if (!__hasOwnProp.call(target, key) && key !== "default")
20
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
21
+ }
22
+ return target;
23
+ };
24
+ var __toModule = (module2) => {
25
+ 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);
26
+ };
27
+
28
+ // src/index.ts
29
+ __export(exports, {
30
+ build: () => build,
31
+ runViteBuild: () => runViteBuild
32
+ });
33
+
34
+ // node_modules/tsup/assets/cjs_shims.js
35
+ var importMetaUrlShim = typeof document === "undefined" ? new (require("url")).URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
36
+
37
+ // src/index.ts
38
+ var import_fs = __toModule(require("fs"));
39
+ var import_path = __toModule(require("path"));
40
+ var import_vite = __toModule(require("vite"));
41
+ var import_vite_plugin_vue2 = __toModule(require("vite-plugin-vue2"));
42
+
43
+ // src/errors.ts
44
+ var import_worker_threads = __toModule(require("worker_threads"));
45
+ var import_chalk = __toModule(require("chalk"));
46
+ var PrettyError = class extends Error {
47
+ constructor(message) {
48
+ super(message);
49
+ this.name = this.constructor.name;
50
+ if (typeof Error.captureStackTrace === "function") {
51
+ Error.captureStackTrace(this, this.constructor);
52
+ } else {
53
+ this.stack = new Error(message).stack;
54
+ }
55
+ }
56
+ };
57
+ function handleError(error) {
58
+ if (error.loc) {
59
+ console.error(import_chalk.default.bold(import_chalk.default.red(`Error parsing: ${error.loc.file}:${error.loc.line}:${error.loc.column}`)));
60
+ }
61
+ if (error.frame) {
62
+ console.error(import_chalk.default.red(error.message));
63
+ console.error(import_chalk.default.dim(error.frame));
64
+ } else {
65
+ if (error instanceof PrettyError) {
66
+ console.error(import_chalk.default.red(error.message));
67
+ } else {
68
+ console.error(import_chalk.default.red(error.stack));
69
+ }
70
+ }
71
+ process.exitCode = 1;
72
+ if (!import_worker_threads.isMainThread && import_worker_threads.parentPort) {
73
+ import_worker_threads.parentPort.postMessage("has-error");
74
+ }
75
+ }
76
+
77
+ // src/utils.ts
78
+ function debouncePromise(fn, delay, onError) {
79
+ let timeout;
80
+ let promiseInFly;
81
+ let callbackPending;
82
+ return function debounced(...args) {
83
+ if (promiseInFly) {
84
+ callbackPending = () => {
85
+ debounced(...args);
86
+ callbackPending = void 0;
87
+ };
88
+ } else {
89
+ if (timeout != null)
90
+ clearTimeout(timeout);
91
+ timeout = setTimeout(() => {
92
+ timeout = void 0;
93
+ promiseInFly = fn(...args).catch(onError).finally(() => {
94
+ promiseInFly = void 0;
95
+ if (callbackPending)
96
+ callbackPending();
97
+ });
98
+ }, delay);
99
+ }
100
+ };
101
+ }
102
+
103
+ // src/log.ts
104
+ var import_chalk2 = __toModule(require("chalk"));
105
+ var label = import_chalk2.default.gray("[kirbyup]");
106
+ var makeMessage = (input, type) => import_chalk2.default[type === "info" ? "yellow" : type === "error" ? "red" : "green"](input);
107
+ function log(type, message) {
108
+ switch (type) {
109
+ case "error": {
110
+ return console.error(label, makeMessage(message, type));
111
+ }
112
+ default:
113
+ console.log(label, makeMessage(message, type));
114
+ }
115
+ }
116
+
117
+ // package.json
118
+ var version = "0.1.0";
119
+
120
+ // src/index.ts
121
+ async function runViteBuild(options) {
122
+ let result;
123
+ try {
124
+ result = await (0, import_vite.build)({
125
+ plugins: [(0, import_vite_plugin_vue2.createVuePlugin)()],
126
+ build: {
127
+ lib: {
128
+ entry: import_path.default.resolve(__dirname, options.entry),
129
+ formats: ["es"]
130
+ },
131
+ outDir: ".",
132
+ rollupOptions: {
133
+ external: ["vue"],
134
+ output: {
135
+ entryFileNames: `[name].js`,
136
+ assetFileNames: `index.[ext]`,
137
+ globals: {
138
+ vue: "Vue"
139
+ }
140
+ }
141
+ }
142
+ },
143
+ logLevel: "error"
144
+ });
145
+ } catch (error) {
146
+ log("error", "Build failed");
147
+ throw error;
148
+ }
149
+ if (result) {
150
+ log("success", `Build success`);
151
+ }
152
+ return result;
153
+ }
154
+ var normalizeOptions = async (options) => {
155
+ if (!options.entry) {
156
+ throw new PrettyError(`No input file, try "kirbyup <path/to/file.js>"`);
157
+ }
158
+ if (!import_fs.default.existsSync(options.entry)) {
159
+ throw new PrettyError(`Cannot find ${options.entry}`);
160
+ }
161
+ return options;
162
+ };
163
+ async function build(_options) {
164
+ const options = await normalizeOptions(_options);
165
+ log("info", `kirbyup v${version}`);
166
+ log("info", `Building: ${options.entry}`);
167
+ if (options.watch) {
168
+ log("info", "Running in watch mode");
169
+ }
170
+ const debouncedBuildAll = debouncePromise(async () => {
171
+ runViteBuild(options);
172
+ }, 100, handleError);
173
+ const startWatcher = async () => {
174
+ if (!options.watch)
175
+ return;
176
+ const { watch } = await import("chokidar");
177
+ const ignored = ["**/{.git,node_modules}/**"];
178
+ 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;
179
+ log("info", `Watching for changes in ${Array.isArray(watchPaths) ? watchPaths.map((v) => '"' + v + '"').join(" | ") : '"' + watchPaths + '"'}`);
180
+ const watcher = watch(watchPaths, {
181
+ ignoreInitial: true,
182
+ ignorePermissionErrors: true,
183
+ ignored
184
+ });
185
+ watcher.on("all", async (type, file) => {
186
+ log("info", `Change detected: ${type} ${file}`);
187
+ debouncedBuildAll();
188
+ });
189
+ };
190
+ await runViteBuild(options);
191
+ startWatcher();
192
+ }
193
+ // Annotate the CommonJS export names for ESM import in node:
194
+ 0 && (module.exports = {
195
+ build,
196
+ runViteBuild
197
+ });
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "kirbyup",
3
+ "version": "0.1.0",
4
+ "description": "Bundle your Kirby Panel plugins with ease",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "main": "dist/index.js",
9
+ "bin": {
10
+ "kirbyup": "dist/cli-default.js"
11
+ },
12
+ "types": "dist/index.d.ts",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/johannschopplich/kirbyup.git"
16
+ },
17
+ "keywords": [
18
+ "kirby",
19
+ "bundler"
20
+ ],
21
+ "author": {
22
+ "name": "Johann Schopplich",
23
+ "email": "pkg@johannschopplich.com",
24
+ "url": "https://johannschopplich.com"
25
+ },
26
+ "license": "MIT",
27
+ "bugs": {
28
+ "url": "https://github.com/johannschopplich/kirbyup/issues"
29
+ },
30
+ "homepage": "https://github.com/johannschopplich/kirbyup#readme",
31
+ "scripts": {
32
+ "build": "tsup src/cli-*.ts src/index.ts --target node14 --clean --dts-resolve",
33
+ "prepublishOnly": "npm run build"
34
+ },
35
+ "dependencies": {
36
+ "cac": "^6.7.3",
37
+ "chalk": "^4.1.2",
38
+ "chokidar": "^3.5.2",
39
+ "prettier": "^2.4.1",
40
+ "ts-essentials": "^8.1.0",
41
+ "tsup": "^5.1.0",
42
+ "vite": "^2.5.7",
43
+ "vite-plugin-vue2": "^1.8.2",
44
+ "vue": "^2.6.14"
45
+ },
46
+ "devDependencies": {
47
+ "@types/node": "^16.9.1",
48
+ "typescript": "^4.4.3"
49
+ }
50
+ }