kirbyup 0.4.0 → 0.8.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # kirbyup
2
2
 
3
- > Take a lool into the [plainkit](./plainkit) folder for an example setup.
3
+ > Take a lool into the [pluginkit](./pluginkit) folder for an example setup.
4
4
 
5
5
  The fastest and leanest way to bundle your Kirby Panel plugins. No configuration necessary.
6
6
 
@@ -12,35 +12,37 @@ Install it locally in your project folder:
12
12
  npm i kirbyup --save-dev
13
13
  ```
14
14
 
15
- You can also install it globally but it's not recommended.
15
+ You can also install it globally.
16
16
 
17
17
  ## Usage
18
18
 
19
19
  ```json
20
20
  {
21
21
  "scripts": {
22
- "dev": "kirbyup src/index.js --watch src",
22
+ "dev": "kirbyup src/index.js --watch",
23
23
  "build": "kirbyup src/index.js"
24
24
  },
25
25
  "devDependencies": {
26
- "kirbyup": "^0.4.0"
26
+ "kirbyup": "^0.8.0"
27
27
  }
28
28
  }
29
29
  ```
30
30
 
31
31
  ### Development
32
32
 
33
+ Rebuild the Panel plugin on any file changes:
34
+
33
35
  ```bash
34
36
  kirbyup src/index.js --watch
35
37
  ```
36
38
 
37
- You can also specify the directories to be watched. By default, if no path is specified, it watches the current directory.
39
+ You can also specify the directories to be watched. By default, if no path is specified, kirbyup watches the directory specified by the input file (`src` for the example above).
38
40
 
39
41
  ```bash
40
42
  kirbyup src/index.js --watch src
41
43
  ```
42
44
 
43
- You can specify more than a single directory
45
+ You can specify more than a single directory:
44
46
 
45
47
  ```bash
46
48
  kirbyup src/index.js --watch src --watch libs
@@ -54,10 +56,14 @@ kirbyup src/index.js
54
56
 
55
57
  The final panel plugin will be bundled, minified, and written into the current directory as `./index.js`.
56
58
 
59
+ ## TODO
60
+
61
+ - [ ] HMR with Vite in lib mode
62
+
57
63
  ## Credits
58
64
 
