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