@lark-apaas/fullstack-cli 1.1.6-alpha.1 → 1.1.6-alpha.3
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 +201 -120
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -438,8 +438,7 @@ var syncCommand = {
|
|
|
438
438
|
// src/commands/action-plugin/utils.ts
|
|
439
439
|
import fs3 from "fs";
|
|
440
440
|
import path3 from "path";
|
|
441
|
-
import { spawnSync as spawnSync2 } from "child_process";
|
|
442
|
-
var CONFIG_FILE_NAME = ".capabilityrc.json";
|
|
441
|
+
import { spawnSync as spawnSync2, execSync } from "child_process";
|
|
443
442
|
function parsePluginName(input) {
|
|
444
443
|
const match = input.match(/^(@[^/]+\/[^@]+)(?:@(.+))?$/);
|
|
445
444
|
if (!match) {
|
|
@@ -455,36 +454,44 @@ function parsePluginName(input) {
|
|
|
455
454
|
function getProjectRoot() {
|
|
456
455
|
return process.cwd();
|
|
457
456
|
}
|
|
458
|
-
function
|
|
459
|
-
return path3.join(getProjectRoot(),
|
|
457
|
+
function getPackageJsonPath() {
|
|
458
|
+
return path3.join(getProjectRoot(), "package.json");
|
|
460
459
|
}
|
|
461
460
|
function getPluginPath(pluginName) {
|
|
462
461
|
return path3.join(getProjectRoot(), "node_modules", pluginName);
|
|
463
462
|
}
|
|
464
|
-
function
|
|
465
|
-
const
|
|
466
|
-
if (!fs3.existsSync(
|
|
467
|
-
|
|
463
|
+
function readPackageJson() {
|
|
464
|
+
const pkgPath = getPackageJsonPath();
|
|
465
|
+
if (!fs3.existsSync(pkgPath)) {
|
|
466
|
+
throw new Error("package.json not found in current directory");
|
|
468
467
|
}
|
|
469
468
|
try {
|
|
470
|
-
const content = fs3.readFileSync(
|
|
469
|
+
const content = fs3.readFileSync(pkgPath, "utf-8");
|
|
471
470
|
return JSON.parse(content);
|
|
472
471
|
} catch {
|
|
473
|
-
|
|
474
|
-
return { plugins: {} };
|
|
472
|
+
throw new Error("Failed to parse package.json");
|
|
475
473
|
}
|
|
476
474
|
}
|
|
477
|
-
function
|
|
478
|
-
const
|
|
479
|
-
fs3.writeFileSync(
|
|
475
|
+
function writePackageJson(pkg2) {
|
|
476
|
+
const pkgPath = getPackageJsonPath();
|
|
477
|
+
fs3.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
478
|
+
}
|
|
479
|
+
function readActionPlugins() {
|
|
480
|
+
const pkg2 = readPackageJson();
|
|
481
|
+
return pkg2.actionPlugins || {};
|
|
482
|
+
}
|
|
483
|
+
function writeActionPlugins(plugins) {
|
|
484
|
+
const pkg2 = readPackageJson();
|
|
485
|
+
pkg2.actionPlugins = plugins;
|
|
486
|
+
writePackageJson(pkg2);
|
|
480
487
|
}
|
|
481
488
|
function isPluginInstalled(pluginName) {
|
|
482
|
-
const
|
|
483
|
-
return pluginName in
|
|
489
|
+
const plugins = readActionPlugins();
|
|
490
|
+
return pluginName in plugins;
|
|
484
491
|
}
|
|
485
|
-
function
|
|
486
|
-
const
|
|
487
|
-
return
|
|
492
|
+
function getInstalledPluginVersion(pluginName) {
|
|
493
|
+
const plugins = readActionPlugins();
|
|
494
|
+
return plugins[pluginName] || null;
|
|
488
495
|
}
|
|
489
496
|
function npmInstall(tgzPath) {
|
|
490
497
|
console.log(`[action-plugin] Running npm install ${tgzPath}...`);
|
|
@@ -499,19 +506,6 @@ function npmInstall(tgzPath) {
|
|
|
499
506
|
throw new Error(`npm install failed with exit code ${result.status}`);
|
|
500
507
|
}
|
|
501
508
|
}
|
|
502
|
-
function npmUninstall(pluginName) {
|
|
503
|
-
console.log(`[action-plugin] Running npm uninstall ${pluginName}...`);
|
|
504
|
-
const result = spawnSync2("npm", ["uninstall", pluginName], {
|
|
505
|
-
cwd: getProjectRoot(),
|
|
506
|
-
stdio: "inherit"
|
|
507
|
-
});
|
|
508
|
-
if (result.error) {
|
|
509
|
-
throw new Error(`npm uninstall failed: ${result.error.message}`);
|
|
510
|
-
}
|
|
511
|
-
if (result.status !== 0) {
|
|
512
|
-
throw new Error(`npm uninstall failed with exit code ${result.status}`);
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
509
|
function getPackageVersion(pluginName) {
|
|
516
510
|
const pkgJsonPath = path3.join(getPluginPath(pluginName), "package.json");
|
|
517
511
|
if (!fs3.existsSync(pkgJsonPath)) {
|
|
@@ -525,6 +519,90 @@ function getPackageVersion(pluginName) {
|
|
|
525
519
|
return null;
|
|
526
520
|
}
|
|
527
521
|
}
|
|
522
|
+
function readPluginPackageJson(pluginPath) {
|
|
523
|
+
const pkgJsonPath = path3.join(pluginPath, "package.json");
|
|
524
|
+
if (!fs3.existsSync(pkgJsonPath)) {
|
|
525
|
+
return null;
|
|
526
|
+
}
|
|
527
|
+
try {
|
|
528
|
+
const content = fs3.readFileSync(pkgJsonPath, "utf-8");
|
|
529
|
+
return JSON.parse(content);
|
|
530
|
+
} catch {
|
|
531
|
+
return null;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
function extractTgzToNodeModules(tgzPath, pluginName) {
|
|
535
|
+
const nodeModulesPath = path3.join(getProjectRoot(), "node_modules");
|
|
536
|
+
const targetDir = path3.join(nodeModulesPath, pluginName);
|
|
537
|
+
const scopeDir = path3.dirname(targetDir);
|
|
538
|
+
if (!fs3.existsSync(scopeDir)) {
|
|
539
|
+
fs3.mkdirSync(scopeDir, { recursive: true });
|
|
540
|
+
}
|
|
541
|
+
if (fs3.existsSync(targetDir)) {
|
|
542
|
+
fs3.rmSync(targetDir, { recursive: true });
|
|
543
|
+
}
|
|
544
|
+
const tempDir = path3.join(nodeModulesPath, ".cache", "fullstack-cli", "extract-temp");
|
|
545
|
+
if (fs3.existsSync(tempDir)) {
|
|
546
|
+
fs3.rmSync(tempDir, { recursive: true });
|
|
547
|
+
}
|
|
548
|
+
fs3.mkdirSync(tempDir, { recursive: true });
|
|
549
|
+
try {
|
|
550
|
+
execSync(`tar -xzf "${tgzPath}" -C "${tempDir}"`, { stdio: "pipe" });
|
|
551
|
+
const extractedDir = path3.join(tempDir, "package");
|
|
552
|
+
if (fs3.existsSync(extractedDir)) {
|
|
553
|
+
fs3.renameSync(extractedDir, targetDir);
|
|
554
|
+
} else {
|
|
555
|
+
const files = fs3.readdirSync(tempDir);
|
|
556
|
+
if (files.length === 1) {
|
|
557
|
+
fs3.renameSync(path3.join(tempDir, files[0]), targetDir);
|
|
558
|
+
} else {
|
|
559
|
+
throw new Error("Unexpected tgz structure");
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
return targetDir;
|
|
563
|
+
} finally {
|
|
564
|
+
if (fs3.existsSync(tempDir)) {
|
|
565
|
+
fs3.rmSync(tempDir, { recursive: true });
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
function checkMissingPeerDeps(peerDeps) {
|
|
570
|
+
if (!peerDeps || Object.keys(peerDeps).length === 0) {
|
|
571
|
+
return [];
|
|
572
|
+
}
|
|
573
|
+
const missing = [];
|
|
574
|
+
const nodeModulesPath = path3.join(getProjectRoot(), "node_modules");
|
|
575
|
+
for (const [depName, _version] of Object.entries(peerDeps)) {
|
|
576
|
+
const depPath = path3.join(nodeModulesPath, depName);
|
|
577
|
+
if (!fs3.existsSync(depPath)) {
|
|
578
|
+
missing.push(depName);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
return missing;
|
|
582
|
+
}
|
|
583
|
+
function installMissingDeps(deps) {
|
|
584
|
+
if (deps.length === 0) {
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
console.log(`[action-plugin] Installing missing dependencies: ${deps.join(", ")}`);
|
|
588
|
+
const result = spawnSync2("npm", ["install", ...deps, "--no-save", "--no-package-lock"], {
|
|
589
|
+
cwd: getProjectRoot(),
|
|
590
|
+
stdio: "inherit"
|
|
591
|
+
});
|
|
592
|
+
if (result.error) {
|
|
593
|
+
throw new Error(`npm install failed: ${result.error.message}`);
|
|
594
|
+
}
|
|
595
|
+
if (result.status !== 0) {
|
|
596
|
+
throw new Error(`npm install failed with exit code ${result.status}`);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
function removePluginDirectory(pluginName) {
|
|
600
|
+
const pluginPath = getPluginPath(pluginName);
|
|
601
|
+
if (fs3.existsSync(pluginPath)) {
|
|
602
|
+
fs3.rmSync(pluginPath, { recursive: true });
|
|
603
|
+
console.log(`[action-plugin] Removed ${pluginName}`);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
528
606
|
|
|
529
607
|
// src/commands/action-plugin/api-client.ts
|
|
530
608
|
import { HttpClient as HttpClient2 } from "@lark-apaas/http-client";
|
|
@@ -665,29 +743,39 @@ async function installOne(nameWithVersion) {
|
|
|
665
743
|
const { name, version: requestedVersion } = parsePluginName(nameWithVersion);
|
|
666
744
|
try {
|
|
667
745
|
console.log(`[action-plugin] Installing ${name}@${requestedVersion}...`);
|
|
668
|
-
if (isPluginInstalled(name)) {
|
|
669
|
-
const
|
|
670
|
-
if (
|
|
746
|
+
if (isPluginInstalled(name) && requestedVersion !== "latest") {
|
|
747
|
+
const installedVer = getInstalledPluginVersion(name);
|
|
748
|
+
if (installedVer === requestedVersion) {
|
|
749
|
+
console.log(`[action-plugin] Plugin ${name}@${requestedVersion} is already installed`);
|
|
750
|
+
return { name, version: installedVer, success: true, skipped: true };
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
if (isPluginInstalled(name) && requestedVersion === "latest") {
|
|
754
|
+
const installedVer = getInstalledPluginVersion(name);
|
|
755
|
+
if (installedVer) {
|
|
671
756
|
const latestInfo = await getPluginVersion(name, "latest");
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
return { name, version: info.version, success: true, skipped: true };
|
|
757
|
+
if (installedVer === latestInfo.version) {
|
|
758
|
+
console.log(`[action-plugin] Plugin ${name} is already up to date (version: ${installedVer})`);
|
|
759
|
+
return { name, version: installedVer, success: true, skipped: true };
|
|
676
760
|
}
|
|
677
|
-
console.log(`[action-plugin] Found newer version: ${
|
|
678
|
-
console.log(`[action-plugin] Updating to ${latestVersion}...`);
|
|
761
|
+
console.log(`[action-plugin] Found newer version: ${latestInfo.version} (installed: ${installedVer})`);
|
|
679
762
|
}
|
|
680
763
|
}
|
|
681
764
|
const downloadResult = await downloadPlugin(name, requestedVersion);
|
|
682
765
|
tgzPath = downloadResult.tgzPath;
|
|
683
|
-
|
|
766
|
+
console.log(`[action-plugin] Extracting to node_modules...`);
|
|
767
|
+
const pluginDir = extractTgzToNodeModules(tgzPath, name);
|
|
768
|
+
const pluginPkg = readPluginPackageJson(pluginDir);
|
|
769
|
+
if (pluginPkg?.peerDependencies) {
|
|
770
|
+
const missingDeps = checkMissingPeerDeps(pluginPkg.peerDependencies);
|
|
771
|
+
if (missingDeps.length > 0) {
|
|
772
|
+
installMissingDeps(missingDeps);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
684
775
|
const installedVersion = getPackageVersion(name) || downloadResult.version;
|
|
685
|
-
const
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
installedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
689
|
-
};
|
|
690
|
-
writeConfig(config);
|
|
776
|
+
const plugins = readActionPlugins();
|
|
777
|
+
plugins[name] = installedVersion;
|
|
778
|
+
writeActionPlugins(plugins);
|
|
691
779
|
console.log(`[action-plugin] Successfully installed ${name}@${installedVersion}`);
|
|
692
780
|
return { name, version: installedVersion, success: true };
|
|
693
781
|
} catch (error) {
|
|
@@ -740,23 +828,19 @@ async function updateOne(nameWithVersion) {
|
|
|
740
828
|
console.error(`[action-plugin] Plugin ${name} is not installed`);
|
|
741
829
|
return { name, success: false, notInstalled: true };
|
|
742
830
|
}
|
|
743
|
-
const
|
|
744
|
-
const oldVersion = currentInfo?.version || "unknown";
|
|
831
|
+
const oldVersion = getInstalledPluginVersion(name) || "unknown";
|
|
745
832
|
console.log(`[action-plugin] Current version: ${oldVersion}`);
|
|
746
833
|
const downloadResult = await downloadPlugin(name, "latest");
|
|
747
834
|
tgzPath = downloadResult.tgzPath;
|
|
748
|
-
if (
|
|
835
|
+
if (oldVersion === downloadResult.version) {
|
|
749
836
|
console.log(`[action-plugin] Plugin ${name} is already up to date (version: ${downloadResult.version})`);
|
|
750
837
|
return { name, oldVersion, newVersion: downloadResult.version, success: true, skipped: true };
|
|
751
838
|
}
|
|
752
839
|
npmInstall(tgzPath);
|
|
753
840
|
const installedVersion = getPackageVersion(name) || downloadResult.version;
|
|
754
|
-
const
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
installedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
758
|
-
};
|
|
759
|
-
writeConfig(config);
|
|
841
|
+
const plugins = readActionPlugins();
|
|
842
|
+
plugins[name] = installedVersion;
|
|
843
|
+
writeActionPlugins(plugins);
|
|
760
844
|
console.log(`[action-plugin] Successfully updated ${name} to ${installedVersion}`);
|
|
761
845
|
return { name, oldVersion, newVersion: installedVersion, success: true };
|
|
762
846
|
} catch (error) {
|
|
@@ -812,10 +896,10 @@ async function remove(nameWithVersion) {
|
|
|
812
896
|
console.error(`[action-plugin] Plugin ${name} is not installed`);
|
|
813
897
|
process.exit(1);
|
|
814
898
|
}
|
|
815
|
-
|
|
816
|
-
const
|
|
817
|
-
delete
|
|
818
|
-
|
|
899
|
+
removePluginDirectory(name);
|
|
900
|
+
const plugins = readActionPlugins();
|
|
901
|
+
delete plugins[name];
|
|
902
|
+
writeActionPlugins(plugins);
|
|
819
903
|
console.log(`[action-plugin] Successfully removed ${name}`);
|
|
820
904
|
} catch (error) {
|
|
821
905
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -827,25 +911,22 @@ async function remove(nameWithVersion) {
|
|
|
827
911
|
// src/commands/action-plugin/list.handler.ts
|
|
828
912
|
async function list() {
|
|
829
913
|
try {
|
|
830
|
-
const
|
|
831
|
-
const plugins = Object.entries(config.plugins);
|
|
914
|
+
const plugins = Object.entries(readActionPlugins());
|
|
832
915
|
if (plugins.length === 0) {
|
|
833
916
|
console.log("[action-plugin] No plugins installed");
|
|
834
917
|
console.log('[action-plugin] Use "action-plugin install <name>" to install a plugin');
|
|
835
918
|
return;
|
|
836
919
|
}
|
|
837
920
|
console.log("[action-plugin] Installed plugins:\n");
|
|
838
|
-
const nameWidth = Math.max(
|
|
921
|
+
const nameWidth = Math.max(40, ...plugins.map(([name]) => name.length + 2));
|
|
839
922
|
const versionWidth = 15;
|
|
840
|
-
const dateWidth = 25;
|
|
841
923
|
console.log(
|
|
842
|
-
" " + "Plugin".padEnd(nameWidth) + "Version"
|
|
924
|
+
" " + "Plugin".padEnd(nameWidth) + "Version"
|
|
843
925
|
);
|
|
844
|
-
console.log(" " + "-".repeat(nameWidth + versionWidth
|
|
845
|
-
for (const [name,
|
|
846
|
-
const installedAt = new Date(info.installedAt).toLocaleString();
|
|
926
|
+
console.log(" " + "-".repeat(nameWidth + versionWidth));
|
|
927
|
+
for (const [name, version] of plugins) {
|
|
847
928
|
console.log(
|
|
848
|
-
" " + name.padEnd(nameWidth) +
|
|
929
|
+
" " + name.padEnd(nameWidth) + version
|
|
849
930
|
);
|
|
850
931
|
}
|
|
851
932
|
console.log(`
|
|
@@ -917,8 +998,8 @@ function getCapabilitiesDir() {
|
|
|
917
998
|
function getCapabilityPath(id) {
|
|
918
999
|
return path5.join(getCapabilitiesDir(), `${id}.json`);
|
|
919
1000
|
}
|
|
920
|
-
function getPluginManifestPath(
|
|
921
|
-
return path5.join(getProjectRoot2(), "node_modules",
|
|
1001
|
+
function getPluginManifestPath(pluginKey) {
|
|
1002
|
+
return path5.join(getProjectRoot2(), "node_modules", pluginKey, "manifest.json");
|
|
922
1003
|
}
|
|
923
1004
|
function capabilitiesDirExists() {
|
|
924
1005
|
return fs5.existsSync(getCapabilitiesDir());
|
|
@@ -950,17 +1031,17 @@ function readAllCapabilities() {
|
|
|
950
1031
|
const ids = listCapabilityIds();
|
|
951
1032
|
return ids.map((id) => readCapability(id));
|
|
952
1033
|
}
|
|
953
|
-
function readPluginManifest(
|
|
954
|
-
const manifestPath = getPluginManifestPath(
|
|
1034
|
+
function readPluginManifest(pluginKey) {
|
|
1035
|
+
const manifestPath = getPluginManifestPath(pluginKey);
|
|
955
1036
|
if (!fs5.existsSync(manifestPath)) {
|
|
956
|
-
throw new Error(`Plugin not installed: ${
|
|
1037
|
+
throw new Error(`Plugin not installed: ${pluginKey} (manifest.json not found)`);
|
|
957
1038
|
}
|
|
958
1039
|
try {
|
|
959
1040
|
const content = fs5.readFileSync(manifestPath, "utf-8");
|
|
960
1041
|
return JSON.parse(content);
|
|
961
1042
|
} catch (error) {
|
|
962
1043
|
if (error instanceof SyntaxError) {
|
|
963
|
-
throw new Error(`Invalid JSON in plugin manifest: ${
|
|
1044
|
+
throw new Error(`Invalid JSON in plugin manifest: ${pluginKey}/manifest.json`);
|
|
964
1045
|
}
|
|
965
1046
|
throw error;
|
|
966
1047
|
}
|
|
@@ -971,19 +1052,19 @@ function isDynamicSchema(schema) {
|
|
|
971
1052
|
function hasValidParamsSchema(paramsSchema) {
|
|
972
1053
|
return paramsSchema !== void 0 && Object.keys(paramsSchema).length > 0;
|
|
973
1054
|
}
|
|
974
|
-
async function loadPlugin(
|
|
1055
|
+
async function loadPlugin(pluginKey) {
|
|
975
1056
|
try {
|
|
976
|
-
const pluginPackage = (await import(
|
|
1057
|
+
const pluginPackage = (await import(pluginKey)).default;
|
|
977
1058
|
if (!pluginPackage || typeof pluginPackage.create !== "function") {
|
|
978
|
-
throw new Error(`Plugin ${
|
|
1059
|
+
throw new Error(`Plugin ${pluginKey} does not export a valid create function`);
|
|
979
1060
|
}
|
|
980
1061
|
return pluginPackage;
|
|
981
1062
|
} catch (error) {
|
|
982
1063
|
if (error.code === "MODULE_NOT_FOUND") {
|
|
983
|
-
throw new Error(`Plugin not installed: ${
|
|
1064
|
+
throw new Error(`Plugin not installed: ${pluginKey}`);
|
|
984
1065
|
}
|
|
985
1066
|
throw new Error(
|
|
986
|
-
`Failed to load plugin ${
|
|
1067
|
+
`Failed to load plugin ${pluginKey}: ${error instanceof Error ? error.message : String(error)}`
|
|
987
1068
|
);
|
|
988
1069
|
}
|
|
989
1070
|
}
|
|
@@ -997,16 +1078,16 @@ async function zodToJsonSchema(zodSchema) {
|
|
|
997
1078
|
}
|
|
998
1079
|
async function hydrateCapability(capability) {
|
|
999
1080
|
try {
|
|
1000
|
-
const manifest = readPluginManifest(capability.
|
|
1081
|
+
const manifest = readPluginManifest(capability.pluginKey);
|
|
1001
1082
|
if (!manifest.actions || manifest.actions.length === 0) {
|
|
1002
|
-
throw new Error(`Plugin ${capability.
|
|
1083
|
+
throw new Error(`Plugin ${capability.pluginKey} has no actions defined`);
|
|
1003
1084
|
}
|
|
1004
1085
|
const hasDynamicSchema = manifest.actions.some(
|
|
1005
1086
|
(action) => isDynamicSchema(action.inputSchema) || isDynamicSchema(action.outputSchema)
|
|
1006
1087
|
);
|
|
1007
1088
|
let pluginInstance = null;
|
|
1008
1089
|
if (hasDynamicSchema) {
|
|
1009
|
-
const plugin = await loadPlugin(capability.
|
|
1090
|
+
const plugin = await loadPlugin(capability.pluginKey);
|
|
1010
1091
|
pluginInstance = plugin.create(capability.formValue || {});
|
|
1011
1092
|
}
|
|
1012
1093
|
const actions = [];
|
|
@@ -1049,7 +1130,7 @@ async function hydrateCapability(capability) {
|
|
|
1049
1130
|
}
|
|
1050
1131
|
return {
|
|
1051
1132
|
id: capability.id,
|
|
1052
|
-
|
|
1133
|
+
pluginKey: capability.pluginKey,
|
|
1053
1134
|
pluginVersion: capability.pluginVersion,
|
|
1054
1135
|
name: capability.name,
|
|
1055
1136
|
description: capability.description,
|
|
@@ -1141,14 +1222,14 @@ function mergeMapping(customMapping) {
|
|
|
1141
1222
|
}
|
|
1142
1223
|
return { ...DEFAULT_MAPPING, ...customMapping };
|
|
1143
1224
|
}
|
|
1144
|
-
function
|
|
1145
|
-
const
|
|
1146
|
-
if (!
|
|
1225
|
+
function getPluginKey(sourceActionID, mapping) {
|
|
1226
|
+
const pluginKey = mapping[sourceActionID];
|
|
1227
|
+
if (!pluginKey) {
|
|
1147
1228
|
throw new Error(
|
|
1148
1229
|
`Unknown sourceActionID: "${sourceActionID}". Please provide mapping via --mapping option or add to default mapping.`
|
|
1149
1230
|
);
|
|
1150
1231
|
}
|
|
1151
|
-
return
|
|
1232
|
+
return pluginKey;
|
|
1152
1233
|
}
|
|
1153
1234
|
|
|
1154
1235
|
// src/commands/capability/migration/json-migrator/index.ts
|
|
@@ -1213,10 +1294,10 @@ function detectJsonMigration() {
|
|
|
1213
1294
|
|
|
1214
1295
|
// src/commands/capability/migration/json-migrator/transformer.ts
|
|
1215
1296
|
function transformCapability(old, mapping) {
|
|
1216
|
-
const
|
|
1297
|
+
const pluginKey = getPluginKey(old.sourceActionID, mapping);
|
|
1217
1298
|
return {
|
|
1218
1299
|
id: old.id,
|
|
1219
|
-
|
|
1300
|
+
pluginKey,
|
|
1220
1301
|
pluginVersion: "latest",
|
|
1221
1302
|
name: old.name,
|
|
1222
1303
|
description: old.desc,
|
|
@@ -1267,7 +1348,7 @@ async function migrateJsonFiles(options) {
|
|
|
1267
1348
|
if (options.dryRun) {
|
|
1268
1349
|
console.log(` Would create ${newCapabilities.length} capability files:`);
|
|
1269
1350
|
for (const cap of newCapabilities) {
|
|
1270
|
-
console.log(` - ${cap.id}.json (
|
|
1351
|
+
console.log(` - ${cap.id}.json (pluginKey: ${cap.pluginKey})`);
|
|
1271
1352
|
}
|
|
1272
1353
|
return {
|
|
1273
1354
|
success: true,
|
|
@@ -1296,22 +1377,22 @@ async function migrateJsonFiles(options) {
|
|
|
1296
1377
|
|
|
1297
1378
|
// src/commands/capability/migration/plugin-installer/detector.ts
|
|
1298
1379
|
import fs8 from "fs";
|
|
1299
|
-
function isPluginInstalled2(
|
|
1300
|
-
const manifestPath = getPluginManifestPath(
|
|
1380
|
+
function isPluginInstalled2(pluginKey) {
|
|
1381
|
+
const manifestPath = getPluginManifestPath(pluginKey);
|
|
1301
1382
|
return fs8.existsSync(manifestPath);
|
|
1302
1383
|
}
|
|
1303
1384
|
function detectPluginsToInstall(capabilities) {
|
|
1304
|
-
const
|
|
1385
|
+
const pluginKeys = /* @__PURE__ */ new Set();
|
|
1305
1386
|
for (const cap of capabilities) {
|
|
1306
|
-
|
|
1387
|
+
pluginKeys.add(cap.pluginKey);
|
|
1307
1388
|
}
|
|
1308
1389
|
const toInstall = [];
|
|
1309
1390
|
const alreadyInstalled = [];
|
|
1310
|
-
for (const
|
|
1311
|
-
if (isPluginInstalled2(
|
|
1312
|
-
alreadyInstalled.push(
|
|
1391
|
+
for (const pluginKey of pluginKeys) {
|
|
1392
|
+
if (isPluginInstalled2(pluginKey)) {
|
|
1393
|
+
alreadyInstalled.push(pluginKey);
|
|
1313
1394
|
} else {
|
|
1314
|
-
toInstall.push(
|
|
1395
|
+
toInstall.push(pluginKey);
|
|
1315
1396
|
}
|
|
1316
1397
|
}
|
|
1317
1398
|
return { toInstall, alreadyInstalled };
|
|
@@ -1330,15 +1411,15 @@ async function installPlugins(capabilities, options) {
|
|
|
1330
1411
|
}
|
|
1331
1412
|
if (options.dryRun) {
|
|
1332
1413
|
console.log(` Would install ${detection.toInstall.length} plugins:`);
|
|
1333
|
-
for (const
|
|
1334
|
-
console.log(` - ${
|
|
1414
|
+
for (const pluginKey of detection.toInstall) {
|
|
1415
|
+
console.log(` - ${pluginKey}`);
|
|
1335
1416
|
}
|
|
1336
1417
|
result.installed = detection.toInstall;
|
|
1337
1418
|
return result;
|
|
1338
1419
|
}
|
|
1339
1420
|
console.log(` \u2B07 Installing ${detection.toInstall.length} plugins...`);
|
|
1340
|
-
for (const
|
|
1341
|
-
console.log(` - ${
|
|
1421
|
+
for (const pluginKey of detection.toInstall) {
|
|
1422
|
+
console.log(` - ${pluginKey}`);
|
|
1342
1423
|
}
|
|
1343
1424
|
try {
|
|
1344
1425
|
const originalExit = process.exit;
|
|
@@ -1353,9 +1434,9 @@ async function installPlugins(capabilities, options) {
|
|
|
1353
1434
|
await install(detection.toInstall);
|
|
1354
1435
|
result.installed = detection.toInstall;
|
|
1355
1436
|
} catch (error) {
|
|
1356
|
-
for (const
|
|
1437
|
+
for (const pluginKey of detection.toInstall) {
|
|
1357
1438
|
result.failed.push({
|
|
1358
|
-
|
|
1439
|
+
pluginKey,
|
|
1359
1440
|
error: error instanceof Error ? error.message : String(error)
|
|
1360
1441
|
});
|
|
1361
1442
|
}
|
|
@@ -1363,9 +1444,9 @@ async function installPlugins(capabilities, options) {
|
|
|
1363
1444
|
process.exit = originalExit;
|
|
1364
1445
|
}
|
|
1365
1446
|
} catch (error) {
|
|
1366
|
-
for (const
|
|
1447
|
+
for (const pluginKey of detection.toInstall) {
|
|
1367
1448
|
result.failed.push({
|
|
1368
|
-
|
|
1449
|
+
pluginKey,
|
|
1369
1450
|
error: error instanceof Error ? error.message : String(error)
|
|
1370
1451
|
});
|
|
1371
1452
|
}
|
|
@@ -1911,10 +1992,10 @@ async function generateReport(result) {
|
|
|
1911
1992
|
} else {
|
|
1912
1993
|
lines.push("### 1.1 \u5DF2\u8FC1\u79FB\u7684 Capabilities");
|
|
1913
1994
|
lines.push("");
|
|
1914
|
-
lines.push("| ID |
|
|
1915
|
-
lines.push("
|
|
1995
|
+
lines.push("| ID | pluginKey |");
|
|
1996
|
+
lines.push("|----|-----------|");
|
|
1916
1997
|
for (const cap of jsonMigration.capabilities) {
|
|
1917
|
-
lines.push(`| ${cap.id} | ${cap.
|
|
1998
|
+
lines.push(`| ${cap.id} | ${cap.pluginKey} |`);
|
|
1918
1999
|
}
|
|
1919
2000
|
lines.push("");
|
|
1920
2001
|
if (jsonMigration.backupPath) {
|
|
@@ -1929,16 +2010,16 @@ async function generateReport(result) {
|
|
|
1929
2010
|
if (pluginInstallation.installed.length === 0 && pluginInstallation.alreadyInstalled.length === 0) {
|
|
1930
2011
|
lines.push("\u65E0\u63D2\u4EF6\u9700\u8981\u5B89\u88C5\u3002");
|
|
1931
2012
|
} else {
|
|
1932
|
-
lines.push("|
|
|
1933
|
-
lines.push("
|
|
1934
|
-
for (const
|
|
1935
|
-
lines.push(`| ${
|
|
2013
|
+
lines.push("| pluginKey | \u72B6\u6001 |");
|
|
2014
|
+
lines.push("|-----------|------|");
|
|
2015
|
+
for (const pluginKey of pluginInstallation.alreadyInstalled) {
|
|
2016
|
+
lines.push(`| ${pluginKey} | \u5DF2\u5B89\u88C5 |`);
|
|
1936
2017
|
}
|
|
1937
|
-
for (const
|
|
1938
|
-
lines.push(`| ${
|
|
2018
|
+
for (const pluginKey of pluginInstallation.installed) {
|
|
2019
|
+
lines.push(`| ${pluginKey} | \u65B0\u5B89\u88C5 |`);
|
|
1939
2020
|
}
|
|
1940
2021
|
for (const failed of pluginInstallation.failed) {
|
|
1941
|
-
lines.push(`| ${failed.
|
|
2022
|
+
lines.push(`| ${failed.pluginKey} | \u274C \u5931\u8D25: ${failed.error} |`);
|
|
1942
2023
|
}
|
|
1943
2024
|
}
|
|
1944
2025
|
lines.push("");
|
|
@@ -2033,7 +2114,7 @@ async function runMigration(options = {}) {
|
|
|
2033
2114
|
console.log(` \u2713 Installed: ${pluginResult.installed.join(", ")}`);
|
|
2034
2115
|
}
|
|
2035
2116
|
if (pluginResult.failed.length > 0) {
|
|
2036
|
-
console.log(` \u2717 Failed: ${pluginResult.failed.map((f) => f.
|
|
2117
|
+
console.log(` \u2717 Failed: ${pluginResult.failed.map((f) => f.pluginKey).join(", ")}`);
|
|
2037
2118
|
}
|
|
2038
2119
|
console.log("");
|
|
2039
2120
|
} else {
|
|
@@ -2126,7 +2207,7 @@ var migrationCommand = {
|
|
|
2126
2207
|
name: "migration",
|
|
2127
2208
|
description: "Execute capability migration",
|
|
2128
2209
|
register(program) {
|
|
2129
|
-
program.command(this.name).description(this.description).option("--dry-run", "Preview mode, do not modify files").option("--skip-install", "Skip plugin installation step").option("--skip-code", "Skip code migration step").option("--mapping <file>", "Custom sourceActionID to
|
|
2210
|
+
program.command(this.name).description(this.description).option("--dry-run", "Preview mode, do not modify files").option("--skip-install", "Skip plugin installation step").option("--skip-code", "Skip code migration step").option("--mapping <file>", "Custom sourceActionID to pluginKey mapping file").action(async (options) => {
|
|
2130
2211
|
await migration(options);
|
|
2131
2212
|
});
|
|
2132
2213
|
}
|