59
65
  - [Vite](https://vitejs.dev) by Evan You and all of its contributors.
60
- - [EGOIST](https://github.com/egoist) for his work on [tsup](https://github.com/egoist/tsup), on which the CLI was built.
66
+ - [EGOIST](https://github.com/egoist) for his work on [tsup](https://github.com/egoist/tsup), which this CLI was forked from.
61
67
 
62
68
  ## License
63
69
 
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env node
2
1
  var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -51,6 +50,15 @@ var init_cjs_shims = __esm({
51
50
  }
52
51
  });
53
52
 
53
+ // package.json
54
+ var name, version;
55
+ var init_package = __esm({
56
+ "package.json"() {
57
+ name = "kirbyup";
58
+ version = "0.8.0";
59
+ }
60
+ });
61
+
54
62
  // src/errors.ts
55
63
  function handleError(error) {
56
64
  if (error.loc) {
@@ -91,15 +99,6 @@ var init_errors = __esm({
91
99
  }
92
100
  });
93
101
 
94
- // package.json
95
- var name, version;
96
- var init_package = __esm({
97
- "package.json"() {
98
- name = "kirbyup";
99
- version = "0.4.0";
100
- }
101
- });
102
-
103
102
  // src/utils.ts
104
103
  function debouncePromise(fn, delay, onError) {
105
104
  let timeout;
@@ -132,23 +131,29 @@ var init_utils = __esm({
132
131
  });
133
132
 
134
133
  // src/log.ts
135
- function log(type, message) {
136
- switch (type) {
137
- case "error": {
138
- return console.error(label, makeMessage(message, type));
139
- }
140
- default:
141
- console.log(label, makeMessage(message, type));
134
+ function log(message, type = "info") {
135
+ var _a;
136
+ const content = [
137
+ import_chalk2.default.gray(`[${name}]`),
138
+ import_chalk2.default[(_a = colorMap.get(type)) != null ? _a : "white"](message)
139
+ ];
140
+ if (type === "error") {
141
+ console.error(...content);
142
+ } else {
143
+ console.log(...content);
142
144
  }
143
145
  }
144
- var import_chalk2, label, makeMessage;
146
+ var import_chalk2, colorMap;
145
147
  var init_log = __esm({
146
148
  "src/log.ts"() {
147
149
  init_cjs_shims();
148
150
  import_chalk2 = __toModule(require("chalk"));
149
151
  init_package();
150
- label = import_chalk2.default.gray(`[${name}]`);
151
- makeMessage = (input, type) => import_chalk2.default[type === "info" ? "yellow" : type === "error" ? "red" : "green"](input);
152
+ colorMap = new Map([
153
+ ["info", "yellow"],
154
+ ["success", "green"],
155
+ ["error", "red"]
156
+ ]);
152
157
  }
153
158
  });
154
159
 
@@ -160,63 +165,67 @@ __export(src_exports, {
160
165
  });
161
166
  async function runViteBuild(options) {
162
167
  let result;
168
+ const fileName = "index";
169
+ const currentDir = process.cwd();
163
170
  try {
164
171
  result = await (0, import_vite.build)({
165
172
  plugins: [(0, import_vite_plugin_vue2.createVuePlugin)()],
166
173
  build: {
167
174
  lib: {
168
- entry: (0, import_path.resolve)(process.cwd(), options.entry),
175
+ entry: (0, import_path.resolve)(currentDir, options.entry),
169
176
  formats: ["es"],
170
- fileName: "index"
177
+ fileName
171
178
  },
172
- outDir: ".",
179
+ outDir: currentDir,
180
+ emptyOutDir: false,
173
181
  rollupOptions: {
174
182
  external: ["vue"],
175
183
  output: {
176
184
  entryFileNames: "[name].js",
177
- assetFileNames: "index.[ext]",
185
+ assetFileNames: `${fileName}.[ext]`,
178
186
  globals: {
179
187
  vue: "Vue"
180
188
  }
181
189
  }
182
190
  }
183
191
  },
184
- logLevel: "error"
192
+ logLevel: "warn"
185
193
  });
186
194
  } catch (error) {
187
- log("error", "Build failed");
195
+ log("Build failed", "error");
188
196
  throw error;
189
197
  }
190
- if (result) {
191
- log("success", `Build success`);
192
- }
198
+ log("Build successful", "success");
193
199
  return result;
194
200
  }
195
201
  async function build(_options) {
196
202
  const options = await normalizeOptions(_options);
197
- log("info", `#{name} v${version}`);
198
- log("info", `Building: ${options.entry}`);
203
+ log(`${name} v${version}`);
204
+ log(`Building: ${options.entry}`);
199
205
  if (options.watch) {
200
- log("info", "Running in watch mode");
206
+ log("Running in watch mode");
201
207
  }
202
- const debouncedBuildAll = debouncePromise(async () => {
208
+ const debouncedBuild = debouncePromise(async () => {
203
209
  runViteBuild(options);
204
210
  }, 100, handleError);
205
211
  const startWatcher = async () => {
206
212
  if (!options.watch)
207
213
  return;
208
214
  const { watch } = await import("chokidar");
209
- const ignored = ["**/{.git,node_modules}/**"];
215
+ const ignored = [
216
+ "**/{.git,node_modules}/**",
217
+ "index.js"
218
+ ];
210
219
  const watchPaths = typeof options.watch === "boolean" ? (0, import_path.dirname)(options.entry) : Array.isArray(options.watch) ? options.watch.filter((path) => typeof path === "string") : options.watch;
211
- log("info", `Watching for changes in ${Array.isArray(watchPaths) ? watchPaths.map((v) => '"' + v + '"').join(" | ") : '"' + watchPaths + '"'}`);
220
+ log(`Watching for changes in ${Array.isArray(watchPaths) ? watchPaths.map((v) => '"' + v + '"').join(" | ") : '"' + watchPaths + '"'}`);
212
221
  const watcher = watch(watchPaths, {
213
222
  ignoreInitial: true,
214
223
  ignorePermissionErrors: true,
215
224
  ignored
216
225
  });
217
226
  watcher.on("all", async (type, file) => {
218
- log("info", `Change detected: ${type} ${file}`);
219
- debouncedBuildAll();
227
+ log(`Change detected: ${type} ${file}`);
228
+ debouncedBuild();
220
229
  });
221
230
  };
222
231
  await runViteBuild(options);
@@ -246,19 +255,16 @@ var init_src = __esm({
246
255
  }
247
256
  });
248
257
 
249
- // src/cli-default.ts
250
- init_cjs_shims();
251
- init_errors();
252
-
253
- // src/cli-main.ts
258
+ // src/cli.ts
254
259
  init_cjs_shims();
255
260
  var import_cac = __toModule(require("cac"));
256
261
  init_package();
262
+ init_errors();
257
263
  async function main(options = {}) {
258
264
  const cli = (0, import_cac.cac)(name);
259
265
  cli.command("[file]", "Panel input file", {
260
266
  ignoreOptionDefaultValue: true
261
- }).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) => {
267
+ }).option("--watch [path]", 'Watch mode, if path is not specified, it watches the folder of the input file. Repeat "--watch" for more than one path').action(async (file, flags) => {
262
268
  const { build: build2 } = await Promise.resolve().then(() => (init_src(), src_exports));
263
269
  Object.assign(options, __spreadValues({}, flags));
264
270
  if (file) {
@@ -271,6 +277,4 @@ async function main(options = {}) {
271
277
  cli.parse(process.argv, { run: false });
272
278
  await cli.runMatchedCommand();
273
279
  }
274
-
275
- // src/cli-default.ts
276
280
  main().catch(handleError);