create-addfox-app 0.2.2 → 0.2.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.
@@ -1,2 +1,7 @@
1
1
  #!/usr/bin/env node
2
+ export declare function resolveLatestVersion(pkgName: string): string | null;
3
+ export declare function updatePackageVersions(destDir: string, versions?: {
4
+ addfox?: string | null;
5
+ utils?: string | null;
6
+ }): void;
2
7
  export declare function runCreateApp(rawArgv?: string[]): Promise<void>;
package/dist/cli.js CHANGED
@@ -212,6 +212,12 @@ const FRAMEWORKS = [
212
212
  function getTemplateName(framework, language) {
213
213
  return `template-${framework}-${language}`;
214
214
  }
215
+ const PACKAGE_MANAGER_ORDER = [
216
+ "pnpm",
217
+ "npm",
218
+ "yarn",
219
+ "bun"
220
+ ];
215
221
  const PACKAGE_MANAGER_CHOICES = [
216
222
  {
217
223
  title: "pnpm",
@@ -907,6 +913,7 @@ async function promptOptions() {
907
913
  name: "packageManager",
908
914
  message: "Select package manager",
909
915
  choices: getPackageManagerChoicesColored(),
916
+ initial: Math.max(0, PACKAGE_MANAGER_ORDER.indexOf(detectPackageManager())),
910
917
  hint: PROMPT_SELECT_HINT
911
918
  },
912
919
  {
@@ -988,6 +995,46 @@ function updatePackageName(destDir, projectName) {
988
995
  pkg.name = projectName.replace(/\s+/g, "-").toLowerCase();
989
996
  writeJsonFile(pkgPath, pkg);
990
997
  }
998
+ function resolveLatestVersion(pkgName) {
999
+ try {
1000
+ const output = execSync(`npm view ${pkgName} version --registry https://registry.npmjs.org/`, {
1001
+ encoding: "utf-8",
1002
+ stdio: [
1003
+ "pipe",
1004
+ "pipe",
1005
+ "ignore"
1006
+ ],
1007
+ timeout: 3000
1008
+ });
1009
+ const version = output.trim();
1010
+ return version || null;
1011
+ } catch {
1012
+ return null;
1013
+ }
1014
+ }
1015
+ function updatePackageVersions(destDir, versions = {}) {
1016
+ const pkgPath = external_node_path_resolve(destDir, "package.json");
1017
+ if (!existsSync(pkgPath)) return;
1018
+ const addfoxVersion = versions.addfox ?? resolveLatestVersion("addfox");
1019
+ const utilsVersion = versions.utils ?? resolveLatestVersion("@addfox/utils");
1020
+ if (!addfoxVersion && !utilsVersion) return;
1021
+ const pkg = readJsonFile(pkgPath);
1022
+ if (addfoxVersion && pkg.devDependencies && "object" == typeof pkg.devDependencies) {
1023
+ const devDeps = pkg.devDependencies;
1024
+ if (devDeps["addfox"]) devDeps["addfox"] = `^${addfoxVersion}`;
1025
+ }
1026
+ if (utilsVersion) {
1027
+ if (pkg.dependencies && "object" == typeof pkg.dependencies) {
1028
+ const deps = pkg.dependencies;
1029
+ if (deps["@addfox/utils"]) deps["@addfox/utils"] = `^${utilsVersion}`;
1030
+ }
1031
+ if (pkg.devDependencies && "object" == typeof pkg.devDependencies) {
1032
+ const devDeps = pkg.devDependencies;
1033
+ if (devDeps["@addfox/utils"]) devDeps["@addfox/utils"] = `^${utilsVersion}`;
1034
+ }
1035
+ }
1036
+ writeJsonFile(pkgPath, pkg);
1037
+ }
991
1038
  async function runCreateApp(rawArgv = process.argv.slice(2)) {
992
1039
  const argv = parseArgv(rawArgv);
993
1040
  if (argv.help || argv.h) return void printHelp();
@@ -1051,6 +1098,7 @@ async function runCreateApp(rawArgv = process.argv.slice(2)) {
1051
1098
  } else configContent = generateAddfoxConfig(options.framework, options.language, options.styleEngine);
1052
1099
  writeFileSync(configPath, configContent, "utf-8");
1053
1100
  updatePackageName(root, targetDir);
1101
+ updatePackageVersions(root);
1054
1102
  applyStyleEngine(root, options.framework, options.language, options.styleEngine);
1055
1103
  applyTestAndReportSetup(root, options.language, testSelection);
1056
1104
  const installCmd = getInstallCommand(pm);
@@ -1099,4 +1147,4 @@ if (isCli) main().catch((e)=>{
1099
1147
  console.error(e);
1100
1148
  process.exit(1);
1101
1149
  });
1102
- export { runCreateApp };
1150
+ export { resolveLatestVersion, runCreateApp, updatePackageVersions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-addfox-app",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Interactive scaffolder for addfox extension projects",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "dependencies": {
21
21
  "prompts": "^2.4.2",
22
- "@addfox/pkg-manager": "0.2.2"
22
+ "@addfox/pkg-manager": "0.2.3"
23
23
  },
24
24
  "engines": {
25
25
  "node": ">=18.0.0"