kirbyup 0.22.2 → 0.24.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Johann Schopplich
3
+ Copyright (c) 2021-2022 Johann Schopplich
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ 'use strict'
3
+ import('../dist/cli.mjs')
@@ -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 as createConfigLoader$1 } from 'unconfig';
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 { white, dim, cyan, magenta, green } from 'colorette';
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 createConfigLoader(configOrPath = process.cwd(), extraConfigSources = []) {
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
- configOrPath = process.cwd();
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$1({
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
- return async () => {
82
- const result = await loader.load();
83
- result.config = result.config || inlineConfig;
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
- if (error instanceof PrettyError) {
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,46 +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
- // src/math.ts
145
-
146
- // src/array.ts
147
- function toArray(array) {
148
- array = array || [];
149
- if (Array.isArray(array))
150
- return array;
151
- 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}`));
152
127
  }
153
128
 
154
129
  const name = "kirbyup";
155
- const version = "0.22.2";
130
+ const version = "0.24.0";
156
131
 
157
132
  let resolvedKirbyupConfig;
158
133
  let resolvedPostCssConfig;
@@ -217,7 +192,7 @@ async function viteBuild(options) {
217
192
  }
218
193
  async function resolveOptions(options) {
219
194
  if (!options.entry) {
220
- 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>`)}`);
221
196
  }
222
197
  if (!existsSync(options.entry)) {
223
198
  throw new PrettyError(`Cannot find ${options.entry}`);
@@ -226,7 +201,6 @@ async function resolveOptions(options) {
226
201
  }
227
202
  async function build(_options) {
228
203
  const options = await resolveOptions(_options);
229
- const loadConfig = createConfigLoader();
230
204
  const { config, sources: configSources } = await loadConfig();
231
205
  resolvedKirbyupConfig = config;
232
206
  try {
@@ -239,14 +213,14 @@ async function build(_options) {
239
213
  plugins: [postcssLogical(), postcssDirPseudoClass()]
240
214
  };
241
215
  }
242
- consola.log(green(`${name} v${version}`));
243
- consola.start("Building " + cyan(options.entry));
216
+ consola.log(colors.green(`${name} v${version}`));
217
+ consola.start(`Building ${colors.cyan(options.entry)}`);
244
218
  if (options.watch) {
245
219
  consola.info("Running in watch mode");
246
220
  }
247
- const debouncedBuild = debouncePromise(async () => {
248
- viteBuild(options);
249
- }, 100, handleError);
221
+ const debouncedBuild = debounce(async () => {
222
+ viteBuild(options).catch(handleError);
223
+ }, 100);
250
224
  const startWatcher = async () => {
251
225
  if (!options.watch)
252
226
  return;
@@ -256,7 +230,7 @@ async function build(_options) {
256
230
  "index.{css,js}"
257
231
  ];
258
232
  const watchPaths = typeof options.watch === "boolean" ? dirname(options.entry) : Array.isArray(options.watch) ? options.watch.filter((path) => typeof path === "string") : options.watch;
259
- 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(", "));
260
234
  const watcher = watch(watchPaths, {
261
235
  ignoreInitial: true,
262
236
  ignorePermissionErrors: true,
@@ -268,9 +242,9 @@ async function build(_options) {
268
242
  watcher.on("all", async (type, file) => {
269
243
  if (configSources.includes(file)) {
270
244
  resolvedKirbyupConfig = (await loadConfig()).config;
271
- consola.info(`${cyan(basename(file))} changed, setting new config`);
245
+ consola.info(`${colors.cyan(basename(file))} changed, setting new config`);
272
246
  } else {
273
- consola.log(green(type) + " " + white(dim(file)));
247
+ consola.log(colors.green(type) + " " + colors.white(colors.dim(file)));
274
248
  }
275
249
  debouncedBuild();
276
250
  });
package/dist/cli.mjs CHANGED
@@ -10,7 +10,8 @@ import 'postcss-load-config';
10
10
  import 'postcss-logical';
11
11
  import 'postcss-dir-pseudo-class';
12
12
  import 'consola';
13
- import 'colorette';
13
+ import 'perfect-debounce';
14
+ import 'picocolors';
14
15
  import 'fs/promises';
15
16
  import 'zlib';
16
17
  import 'util';
@@ -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, if path is not specified, it watches the folder of the input file. Repeat "--watch" for multiple paths').action(async (file, flags) => {
25
+ }).option("-w [path], --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
@@ -7,7 +7,8 @@ import 'postcss-load-config';
7
7
  import 'postcss-logical';
8
8
  import 'postcss-dir-pseudo-class';
9
9
  import 'consola';
10
- import 'colorette';
10
+ import 'perfect-debounce';
11
+ import 'picocolors';
11
12
  import 'magic-string';
12
13
  import 'unconfig';
13
14
  import 'fs/promises';
package/dist/plugin.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- /** Inherits Vite's `import.meta.globEager` result type */
2
- declare type GlobEagerResult = Record<string, {
1
+ declare type Module = {
3
2
  [key: string]: any;
4
- }>;
3
+ };
5
4
  declare const kirbyup: Readonly<{
6
5
  /**
7
6
  * Auto-import Kirby Panel components, will be transformed by
@@ -10,7 +9,7 @@ declare const kirbyup: Readonly<{
10
9
  * @example
11
10
  * kirbyup.import('./components/blocks/*.vue')
12
11
  */
13
- import(modules: GlobEagerResult): Record<string, any>;
12
+ import(modules: Record<string, Module>): Record<string, any>;
14
13
  }>;
15
14
 
16
15
  export { kirbyup };
package/package.json CHANGED
@@ -1,7 +1,21 @@
1
1
  {
2
2
  "name": "kirbyup",
3
- "version": "0.22.2",
3
+ "version": "0.24.0",
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.cjs"
40
+ "kirbyup": "./bin/kirbyup.mjs"
41
41
  },
42
42
  "files": [
43
43
  "bin",
@@ -49,46 +49,50 @@
49
49
  "scripts": {
50
50
  "build": "unbuild",
51
51
  "stub": "unbuild --stub",
52
- "test": "vitest",
53
- "test:update": "vitest -u",
52
+ "test": "vitest --watch",
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": "node scripts/release.js",
57
- "prepare": "husky install"
56
+ "release": "vitest --run && tsx scripts/release.ts",
57
+ "prepare": "pnpm exec simple-git-hooks"
58
+ },
59
+ "simple-git-hooks": {
60
+ "commit-msg": "node scripts/verifyCommit.mjs $1"
58
61
  },
59
62
  "dependencies": {
60
63
  "cac": "^6.7.12",
61
- "chokidar": "^3.5.2",
62
- "colorette": "^2.0.16",
64
+ "chokidar": "^3.5.3",
63
65
  "consola": "^2.15.3",
64
- "pathe": "^0.2.0",
65
- "postcss": "^8.4.5",
66
- "postcss-dir-pseudo-class": "^6.0.2",
67
- "postcss-load-config": "^3.1.1",
68
- "postcss-logical": "^5.0.2",
69
- "sass": "^1.46.0",
70
- "unconfig": "^0.2.2",
71
- "vite": "^2.7.10",
72
- "vite-plugin-vue2": "^1.9.2",
66
+ "execa": "6.1.0",
67
+ "pathe": "^0.3.0",
68
+ "perfect-debounce": "^0.1.3",
69
+ "picocolors": "^1.0.0",
70
+ "postcss": "^8.4.14",
71
+ "postcss-dir-pseudo-class": "^6.0.4",
72
+ "postcss-load-config": "^4.0.1",
73
+ "postcss-logical": "^5.0.4",
74
+ "sass": "^1.52.1",
75
+ "unconfig": "^0.3.4",
76
+ "vite": "^2.9.9",
77
+ "vite-plugin-vue2": "^2.0.1",
73
78
  "vue": "^2.6.14",
74
79
  "vue-template-compiler": "^2.6.14"
75
80
  },
76
81
  "devDependencies": {
77
- "@antfu/utils": "^0.4.0",
78
- "@types/cross-spawn": "^6.0.2",
79
82
  "@types/fs-extra": "^9.0.13",
80
- "@types/node": "^17.0.8",
83
+ "@types/node": "^17.0.38",
84
+ "@types/prompts": "^2.4.0",
85
+ "@types/semver": "^7.3.9",
81
86
  "conventional-changelog-cli": "^2.2.2",
82
- "esno": "^0.13.0",
83
- "execa": "5.1.1",
84
- "fast-glob": "^3.2.7",
85
- "fs-extra": "^10.0.0",
86
- "husky": "^7.0.4",
87
- "prettier": "^2.5.1",
87
+ "fast-glob": "^3.2.11",
88
+ "fs-extra": "^10.1.0",
89
+ "minimist": "^1.2.6",
90
+ "prettier": "^2.6.2",
88
91
  "prompts": "^2.4.2",
89
- "ts-essentials": "^9.1.2",
90
- "typescript": "^4.5.4",
91
- "unbuild": "^0.6.7",
92
- "vitest": "^0.0.134"
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"
93
97
  }
94
98
  }
package/bin/kirbyup.cjs DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- require('../dist/cli.cjs')
@@ -1,298 +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 colorette = require('colorette');
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" ? colorette.cyan : colorette.magenta;
127
- consola__default.log(colorette.white(colorette.dim(prettyOutDir)) + writeColor(filePath) + " " + colorette.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
- // src/math.ts
155
-
156
- // src/array.ts
157
- function toArray(array) {
158
- array = array || [];
159
- if (Array.isArray(array))
160
- return array;
161
- return [array];
162
- }
163
-
164
- const name = "kirbyup";
165
- const version = "0.22.2";
166
-
167
- let resolvedKirbyupConfig;
168
- let resolvedPostCssConfig;
169
- async function viteBuild(options) {
170
- let result;
171
- const mode = options.watch ? "development" : "production";
172
- const root = process.cwd();
173
- const outDir = options.outDir ?? root;
174
- const aliasDir = pathe.resolve(root, pathe.dirname(options.entry));
175
- const { alias = {}, extendViteConfig = {} } = resolvedKirbyupConfig;
176
- const defaultConfig = {
177
- mode,
178
- plugins: [vitePluginVue2.createVuePlugin(), kirbyupAutoImportPlugin()],
179
- build: {
180
- lib: {
181
- entry: pathe.resolve(root, options.entry),
182
- formats: ["iife"],
183
- name: "kirbyupExport",
184
- fileName: () => "index.js"
185
- },
186
- minify: mode === "production",
187
- outDir,
188
- emptyOutDir: false,
189
- rollupOptions: {
190
- external: ["vue"],
191
- output: {
192
- assetFileNames: "index.[ext]",
193
- globals: {
194
- vue: "Vue"
195
- }
196
- }
197
- }
198
- },
199
- resolve: {
200
- alias: {
201
- "~/": `${aliasDir}/`,
202
- "@/": `${aliasDir}/`,
203
- ...alias
204
- }
205
- },
206
- css: {
207
- postcss: resolvedPostCssConfig
208
- },
209
- envPrefix: ["VITE_", "KIRBYUP_"],
210
- logLevel: "warn"
211
- };
212
- try {
213
- result = await vite.build(vite.mergeConfig(defaultConfig, extendViteConfig));
214
- } catch (error) {
215
- consola__default.error("Build failed");
216
- if (mode === "production") {
217
- throw error;
218
- }
219
- }
220
- if (result && !options.watch) {
221
- const { output } = toArray(result)[0];
222
- for (const { fileName, type, code } of output) {
223
- printFileInfo(root, outDir, fileName, type, code);
224
- }
225
- }
226
- return result;
227
- }
228
- async function resolveOptions(options) {
229
- if (!options.entry) {
230
- throw new PrettyError("No input file, try " + colorette.cyan(`${name} <path/to/file.js>`));
231
- }
232
- if (!fs.existsSync(options.entry)) {
233
- throw new PrettyError(`Cannot find ${options.entry}`);
234
- }
235
- return options;
236
- }
237
- async function build(_options) {
238
- const options = await resolveOptions(_options);
239
- const loadConfig = createConfigLoader();
240
- const { config, sources: configSources } = await loadConfig();
241
- resolvedKirbyupConfig = config;
242
- try {
243
- resolvedPostCssConfig = await postcssrc__default({});
244
- } catch (err) {
245
- if (!/No PostCSS Config found/.test(err.message)) {
246
- throw err;
247
- }
248
- resolvedPostCssConfig = {
249
- plugins: [postcssLogical__default(), postcssDirPseudoClass__default()]
250
- };
251
- }
252
- consola__default.log(colorette.green(`${name} v${version}`));
253
- consola__default.start("Building " + colorette.cyan(options.entry));
254
- if (options.watch) {
255
- consola__default.info("Running in watch mode");
256
- }
257
- const debouncedBuild = debouncePromise(async () => {
258
- viteBuild(options);
259
- }, 100, handleError);
260
- const startWatcher = async () => {
261
- if (!options.watch)
262
- return;
263
- const { watch } = await import('chokidar');
264
- const ignored = [
265
- "**/{.git,node_modules}/**",
266
- "index.{css,js}"
267
- ];
268
- const watchPaths = typeof options.watch === "boolean" ? pathe.dirname(options.entry) : Array.isArray(options.watch) ? options.watch.filter((path) => typeof path === "string") : options.watch;
269
- consola__default.info("Watching for changes in " + toArray(watchPaths).map((i) => colorette.cyan(i)).join(", "));
270
- const watcher = watch(watchPaths, {
271
- ignoreInitial: true,
272
- ignorePermissionErrors: true,
273
- ignored
274
- });
275
- if (configSources.length) {
276
- watcher.add(configSources);
277
- }
278
- watcher.on("all", async (type, file) => {
279
- if (configSources.includes(file)) {
280
- resolvedKirbyupConfig = (await loadConfig()).config;
281
- consola__default.info(`${colorette.cyan(pathe.basename(file))} changed, setting new config`);
282
- } else {
283
- consola__default.log(colorette.green(type) + " " + colorette.white(colorette.dim(file)));
284
- }
285
- debouncedBuild();
286
- });
287
- };
288
- await viteBuild(options);
289
- consola__default.success("Build successful");
290
- startWatcher();
291
- }
292
-
293
- exports.build = build;
294
- exports.defineConfig = defineConfig;
295
- exports.handleError = handleError;
296
- exports.name = name;
297
- exports.resolveOptions = resolveOptions;
298
- 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('colorette');
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('colorette');
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;