@konomi-app/k2 2.1.5 → 3.0.1

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/plugin.js CHANGED
@@ -1,32 +1,40 @@
1
1
  #!/usr/bin/env node
2
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
+ }) : x)(function(x) {
5
+ if (typeof require !== "undefined") return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
2
8
 
3
9
  // src/plugin.ts
4
10
  import { program as program11 } from "commander";
5
11
 
6
12
  // src/commands/plugin-build.ts
7
13
  import { program } from "commander";
8
- import fs2 from "fs-extra";
14
+ import fs3 from "fs-extra";
9
15
  import path5 from "path";
10
- import "webpack";
16
+ import chalk2 from "chalk";
11
17
 
12
18
  // src/lib/constants.ts
13
19
  import path from "path";
14
20
  var WORKSPACE_DIRECTORY = ".k2";
15
21
  var DEVELOPMENT_DIRECTORY = path.join(WORKSPACE_DIRECTORY, "dev");
22
+ var PRODUCTION_DIRECTORY = path.join(WORKSPACE_DIRECTORY, "prod");
16
23
  var PLUGIN_CONFIG_FILE_NAME = "plugin.config.mjs";
17
24
  var PLUGIN_WORKSPACE_DIRECTORY = ".plugin";
18
25
  var PLUGIN_CONTENTS_DIRECTORY = path.join(PLUGIN_WORKSPACE_DIRECTORY, "contents");
19
26
  var PLUGIN_DEVELOPMENT_DIRECTORY = path.join(PLUGIN_WORKSPACE_DIRECTORY, "dev");
27
+ var PLUGIN_PRODUCTION_DIRECTORY = path.join(PLUGIN_WORKSPACE_DIRECTORY, "prod");
20
28
  var DEFAULT_PORT = 32767;
21
29
 
22
30
  // src/lib/import.ts
23
31
  import { pathToFileURL } from "url";
24
32
  import path2 from "path";
25
- var esmImport = (path19) => {
33
+ var esmImport = (path18) => {
26
34
  if (process.platform === "win32") {
27
- return import(pathToFileURL(path19).toString());
35
+ return import(pathToFileURL(path18).toString());
28
36
  } else {
29
- return import(path19);
37
+ return import(path18);
30
38
  }
31
39
  };
32
40
  var importK2PluginConfig = async (configFileName) => {
@@ -106,106 +114,21 @@ var watchTailwindCSS = async (params) => {
106
114
  watcher.on("error", (error) => {
107
115
  console.error("Error watching Tailwind CSS:", error);
108
116
  });
109
- watcher.on("add", (path19) => {
117
+ watcher.on("add", (path18) => {
110
118
  debouncedProcessChanges.call("add");
111
119
  });
112
- watcher.on("change", (path19) => {
120
+ watcher.on("change", (path18) => {
113
121
  debouncedProcessChanges.call("change");
114
122
  });
115
- watcher.on("unlink", (path19) => {
123
+ watcher.on("unlink", (path18) => {
116
124
  debouncedProcessChanges.call("unlink");
117
125
  });
118
- watcher.on("unlinkDir", (path19) => {
126
+ watcher.on("unlinkDir", (path18) => {
119
127
  debouncedProcessChanges.call("unlink");
120
128
  });
121
129
  return watcher;
122
130
  };
123
131
 
124
- // src/commands/build-base.ts
125
- import "webpack";
126
-
127
- // src/lib/webpack.ts
128
- import MiniCssExtractPlugin from "mini-css-extract-plugin";
129
- import path4 from "path";
130
- import { cwd } from "process";
131
- import TerserPlugin from "terser-webpack-plugin";
132
- import webpack from "webpack";
133
- import chalk from "chalk";
134
- import { TsconfigPathsPlugin } from "tsconfig-paths-webpack-plugin";
135
- var buildWithWebpack = async (props) => {
136
- const { entries, outDir } = props;
137
- const exclude = /node_modules/;
138
- const styleLoader = MiniCssExtractPlugin.loader;
139
- const tsConfigPath = path4.join(cwd(), "tsconfig.json");
140
- console.group(chalk.blue("\u{1F680} Building with Webpack..."));
141
- console.log("\u{1F527} tsconfig.json path:", tsConfigPath);
142
- console.groupEnd();
143
- return new Promise((resolve, reject) => {
144
- webpack(
145
- {
146
- mode: "production",
147
- target: ["web", "es2023"],
148
- entry: entries,
149
- resolve: {
150
- extensions: [".ts", ".tsx", ".js", ".json"],
151
- fallback: {
152
- path: false
153
- },
154
- plugins: [new TsconfigPathsPlugin({ configFile: tsConfigPath })]
155
- },
156
- cache: { type: "filesystem" },
157
- output: { filename: "[name].js", path: path4.resolve(outDir) },
158
- module: {
159
- rules: [
160
- { test: /\.tsx?$/, exclude, loader: "ts-loader" },
161
- { test: /\.css$/, use: [styleLoader, "css-loader"] },
162
- {
163
- test: /\.scss$/,
164
- use: [
165
- styleLoader,
166
- "css-loader",
167
- { loader: "sass-loader", options: { sassOptions: { outputStyle: "expanded" } } }
168
- ]
169
- }
170
- ]
171
- },
172
- plugins: [new MiniCssExtractPlugin()],
173
- optimization: {
174
- minimize: true,
175
- minimizer: [
176
- new TerserPlugin({
177
- terserOptions: { format: { comments: false } },
178
- extractComments: false
179
- })
180
- ]
181
- }
182
- },
183
- (err, stats) => {
184
- if (err) {
185
- reject(err);
186
- } else {
187
- if (stats?.compilation.errors.length) {
188
- reject(
189
- [
190
- chalk.red("\u26A0 Build failed."),
191
- ...stats.compilation.errors.map((error) => error.message)
192
- ].join("\n")
193
- );
194
- } else {
195
- resolve();
196
- }
197
- }
198
- }
199
- );
200
- });
201
- };
202
-
203
- // src/commands/build-base.ts
204
- async function action(params) {
205
- const { entries, outDir } = params;
206
- return buildWithWebpack({ entries, outDir });
207
- }
208
-
209
132
  // src/lib/lint.ts
210
133
  import { ESLint } from "eslint";
211
134
  import globals from "globals";
@@ -235,11 +158,127 @@ async function lint() {
235
158
  }
236
159
  }
237
160
 
161
+ // src/lib/vite.ts
162
+ import path4 from "path";
163
+ import fs2 from "fs-extra";
164
+ import { build as viteBuild } from "vite";
165
+ import chalk from "chalk";
166
+ var createViteConfig = (config2 = {}) => {
167
+ const plugins = [...config2.plugins ?? []];
168
+ try {
169
+ const tsconfigPaths = __require("vite-tsconfig-paths");
170
+ plugins.push(tsconfigPaths.default ? tsconfigPaths.default() : tsconfigPaths());
171
+ } catch {
172
+ }
173
+ const mode = config2.mode ?? "production";
174
+ return {
175
+ ...config2,
176
+ configFile: false,
177
+ // ブラウザ向けにNode.js固有のオブジェクトをビルド時に解決
178
+ define: {
179
+ "process.env.NODE_ENV": JSON.stringify(mode),
180
+ "process.env": JSON.stringify({}),
181
+ ...config2.define
182
+ },
183
+ build: {
184
+ ...config2.build,
185
+ // ブラウザ向けターゲット
186
+ target: config2.build?.target ?? "es2020",
187
+ cssCodeSplit: false,
188
+ rollupOptions: {
189
+ ...config2.build?.rollupOptions,
190
+ onwarn: (warning, warn) => {
191
+ if (["MODULE_LEVEL_DIRECTIVE"].includes(warning.code ?? "")) {
192
+ return;
193
+ }
194
+ warn(warning);
195
+ }
196
+ }
197
+ },
198
+ plugins,
199
+ resolve: {
200
+ ...config2.resolve,
201
+ alias: {
202
+ "@": path4.resolve(process.cwd(), "src"),
203
+ ...config2.resolve?.alias
204
+ }
205
+ }
206
+ };
207
+ };
208
+ async function buildEntriesWithVite(params) {
209
+ const {
210
+ entries,
211
+ outDir,
212
+ mode = "production",
213
+ sourcemap = false,
214
+ minify = true,
215
+ viteConfig = {}
216
+ } = params;
217
+ for (const name of Object.keys(entries)) {
218
+ const entryPath = entries[name];
219
+ const config2 = createViteConfig({
220
+ ...viteConfig,
221
+ mode,
222
+ build: {
223
+ ...viteConfig.build,
224
+ lib: {
225
+ entry: entryPath,
226
+ name,
227
+ fileName: () => `${name}.js`,
228
+ formats: ["iife"]
229
+ },
230
+ rollupOptions: {
231
+ ...viteConfig.build?.rollupOptions,
232
+ output: {
233
+ assetFileNames: `${name}.[ext]`,
234
+ ...viteConfig.build?.rollupOptions?.output
235
+ }
236
+ },
237
+ outDir,
238
+ emptyOutDir: false,
239
+ sourcemap,
240
+ minify,
241
+ cssCodeSplit: false
242
+ }
243
+ });
244
+ await viteBuild(config2);
245
+ }
246
+ }
247
+ var ENTRY_FILE_NAMES = ["index.ts", "index.tsx", "index.js", "index.jsx", "index.mjs"];
248
+ function findEntryPoint(basePath) {
249
+ for (const filename of ENTRY_FILE_NAMES) {
250
+ const entryPath = path4.join(basePath, filename);
251
+ if (fs2.existsSync(entryPath)) {
252
+ return entryPath;
253
+ }
254
+ }
255
+ if (fs2.existsSync(basePath) && fs2.statSync(basePath).isFile()) {
256
+ return basePath;
257
+ }
258
+ return null;
259
+ }
260
+ function getPluginEntryPoints(options) {
261
+ const entries = {};
262
+ const configPath = findEntryPoint(options.configEntry);
263
+ if (configPath) {
264
+ entries["config"] = configPath;
265
+ } else {
266
+ console.log(chalk.yellow(` \u26A0 Config entry not found: ${options.configEntry}`));
267
+ }
268
+ const desktopPath = findEntryPoint(options.desktopEntry);
269
+ if (desktopPath) {
270
+ entries["desktop"] = desktopPath;
271
+ } else {
272
+ console.log(chalk.yellow(` \u26A0 Desktop entry not found: ${options.desktopEntry}`));
273
+ }
274
+ return entries;
275
+ }
276
+
238
277
  // src/commands/plugin-build.ts
239
278
  function command() {
240
- program.command("build").description("Build the project for production. (It's a wrapper of webpack build command.)").action(action2);
279
+ program.command("build").description("Build the project for production with Vite.").action(action);
241
280
  }
242
- async function action2() {
281
+ async function action() {
243
282
  console.group("\u{1F373} Build the project for production");
244
283
  try {
245
284
  const config2 = await importK2PluginConfig();
@@ -247,13 +286,19 @@ async function action2() {
247
286
  await lint();
248
287
  console.log("\u2728 Lint success.");
249
288
  }
250
- if (!fs2.existsSync(PLUGIN_CONTENTS_DIRECTORY)) {
251
- await fs2.mkdir(PLUGIN_CONTENTS_DIRECTORY, { recursive: true });
289
+ if (!fs3.existsSync(PLUGIN_CONTENTS_DIRECTORY)) {
290
+ await fs3.mkdir(PLUGIN_CONTENTS_DIRECTORY, { recursive: true });
291
+ }
292
+ await fs3.emptyDir(PLUGIN_CONTENTS_DIRECTORY);
293
+ const entries = getPluginEntryPoints({
294
+ configEntry: path5.resolve("src", "config"),
295
+ desktopEntry: path5.resolve("src", "desktop")
296
+ });
297
+ const entryNames = Object.keys(entries);
298
+ if (entryNames.length === 0) {
299
+ throw new Error("No entry points found for plugin. Check src/config and src/desktop paths.");
252
300
  }
253
- const entries = {
254
- desktop: path5.join("src", "desktop", "index.ts"),
255
- config: path5.join("src", "config", "index.ts")
256
- };
301
+ console.log(chalk2.gray(` Entry points: ${entryNames.join(", ")}`));
257
302
  if (config2.tailwind?.css && config2.tailwind?.config) {
258
303
  const tailwindConfig = await getTailwindConfig(config2.tailwind);
259
304
  const inputFile = getTailwindInputCss(config2.tailwind);
@@ -272,7 +317,13 @@ async function action2() {
272
317
  });
273
318
  console.log("\u2728 Built desktop.css");
274
319
  }
275
- await action({ entries, outDir: PLUGIN_CONTENTS_DIRECTORY });
320
+ await buildEntriesWithVite({
321
+ entries,
322
+ outDir: PLUGIN_CONTENTS_DIRECTORY,
323
+ mode: "production",
324
+ sourcemap: false,
325
+ minify: true
326
+ });
276
327
  console.log("\u2728 Built desktop.js and config.js");
277
328
  console.log("\u2728 Build success.");
278
329
  } catch (error) {
@@ -284,56 +335,13 @@ async function action2() {
284
335
 
285
336
  // src/commands/plugin-esbuild.ts
286
337
  import { program as program2 } from "commander";
287
- import fs3 from "fs-extra";
338
+ import fs4 from "fs-extra";
288
339
  import path6 from "path";
289
- import "esbuild";
290
-
291
- // src/lib/esbuild.ts
292
- import chalk2 from "chalk";
293
- import esbuild from "esbuild";
294
- var completeBuildOptions = (params) => {
295
- return {
296
- bundle: true,
297
- platform: "browser",
298
- ...params,
299
- plugins: [...params.plugins ?? []]
300
- };
301
- };
302
- var completeDevBuildOptions = (params) => {
303
- return completeBuildOptions({
304
- ...params,
305
- plugins: [
306
- ...params.plugins ?? [],
307
- {
308
- name: "on-end",
309
- setup: ({ onEnd }) => onEnd(
310
- () => console.log(
311
- chalk2.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk2.cyan(`[js] `) + `rebuilt`
312
- )
313
- )
314
- }
315
- ]
316
- });
317
- };
318
- var getEsbuildContext = async (params) => {
319
- return esbuild.context(completeDevBuildOptions(params));
320
- };
321
- var buildWithEsbuild = async (params) => {
322
- const { watch = false, ...rest } = params;
323
- if (watch) {
324
- const context = await getEsbuildContext(rest);
325
- context.watch();
326
- } else {
327
- const options = completeBuildOptions(rest);
328
- await esbuild.build(options);
329
- }
330
- };
331
-
332
- // src/commands/plugin-esbuild.ts
340
+ import chalk3 from "chalk";
333
341
  function command2() {
334
- program2.command("esbuild").description("Build the project for production. (It's a wrapper of webpack build command.)").action(action3);
342
+ program2.command("esbuild").description("Build the project for production with Vite. (Legacy command name, now uses Vite)").action(action2);
335
343
  }
336
- async function action3() {
344
+ async function action2() {
337
345
  console.group("\u{1F373} Build the project for production");
338
346
  try {
339
347
  const config2 = await importK2PluginConfig();
@@ -341,9 +349,10 @@ async function action3() {
341
349
  await lint();
342
350
  console.log("\u2728 Lint success.");
343
351
  }
344
- if (!fs3.existsSync(PLUGIN_CONTENTS_DIRECTORY)) {
345
- await fs3.mkdir(PLUGIN_CONTENTS_DIRECTORY, { recursive: true });
352
+ if (!fs4.existsSync(PLUGIN_CONTENTS_DIRECTORY)) {
353
+ await fs4.mkdir(PLUGIN_CONTENTS_DIRECTORY, { recursive: true });
346
354
  }
355
+ await fs4.emptyDir(PLUGIN_CONTENTS_DIRECTORY);
347
356
  if (config2.tailwind?.css && config2.tailwind?.config) {
348
357
  const tailwindConfig = await getTailwindConfig(config2.tailwind);
349
358
  const inputFile = getTailwindInputCss(config2.tailwind);
@@ -362,16 +371,21 @@ async function action3() {
362
371
  });
363
372
  console.log("\u2728 Built desktop.css");
364
373
  }
365
- const entryPoints = ["desktop", "config"].map((dir) => ({
366
- in: path6.join("src", dir, "index.ts"),
367
- out: dir
368
- }));
369
- await buildWithEsbuild({
370
- entryPoints,
371
- outdir: PLUGIN_CONTENTS_DIRECTORY,
372
- minify: true,
374
+ const entries = getPluginEntryPoints({
375
+ configEntry: path6.resolve("src", "config"),
376
+ desktopEntry: path6.resolve("src", "desktop")
377
+ });
378
+ const entryNames = Object.keys(entries);
379
+ if (entryNames.length === 0) {
380
+ throw new Error("No entry points found for plugin. Check src/config and src/desktop paths.");
381
+ }
382
+ console.log(chalk3.gray(` Entry points: ${entryNames.join(", ")}`));
383
+ await buildEntriesWithVite({
384
+ entries,
385
+ outDir: PLUGIN_CONTENTS_DIRECTORY,
386
+ mode: "production",
373
387
  sourcemap: false,
374
- legalComments: "none"
388
+ minify: true
375
389
  });
376
390
  console.log("\u2728 Built desktop.js and config.js");
377
391
  console.log("\u2728 Build success.");
@@ -384,37 +398,55 @@ async function action3() {
384
398
 
385
399
  // src/commands/plugin-dev/index.ts
386
400
  import { program as program3 } from "commander";
387
- import "esbuild";
388
- import fs9 from "fs-extra";
401
+ import { createServer } from "vite";
402
+ import fs11 from "fs-extra";
389
403
  import path14 from "path";
404
+ import chalk6 from "chalk";
405
+
406
+ // src/lib/exec.ts
407
+ import { exec as defaultExec } from "child_process";
408
+ import { promisify } from "util";
409
+ var exec = promisify(defaultExec);
390
410
 
391
- // src/commands/dev-base-esbuild.ts
392
- import "esbuild";
411
+ // src/lib/cert.ts
412
+ import fs5 from "fs-extra";
393
413
  import path7 from "path";
394
- async function action4(params) {
395
- const { entryPoints, staticDir: outdir, certDir, port } = params;
396
- const context = await getEsbuildContext({ sourcemap: "inline", entryPoints, outdir });
397
- const [_, serveResult] = await Promise.all([
398
- context.watch(),
399
- context.serve({
400
- port,
401
- keyfile: path7.join(certDir, "localhost-key.pem"),
402
- certfile: path7.join(certDir, "localhost-cert.pem"),
403
- servedir: outdir
404
- })
405
- ]);
406
- console.log(`\u{1F680} Start development server at https://localhost:${serveResult.port}`);
414
+ var CERT_KEY_FILENAME = "localhost-key.pem";
415
+ var CERT_FILENAME = "localhost-cert.pem";
416
+ var generateCert = async (outDir) => {
417
+ await fs5.ensureDir(outDir);
418
+ const { stdout } = await exec(`mkcert localhost 127.0.0.1 ::1`);
419
+ [
420
+ { input: "localhost+2.pem", output: CERT_FILENAME },
421
+ { input: "localhost+2-key.pem", output: CERT_KEY_FILENAME }
422
+ ].forEach(({ input, output }) => {
423
+ if (fs5.existsSync(input)) {
424
+ fs5.moveSync(`./${input}`, path7.join(outDir, output), {
425
+ overwrite: true
426
+ });
427
+ }
428
+ });
429
+ return { stdout };
430
+ };
431
+ function hasCertificates(certDir) {
432
+ return fs5.existsSync(path7.join(certDir, CERT_KEY_FILENAME)) && fs5.existsSync(path7.join(certDir, CERT_FILENAME));
433
+ }
434
+ function loadCertificates(certDir) {
435
+ return {
436
+ key: fs5.readFileSync(path7.join(certDir, CERT_KEY_FILENAME)),
437
+ cert: fs5.readFileSync(path7.join(certDir, CERT_FILENAME))
438
+ };
407
439
  }
408
440
 
409
441
  // src/lib/plugin-manifest.ts
410
- import fs4 from "fs-extra";
442
+ import fs6 from "fs-extra";
411
443
  import path8 from "path";
412
444
  import merge from "deepmerge";
413
445
  var outputManifest = async (env, options) => {
414
446
  const config2 = options?.config || await importK2PluginConfig();
415
447
  const merged = merge(config2.manifest.base, config2.manifest[env] || {});
416
- await fs4.mkdirs(PLUGIN_CONTENTS_DIRECTORY);
417
- await fs4.writeJson(path8.join(PLUGIN_CONTENTS_DIRECTORY, "manifest.json"), merged);
448
+ await fs6.mkdirs(PLUGIN_CONTENTS_DIRECTORY);
449
+ await fs6.writeJson(path8.join(PLUGIN_CONTENTS_DIRECTORY, "manifest.json"), merged);
418
450
  return merged;
419
451
  };
420
452
 
@@ -451,7 +483,7 @@ var getManifest = async (params) => {
451
483
  // src/commands/plugin-dev/tailwind.ts
452
484
  import path9 from "path";
453
485
  import "tailwindcss";
454
- import chalk3 from "chalk";
486
+ import chalk4 from "chalk";
455
487
  async function buildTailwindCSS(params) {
456
488
  const { inputFile, outputFileName, config: config2 } = params;
457
489
  const inputPath = path9.resolve(inputFile);
@@ -463,7 +495,7 @@ async function buildTailwindCSS(params) {
463
495
  onChanges: ({ output, type }) => {
464
496
  const outputFileName2 = path9.basename(output);
465
497
  console.log(
466
- chalk3.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk3.cyan(`[css] `) + outputFileName2 + (type === "init" ? " init" : ` rebuilt`)
498
+ chalk4.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk4.cyan(`[css] `) + outputFileName2 + (type === "init" ? " init" : ` rebuilt`)
467
499
  );
468
500
  }
469
501
  });
@@ -492,20 +524,20 @@ var watchCss = async (pluginConfig) => {
492
524
  import packer from "@kintone/plugin-packer";
493
525
 
494
526
  // src/lib/plugin-contents.ts
495
- import fs5 from "fs-extra";
527
+ import fs7 from "fs-extra";
496
528
  import path10 from "path";
497
529
  import htmlMinifier from "html-minifier";
498
530
  var copyPluginContents = async (params = {}) => {
499
531
  const { inputDir = path10.join("src", "contents"), outputDir = PLUGIN_CONTENTS_DIRECTORY } = params;
500
- if (!fs5.existsSync(inputDir)) {
501
- await fs5.mkdir(inputDir, { recursive: true });
532
+ if (!fs7.existsSync(inputDir)) {
533
+ await fs7.mkdir(inputDir, { recursive: true });
502
534
  }
503
- await fs5.copy(inputDir, outputDir, { overwrite: true });
535
+ await fs7.copy(inputDir, outputDir, { overwrite: true });
504
536
  const configHtmlPath = path10.join(outputDir, "config.html");
505
- if (!fs5.existsSync(configHtmlPath)) {
537
+ if (!fs7.existsSync(configHtmlPath)) {
506
538
  throw new Error(`Plugin HTML file not found. Create "config.html" in ${inputDir}.`);
507
539
  }
508
- const html = await fs5.readFile(configHtmlPath, "utf8");
540
+ const html = await fs7.readFile(configHtmlPath, "utf8");
509
541
  const minified = htmlMinifier.minify(html, {
510
542
  minifyCSS: true,
511
543
  collapseWhitespace: true,
@@ -516,12 +548,12 @@ var copyPluginContents = async (params = {}) => {
516
548
  removeTagWhitespace: true,
517
549
  useShortDoctype: true
518
550
  });
519
- await fs5.writeFile(configHtmlPath, minified);
551
+ await fs7.writeFile(configHtmlPath, minified);
520
552
  };
521
553
 
522
554
  // src/lib/zip.ts
523
555
  import archiver from "archiver";
524
- import fs6 from "fs-extra";
556
+ import fs8 from "fs-extra";
525
557
  import path11 from "path";
526
558
  import invariant2 from "tiny-invariant";
527
559
  var outputContentsZip = async (manifest) => {
@@ -534,7 +566,7 @@ var outputContentsZip = async (manifest) => {
534
566
  }
535
567
  });
536
568
  const outputZipPath = path11.join(PLUGIN_WORKSPACE_DIRECTORY, "contents.zip");
537
- const outputZipStream = fs6.createWriteStream(outputZipPath);
569
+ const outputZipStream = fs8.createWriteStream(outputZipPath);
538
570
  outputZipStream.on("close", () => {
539
571
  console.log(`\u{1F4E6} ${archive.pointer()} total bytes`);
540
572
  });
@@ -566,7 +598,7 @@ var outputContentsZip = async (manifest) => {
566
598
  console.groupEnd();
567
599
  for (const file of targetFiles) {
568
600
  const filePath = path11.join(PLUGIN_CONTENTS_DIRECTORY, file);
569
- if (!fs6.existsSync(filePath)) {
601
+ if (!fs8.existsSync(filePath)) {
570
602
  throw new Error(`${filePath} does not exist`);
571
603
  }
572
604
  archive.file(filePath, { name: file });
@@ -577,14 +609,14 @@ var outputContentsZip = async (manifest) => {
577
609
  };
578
610
  var getContentsZipBuffer = async () => {
579
611
  const outputZipPath = path11.join(PLUGIN_WORKSPACE_DIRECTORY, "contents.zip");
580
- return fs6.readFile(outputZipPath);
612
+ return fs8.readFile(outputZipPath);
581
613
  };
582
614
  var getZipFileNameSuffix = (env) => {
583
615
  return env === "prod" ? "" : `-${env}`;
584
616
  };
585
617
 
586
618
  // src/commands/plugin-dev/upload.ts
587
- import fs8 from "fs-extra";
619
+ import fs10 from "fs-extra";
588
620
  import path13 from "path";
589
621
 
590
622
  // src/lib/kintone-api-client.ts
@@ -620,8 +652,8 @@ KINTONE_PASSWORD`);
620
652
  this.#baseUrl = KINTONE_BASE_URL;
621
653
  this.#authHeader = authHeader;
622
654
  }
623
- getEndpointUrl(path19) {
624
- return `${this.#baseUrl}${path19}`;
655
+ getEndpointUrl(path18) {
656
+ return `${this.#baseUrl}${path18}`;
625
657
  }
626
658
  async upload(params) {
627
659
  const { blob, fileName } = params;
@@ -692,7 +724,7 @@ KINTONE_PASSWORD`);
692
724
  };
693
725
 
694
726
  // src/lib/utils.ts
695
- import fs7 from "fs-extra";
727
+ import fs9 from "fs-extra";
696
728
  import path12 from "path";
697
729
  var isEnv = (env) => {
698
730
  return ["prod", "dev", "standalone"].includes(env);
@@ -701,7 +733,7 @@ var apiUploadZip = async (params) => {
701
733
  const { env, pluginId } = params;
702
734
  const kc = new KintoneApiClient();
703
735
  const zipFileName = `plugin${getZipFileNameSuffix(env)}.zip`;
704
- const zipFile = new Blob([await fs7.readFile(path12.join(PLUGIN_WORKSPACE_DIRECTORY, zipFileName))]);
736
+ const zipFile = new Blob([await fs9.readFile(path12.join(PLUGIN_WORKSPACE_DIRECTORY, zipFileName))]);
705
737
  const fileKey = await kc.upload({ blob: zipFile, fileName: zipFileName });
706
738
  const plugins = await kc.getAllPlugins();
707
739
  const plugin = plugins.find((p) => p.id === pluginId);
@@ -721,7 +753,7 @@ var apiUploadZip = async (params) => {
721
753
 
722
754
  // src/commands/plugin-dev/upload.ts
723
755
  import chokider from "chokidar";
724
- import chalk4 from "chalk";
756
+ import chalk5 from "chalk";
725
757
  var watchContentsAndUploadZip = async (params) => {
726
758
  const { manifest, ppkPath } = params;
727
759
  let initialScanComplete = false;
@@ -732,7 +764,7 @@ var watchContentsAndUploadZip = async (params) => {
732
764
  }
733
765
  await copyPluginContents();
734
766
  console.log(
735
- chalk4.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk4.cyan(`[contents] `) + `updated`
767
+ chalk5.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk5.cyan(`[contents] `) + `updated`
736
768
  );
737
769
  } catch (error) {
738
770
  console.error("Error copying plugin contents:", error);
@@ -741,17 +773,17 @@ var watchContentsAndUploadZip = async (params) => {
741
773
  try {
742
774
  await outputContentsZip(manifest);
743
775
  const buffer = await getContentsZipBuffer();
744
- const pluginPrivateKey = await fs8.readFile(path13.resolve(ppkPath), "utf8");
776
+ const pluginPrivateKey = await fs10.readFile(path13.resolve(ppkPath), "utf8");
745
777
  const output = await packer(buffer, pluginPrivateKey);
746
778
  const zipFileName = `plugin${getZipFileNameSuffix("dev")}.zip`;
747
- await fs8.writeFile(path13.join(PLUGIN_WORKSPACE_DIRECTORY, zipFileName), output.plugin);
779
+ await fs10.writeFile(path13.join(PLUGIN_WORKSPACE_DIRECTORY, zipFileName), output.plugin);
748
780
  const { method } = await apiUploadZip({ env: "dev", pluginId: output.id });
749
781
  console.log(
750
- chalk4.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk4.cyan(`[upload] `) + `uploaded ${method === "POST" ? "(new)" : "(update)"}`
782
+ chalk5.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk5.cyan(`[upload] `) + `uploaded ${method === "POST" ? "(new)" : "(update)"}`
751
783
  );
752
784
  } catch (error) {
753
785
  console.log(
754
- chalk4.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk4.cyan(`[upload] `) + chalk4.red(`failed`) + chalk4.hex("#e5e7eb")(`: ${error?.message ?? "Unknown error"}`)
786
+ chalk5.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk5.cyan(`[upload] `) + chalk5.red(`failed`) + chalk5.hex("#e5e7eb")(`: ${error?.message ?? "Unknown error"}`)
755
787
  );
756
788
  }
757
789
  };
@@ -774,64 +806,103 @@ function command3() {
774
806
  "-p, --ppk <ppk>",
775
807
  ".ppk file path",
776
808
  path14.join(PLUGIN_WORKSPACE_DIRECTORY, "private.ppk")
777
- ).option("-c, --cert-dir <certDir>", "Certificate directory", PLUGIN_WORKSPACE_DIRECTORY).description("Start development server.").action(action5);
809
+ ).option("-c, --cert-dir <certDir>", "Certificate directory", PLUGIN_WORKSPACE_DIRECTORY).description("Start development server with Vite.").action(action3);
778
810
  }
779
- async function action5(options) {
811
+ async function action3(options) {
780
812
  console.group("\u{1F373} Start development server");
781
813
  try {
782
814
  const { ppk: ppkPath, certDir } = options;
783
815
  const config2 = await importK2PluginConfig();
784
- if (!fs9.existsSync(PLUGIN_DEVELOPMENT_DIRECTORY)) {
785
- await fs9.mkdir(PLUGIN_DEVELOPMENT_DIRECTORY, { recursive: true });
816
+ const certDirPath = path14.resolve(certDir);
817
+ const outputDir = path14.resolve(PLUGIN_DEVELOPMENT_DIRECTORY);
818
+ if (!fs11.existsSync(PLUGIN_DEVELOPMENT_DIRECTORY)) {
819
+ await fs11.mkdir(PLUGIN_DEVELOPMENT_DIRECTORY, { recursive: true });
786
820
  }
787
821
  const port = config2.server?.port ?? DEFAULT_PORT;
822
+ if (!hasCertificates(certDirPath)) {
823
+ console.log(chalk6.yellow("\u{1F4DC} SSL certificates not found. Generating..."));
824
+ try {
825
+ await generateCert(certDirPath);
826
+ console.log(chalk6.green("\u2705 SSL certificates generated successfully"));
827
+ } catch (error) {
828
+ console.log(
829
+ chalk6.red("\u274C Failed to generate SSL certificates. Make sure mkcert is installed.")
830
+ );
831
+ console.log(chalk6.gray(" Install mkcert: https://github.com/FiloSottile/mkcert"));
832
+ throw error;
833
+ }
834
+ }
788
835
  const manifest = await getManifest({ config: config2, port });
789
836
  console.log(`\u{1F4DD} manifest.json generated`);
790
- Promise.all([
791
- watchContentsAndUploadZip({ manifest, ppkPath }),
792
- watchCss(config2),
793
- build(port, certDir)
794
- ]);
837
+ const entries = getPluginEntryPoints({
838
+ configEntry: path14.resolve("src", "config"),
839
+ desktopEntry: path14.resolve("src", "desktop")
840
+ });
841
+ const entryNames = Object.keys(entries);
842
+ if (entryNames.length === 0) {
843
+ throw new Error("No entry points found for plugin. Check src/config and src/desktop paths.");
844
+ }
845
+ console.log(chalk6.gray(` Entry points: ${entryNames.join(", ")}`));
846
+ await fs11.emptyDir(outputDir);
847
+ const { key, cert } = loadCertificates(certDirPath);
848
+ console.log(chalk6.gray(" Building..."));
849
+ await buildEntriesWithVite({
850
+ entries,
851
+ outDir: outputDir,
852
+ mode: "development",
853
+ sourcemap: "inline",
854
+ minify: false
855
+ });
856
+ const serverConfig = createViteConfig({
857
+ root: outputDir,
858
+ server: {
859
+ port,
860
+ https: { key, cert }
861
+ }
862
+ });
863
+ const server = await createServer(serverConfig);
864
+ await server.listen();
865
+ console.log(chalk6.green(`
866
+ \u2728 Plugin development server ready!`));
867
+ console.log(chalk6.cyan(` Local: https://localhost:${port}`));
868
+ console.log(chalk6.gray(` Output: ${outputDir}`));
869
+ console.log(chalk6.gray(` Files: config.js, desktop.js`));
870
+ console.log(chalk6.gray("\n Watching for changes...\n"));
871
+ const chokidar2 = await import("chokidar");
872
+ const watchPaths = [
873
+ "src/config/**/*.{ts,tsx,js,jsx,css,scss}",
874
+ "src/desktop/**/*.{ts,tsx,js,jsx,css,scss}"
875
+ ];
876
+ const watcher = chokidar2.watch(watchPaths, {
877
+ ignored: /node_modules/,
878
+ persistent: true
879
+ });
880
+ const rebuild = async () => {
881
+ console.log(chalk6.gray(" Rebuilding..."));
882
+ await buildEntriesWithVite({
883
+ entries,
884
+ outDir: outputDir,
885
+ mode: "development",
886
+ sourcemap: "inline",
887
+ minify: false
888
+ });
889
+ };
890
+ watcher.on("change", rebuild);
891
+ watcher.on("add", rebuild);
892
+ watcher.on("unlink", rebuild);
893
+ Promise.all([watchContentsAndUploadZip({ manifest, ppkPath }), watchCss(config2)]);
795
894
  } catch (error) {
796
895
  throw error;
797
896
  } finally {
798
897
  console.groupEnd();
799
898
  }
800
899
  }
801
- async function build(port, certDir = PLUGIN_WORKSPACE_DIRECTORY, staticDir = PLUGIN_DEVELOPMENT_DIRECTORY) {
802
- const entryPoints = ["desktop", "config"].map((dir) => ({
803
- in: path14.join("src", dir, "index.ts"),
804
- out: dir
805
- }));
806
- action4({ port, entryPoints, certDir, staticDir });
807
- }
808
900
 
809
901
  // src/commands/plugin-genkey.ts
810
902
  import { program as program4 } from "commander";
811
903
 
812
- // src/lib/exec.ts
813
- import { exec as defaultExec } from "child_process";
814
- import { promisify } from "util";
815
- var exec = promisify(defaultExec);
816
-
817
- // src/lib/cert.ts
818
- import fs10 from "fs-extra";
819
- import path15 from "path";
820
- var generateCert = async (outDir) => {
821
- const { stdout } = await exec(`mkcert localhost 127.0.0.1 ::1`);
822
- [
823
- { input: "localhost+2.pem", output: "localhost-cert.pem" },
824
- { input: "localhost+2-key.pem", output: "localhost-key.pem" }
825
- ].forEach(({ input, output }) => {
826
- fs10.moveSync(`./${input}`, path15.join(outDir, output), {
827
- overwrite: true
828
- });
829
- });
830
- return { stdout };
831
- };
832
-
833
904
  // src/commands/genkey-base.ts
834
- async function action6(options) {
905
+ async function action4(options) {
835
906
  const { output } = options;
836
907
  console.group("\u{1F373} Generate SSL key for localhost");
837
908
  try {
@@ -849,21 +920,21 @@ async function action6(options) {
849
920
 
850
921
  // src/commands/plugin-genkey.ts
851
922
  function command4() {
852
- program4.command("genkey").description("Generate SSL key for localhost. (Require mkcert)").action(action7);
923
+ program4.command("genkey").description("Generate SSL key for localhost. (Require mkcert)").action(action5);
853
924
  }
854
- async function action7() {
855
- await action6({ output: PLUGIN_WORKSPACE_DIRECTORY });
925
+ async function action5() {
926
+ await action4({ output: PLUGIN_WORKSPACE_DIRECTORY });
856
927
  }
857
928
 
858
929
  // src/commands/plugin-init.ts
859
930
  import { program as program5 } from "commander";
860
- import fs11 from "fs-extra";
861
- import path16 from "path";
931
+ import fs12 from "fs-extra";
932
+ import path15 from "path";
862
933
  import packer2 from "@kintone/plugin-packer";
863
934
  function command5() {
864
- program5.command("init").description("generate private.ppk and kitting config").action(action8);
935
+ program5.command("init").description("generate private.ppk and kitting config").action(action6);
865
936
  }
866
- async function action8() {
937
+ async function action6() {
867
938
  console.group("\u{1F373} Executing plugin initialization setup");
868
939
  try {
869
940
  const manifest = await outputManifest("dev");
@@ -871,20 +942,20 @@ async function action8() {
871
942
  await copyPluginContents();
872
943
  console.log("\u{1F4C1} contents copied");
873
944
  let privateKey;
874
- const keyPath = path16.join(PLUGIN_WORKSPACE_DIRECTORY, "private.ppk");
875
- if (fs11.existsSync(keyPath)) {
876
- privateKey = await fs11.readFile(keyPath, "utf8");
945
+ const keyPath = path15.join(PLUGIN_WORKSPACE_DIRECTORY, "private.ppk");
946
+ if (fs12.existsSync(keyPath)) {
947
+ privateKey = await fs12.readFile(keyPath, "utf8");
877
948
  }
878
949
  await outputContentsZip(manifest);
879
950
  const buffer = await getContentsZipBuffer();
880
951
  const output = await packer2(buffer, privateKey);
881
952
  if (!privateKey) {
882
- await fs11.writeFile(path16.join(PLUGIN_WORKSPACE_DIRECTORY, "private.ppk"), output.privateKey);
953
+ await fs12.writeFile(path15.join(PLUGIN_WORKSPACE_DIRECTORY, "private.ppk"), output.privateKey);
883
954
  console.log("\u{1F511} private.ppk generated");
884
955
  } else {
885
956
  console.log("\u{1F511} private.ppk already exists. The existing private.ppk will be used.");
886
957
  }
887
- await fs11.writeFile(path16.join(PLUGIN_WORKSPACE_DIRECTORY, "plugin.zip"), output.plugin);
958
+ await fs12.writeFile(path15.join(PLUGIN_WORKSPACE_DIRECTORY, "plugin.zip"), output.plugin);
888
959
  console.log("\u{1F4E6} plugin.zip generated");
889
960
  console.log("\u2728 Plugin initialization setup completed! zip file path is ./.plugin/plugin.zip");
890
961
  } catch (error) {
@@ -897,9 +968,9 @@ async function action8() {
897
968
  // src/commands/manifest/index.ts
898
969
  import { program as program6 } from "commander";
899
970
  function command6() {
900
- program6.command("manifest").option("-e, --env <env>", "create manifest", "prod").action(action9);
971
+ program6.command("manifest").option("-e, --env <env>", "create manifest", "prod").action(action7);
901
972
  }
902
- async function action9(options) {
973
+ async function action7(options) {
903
974
  console.group("\u{1F680} Executing manifest generation");
904
975
  try {
905
976
  const { env } = options;
@@ -919,13 +990,13 @@ async function action9(options) {
919
990
 
920
991
  // src/commands/test/index.ts
921
992
  import { program as program7 } from "commander";
922
- import fs12 from "fs-extra";
993
+ import fs13 from "fs-extra";
923
994
  function command7() {
924
- program7.command("test").description("test").action(action10);
995
+ program7.command("test").description("test").action(action8);
925
996
  }
926
- async function action10() {
997
+ async function action8() {
927
998
  console.group("package.json");
928
- const packageJson = fs12.readJSONSync("package.json");
999
+ const packageJson = fs13.readJSONSync("package.json");
929
1000
  console.log("package.json detected");
930
1001
  console.groupEnd();
931
1002
  console.group("Config");
@@ -936,17 +1007,17 @@ async function action10() {
936
1007
 
937
1008
  // src/commands/plugin-zip.ts
938
1009
  import { program as program8 } from "commander";
939
- import fs13 from "fs-extra";
940
- import path17 from "path";
1010
+ import fs14 from "fs-extra";
1011
+ import path16 from "path";
941
1012
  import packer3 from "@kintone/plugin-packer";
942
1013
  function command8() {
943
1014
  program8.command("zip").description("generate plugin zip").option("-e, --env <env>", "plugin environment (dev, prod, standalone)", "prod").option(
944
1015
  "-p, --ppk <ppk>",
945
1016
  ".ppk file path",
946
- path17.join(PLUGIN_WORKSPACE_DIRECTORY, "private.ppk")
947
- ).action(action11);
1017
+ path16.join(PLUGIN_WORKSPACE_DIRECTORY, "private.ppk")
1018
+ ).action(action9);
948
1019
  }
949
- async function action11(options) {
1020
+ async function action9(options) {
950
1021
  console.group("\u{1F373} Executing plugin zip generation");
951
1022
  try {
952
1023
  const { env, ppk: ppkPath } = options;
@@ -960,13 +1031,13 @@ async function action11(options) {
960
1031
  await outputContentsZip(manifest);
961
1032
  console.log("\u{1F4E6} contents.zip generated");
962
1033
  const buffer = await getContentsZipBuffer();
963
- const privateKey = await fs13.readFile(path17.resolve(ppkPath), "utf8");
1034
+ const privateKey = await fs14.readFile(path16.resolve(ppkPath), "utf8");
964
1035
  const output = await packer3(buffer, privateKey);
965
1036
  const zipFileName = `plugin${getZipFileNameSuffix(env)}.zip`;
966
- await fs13.writeFile(path17.join(PLUGIN_WORKSPACE_DIRECTORY, zipFileName), output.plugin);
1037
+ await fs14.writeFile(path16.join(PLUGIN_WORKSPACE_DIRECTORY, zipFileName), output.plugin);
967
1038
  console.log("\u{1F4E6} plugin.zip generated");
968
1039
  const version = String(manifest.version);
969
- await fs13.writeFile(path17.join(PLUGIN_WORKSPACE_DIRECTORY, "version"), version);
1040
+ await fs14.writeFile(path16.join(PLUGIN_WORKSPACE_DIRECTORY, "version"), version);
970
1041
  console.log(`\u{1F4DD} version file generated (${version})`);
971
1042
  console.log(`\u2728 Plugin zip generation completed! zip file path is ./.plugin/${zipFileName}`);
972
1043
  } catch (error) {
@@ -979,9 +1050,9 @@ async function action11(options) {
979
1050
  // src/commands/lint.ts
980
1051
  import { program as program9 } from "commander";
981
1052
  function command9() {
982
- program9.command("lint").description("Lint source files").option("-c, --config <config>", "Config file path").action(action12);
1053
+ program9.command("lint").description("Lint source files").option("-c, --config <config>", "Config file path").action(action10);
983
1054
  }
984
- async function action12(options) {
1055
+ async function action10(options) {
985
1056
  try {
986
1057
  lint();
987
1058
  } catch (error) {
@@ -992,12 +1063,12 @@ async function action12(options) {
992
1063
 
993
1064
  // src/commands/plugin-tsup.ts
994
1065
  import { program as program10 } from "commander";
995
- import fs14 from "fs-extra";
996
- import path18 from "path";
1066
+ import fs15 from "fs-extra";
1067
+ import path17 from "path";
997
1068
 
998
1069
  // src/lib/tsup.ts
999
- import { build as build2 } from "tsup";
1000
- var completeBuildOptions2 = (params) => {
1070
+ import { build } from "tsup";
1071
+ var completeBuildOptions = (params) => {
1001
1072
  return {
1002
1073
  bundle: true,
1003
1074
  minify: "terser",
@@ -1012,15 +1083,15 @@ var completeBuildOptions2 = (params) => {
1012
1083
  };
1013
1084
  };
1014
1085
  var buildWithTsup = async (buildOptions) => {
1015
- const options = completeBuildOptions2(buildOptions);
1016
- await build2(options);
1086
+ const options = completeBuildOptions(buildOptions);
1087
+ await build(options);
1017
1088
  };
1018
1089
 
1019
1090
  // src/commands/plugin-tsup.ts
1020
1091
  function command10() {
1021
- program10.command("tsup").description("Build the project for production. (It's a wrapper of webpack build command.)").action(action13);
1092
+ program10.command("tsup").description("Build the project for production. (It's a wrapper of webpack build command.)").action(action11);
1022
1093
  }
1023
- async function action13() {
1094
+ async function action11() {
1024
1095
  console.group("\u{1F373} Build the project for production");
1025
1096
  try {
1026
1097
  const config2 = await importK2PluginConfig();
@@ -1028,22 +1099,22 @@ async function action13() {
1028
1099
  await lint();
1029
1100
  console.log("\u2728 Lint success.");
1030
1101
  }
1031
- if (!fs14.existsSync(PLUGIN_CONTENTS_DIRECTORY)) {
1032
- await fs14.mkdir(PLUGIN_CONTENTS_DIRECTORY, { recursive: true });
1102
+ if (!fs15.existsSync(PLUGIN_CONTENTS_DIRECTORY)) {
1103
+ await fs15.mkdir(PLUGIN_CONTENTS_DIRECTORY, { recursive: true });
1033
1104
  }
1034
1105
  if (config2.tailwind?.css && config2.tailwind?.config) {
1035
1106
  const tailwindConfig = await getTailwindConfig(config2.tailwind);
1036
1107
  const inputFile = getTailwindInputCss(config2.tailwind);
1037
1108
  await outputCss({
1038
1109
  inputPath: inputFile.config,
1039
- outputPath: path18.join(PLUGIN_CONTENTS_DIRECTORY, "config.css"),
1110
+ outputPath: path17.join(PLUGIN_CONTENTS_DIRECTORY, "config.css"),
1040
1111
  config: tailwindConfig.config,
1041
1112
  minify: true
1042
1113
  });
1043
1114
  console.log("\u2728 Built config.css");
1044
1115
  await outputCss({
1045
1116
  inputPath: inputFile.desktop,
1046
- outputPath: path18.join(PLUGIN_CONTENTS_DIRECTORY, "desktop.css"),
1117
+ outputPath: path17.join(PLUGIN_CONTENTS_DIRECTORY, "desktop.css"),
1047
1118
  config: tailwindConfig.desktop,
1048
1119
  minify: true
1049
1120
  });
@@ -1052,7 +1123,7 @@ async function action13() {
1052
1123
  const entryPoints = ["desktop", "config"].reduce(
1053
1124
  (acc, dir) => ({
1054
1125
  ...acc,
1055
- [dir]: path18.join("src", dir, "index.ts")
1126
+ [dir]: path17.join("src", dir, "index.ts")
1056
1127
  }),
1057
1128
  {}
1058
1129
  );