@camox/cli 0.28.3 → 0.28.5
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.mjs +138 -24
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -635,22 +635,76 @@ async function handler$6(args) {
|
|
|
635
635
|
}
|
|
636
636
|
//#endregion
|
|
637
637
|
//#region src/lib/utils.ts
|
|
638
|
+
const packageManagerVersions = {
|
|
639
|
+
pnpm: "pnpm@11.1.3",
|
|
640
|
+
bun: "bun@1.2.23",
|
|
641
|
+
npm: "npm@11.6.2",
|
|
642
|
+
yarn: "yarn@4.9.2"
|
|
643
|
+
};
|
|
638
644
|
const pmCommands = {
|
|
639
645
|
pnpm: {
|
|
640
|
-
install:
|
|
641
|
-
|
|
646
|
+
install: {
|
|
647
|
+
bin: "corepack",
|
|
648
|
+
args: ["pnpm", "install"],
|
|
649
|
+
display: "pnpm install",
|
|
650
|
+
fallback: {
|
|
651
|
+
bin: "pnpm",
|
|
652
|
+
args: ["install"]
|
|
653
|
+
}
|
|
654
|
+
},
|
|
655
|
+
dev: {
|
|
656
|
+
bin: "corepack",
|
|
657
|
+
args: ["pnpm", "dev"],
|
|
658
|
+
display: "pnpm dev",
|
|
659
|
+
fallback: {
|
|
660
|
+
bin: "pnpm",
|
|
661
|
+
args: ["dev"]
|
|
662
|
+
}
|
|
663
|
+
}
|
|
642
664
|
},
|
|
643
665
|
bun: {
|
|
644
|
-
install:
|
|
645
|
-
|
|
666
|
+
install: {
|
|
667
|
+
bin: "bun",
|
|
668
|
+
args: ["install"],
|
|
669
|
+
display: "bun install"
|
|
670
|
+
},
|
|
671
|
+
dev: {
|
|
672
|
+
bin: "bun",
|
|
673
|
+
args: ["dev"],
|
|
674
|
+
display: "bun dev"
|
|
675
|
+
}
|
|
646
676
|
},
|
|
647
677
|
npm: {
|
|
648
|
-
install:
|
|
649
|
-
|
|
678
|
+
install: {
|
|
679
|
+
bin: "npm",
|
|
680
|
+
args: ["install"],
|
|
681
|
+
display: "npm install"
|
|
682
|
+
},
|
|
683
|
+
dev: {
|
|
684
|
+
bin: "npm",
|
|
685
|
+
args: ["run", "dev"],
|
|
686
|
+
display: "npm run dev"
|
|
687
|
+
}
|
|
650
688
|
},
|
|
651
689
|
yarn: {
|
|
652
|
-
install:
|
|
653
|
-
|
|
690
|
+
install: {
|
|
691
|
+
bin: "corepack",
|
|
692
|
+
args: ["yarn", "install"],
|
|
693
|
+
display: "yarn install",
|
|
694
|
+
fallback: {
|
|
695
|
+
bin: "yarn",
|
|
696
|
+
args: ["install"]
|
|
697
|
+
}
|
|
698
|
+
},
|
|
699
|
+
dev: {
|
|
700
|
+
bin: "corepack",
|
|
701
|
+
args: ["yarn", "dev"],
|
|
702
|
+
display: "yarn dev",
|
|
703
|
+
fallback: {
|
|
704
|
+
bin: "yarn",
|
|
705
|
+
args: ["dev"]
|
|
706
|
+
}
|
|
707
|
+
}
|
|
654
708
|
}
|
|
655
709
|
};
|
|
656
710
|
function copyDir(src, dest, replacements) {
|
|
@@ -673,16 +727,27 @@ const parser$5 = command("init", object({ command: constant("init") }));
|
|
|
673
727
|
const handler$5 = init;
|
|
674
728
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
675
729
|
const ownPkg = JSON.parse(fs.readFileSync(path.resolve(__dirname, "..", "package.json"), "utf-8"));
|
|
676
|
-
const PNPM_VERSION = "11.1.3";
|
|
677
730
|
const PNPM_WORKSPACE = `allowBuilds:
|
|
678
731
|
core-js: true
|
|
679
732
|
msw: true
|
|
680
733
|
protobufjs: true
|
|
681
734
|
`;
|
|
735
|
+
var CommandError = class extends Error {
|
|
736
|
+
constructor(message, cause) {
|
|
737
|
+
super(message);
|
|
738
|
+
this.cause = cause;
|
|
739
|
+
}
|
|
740
|
+
};
|
|
682
741
|
function onCancel() {
|
|
683
742
|
p.cancel("Cancelled.");
|
|
684
743
|
process.exit(0);
|
|
685
744
|
}
|
|
745
|
+
function versionFromSpecifier(specifier, dependency) {
|
|
746
|
+
if (typeof specifier !== "string") throw new Error(`Expected ${dependency} to use a string version specifier.`);
|
|
747
|
+
const match = specifier.match(/\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?/);
|
|
748
|
+
if (match) return match[0];
|
|
749
|
+
throw new Error(`Could not infer a concrete version from ${dependency}@${specifier}.`);
|
|
750
|
+
}
|
|
686
751
|
function runCommand(bin, args, cwd) {
|
|
687
752
|
return new Promise((resolve, reject) => {
|
|
688
753
|
const child = spawn(bin, args, {
|
|
@@ -693,9 +758,53 @@ function runCommand(bin, args, cwd) {
|
|
|
693
758
|
if (code === 0) resolve();
|
|
694
759
|
else reject(/* @__PURE__ */ new Error(`Exit code ${code}`));
|
|
695
760
|
});
|
|
696
|
-
child.on("error", reject);
|
|
761
|
+
child.on("error", (err) => reject(new CommandError(`Failed to start ${bin}`, err)));
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
function spawnCommand(bin, args, cwd) {
|
|
765
|
+
return spawn(bin, args, {
|
|
766
|
+
cwd,
|
|
767
|
+
stdio: "inherit",
|
|
768
|
+
detached: true
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
function isMissingCommandError(err) {
|
|
772
|
+
if (!(err instanceof CommandError)) return false;
|
|
773
|
+
const cause = err.cause;
|
|
774
|
+
if (!(cause instanceof Error) || "code" in cause === false) return false;
|
|
775
|
+
return cause.code === "ENOENT";
|
|
776
|
+
}
|
|
777
|
+
async function runPackageManagerCommand(command, cwd) {
|
|
778
|
+
try {
|
|
779
|
+
await runCommand(command.bin, command.args, cwd);
|
|
780
|
+
} catch (err) {
|
|
781
|
+
if (!isMissingCommandError(err) || !command.fallback) throw err;
|
|
782
|
+
await runCommand(command.fallback.bin, command.fallback.args, cwd);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
function startPackageManagerCommand(command, cwd) {
|
|
786
|
+
return new Promise((resolve, reject) => {
|
|
787
|
+
const child = spawnCommand(command.bin, command.args, cwd);
|
|
788
|
+
child.once("spawn", () => resolve(child));
|
|
789
|
+
child.once("error", (err) => {
|
|
790
|
+
const commandError = new CommandError(`Failed to start ${command.bin}`, err);
|
|
791
|
+
if (!isMissingCommandError(commandError) || !command.fallback) {
|
|
792
|
+
reject(commandError);
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
const fallback = spawnCommand(command.fallback.bin, command.fallback.args, cwd);
|
|
796
|
+
fallback.once("spawn", () => resolve(fallback));
|
|
797
|
+
fallback.once("error", (fallbackErr) => reject(new CommandError(`Failed to start ${command.fallback?.bin}`, fallbackErr)));
|
|
798
|
+
});
|
|
697
799
|
});
|
|
698
800
|
}
|
|
801
|
+
function getCommandFailureMessage(pm, err) {
|
|
802
|
+
if (!isMissingCommandError(err)) return "Failed to install dependencies.";
|
|
803
|
+
if (pm === "pnpm") return "Corepack or pnpm is required to install dependencies with the selected package manager. Enable Corepack with `corepack enable` or install pnpm, then run the setup commands below.";
|
|
804
|
+
if (pm === "yarn") return "Corepack or Yarn is required to install dependencies with the selected package manager. Enable Corepack with `corepack enable` or install Yarn, then run the setup commands below.";
|
|
805
|
+
if (pm === "bun") return "Bun is required to install dependencies with the selected package manager. Install Bun, then run the setup commands below.";
|
|
806
|
+
return "npm is required to install dependencies. Install npm, then run the setup commands below.";
|
|
807
|
+
}
|
|
699
808
|
const CREATE_NEW_ORG = "__create_new__";
|
|
700
809
|
async function selectOrCreateOrganization(token) {
|
|
701
810
|
const orgs = await listOrganizations(token);
|
|
@@ -833,7 +942,11 @@ async function init() {
|
|
|
833
942
|
pkg.name = project.slug;
|
|
834
943
|
delete pkg.version;
|
|
835
944
|
pkg.dependencies.camox = `^${ownPkg.version}`;
|
|
836
|
-
|
|
945
|
+
pkg.packageManager = packageManagerVersions[pm];
|
|
946
|
+
if (pm === "yarn") {
|
|
947
|
+
const vitePlusVersion = versionFromSpecifier(pkg.devDependencies["vite-plus"], "vite-plus");
|
|
948
|
+
pkg.devDependencies.vite = `npm:@voidzero-dev/vite-plus-core@${vitePlusVersion}`;
|
|
949
|
+
}
|
|
837
950
|
fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
838
951
|
if (pm === "pnpm") fs.writeFileSync(path.join(targetDir, "pnpm-workspace.yaml"), PNPM_WORKSPACE);
|
|
839
952
|
fs.writeFileSync(path.join(targetDir, ".env"), `CAMOX_SYNC_SECRET=${project.syncSecret}\n`);
|
|
@@ -860,25 +973,26 @@ src/routeTree.gen.ts
|
|
|
860
973
|
`);
|
|
861
974
|
s.stop("Project scaffolded!");
|
|
862
975
|
const { install: installCmd, dev: devCmd } = pmCommands[pm];
|
|
863
|
-
const [installBin, ...installArgs] = installCmd.split(" ");
|
|
864
976
|
const s2 = p.spinner();
|
|
865
|
-
s2.start(`Running ${installCmd}...`);
|
|
977
|
+
s2.start(`Running ${installCmd.display}...`);
|
|
866
978
|
try {
|
|
867
|
-
await
|
|
979
|
+
await runPackageManagerCommand(installCmd, targetDir);
|
|
868
980
|
s2.stop("Dependencies installed!");
|
|
869
|
-
} catch {
|
|
981
|
+
} catch (err) {
|
|
870
982
|
s2.stop("Install failed.");
|
|
871
|
-
p.log.error(
|
|
872
|
-
p.outro(`To finish setup:\n cd ${resolvedPath}\n ${installCmd}\n ${devCmd}`);
|
|
983
|
+
p.log.error(getCommandFailureMessage(pm, err));
|
|
984
|
+
p.outro(`To finish setup:\n cd ${resolvedPath}\n ${installCmd.display}\n ${devCmd.display}`);
|
|
873
985
|
process.exit(1);
|
|
874
986
|
}
|
|
875
987
|
p.log.info(`Starting dev server... (Ctrl+C to stop)`);
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
988
|
+
let child;
|
|
989
|
+
try {
|
|
990
|
+
child = await startPackageManagerCommand(devCmd, targetDir);
|
|
991
|
+
} catch (err) {
|
|
992
|
+
p.log.error(getCommandFailureMessage(pm, err));
|
|
993
|
+
p.outro(`To start the dev server:\n cd ${resolvedPath}\n ${devCmd.display}`);
|
|
994
|
+
process.exit(1);
|
|
995
|
+
}
|
|
882
996
|
const sigintHandler = () => {
|
|
883
997
|
if (child.pid) try {
|
|
884
998
|
process.kill(-child.pid, "SIGTERM");
|
|
@@ -889,7 +1003,7 @@ src/routeTree.gen.ts
|
|
|
889
1003
|
child.on("close", () => {
|
|
890
1004
|
process.removeListener("SIGINT", sigintHandler);
|
|
891
1005
|
process.removeListener("exit", sigintHandler);
|
|
892
|
-
p.outro(`To restart the dev server:\n cd ${resolvedPath}\n ${devCmd}`);
|
|
1006
|
+
p.outro(`To restart the dev server:\n cd ${resolvedPath}\n ${devCmd.display}`);
|
|
893
1007
|
process.exit(0);
|
|
894
1008
|
});
|
|
895
1009
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@camox/cli",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.5",
|
|
4
4
|
"bin": {
|
|
5
5
|
"camox": "./dist/index.mjs"
|
|
6
6
|
},
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@types/node": "^24.12.4",
|
|
27
27
|
"@typescript/native-preview": "7.0.0-dev.20260412.1",
|
|
28
28
|
"vite-plus": "^0.1.21",
|
|
29
|
-
"@camox/api-contract": "0.28.
|
|
29
|
+
"@camox/api-contract": "0.28.5"
|
|
30
30
|
},
|
|
31
31
|
"nx": {
|
|
32
32
|
"tags": [
|