@atlashub/smartstack-cli 2.6.0 → 2.6.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 CHANGED
@@ -116644,16 +116644,7 @@ EndGlobal
116644
116644
  ]
116645
116645
  }
116646
116646
  ];
116647
- let smartstackVersion = null;
116648
- if (config.preview) {
116649
- logger.info("Fetching latest SmartStack preview version from NuGet...");
116650
- smartstackVersion = await getLatestNuGetVersion("SmartStack", true);
116651
- if (smartstackVersion) {
116652
- logger.info(`Latest preview version: ${source_default.cyan(smartstackVersion)}`);
116653
- } else {
116654
- logger.warning("Could not fetch latest version, using --prerelease fallback");
116655
- }
116656
- }
116647
+ const smartstackVersion = config.smartStackVersion || null;
116657
116648
  const prereleaseFlag = config.preview ? " --prerelease" : "";
116658
116649
  for (const { project, packages } of nugetPackages) {
116659
116650
  for (const pkg2 of packages) {
@@ -116784,7 +116775,7 @@ appsettings.*.Local.json
116784
116775
  projectType: "client",
116785
116776
  dbContext: "extensions",
116786
116777
  baseNamespace: projectName,
116787
- smartStackVersion: "1.0.0",
116778
+ smartStackVersion: config.smartStackVersion || "1.0.0",
116788
116779
  initialized: (/* @__PURE__ */ new Date()).toISOString()
116789
116780
  };
116790
116781
  const relPath3 = ".smartstack/config.json";
@@ -117738,6 +117729,14 @@ var initCommand = new Command("init").description("Initialize a new SmartStack p
117738
117729
  await import_fs_extra5.default.ensureDir((0, import_path6.join)(finalProjectDir, ".smartstack"));
117739
117730
  await saveInitState(finalProjectDir, state);
117740
117731
  }
117732
+ if (!config.smartStackVersion) {
117733
+ logger.info("Resolving SmartStack package version...");
117734
+ const resolvedVersion = await getLatestNuGetVersion("SmartStack", config.preview);
117735
+ if (resolvedVersion) {
117736
+ config.smartStackVersion = resolvedVersion;
117737
+ logger.info(`SmartStack version: ${source_default.cyan(resolvedVersion)}`);
117738
+ }
117739
+ }
117741
117740
  await executeStep(state, "config", finalProjectDir, dryRun, () => createConfigFiles(config, state, dryRun));
117742
117741
  await executeStep(state, "backend", finalProjectDir, dryRun, () => createBackendStructure(config, state, dryRun));
117743
117742
  await executeStep(state, "frontend", finalProjectDir, dryRun, () => createFrontendStructure(config, state, dryRun));
@@ -124543,11 +124542,19 @@ async function getLatestNuGetVersion2(packageName, prerelease) {
124543
124542
  if (!versions || versions.length === 0) {
124544
124543
  return null;
124545
124544
  }
124546
- const filteredVersions = prerelease ? versions.filter((v) => v.includes("-")) : versions.filter((v) => !v.includes("-"));
124547
- if (filteredVersions.length === 0) {
124548
- return null;
124545
+ if (prerelease) {
124546
+ const prereleaseVersions = versions.filter((v) => v.includes("-"));
124547
+ if (prereleaseVersions.length > 0) {
124548
+ return prereleaseVersions[prereleaseVersions.length - 1];
124549
+ }
124550
+ return versions[versions.length - 1];
124549
124551
  }
124550
- return filteredVersions[filteredVersions.length - 1];
124552
+ const stableVersions = versions.filter((v) => !v.includes("-"));
124553
+ if (stableVersions.length > 0) {
124554
+ return stableVersions[stableVersions.length - 1];
124555
+ }
124556
+ logger.warning(`No stable version found for ${packageName}, using latest prerelease`);
124557
+ return versions[versions.length - 1];
124551
124558
  } catch (error) {
124552
124559
  logger.warning(`Error fetching latest version for ${packageName}: ${error instanceof Error ? error.message : error}`);
124553
124560
  return null;
@@ -124561,15 +124568,31 @@ async function getLatestNpmVersion(packageName, prerelease) {
124561
124568
  return null;
124562
124569
  }
124563
124570
  const data = await response.json();
124571
+ const distTags = data["dist-tags"];
124572
+ if (distTags) {
124573
+ const tag = prerelease ? "next" : "latest";
124574
+ if (distTags[tag]) {
124575
+ return distTags[tag];
124576
+ }
124577
+ if (prerelease && distTags["latest"]) {
124578
+ return distTags["latest"];
124579
+ }
124580
+ }
124564
124581
  const versions = Object.keys(data.versions);
124565
124582
  if (!versions || versions.length === 0) {
124566
124583
  return null;
124567
124584
  }
124568
- const filteredVersions = prerelease ? versions.filter((v) => v.includes("-")) : versions.filter((v) => !v.includes("-"));
124569
- if (filteredVersions.length === 0) {
124570
- return null;
124585
+ if (prerelease) {
124586
+ const prereleaseVersions = versions.filter((v) => v.includes("-"));
124587
+ if (prereleaseVersions.length > 0) {
124588
+ return prereleaseVersions[prereleaseVersions.length - 1];
124589
+ }
124571
124590
  }
124572
- return filteredVersions[filteredVersions.length - 1];
124591
+ const stableVersions = versions.filter((v) => !v.includes("-"));
124592
+ if (stableVersions.length > 0) {
124593
+ return stableVersions[stableVersions.length - 1];
124594
+ }
124595
+ return versions[versions.length - 1];
124573
124596
  } catch (error) {
124574
124597
  logger.warning(`Error fetching latest npm version for ${packageName}: ${error instanceof Error ? error.message : error}`);
124575
124598
  return null;
@@ -124589,6 +124612,23 @@ async function detectSmartStackProject() {
124589
124612
  return { isProject: false, projectDir: cwd };
124590
124613
  }
124591
124614
  }
124615
+ function readPackageVersion(csprojContent, packageName) {
124616
+ const regex2 = new RegExp(
124617
+ `<PackageReference\\s+Include="${packageName}"\\s+Version="([^"]+)"`,
124618
+ "i"
124619
+ );
124620
+ const match2 = csprojContent.match(regex2);
124621
+ return match2 ? match2[1] : null;
124622
+ }
124623
+ function readAllPackageReferences(csprojContent) {
124624
+ const regex2 = /<PackageReference\s+Include="([^"]+)"\s+Version="([^"]+)"/gi;
124625
+ const packages = [];
124626
+ let match2;
124627
+ while ((match2 = regex2.exec(csprojContent)) !== null) {
124628
+ packages.push({ name: match2[1], currentVersion: match2[2] });
124629
+ }
124630
+ return packages;
124631
+ }
124592
124632
  async function findProjectsWithSmartStack(projectDir) {
124593
124633
  const srcDir = (0, import_path7.join)(projectDir, "src");
124594
124634
  if (!await import_fs_extra6.default.pathExists(srcDir)) {
@@ -124604,14 +124644,32 @@ async function findProjectsWithSmartStack(projectDir) {
124604
124644
  for (const csproj of csprojFiles) {
124605
124645
  const csprojPath = (0, import_path7.join)(folderPath, csproj);
124606
124646
  const content = await import_fs_extra6.default.readFile(csprojPath, "utf-8");
124607
- if (content.includes("SmartStack")) {
124608
- projects.push(csprojPath);
124647
+ const currentVersion = readPackageVersion(content, "SmartStack");
124648
+ if (currentVersion !== null) {
124649
+ projects.push({
124650
+ csprojPath,
124651
+ relPath: csprojPath.replace(projectDir, "").replace(/^[/\\]/, ""),
124652
+ currentVersion
124653
+ });
124609
124654
  }
124610
124655
  }
124611
124656
  }
124612
124657
  }
124613
124658
  return projects;
124614
124659
  }
124660
+ async function readFrontendVersion(frontendDir) {
124661
+ try {
124662
+ const packageJsonPath = (0, import_path7.join)(frontendDir, "package.json");
124663
+ const packageJson = await import_fs_extra6.default.readJson(packageJsonPath);
124664
+ const version2 = packageJson.dependencies?.["@atlashub/smartstack"];
124665
+ if (!version2 || version2 === "latest" || version2 === "next") {
124666
+ return null;
124667
+ }
124668
+ return version2.replace(/^[\^~]/, "");
124669
+ } catch {
124670
+ return null;
124671
+ }
124672
+ }
124615
124673
  async function findFrontendDirectory(projectDir) {
124616
124674
  const webDir = (0, import_path7.join)(projectDir, "web");
124617
124675
  if (!await import_fs_extra6.default.pathExists(webDir)) {
@@ -124734,6 +124792,16 @@ async function executeMigrations(projectDir, fromVersion, toVersion, dryRun) {
124734
124792
  var upgradeCommand = new Command("upgrade").description("Upgrade SmartStack packages to the latest version").option("--preview", "Upgrade to latest preview/prerelease version").option("--dry-run", "Show what would be upgraded without actually upgrading").action(async (options) => {
124735
124793
  logger.header("SmartStack Package Upgrade");
124736
124794
  const dryRun = options.dryRun || false;
124795
+ const result = {
124796
+ nugetUpgraded: 0,
124797
+ nugetSkipped: 0,
124798
+ nugetFailed: 0,
124799
+ otherPkgUpdated: 0,
124800
+ otherPkgSkipped: 0,
124801
+ otherPkgFailed: 0,
124802
+ npmUpgraded: false,
124803
+ npmSkipped: false
124804
+ };
124737
124805
  if (dryRun) {
124738
124806
  logger.warning("DRY RUN MODE - No packages will be upgraded");
124739
124807
  console.log();
@@ -124747,8 +124815,8 @@ var upgradeCommand = new Command("upgrade").description("Upgrade SmartStack pack
124747
124815
  const { config, projectDir } = detection;
124748
124816
  logger.info(`Project: ${source_default.cyan(config.baseNamespace)}`);
124749
124817
  logger.info(`Type: ${source_default.cyan(config.projectType)}`);
124750
- const currentVersion = config.smartStackVersion || "2.0.0-preview.380";
124751
- logger.info(`Current version: ${source_default.yellow(currentVersion)}`);
124818
+ const configVersion = config.smartStackVersion || "unknown";
124819
+ logger.info(`Config version: ${source_default.yellow(configVersion)}`);
124752
124820
  console.log();
124753
124821
  const usePreview = options.preview || false;
124754
124822
  logger.info(`Target: ${usePreview ? source_default.yellow("Preview/Prerelease") : source_default.green("Stable")}`);
@@ -124768,21 +124836,82 @@ var upgradeCommand = new Command("upgrade").description("Upgrade SmartStack pack
124768
124836
  logger.info("Scanning for SmartStack projects...");
124769
124837
  const projects = await findProjectsWithSmartStack(projectDir);
124770
124838
  if (projects.length === 0) {
124771
- logger.warning("No .NET projects found with SmartStack package.");
124839
+ logger.warning("No .NET projects found with SmartStack PackageReference.");
124840
+ logger.info('Tip: Ensure your .csproj files contain <PackageReference Include="SmartStack" Version="..." />');
124772
124841
  } else {
124773
- logger.info(`Found ${source_default.cyan(projects.length)} project(s) to upgrade:`);
124774
- projects.forEach((p) => {
124775
- const relPath = p.replace(projectDir, "").replace(/^[/\\]/, "");
124776
- logger.info(` \u2022 ${relPath}`);
124777
- });
124842
+ logger.info(`Found ${source_default.cyan(projects.length)} project(s):`);
124843
+ for (const p of projects) {
124844
+ const versionInfo = p.currentVersion ? `${source_default.yellow(p.currentVersion)} \u2192 ${source_default.cyan(nugetVersion)}` : source_default.gray("version unknown");
124845
+ const upToDate = p.currentVersion === nugetVersion;
124846
+ const statusIcon = upToDate ? source_default.green("\u2713") : source_default.yellow("\u2191");
124847
+ logger.info(` ${statusIcon} ${p.relPath} (${upToDate ? source_default.green("up to date") : versionInfo})`);
124848
+ }
124849
+ console.log();
124850
+ const projectsToUpgrade = projects.filter((p) => p.currentVersion !== nugetVersion);
124851
+ result.nugetSkipped = projects.length - projectsToUpgrade.length;
124852
+ if (projectsToUpgrade.length === 0) {
124853
+ logger.success(`All ${projects.length} project(s) already at ${source_default.cyan(nugetVersion)}`);
124854
+ } else {
124855
+ logger.info(`Upgrading ${projectsToUpgrade.length} project(s)...`);
124856
+ for (const project of projectsToUpgrade) {
124857
+ logger.info(`Upgrading ${source_default.cyan(project.relPath)}...`);
124858
+ try {
124859
+ execCommand2(`dotnet add "${project.csprojPath}" package SmartStack --version ${nugetVersion}`, void 0, dryRun);
124860
+ result.nugetUpgraded++;
124861
+ } catch (error) {
124862
+ result.nugetFailed++;
124863
+ logger.error(`Failed to upgrade ${project.relPath}: ${error instanceof Error ? error.message : error}`);
124864
+ }
124865
+ }
124866
+ if (result.nugetUpgraded > 0) {
124867
+ logger.success(`${result.nugetUpgraded} project(s) upgraded to ${source_default.cyan(nugetVersion)}`);
124868
+ }
124869
+ if (result.nugetFailed > 0) {
124870
+ logger.error(`${result.nugetFailed} project(s) failed to upgrade`);
124871
+ }
124872
+ }
124778
124873
  console.log();
124779
- logger.info("Upgrading NuGet packages...");
124874
+ logger.info("Checking other NuGet packages...");
124780
124875
  for (const project of projects) {
124781
- const relPath = project.replace(projectDir, "").replace(/^[/\\]/, "");
124782
- logger.info(`Upgrading ${source_default.cyan(relPath)}...`);
124783
- execCommand2(`dotnet add "${project}" package SmartStack --version ${nugetVersion}`, void 0, dryRun);
124876
+ const content = await import_fs_extra6.default.readFile(project.csprojPath, "utf-8");
124877
+ const allPackages = readAllPackageReferences(content);
124878
+ const otherPackages = allPackages.filter((p) => p.name !== "SmartStack");
124879
+ if (otherPackages.length === 0) continue;
124880
+ const relPath = project.relPath;
124881
+ for (const pkg2 of otherPackages) {
124882
+ try {
124883
+ const output = dryRun ? `[DRY RUN] dotnet add "${project.csprojPath}" package ${pkg2.name}` : (0, import_child_process6.execSync)(
124884
+ `dotnet add "${project.csprojPath}" package ${pkg2.name}`,
124885
+ { shell: true, encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }
124886
+ );
124887
+ if (dryRun) {
124888
+ logger.info(` [DRY RUN] ${pkg2.name} ${source_default.yellow(pkg2.currentVersion)} \u2192 latest`);
124889
+ result.otherPkgUpdated++;
124890
+ continue;
124891
+ }
124892
+ const newContent = await import_fs_extra6.default.readFile(project.csprojPath, "utf-8");
124893
+ const newVersion = readPackageVersion(newContent, pkg2.name);
124894
+ if (newVersion && newVersion !== pkg2.currentVersion) {
124895
+ logger.success(` ${source_default.green("\u2713")} ${pkg2.name} ${source_default.yellow(pkg2.currentVersion)} \u2192 ${source_default.cyan(newVersion)}`);
124896
+ result.otherPkgUpdated++;
124897
+ } else {
124898
+ result.otherPkgSkipped++;
124899
+ }
124900
+ } catch (error) {
124901
+ result.otherPkgFailed++;
124902
+ logger.error(` ${source_default.red("\u2717")} ${pkg2.name}: ${error instanceof Error ? error.message : error}`);
124903
+ }
124904
+ }
124905
+ }
124906
+ if (result.otherPkgUpdated > 0) {
124907
+ logger.success(`${result.otherPkgUpdated} package(s) updated`);
124908
+ }
124909
+ if (result.otherPkgSkipped > 0) {
124910
+ logger.info(`${result.otherPkgSkipped} package(s) already at latest`);
124911
+ }
124912
+ if (result.otherPkgFailed > 0) {
124913
+ logger.error(`${result.otherPkgFailed} package(s) failed to update`);
124784
124914
  }
124785
- logger.success(`NuGet packages upgraded to ${source_default.cyan(nugetVersion)}`);
124786
124915
  console.log();
124787
124916
  }
124788
124917
  const frontendDir = await findFrontendDirectory(projectDir);
@@ -124790,18 +124919,25 @@ var upgradeCommand = new Command("upgrade").description("Upgrade SmartStack pack
124790
124919
  logger.warning("No frontend directory found with @atlashub/smartstack package.");
124791
124920
  } else {
124792
124921
  const relFrontendPath = frontendDir.replace(projectDir, "").replace(/^[/\\]/, "");
124793
- logger.info(`Frontend: ${source_default.cyan(relFrontendPath)}`);
124794
- if (npmVersion) {
124922
+ const currentFrontendVersion = await readFrontendVersion(frontendDir);
124923
+ if (currentFrontendVersion && npmVersion && currentFrontendVersion === npmVersion) {
124924
+ logger.info(`Frontend: ${source_default.cyan(relFrontendPath)} ${source_default.green("\u2713")} already at ${source_default.cyan(npmVersion)}`);
124925
+ result.npmSkipped = true;
124926
+ } else if (npmVersion) {
124927
+ const versionInfo = currentFrontendVersion ? `${source_default.yellow(currentFrontendVersion)} \u2192 ${source_default.cyan(npmVersion)}` : `\u2192 ${source_default.cyan(npmVersion)}`;
124928
+ logger.info(`Frontend: ${source_default.cyan(relFrontendPath)} (${versionInfo})`);
124795
124929
  logger.info("Upgrading npm package...");
124796
124930
  const success = tryExecCommand(`npm install @atlashub/smartstack@${npmVersion}`, frontendDir, dryRun);
124797
124931
  if (success) {
124798
124932
  logger.success(`npm package upgraded to ${source_default.cyan(npmVersion)}`);
124933
+ result.npmUpgraded = true;
124799
124934
  } else {
124800
124935
  logger.warning(`Version ${npmVersion} not yet available, trying @next tag...`);
124801
124936
  const tag = usePreview ? "next" : "latest";
124802
124937
  const fallbackSuccess = tryExecCommand(`npm install @atlashub/smartstack@${tag}`, frontendDir, dryRun);
124803
124938
  if (fallbackSuccess) {
124804
124939
  logger.success(`npm package upgraded to @${tag}`);
124940
+ result.npmUpgraded = true;
124805
124941
  } else {
124806
124942
  logger.error("Failed to upgrade npm package. Please try again later or run: npm install @atlashub/smartstack@next");
124807
124943
  }
@@ -124814,7 +124950,7 @@ var upgradeCommand = new Command("upgrade").description("Upgrade SmartStack pack
124814
124950
  logger.info("Checking for code migrations...");
124815
124951
  const migrationSummary = await executeMigrations(
124816
124952
  projectDir,
124817
- currentVersion,
124953
+ configVersion,
124818
124954
  nugetVersion,
124819
124955
  dryRun
124820
124956
  );
@@ -124832,26 +124968,57 @@ var upgradeCommand = new Command("upgrade").description("Upgrade SmartStack pack
124832
124968
  config.smartStackVersion = nugetVersion;
124833
124969
  const configPath = (0, import_path7.join)(projectDir, ".smartstack", "config.json");
124834
124970
  await import_fs_extra6.default.writeJson(configPath, config, { spaces: 2 });
124835
- logger.success(`Updated project version to ${source_default.cyan(nugetVersion)}`);
124971
+ logger.success(`Updated config version to ${source_default.cyan(nugetVersion)}`);
124836
124972
  console.log();
124837
124973
  }
124838
- const summary = [
124839
- source_default.green.bold("Upgrade completed successfully!"),
124840
- "",
124841
- source_default.bold("Upgraded packages:"),
124842
- ` \u2022 NuGet SmartStack: ${source_default.cyan(nugetVersion)}`,
124843
- npmVersion ? ` \u2022 npm @atlashub/smartstack: ${source_default.cyan(npmVersion)}` : "",
124844
- "",
124845
- migrationSummary.totalApplied > 0 ? source_default.bold("Code migrations:") : "",
124846
- migrationSummary.totalApplied > 0 ? ` \u2022 ${source_default.green(migrationSummary.totalApplied)} migration(s) applied` : "",
124847
- migrationSummary.hasErrors ? ` \u2022 ${source_default.red("Some migrations failed - review errors above")}` : "",
124848
- migrationSummary.totalApplied > 0 ? "" : "",
124849
- source_default.yellow("Next steps:"),
124850
- ` 1. Review changes: ${source_default.cyan("git diff")}`,
124851
- ` 2. Test your application`,
124852
- ` 3. Commit changes: ${source_default.cyan('git add . && git commit -m "chore: upgrade SmartStack packages"')}`
124853
- ].filter(Boolean);
124854
- logger.box(summary, "success");
124974
+ const totalChanged = result.nugetUpgraded + result.otherPkgUpdated + (result.npmUpgraded ? 1 : 0) + migrationSummary.totalApplied;
124975
+ const allUpToDate = totalChanged === 0 && result.nugetFailed === 0 && result.otherPkgFailed === 0;
124976
+ if (allUpToDate) {
124977
+ const summary = [
124978
+ source_default.green.bold("Already up to date!"),
124979
+ "",
124980
+ ` NuGet SmartStack: ${source_default.cyan(nugetVersion)}`,
124981
+ npmVersion ? ` npm @atlashub/smartstack: ${source_default.cyan(npmVersion)}` : "",
124982
+ "",
124983
+ "All packages at latest versions."
124984
+ ].filter(Boolean);
124985
+ logger.box(summary, "success");
124986
+ } else {
124987
+ const lines = [
124988
+ source_default.green.bold("Upgrade completed!"),
124989
+ ""
124990
+ ];
124991
+ if (result.nugetUpgraded > 0) {
124992
+ lines.push(` ${source_default.green("\u2713")} SmartStack: ${result.nugetUpgraded} project(s) \u2192 ${source_default.cyan(nugetVersion)}`);
124993
+ }
124994
+ if (result.nugetSkipped > 0) {
124995
+ lines.push(` ${source_default.gray("\u2013")} SmartStack: ${result.nugetSkipped} project(s) already up to date`);
124996
+ }
124997
+ if (result.nugetFailed > 0) {
124998
+ lines.push(` ${source_default.red("\u2717")} SmartStack: ${result.nugetFailed} project(s) failed`);
124999
+ }
125000
+ if (result.otherPkgUpdated > 0) {
125001
+ lines.push(` ${source_default.green("\u2713")} Other NuGet: ${result.otherPkgUpdated} package(s) updated`);
125002
+ }
125003
+ if (result.otherPkgFailed > 0) {
125004
+ lines.push(` ${source_default.red("\u2717")} Other NuGet: ${result.otherPkgFailed} package(s) failed`);
125005
+ }
125006
+ if (result.npmUpgraded) {
125007
+ lines.push(` ${source_default.green("\u2713")} npm: @atlashub/smartstack \u2192 ${source_default.cyan(npmVersion)}`);
125008
+ }
125009
+ if (result.npmSkipped) {
125010
+ lines.push(` ${source_default.gray("\u2013")} npm: already up to date`);
125011
+ }
125012
+ if (migrationSummary.totalApplied > 0) {
125013
+ lines.push(` ${source_default.green("\u2713")} Code migrations: ${migrationSummary.totalApplied} applied`);
125014
+ }
125015
+ lines.push("");
125016
+ lines.push(source_default.yellow("Next steps:"));
125017
+ lines.push(` 1. Review changes: ${source_default.cyan("git diff")}`);
125018
+ lines.push(` 2. Test your application`);
125019
+ lines.push(` 3. Commit changes: ${source_default.cyan('git add . && git commit -m "chore: upgrade SmartStack to ' + nugetVersion + '"')}`);
125020
+ logger.box(lines, "success");
125021
+ }
124855
125022
  });
124856
125023
 
124857
125024
  // src/lib/license.ts