@konomi-app/k2 3.3.0 → 3.3.2
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 +1 -3
- package/dist/index.js.map +1 -1
- package/dist/plugin.js +125 -184
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
package/dist/plugin.js
CHANGED
|
@@ -30,11 +30,11 @@ var DEFAULT_PORT = 32767;
|
|
|
30
30
|
// src/lib/import.ts
|
|
31
31
|
import { pathToFileURL } from "url";
|
|
32
32
|
import path2 from "path";
|
|
33
|
-
var esmImport = (
|
|
33
|
+
var esmImport = (path16) => {
|
|
34
34
|
if (process.platform === "win32") {
|
|
35
|
-
return import(pathToFileURL(
|
|
35
|
+
return import(pathToFileURL(path16).toString());
|
|
36
36
|
} else {
|
|
37
|
-
return import(
|
|
37
|
+
return import(path16);
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
var importK2PluginConfig = async (configFileName) => {
|
|
@@ -114,16 +114,16 @@ var watchTailwindCSS = async (params) => {
|
|
|
114
114
|
watcher.on("error", (error) => {
|
|
115
115
|
console.error("Error watching Tailwind CSS:", error);
|
|
116
116
|
});
|
|
117
|
-
watcher.on("add", (
|
|
117
|
+
watcher.on("add", (path16) => {
|
|
118
118
|
debouncedProcessChanges.call("add");
|
|
119
119
|
});
|
|
120
|
-
watcher.on("change", (
|
|
120
|
+
watcher.on("change", (path16) => {
|
|
121
121
|
debouncedProcessChanges.call("change");
|
|
122
122
|
});
|
|
123
|
-
watcher.on("unlink", (
|
|
123
|
+
watcher.on("unlink", (path16) => {
|
|
124
124
|
debouncedProcessChanges.call("unlink");
|
|
125
125
|
});
|
|
126
|
-
watcher.on("unlinkDir", (
|
|
126
|
+
watcher.on("unlinkDir", (path16) => {
|
|
127
127
|
debouncedProcessChanges.call("unlink");
|
|
128
128
|
});
|
|
129
129
|
return watcher;
|
|
@@ -272,9 +272,6 @@ async function buildSingleEntry(params) {
|
|
|
272
272
|
const config2 = createViteConfig({
|
|
273
273
|
...viteConfig,
|
|
274
274
|
mode,
|
|
275
|
-
esbuild: {
|
|
276
|
-
target: "es2022"
|
|
277
|
-
},
|
|
278
275
|
build: {
|
|
279
276
|
...viteConfig.build,
|
|
280
277
|
lib: {
|
|
@@ -286,6 +283,7 @@ async function buildSingleEntry(params) {
|
|
|
286
283
|
rollupOptions: {
|
|
287
284
|
...viteConfig.build?.rollupOptions,
|
|
288
285
|
output: {
|
|
286
|
+
format: "iife",
|
|
289
287
|
assetFileNames: `${name}.[ext]`,
|
|
290
288
|
// 外部ライブラリのソースマップを無視して警告を抑制
|
|
291
289
|
sourcemapIgnoreList: (relativeSourcePath) => {
|
|
@@ -396,75 +394,18 @@ async function action() {
|
|
|
396
394
|
|
|
397
395
|
// src/commands/plugin-esbuild.ts
|
|
398
396
|
import { program as program2 } from "commander";
|
|
399
|
-
import fs4 from "fs-extra";
|
|
400
|
-
import path6 from "path";
|
|
401
|
-
import chalk3 from "chalk";
|
|
402
397
|
function command2() {
|
|
403
|
-
program2.command("esbuild").description(
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
console.group("\u{1F373} Build the project for production");
|
|
407
|
-
try {
|
|
408
|
-
const config2 = await importK2PluginConfig();
|
|
409
|
-
if (config2?.lint?.build) {
|
|
410
|
-
await lint();
|
|
411
|
-
console.log("\u2728 Lint success.");
|
|
412
|
-
}
|
|
413
|
-
if (!fs4.existsSync(PLUGIN_CONTENTS_DIRECTORY)) {
|
|
414
|
-
await fs4.mkdir(PLUGIN_CONTENTS_DIRECTORY, { recursive: true });
|
|
415
|
-
}
|
|
416
|
-
const entries = getPluginEntryPoints({
|
|
417
|
-
configEntry: path6.resolve("src", "config"),
|
|
418
|
-
desktopEntry: path6.resolve("src", "desktop")
|
|
419
|
-
});
|
|
420
|
-
const entryNames = Object.keys(entries);
|
|
421
|
-
if (entryNames.length === 0) {
|
|
422
|
-
throw new Error("No entry points found for plugin. Check src/config and src/desktop paths.");
|
|
423
|
-
}
|
|
424
|
-
console.log(chalk3.gray(` Entry points: ${entryNames.join(", ")}`));
|
|
425
|
-
const buildTasks = [];
|
|
426
|
-
if (config2.tailwind?.css && config2.tailwind?.config) {
|
|
427
|
-
const tailwindConfig = await getTailwindConfig(config2.tailwind);
|
|
428
|
-
const inputFile = getTailwindInputCss(config2.tailwind);
|
|
429
|
-
buildTasks.push(
|
|
430
|
-
outputCss({
|
|
431
|
-
inputPath: inputFile.config,
|
|
432
|
-
outputPath: path6.join(PLUGIN_CONTENTS_DIRECTORY, "config.css"),
|
|
433
|
-
config: tailwindConfig.config,
|
|
434
|
-
minify: true
|
|
435
|
-
}).then(() => console.log("\u2728 Built config.css")),
|
|
436
|
-
outputCss({
|
|
437
|
-
inputPath: inputFile.desktop,
|
|
438
|
-
outputPath: path6.join(PLUGIN_CONTENTS_DIRECTORY, "desktop.css"),
|
|
439
|
-
config: tailwindConfig.desktop,
|
|
440
|
-
minify: true
|
|
441
|
-
}).then(() => console.log("\u2728 Built desktop.css"))
|
|
442
|
-
);
|
|
443
|
-
}
|
|
444
|
-
buildTasks.push(
|
|
445
|
-
buildEntriesWithVite({
|
|
446
|
-
entries,
|
|
447
|
-
outDir: PLUGIN_CONTENTS_DIRECTORY,
|
|
448
|
-
mode: "production",
|
|
449
|
-
sourcemap: false,
|
|
450
|
-
minify: true
|
|
451
|
-
}).then(() => console.log("\u2728 Built desktop.js and config.js"))
|
|
452
|
-
);
|
|
453
|
-
await Promise.all(buildTasks);
|
|
454
|
-
console.log("\u2728 Build success.");
|
|
455
|
-
} catch (error) {
|
|
456
|
-
throw error;
|
|
457
|
-
} finally {
|
|
458
|
-
console.groupEnd();
|
|
459
|
-
}
|
|
398
|
+
program2.command("esbuild").description(
|
|
399
|
+
"[DEPRECATED] Build the project for production with esbuild. (Use `plugin build` instead.)"
|
|
400
|
+
).action(action);
|
|
460
401
|
}
|
|
461
402
|
|
|
462
403
|
// src/commands/plugin-dev/index.ts
|
|
463
404
|
import { program as program3 } from "commander";
|
|
464
405
|
import { createServer } from "vite";
|
|
465
|
-
import
|
|
466
|
-
import
|
|
467
|
-
import
|
|
406
|
+
import fs10 from "fs-extra";
|
|
407
|
+
import path13 from "path";
|
|
408
|
+
import chalk5 from "chalk";
|
|
468
409
|
|
|
469
410
|
// src/lib/exec.ts
|
|
470
411
|
import { exec as defaultExec } from "child_process";
|
|
@@ -472,19 +413,19 @@ import { promisify } from "util";
|
|
|
472
413
|
var exec = promisify(defaultExec);
|
|
473
414
|
|
|
474
415
|
// src/lib/cert.ts
|
|
475
|
-
import
|
|
476
|
-
import
|
|
416
|
+
import fs4 from "fs-extra";
|
|
417
|
+
import path6 from "path";
|
|
477
418
|
var CERT_KEY_FILENAME = "localhost-key.pem";
|
|
478
419
|
var CERT_FILENAME = "localhost-cert.pem";
|
|
479
420
|
var generateCert = async (outDir) => {
|
|
480
|
-
await
|
|
421
|
+
await fs4.ensureDir(outDir);
|
|
481
422
|
const { stdout } = await exec(`mkcert localhost 127.0.0.1 ::1`);
|
|
482
423
|
[
|
|
483
424
|
{ input: "localhost+2.pem", output: CERT_FILENAME },
|
|
484
425
|
{ input: "localhost+2-key.pem", output: CERT_KEY_FILENAME }
|
|
485
426
|
].forEach(({ input, output }) => {
|
|
486
|
-
if (
|
|
487
|
-
|
|
427
|
+
if (fs4.existsSync(input)) {
|
|
428
|
+
fs4.moveSync(`./${input}`, path6.join(outDir, output), {
|
|
488
429
|
overwrite: true
|
|
489
430
|
});
|
|
490
431
|
}
|
|
@@ -492,24 +433,24 @@ var generateCert = async (outDir) => {
|
|
|
492
433
|
return { stdout };
|
|
493
434
|
};
|
|
494
435
|
function hasCertificates(certDir) {
|
|
495
|
-
return
|
|
436
|
+
return fs4.existsSync(path6.join(certDir, CERT_KEY_FILENAME)) && fs4.existsSync(path6.join(certDir, CERT_FILENAME));
|
|
496
437
|
}
|
|
497
438
|
function loadCertificates(certDir) {
|
|
498
439
|
return {
|
|
499
|
-
key:
|
|
500
|
-
cert:
|
|
440
|
+
key: fs4.readFileSync(path6.join(certDir, CERT_KEY_FILENAME)),
|
|
441
|
+
cert: fs4.readFileSync(path6.join(certDir, CERT_FILENAME))
|
|
501
442
|
};
|
|
502
443
|
}
|
|
503
444
|
|
|
504
445
|
// src/lib/plugin-manifest.ts
|
|
505
|
-
import
|
|
506
|
-
import
|
|
446
|
+
import fs5 from "fs-extra";
|
|
447
|
+
import path7 from "path";
|
|
507
448
|
import merge from "deepmerge";
|
|
508
449
|
var outputManifest = async (env, options) => {
|
|
509
450
|
const config2 = options?.config || await importK2PluginConfig();
|
|
510
451
|
const merged = merge(config2.manifest.base, config2.manifest[env] || {});
|
|
511
|
-
await
|
|
512
|
-
await
|
|
452
|
+
await fs5.mkdirs(PLUGIN_CONTENTS_DIRECTORY);
|
|
453
|
+
await fs5.writeJson(path7.join(PLUGIN_CONTENTS_DIRECTORY, "manifest.json"), merged);
|
|
513
454
|
return merged;
|
|
514
455
|
};
|
|
515
456
|
|
|
@@ -544,21 +485,21 @@ var getManifest = async (params) => {
|
|
|
544
485
|
};
|
|
545
486
|
|
|
546
487
|
// src/commands/plugin-dev/tailwind.ts
|
|
547
|
-
import
|
|
488
|
+
import path8 from "path";
|
|
548
489
|
import "tailwindcss";
|
|
549
|
-
import
|
|
490
|
+
import chalk3 from "chalk";
|
|
550
491
|
async function buildTailwindCSS(params) {
|
|
551
492
|
const { inputFile, outputFileName, config: config2 } = params;
|
|
552
|
-
const inputPath =
|
|
553
|
-
const outputPath =
|
|
493
|
+
const inputPath = path8.resolve(inputFile);
|
|
494
|
+
const outputPath = path8.join(PLUGIN_DEVELOPMENT_DIRECTORY, outputFileName);
|
|
554
495
|
return watchTailwindCSS({
|
|
555
496
|
input: inputPath,
|
|
556
497
|
output: outputPath,
|
|
557
498
|
config: config2,
|
|
558
499
|
onChanges: ({ output, type }) => {
|
|
559
|
-
const outputFileName2 =
|
|
500
|
+
const outputFileName2 = path8.basename(output);
|
|
560
501
|
console.log(
|
|
561
|
-
|
|
502
|
+
chalk3.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk3.cyan(`[css] `) + outputFileName2 + (type === "init" ? " init" : ` rebuilt`)
|
|
562
503
|
);
|
|
563
504
|
}
|
|
564
505
|
});
|
|
@@ -587,20 +528,20 @@ var watchCss = async (pluginConfig) => {
|
|
|
587
528
|
import packer from "@kintone/plugin-packer";
|
|
588
529
|
|
|
589
530
|
// src/lib/plugin-contents.ts
|
|
590
|
-
import
|
|
591
|
-
import
|
|
531
|
+
import fs6 from "fs-extra";
|
|
532
|
+
import path9 from "path";
|
|
592
533
|
import htmlMinifier from "html-minifier";
|
|
593
534
|
var copyPluginContents = async (params = {}) => {
|
|
594
|
-
const { inputDir =
|
|
595
|
-
if (!
|
|
596
|
-
await
|
|
535
|
+
const { inputDir = path9.join("src", "contents"), outputDir = PLUGIN_CONTENTS_DIRECTORY } = params;
|
|
536
|
+
if (!fs6.existsSync(inputDir)) {
|
|
537
|
+
await fs6.mkdir(inputDir, { recursive: true });
|
|
597
538
|
}
|
|
598
|
-
await
|
|
599
|
-
const configHtmlPath =
|
|
600
|
-
if (!
|
|
539
|
+
await fs6.copy(inputDir, outputDir, { overwrite: true });
|
|
540
|
+
const configHtmlPath = path9.join(outputDir, "config.html");
|
|
541
|
+
if (!fs6.existsSync(configHtmlPath)) {
|
|
601
542
|
throw new Error(`Plugin HTML file not found. Create "config.html" in ${inputDir}.`);
|
|
602
543
|
}
|
|
603
|
-
const html = await
|
|
544
|
+
const html = await fs6.readFile(configHtmlPath, "utf8");
|
|
604
545
|
const minified = htmlMinifier.minify(html, {
|
|
605
546
|
minifyCSS: true,
|
|
606
547
|
collapseWhitespace: true,
|
|
@@ -611,13 +552,13 @@ var copyPluginContents = async (params = {}) => {
|
|
|
611
552
|
removeTagWhitespace: true,
|
|
612
553
|
useShortDoctype: true
|
|
613
554
|
});
|
|
614
|
-
await
|
|
555
|
+
await fs6.writeFile(configHtmlPath, minified);
|
|
615
556
|
};
|
|
616
557
|
|
|
617
558
|
// src/lib/zip.ts
|
|
618
559
|
import archiver from "archiver";
|
|
619
|
-
import
|
|
620
|
-
import
|
|
560
|
+
import fs7 from "fs-extra";
|
|
561
|
+
import path10 from "path";
|
|
621
562
|
import invariant2 from "tiny-invariant";
|
|
622
563
|
var outputContentsZip = async (manifest) => {
|
|
623
564
|
const archive = archiver("zip", { zlib: { level: 9 } });
|
|
@@ -628,8 +569,8 @@ var outputContentsZip = async (manifest) => {
|
|
|
628
569
|
throw error;
|
|
629
570
|
}
|
|
630
571
|
});
|
|
631
|
-
const outputZipPath =
|
|
632
|
-
const outputZipStream =
|
|
572
|
+
const outputZipPath = path10.join(PLUGIN_WORKSPACE_DIRECTORY, "contents.zip");
|
|
573
|
+
const outputZipStream = fs7.createWriteStream(outputZipPath);
|
|
633
574
|
outputZipStream.on("close", () => {
|
|
634
575
|
console.log(`\u{1F4E6} ${archive.pointer()} total bytes`);
|
|
635
576
|
});
|
|
@@ -660,8 +601,8 @@ var outputContentsZip = async (manifest) => {
|
|
|
660
601
|
});
|
|
661
602
|
console.groupEnd();
|
|
662
603
|
for (const file of targetFiles) {
|
|
663
|
-
const filePath =
|
|
664
|
-
if (!
|
|
604
|
+
const filePath = path10.join(PLUGIN_CONTENTS_DIRECTORY, file);
|
|
605
|
+
if (!fs7.existsSync(filePath)) {
|
|
665
606
|
throw new Error(`${filePath} does not exist`);
|
|
666
607
|
}
|
|
667
608
|
archive.file(filePath, { name: file });
|
|
@@ -671,16 +612,16 @@ var outputContentsZip = async (manifest) => {
|
|
|
671
612
|
await new Promise((resolve) => outputZipStream.on("close", resolve));
|
|
672
613
|
};
|
|
673
614
|
var getContentsZipBuffer = async () => {
|
|
674
|
-
const outputZipPath =
|
|
675
|
-
return
|
|
615
|
+
const outputZipPath = path10.join(PLUGIN_WORKSPACE_DIRECTORY, "contents.zip");
|
|
616
|
+
return fs7.readFile(outputZipPath);
|
|
676
617
|
};
|
|
677
618
|
var getZipFileNameSuffix = (env) => {
|
|
678
619
|
return env === "prod" ? "" : `-${env}`;
|
|
679
620
|
};
|
|
680
621
|
|
|
681
622
|
// src/commands/plugin-dev/upload.ts
|
|
682
|
-
import
|
|
683
|
-
import
|
|
623
|
+
import fs9 from "fs-extra";
|
|
624
|
+
import path12 from "path";
|
|
684
625
|
|
|
685
626
|
// src/lib/kintone-api-client.ts
|
|
686
627
|
import { config } from "dotenv";
|
|
@@ -715,8 +656,8 @@ KINTONE_PASSWORD`);
|
|
|
715
656
|
this.#baseUrl = KINTONE_BASE_URL;
|
|
716
657
|
this.#authHeader = authHeader;
|
|
717
658
|
}
|
|
718
|
-
getEndpointUrl(
|
|
719
|
-
return `${this.#baseUrl}${
|
|
659
|
+
getEndpointUrl(path16) {
|
|
660
|
+
return `${this.#baseUrl}${path16}`;
|
|
720
661
|
}
|
|
721
662
|
async upload(params) {
|
|
722
663
|
const { blob, fileName } = params;
|
|
@@ -787,8 +728,8 @@ KINTONE_PASSWORD`);
|
|
|
787
728
|
};
|
|
788
729
|
|
|
789
730
|
// src/lib/utils.ts
|
|
790
|
-
import
|
|
791
|
-
import
|
|
731
|
+
import fs8 from "fs-extra";
|
|
732
|
+
import path11 from "path";
|
|
792
733
|
var isEnv = (env) => {
|
|
793
734
|
return ["prod", "dev", "standalone"].includes(env);
|
|
794
735
|
};
|
|
@@ -796,7 +737,7 @@ var apiUploadZip = async (params) => {
|
|
|
796
737
|
const { env, pluginId } = params;
|
|
797
738
|
const kc = new KintoneApiClient();
|
|
798
739
|
const zipFileName = `plugin${getZipFileNameSuffix(env)}.zip`;
|
|
799
|
-
const zipFile = new Blob([await
|
|
740
|
+
const zipFile = new Blob([await fs8.readFile(path11.join(PLUGIN_WORKSPACE_DIRECTORY, zipFileName))]);
|
|
800
741
|
const fileKey = await kc.upload({ blob: zipFile, fileName: zipFileName });
|
|
801
742
|
const plugins = await kc.getAllPlugins();
|
|
802
743
|
const plugin = plugins.find((p) => p.id === pluginId);
|
|
@@ -816,7 +757,7 @@ var apiUploadZip = async (params) => {
|
|
|
816
757
|
|
|
817
758
|
// src/commands/plugin-dev/upload.ts
|
|
818
759
|
import chokider from "chokidar";
|
|
819
|
-
import
|
|
760
|
+
import chalk4 from "chalk";
|
|
820
761
|
var watchContentsAndUploadZip = async (params) => {
|
|
821
762
|
const { manifest, ppkPath } = params;
|
|
822
763
|
let initialScanComplete = false;
|
|
@@ -827,7 +768,7 @@ var watchContentsAndUploadZip = async (params) => {
|
|
|
827
768
|
}
|
|
828
769
|
await copyPluginContents();
|
|
829
770
|
console.log(
|
|
830
|
-
|
|
771
|
+
chalk4.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk4.cyan(`[contents] `) + `updated`
|
|
831
772
|
);
|
|
832
773
|
} catch (error) {
|
|
833
774
|
console.error("Error copying plugin contents:", error);
|
|
@@ -836,17 +777,17 @@ var watchContentsAndUploadZip = async (params) => {
|
|
|
836
777
|
try {
|
|
837
778
|
await outputContentsZip(manifest);
|
|
838
779
|
const buffer = await getContentsZipBuffer();
|
|
839
|
-
const pluginPrivateKey = await
|
|
780
|
+
const pluginPrivateKey = await fs9.readFile(path12.resolve(ppkPath), "utf8");
|
|
840
781
|
const output = await packer(buffer, pluginPrivateKey);
|
|
841
782
|
const zipFileName = `plugin${getZipFileNameSuffix("dev")}.zip`;
|
|
842
|
-
await
|
|
783
|
+
await fs9.writeFile(path12.join(PLUGIN_WORKSPACE_DIRECTORY, zipFileName), output.plugin);
|
|
843
784
|
const { method } = await apiUploadZip({ env: "dev", pluginId: output.id });
|
|
844
785
|
console.log(
|
|
845
|
-
|
|
786
|
+
chalk4.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk4.cyan(`[upload] `) + `uploaded ${method === "POST" ? "(new)" : "(update)"}`
|
|
846
787
|
);
|
|
847
788
|
} catch (error) {
|
|
848
789
|
console.log(
|
|
849
|
-
|
|
790
|
+
chalk4.hex("#e5e7eb")(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} `) + chalk4.cyan(`[upload] `) + chalk4.red(`failed`) + chalk4.hex("#e5e7eb")(`: ${error?.message ?? "Unknown error"}`)
|
|
850
791
|
);
|
|
851
792
|
}
|
|
852
793
|
};
|
|
@@ -868,46 +809,46 @@ function command3() {
|
|
|
868
809
|
program3.command("dev").option(
|
|
869
810
|
"-p, --ppk <ppk>",
|
|
870
811
|
".ppk file path",
|
|
871
|
-
|
|
872
|
-
).option("-c, --cert-dir <certDir>", "Certificate directory", PLUGIN_WORKSPACE_DIRECTORY).description("Start development server with Vite.").action(
|
|
812
|
+
path13.join(PLUGIN_WORKSPACE_DIRECTORY, "private.ppk")
|
|
813
|
+
).option("-c, --cert-dir <certDir>", "Certificate directory", PLUGIN_WORKSPACE_DIRECTORY).description("Start development server with Vite.").action(action2);
|
|
873
814
|
}
|
|
874
|
-
async function
|
|
815
|
+
async function action2(options) {
|
|
875
816
|
console.group("\u{1F373} Start development server");
|
|
876
817
|
try {
|
|
877
818
|
const { ppk: ppkPath, certDir } = options;
|
|
878
819
|
const config2 = await importK2PluginConfig();
|
|
879
|
-
const certDirPath =
|
|
880
|
-
const outputDir =
|
|
881
|
-
if (!
|
|
882
|
-
await
|
|
820
|
+
const certDirPath = path13.resolve(certDir);
|
|
821
|
+
const outputDir = path13.resolve(PLUGIN_DEVELOPMENT_DIRECTORY);
|
|
822
|
+
if (!fs10.existsSync(PLUGIN_DEVELOPMENT_DIRECTORY)) {
|
|
823
|
+
await fs10.mkdir(PLUGIN_DEVELOPMENT_DIRECTORY, { recursive: true });
|
|
883
824
|
}
|
|
884
825
|
const port = config2.server?.port ?? DEFAULT_PORT;
|
|
885
826
|
if (!hasCertificates(certDirPath)) {
|
|
886
|
-
console.log(
|
|
827
|
+
console.log(chalk5.yellow("\u{1F4DC} SSL certificates not found. Generating..."));
|
|
887
828
|
try {
|
|
888
829
|
await generateCert(certDirPath);
|
|
889
|
-
console.log(
|
|
830
|
+
console.log(chalk5.green("\u2705 SSL certificates generated successfully"));
|
|
890
831
|
} catch (error) {
|
|
891
832
|
console.log(
|
|
892
|
-
|
|
833
|
+
chalk5.red("\u274C Failed to generate SSL certificates. Make sure mkcert is installed.")
|
|
893
834
|
);
|
|
894
|
-
console.log(
|
|
835
|
+
console.log(chalk5.gray(" Install mkcert: https://github.com/FiloSottile/mkcert"));
|
|
895
836
|
throw error;
|
|
896
837
|
}
|
|
897
838
|
}
|
|
898
839
|
const manifest = await getManifest({ config: config2, port });
|
|
899
840
|
console.log(`\u{1F4DD} manifest.json generated`);
|
|
900
841
|
const entries = getPluginEntryPoints({
|
|
901
|
-
configEntry:
|
|
902
|
-
desktopEntry:
|
|
842
|
+
configEntry: path13.resolve("src", "config"),
|
|
843
|
+
desktopEntry: path13.resolve("src", "desktop")
|
|
903
844
|
});
|
|
904
845
|
const entryNames = Object.keys(entries);
|
|
905
846
|
if (entryNames.length === 0) {
|
|
906
847
|
throw new Error("No entry points found for plugin. Check src/config and src/desktop paths.");
|
|
907
848
|
}
|
|
908
|
-
console.log(
|
|
849
|
+
console.log(chalk5.gray(` Entry points: ${entryNames.join(", ")}`));
|
|
909
850
|
const { key, cert } = loadCertificates(certDirPath);
|
|
910
|
-
console.log(
|
|
851
|
+
console.log(chalk5.gray(" Building..."));
|
|
911
852
|
await buildEntriesWithVite({
|
|
912
853
|
entries,
|
|
913
854
|
outDir: outputDir,
|
|
@@ -924,19 +865,19 @@ async function action3(options) {
|
|
|
924
865
|
});
|
|
925
866
|
const server = await createServer(serverConfig);
|
|
926
867
|
await server.listen();
|
|
927
|
-
console.log(
|
|
868
|
+
console.log(chalk5.green(`
|
|
928
869
|
\u2728 Plugin development server ready!`));
|
|
929
|
-
console.log(
|
|
930
|
-
console.log(
|
|
931
|
-
console.log(
|
|
932
|
-
console.log(
|
|
870
|
+
console.log(chalk5.cyan(` Local: https://localhost:${port}`));
|
|
871
|
+
console.log(chalk5.gray(` Output: ${outputDir}`));
|
|
872
|
+
console.log(chalk5.gray(` Files: config.js, desktop.js`));
|
|
873
|
+
console.log(chalk5.gray("\n Watching for changes...\n"));
|
|
933
874
|
const chokidar2 = await import("chokidar");
|
|
934
875
|
const watchDirs = [
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
].filter((dir) =>
|
|
939
|
-
console.log(
|
|
876
|
+
path13.resolve("src", "config"),
|
|
877
|
+
path13.resolve("src", "desktop"),
|
|
878
|
+
path13.resolve("src", "lib")
|
|
879
|
+
].filter((dir) => fs10.existsSync(dir));
|
|
880
|
+
console.log(chalk5.gray(` Watching directories: ${watchDirs.join(", ")}`));
|
|
940
881
|
const watcher = chokidar2.watch(watchDirs, {
|
|
941
882
|
ignored: /node_modules/,
|
|
942
883
|
persistent: true,
|
|
@@ -944,11 +885,11 @@ async function action3(options) {
|
|
|
944
885
|
});
|
|
945
886
|
const watchExtensions = [".ts", ".tsx", ".js", ".jsx", ".css", ".scss"];
|
|
946
887
|
const shouldRebuild = (filePath) => {
|
|
947
|
-
const ext =
|
|
888
|
+
const ext = path13.extname(filePath).toLowerCase();
|
|
948
889
|
return watchExtensions.includes(ext);
|
|
949
890
|
};
|
|
950
891
|
const rebuild = async () => {
|
|
951
|
-
console.log(
|
|
892
|
+
console.log(chalk5.gray(` ${(/* @__PURE__ */ new Date()).toLocaleTimeString()} Rebuilding...`));
|
|
952
893
|
await buildEntriesWithVite({
|
|
953
894
|
entries,
|
|
954
895
|
outDir: outputDir,
|
|
@@ -956,31 +897,31 @@ async function action3(options) {
|
|
|
956
897
|
sourcemap: "inline",
|
|
957
898
|
minify: false
|
|
958
899
|
});
|
|
959
|
-
console.log(
|
|
900
|
+
console.log(chalk5.gray(` ${(/* @__PURE__ */ new Date()).toLocaleTimeString()} Rebuild complete`));
|
|
960
901
|
};
|
|
961
902
|
watcher.on("ready", () => {
|
|
962
|
-
console.log(
|
|
903
|
+
console.log(chalk5.green(" \u2713 File watcher ready"));
|
|
963
904
|
});
|
|
964
905
|
watcher.on("change", (filePath) => {
|
|
965
906
|
if (shouldRebuild(filePath)) {
|
|
966
|
-
console.log(
|
|
907
|
+
console.log(chalk5.cyan(` [change] ${filePath}`));
|
|
967
908
|
rebuild();
|
|
968
909
|
}
|
|
969
910
|
});
|
|
970
911
|
watcher.on("add", (filePath) => {
|
|
971
912
|
if (shouldRebuild(filePath)) {
|
|
972
|
-
console.log(
|
|
913
|
+
console.log(chalk5.cyan(` [add] ${filePath}`));
|
|
973
914
|
rebuild();
|
|
974
915
|
}
|
|
975
916
|
});
|
|
976
917
|
watcher.on("unlink", (filePath) => {
|
|
977
918
|
if (shouldRebuild(filePath)) {
|
|
978
|
-
console.log(
|
|
919
|
+
console.log(chalk5.cyan(` [unlink] ${filePath}`));
|
|
979
920
|
rebuild();
|
|
980
921
|
}
|
|
981
922
|
});
|
|
982
923
|
watcher.on("error", (error) => {
|
|
983
|
-
console.error(
|
|
924
|
+
console.error(chalk5.red(` Watcher error: ${error}`));
|
|
984
925
|
});
|
|
985
926
|
Promise.all([watchContentsAndUploadZip({ manifest, ppkPath }), watchCss(config2)]);
|
|
986
927
|
} catch (error) {
|
|
@@ -994,7 +935,7 @@ async function action3(options) {
|
|
|
994
935
|
import { program as program4 } from "commander";
|
|
995
936
|
|
|
996
937
|
// src/commands/genkey-base.ts
|
|
997
|
-
async function
|
|
938
|
+
async function action3(options) {
|
|
998
939
|
const { output } = options;
|
|
999
940
|
console.group("\u{1F373} Generate SSL key for localhost");
|
|
1000
941
|
try {
|
|
@@ -1012,21 +953,21 @@ async function action4(options) {
|
|
|
1012
953
|
|
|
1013
954
|
// src/commands/plugin-genkey.ts
|
|
1014
955
|
function command4() {
|
|
1015
|
-
program4.command("genkey").description("Generate SSL key for localhost. (Require mkcert)").action(
|
|
956
|
+
program4.command("genkey").description("Generate SSL key for localhost. (Require mkcert)").action(action4);
|
|
1016
957
|
}
|
|
1017
|
-
async function
|
|
1018
|
-
await
|
|
958
|
+
async function action4() {
|
|
959
|
+
await action3({ output: PLUGIN_WORKSPACE_DIRECTORY });
|
|
1019
960
|
}
|
|
1020
961
|
|
|
1021
962
|
// src/commands/plugin-init.ts
|
|
1022
963
|
import { program as program5 } from "commander";
|
|
1023
|
-
import
|
|
1024
|
-
import
|
|
964
|
+
import fs11 from "fs-extra";
|
|
965
|
+
import path14 from "path";
|
|
1025
966
|
import packer2 from "@kintone/plugin-packer";
|
|
1026
967
|
function command5() {
|
|
1027
|
-
program5.command("init").description("generate private.ppk and kitting config").action(
|
|
968
|
+
program5.command("init").description("generate private.ppk and kitting config").action(action5);
|
|
1028
969
|
}
|
|
1029
|
-
async function
|
|
970
|
+
async function action5() {
|
|
1030
971
|
console.group("\u{1F373} Executing plugin initialization setup");
|
|
1031
972
|
try {
|
|
1032
973
|
const manifest = await outputManifest("dev");
|
|
@@ -1034,20 +975,20 @@ async function action6() {
|
|
|
1034
975
|
await copyPluginContents();
|
|
1035
976
|
console.log("\u{1F4C1} contents copied");
|
|
1036
977
|
let privateKey;
|
|
1037
|
-
const keyPath =
|
|
1038
|
-
if (
|
|
1039
|
-
privateKey = await
|
|
978
|
+
const keyPath = path14.join(PLUGIN_WORKSPACE_DIRECTORY, "private.ppk");
|
|
979
|
+
if (fs11.existsSync(keyPath)) {
|
|
980
|
+
privateKey = await fs11.readFile(keyPath, "utf8");
|
|
1040
981
|
}
|
|
1041
982
|
await outputContentsZip(manifest);
|
|
1042
983
|
const buffer = await getContentsZipBuffer();
|
|
1043
984
|
const output = await packer2(buffer, privateKey);
|
|
1044
985
|
if (!privateKey) {
|
|
1045
|
-
await
|
|
986
|
+
await fs11.writeFile(path14.join(PLUGIN_WORKSPACE_DIRECTORY, "private.ppk"), output.privateKey);
|
|
1046
987
|
console.log("\u{1F511} private.ppk generated");
|
|
1047
988
|
} else {
|
|
1048
989
|
console.log("\u{1F511} private.ppk already exists. The existing private.ppk will be used.");
|
|
1049
990
|
}
|
|
1050
|
-
await
|
|
991
|
+
await fs11.writeFile(path14.join(PLUGIN_WORKSPACE_DIRECTORY, "plugin.zip"), output.plugin);
|
|
1051
992
|
console.log("\u{1F4E6} plugin.zip generated");
|
|
1052
993
|
console.log("\u2728 Plugin initialization setup completed! zip file path is ./.plugin/plugin.zip");
|
|
1053
994
|
} catch (error) {
|
|
@@ -1060,9 +1001,9 @@ async function action6() {
|
|
|
1060
1001
|
// src/commands/manifest/index.ts
|
|
1061
1002
|
import { program as program6 } from "commander";
|
|
1062
1003
|
function command6() {
|
|
1063
|
-
program6.command("manifest").option("-e, --env <env>", "create manifest", "prod").action(
|
|
1004
|
+
program6.command("manifest").option("-e, --env <env>", "create manifest", "prod").action(action6);
|
|
1064
1005
|
}
|
|
1065
|
-
async function
|
|
1006
|
+
async function action6(options) {
|
|
1066
1007
|
console.group("\u{1F680} Executing manifest generation");
|
|
1067
1008
|
try {
|
|
1068
1009
|
const { env } = options;
|
|
@@ -1082,13 +1023,13 @@ async function action7(options) {
|
|
|
1082
1023
|
|
|
1083
1024
|
// src/commands/test/index.ts
|
|
1084
1025
|
import { program as program7 } from "commander";
|
|
1085
|
-
import
|
|
1026
|
+
import fs12 from "fs-extra";
|
|
1086
1027
|
function command7() {
|
|
1087
|
-
program7.command("test").description("test").action(
|
|
1028
|
+
program7.command("test").description("test").action(action7);
|
|
1088
1029
|
}
|
|
1089
|
-
async function
|
|
1030
|
+
async function action7() {
|
|
1090
1031
|
console.group("package.json");
|
|
1091
|
-
const packageJson =
|
|
1032
|
+
const packageJson = fs12.readJSONSync("package.json");
|
|
1092
1033
|
console.log("package.json detected");
|
|
1093
1034
|
console.groupEnd();
|
|
1094
1035
|
console.group("Config");
|
|
@@ -1099,17 +1040,17 @@ async function action8() {
|
|
|
1099
1040
|
|
|
1100
1041
|
// src/commands/plugin-zip.ts
|
|
1101
1042
|
import { program as program8 } from "commander";
|
|
1102
|
-
import
|
|
1103
|
-
import
|
|
1043
|
+
import fs13 from "fs-extra";
|
|
1044
|
+
import path15 from "path";
|
|
1104
1045
|
import packer3 from "@kintone/plugin-packer";
|
|
1105
1046
|
function command8() {
|
|
1106
1047
|
program8.command("zip").description("generate plugin zip").option("-e, --env <env>", "plugin environment (dev, prod, standalone)", "prod").option(
|
|
1107
1048
|
"-p, --ppk <ppk>",
|
|
1108
1049
|
".ppk file path",
|
|
1109
|
-
|
|
1110
|
-
).action(
|
|
1050
|
+
path15.join(PLUGIN_WORKSPACE_DIRECTORY, "private.ppk")
|
|
1051
|
+
).action(action8);
|
|
1111
1052
|
}
|
|
1112
|
-
async function
|
|
1053
|
+
async function action8(options) {
|
|
1113
1054
|
console.group("\u{1F373} Executing plugin zip generation");
|
|
1114
1055
|
try {
|
|
1115
1056
|
const { env, ppk: ppkPath } = options;
|
|
@@ -1123,13 +1064,13 @@ async function action9(options) {
|
|
|
1123
1064
|
await outputContentsZip(manifest);
|
|
1124
1065
|
console.log("\u{1F4E6} contents.zip generated");
|
|
1125
1066
|
const buffer = await getContentsZipBuffer();
|
|
1126
|
-
const privateKey = await
|
|
1067
|
+
const privateKey = await fs13.readFile(path15.resolve(ppkPath), "utf8");
|
|
1127
1068
|
const output = await packer3(buffer, privateKey);
|
|
1128
1069
|
const zipFileName = `plugin${getZipFileNameSuffix(env)}.zip`;
|
|
1129
|
-
await
|
|
1070
|
+
await fs13.writeFile(path15.join(PLUGIN_WORKSPACE_DIRECTORY, zipFileName), output.plugin);
|
|
1130
1071
|
console.log("\u{1F4E6} plugin.zip generated");
|
|
1131
1072
|
const version = String(manifest.version);
|
|
1132
|
-
await
|
|
1073
|
+
await fs13.writeFile(path15.join(PLUGIN_WORKSPACE_DIRECTORY, "version"), version);
|
|
1133
1074
|
console.log(`\u{1F4DD} version file generated (${version})`);
|
|
1134
1075
|
console.log(`\u2728 Plugin zip generation completed! zip file path is ./.plugin/${zipFileName}`);
|
|
1135
1076
|
} catch (error) {
|
|
@@ -1142,9 +1083,9 @@ async function action9(options) {
|
|
|
1142
1083
|
// src/commands/lint.ts
|
|
1143
1084
|
import { program as program9 } from "commander";
|
|
1144
1085
|
function command9() {
|
|
1145
|
-
program9.command("lint").description("Lint source files").option("-c, --config <config>", "Config file path").action(
|
|
1086
|
+
program9.command("lint").description("Lint source files").option("-c, --config <config>", "Config file path").action(action9);
|
|
1146
1087
|
}
|
|
1147
|
-
async function
|
|
1088
|
+
async function action9(options) {
|
|
1148
1089
|
try {
|
|
1149
1090
|
lint();
|
|
1150
1091
|
} catch (error) {
|