@lark-apaas/fullstack-cli 1.1.6-alpha.2 → 1.1.6-alpha.4

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.
Files changed (2) hide show
  1. package/dist/index.js +125 -55
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -439,7 +439,6 @@ var syncCommand = {
439
439
  import fs3 from "fs";
440
440
  import path3 from "path";
441
441
  import { spawnSync as spawnSync2, execSync } from "child_process";
442
- var CONFIG_FILE_NAME = ".capabilityrc.json";
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 getConfigPath() {
459
- return path3.join(getProjectRoot(), CONFIG_FILE_NAME);
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 readConfig() {
465
- const configPath = getConfigPath();
466
- if (!fs3.existsSync(configPath)) {
467
- return { plugins: {} };
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(configPath, "utf-8");
469
+ const content = fs3.readFileSync(pkgPath, "utf-8");
471
470
  return JSON.parse(content);
472
471
  } catch {
473
- console.warn(`[action-plugin] Warning: Failed to parse ${CONFIG_FILE_NAME}, using empty config`);
474
- return { plugins: {} };
472
+ throw new Error("Failed to parse package.json");
475
473
  }
476
474
  }
477
- function writeConfig(config) {
478
- const configPath = getConfigPath();
479
- fs3.writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n", "utf-8");
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 config = readConfig();
483
- return pluginName in config.plugins;
489
+ const plugins = readActionPlugins();
490
+ return pluginName in plugins;
484
491
  }
485
- function getInstalledPluginInfo(pluginName) {
486
- const config = readConfig();
487
- return config.plugins[pluginName] || null;
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}...`);
@@ -730,6 +737,70 @@ function cleanupTempFile(tgzPath) {
730
737
  }
731
738
  }
732
739
 
740
+ // src/commands/action-plugin/init.handler.ts
741
+ async function installOneForInit(name, version) {
742
+ let tgzPath;
743
+ try {
744
+ const installedVersion = getPackageVersion(name);
745
+ if (installedVersion === version) {
746
+ return { name, version, success: true, skipped: true };
747
+ }
748
+ console.log(`[action-plugin] Installing ${name}@${version}...`);
749
+ const downloadResult = await downloadPlugin(name, version);
750
+ tgzPath = downloadResult.tgzPath;
751
+ const pluginDir = extractTgzToNodeModules(tgzPath, name);
752
+ const pluginPkg = readPluginPackageJson(pluginDir);
753
+ if (pluginPkg?.peerDependencies) {
754
+ const missingDeps = checkMissingPeerDeps(pluginPkg.peerDependencies);
755
+ if (missingDeps.length > 0) {
756
+ installMissingDeps(missingDeps);
757
+ }
758
+ }
759
+ console.log(`[action-plugin] \u2713 Installed ${name}@${version}`);
760
+ return { name, version, success: true };
761
+ } catch (error) {
762
+ const message = error instanceof Error ? error.message : String(error);
763
+ console.error(`[action-plugin] \u2717 Failed to install ${name}: ${message}`);
764
+ return { name, version, success: false, error: message };
765
+ } finally {
766
+ if (tgzPath) {
767
+ cleanupTempFile(tgzPath);
768
+ }
769
+ }
770
+ }
771
+ async function init() {
772
+ console.log("[action-plugin] Reading plugins from package.json...");
773
+ const plugins = readActionPlugins();
774
+ const entries = Object.entries(plugins);
775
+ if (entries.length === 0) {
776
+ console.log("[action-plugin] No plugins found in package.json");
777
+ return;
778
+ }
779
+ console.log(`[action-plugin] Found ${entries.length} plugin(s) to install
780
+ `);
781
+ const results = [];
782
+ for (const [name, version] of entries) {
783
+ const result = await installOneForInit(name, version);
784
+ results.push(result);
785
+ }
786
+ console.log("");
787
+ const successful = results.filter((r) => r.success && !r.skipped);
788
+ const skipped = results.filter((r) => r.skipped);
789
+ const failed = results.filter((r) => !r.success);
790
+ if (successful.length > 0 || skipped.length > 0) {
791
+ console.log(
792
+ `[action-plugin] \u2713 All plugins installed successfully (${successful.length + skipped.length}/${entries.length})`
793
+ );
794
+ if (skipped.length > 0) {
795
+ console.log(` Skipped (already installed): ${skipped.map((r) => r.name).join(", ")}`);
796
+ }
797
+ }
798
+ if (failed.length > 0) {
799
+ console.log(`[action-plugin] \u2717 Failed to install ${failed.length} plugin(s): ${failed.map((r) => r.name).join(", ")}`);
800
+ process.exit(1);
801
+ }
802
+ }
803
+
733
804
  // src/commands/action-plugin/install.handler.ts
734
805
  async function installOne(nameWithVersion) {
735
806
  let tgzPath;
@@ -737,21 +808,21 @@ async function installOne(nameWithVersion) {
737
808
  try {
738
809
  console.log(`[action-plugin] Installing ${name}@${requestedVersion}...`);
739
810
  if (isPluginInstalled(name) && requestedVersion !== "latest") {
740
- const info = getInstalledPluginInfo(name);
741
- if (info && info.version === requestedVersion) {
811
+ const installedVer = getInstalledPluginVersion(name);
812
+ if (installedVer === requestedVersion) {
742
813
  console.log(`[action-plugin] Plugin ${name}@${requestedVersion} is already installed`);
743
- return { name, version: info.version, success: true, skipped: true };
814
+ return { name, version: installedVer, success: true, skipped: true };
744
815
  }
745
816
  }
746
817
  if (isPluginInstalled(name) && requestedVersion === "latest") {
747
- const info = getInstalledPluginInfo(name);
748
- if (info) {
818
+ const installedVer = getInstalledPluginVersion(name);
819
+ if (installedVer) {
749
820
  const latestInfo = await getPluginVersion(name, "latest");
750
- if (info.version === latestInfo.version) {
751
- console.log(`[action-plugin] Plugin ${name} is already up to date (version: ${info.version})`);
752
- return { name, version: info.version, success: true, skipped: true };
821
+ if (installedVer === latestInfo.version) {
822
+ console.log(`[action-plugin] Plugin ${name} is already up to date (version: ${installedVer})`);
823
+ return { name, version: installedVer, success: true, skipped: true };
753
824
  }
754
- console.log(`[action-plugin] Found newer version: ${latestInfo.version} (installed: ${info.version})`);
825
+ console.log(`[action-plugin] Found newer version: ${latestInfo.version} (installed: ${installedVer})`);
755
826
  }
756
827
  }
757
828
  const downloadResult = await downloadPlugin(name, requestedVersion);
@@ -766,12 +837,9 @@ async function installOne(nameWithVersion) {
766
837
  }
767
838
  }
768
839
  const installedVersion = getPackageVersion(name) || downloadResult.version;
769
- const config = readConfig();
770
- config.plugins[name] = {
771
- version: installedVersion,
772
- installedAt: (/* @__PURE__ */ new Date()).toISOString()
773
- };
774
- writeConfig(config);
840
+ const plugins = readActionPlugins();
841
+ plugins[name] = installedVersion;
842
+ writeActionPlugins(plugins);
775
843
  console.log(`[action-plugin] Successfully installed ${name}@${installedVersion}`);
776
844
  return { name, version: installedVersion, success: true };
777
845
  } catch (error) {
@@ -824,23 +892,19 @@ async function updateOne(nameWithVersion) {
824
892
  console.error(`[action-plugin] Plugin ${name} is not installed`);
825
893
  return { name, success: false, notInstalled: true };
826
894
  }
827
- const currentInfo = getInstalledPluginInfo(name);
828
- const oldVersion = currentInfo?.version || "unknown";
895
+ const oldVersion = getInstalledPluginVersion(name) || "unknown";
829
896
  console.log(`[action-plugin] Current version: ${oldVersion}`);
830
897
  const downloadResult = await downloadPlugin(name, "latest");
831
898
  tgzPath = downloadResult.tgzPath;
832
- if (currentInfo && currentInfo.version === downloadResult.version) {
899
+ if (oldVersion === downloadResult.version) {
833
900
  console.log(`[action-plugin] Plugin ${name} is already up to date (version: ${downloadResult.version})`);
834
901
  return { name, oldVersion, newVersion: downloadResult.version, success: true, skipped: true };
835
902
  }
836
903
  npmInstall(tgzPath);
837
904
  const installedVersion = getPackageVersion(name) || downloadResult.version;
838
- const config = readConfig();
839
- config.plugins[name] = {
840
- version: installedVersion,
841
- installedAt: (/* @__PURE__ */ new Date()).toISOString()
842
- };
843
- writeConfig(config);
905
+ const plugins = readActionPlugins();
906
+ plugins[name] = installedVersion;
907
+ writeActionPlugins(plugins);
844
908
  console.log(`[action-plugin] Successfully updated ${name} to ${installedVersion}`);
845
909
  return { name, oldVersion, newVersion: installedVersion, success: true };
846
910
  } catch (error) {
@@ -897,9 +961,9 @@ async function remove(nameWithVersion) {
897
961
  process.exit(1);
898
962
  }
899
963
  removePluginDirectory(name);
900
- const config = readConfig();
901
- delete config.plugins[name];
902
- writeConfig(config);
964
+ const plugins = readActionPlugins();
965
+ delete plugins[name];
966
+ writeActionPlugins(plugins);
903
967
  console.log(`[action-plugin] Successfully removed ${name}`);
904
968
  } catch (error) {
905
969
  const message = error instanceof Error ? error.message : String(error);
@@ -911,25 +975,22 @@ async function remove(nameWithVersion) {
911
975
  // src/commands/action-plugin/list.handler.ts
912
976
  async function list() {
913
977
  try {
914
- const config = readConfig();
915
- const plugins = Object.entries(config.plugins);
978
+ const plugins = Object.entries(readActionPlugins());
916
979
  if (plugins.length === 0) {
917
980
  console.log("[action-plugin] No plugins installed");
918
981
  console.log('[action-plugin] Use "action-plugin install <name>" to install a plugin');
919
982
  return;
920
983
  }
921
984
  console.log("[action-plugin] Installed plugins:\n");
922
- const nameWidth = Math.max(30, ...plugins.map(([name]) => name.length + 2));
985
+ const nameWidth = Math.max(40, ...plugins.map(([name]) => name.length + 2));
923
986
  const versionWidth = 15;
924
- const dateWidth = 25;
925
987
  console.log(
926
- " " + "Plugin".padEnd(nameWidth) + "Version".padEnd(versionWidth) + "Installed At"
988
+ " " + "Plugin".padEnd(nameWidth) + "Version"
927
989
  );
928
- console.log(" " + "-".repeat(nameWidth + versionWidth + dateWidth));
929
- for (const [name, info] of plugins) {
930
- const installedAt = new Date(info.installedAt).toLocaleString();
990
+ console.log(" " + "-".repeat(nameWidth + versionWidth));
991
+ for (const [name, version] of plugins) {
931
992
  console.log(
932
- " " + name.padEnd(nameWidth) + info.version.padEnd(versionWidth) + installedAt
993
+ " " + name.padEnd(nameWidth) + version
933
994
  );
934
995
  }
935
996
  console.log(`
@@ -942,6 +1003,15 @@ async function list() {
942
1003
  }
943
1004
 
944
1005
  // src/commands/action-plugin/index.ts
1006
+ var initCommand = {
1007
+ name: "init",
1008
+ description: "Install all plugins from package.json",
1009
+ register(program) {
1010
+ program.command(this.name).description(this.description).action(async () => {
1011
+ await init();
1012
+ });
1013
+ }
1014
+ };
945
1015
  var installCommand = {
946
1016
  name: "install",
947
1017
  description: "Install action plugin(s) (default: latest version)",
@@ -985,7 +1055,7 @@ var listCommand = {
985
1055
  var actionPluginCommandGroup = {
986
1056
  name: "action-plugin",
987
1057
  description: "Manage action plugins",
988
- commands: [installCommand, updateCommand, removeCommand, listCommand]
1058
+ commands: [initCommand, installCommand, updateCommand, removeCommand, listCommand]
989
1059
  };
990
1060
 
991
1061
  // src/commands/capability/utils.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-cli",
3
- "version": "1.1.6-alpha.2",
3
+ "version": "1.1.6-alpha.4",
4
4
  "description": "CLI tool for fullstack template management",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",