@camox/cli 0.28.2 → 0.28.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.
- package/dist/index.mjs +131 -27
- 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,12 +727,17 @@ 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
|
-
core-js
|
|
679
|
-
msw
|
|
680
|
-
protobufjs
|
|
731
|
+
core-js: true
|
|
732
|
+
msw: true
|
|
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);
|
|
@@ -693,9 +752,53 @@ function runCommand(bin, args, cwd) {
|
|
|
693
752
|
if (code === 0) resolve();
|
|
694
753
|
else reject(/* @__PURE__ */ new Error(`Exit code ${code}`));
|
|
695
754
|
});
|
|
696
|
-
child.on("error", reject);
|
|
755
|
+
child.on("error", (err) => reject(new CommandError(`Failed to start ${bin}`, err)));
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
function spawnCommand(bin, args, cwd) {
|
|
759
|
+
return spawn(bin, args, {
|
|
760
|
+
cwd,
|
|
761
|
+
stdio: "inherit",
|
|
762
|
+
detached: true
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
function isMissingCommandError(err) {
|
|
766
|
+
if (!(err instanceof CommandError)) return false;
|
|
767
|
+
const cause = err.cause;
|
|
768
|
+
if (!(cause instanceof Error) || "code" in cause === false) return false;
|
|
769
|
+
return cause.code === "ENOENT";
|
|
770
|
+
}
|
|
771
|
+
async function runPackageManagerCommand(command, cwd) {
|
|
772
|
+
try {
|
|
773
|
+
await runCommand(command.bin, command.args, cwd);
|
|
774
|
+
} catch (err) {
|
|
775
|
+
if (!isMissingCommandError(err) || !command.fallback) throw err;
|
|
776
|
+
await runCommand(command.fallback.bin, command.fallback.args, cwd);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
function startPackageManagerCommand(command, cwd) {
|
|
780
|
+
return new Promise((resolve, reject) => {
|
|
781
|
+
const child = spawnCommand(command.bin, command.args, cwd);
|
|
782
|
+
child.once("spawn", () => resolve(child));
|
|
783
|
+
child.once("error", (err) => {
|
|
784
|
+
const commandError = new CommandError(`Failed to start ${command.bin}`, err);
|
|
785
|
+
if (!isMissingCommandError(commandError) || !command.fallback) {
|
|
786
|
+
reject(commandError);
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
const fallback = spawnCommand(command.fallback.bin, command.fallback.args, cwd);
|
|
790
|
+
fallback.once("spawn", () => resolve(fallback));
|
|
791
|
+
fallback.once("error", (fallbackErr) => reject(new CommandError(`Failed to start ${command.fallback?.bin}`, fallbackErr)));
|
|
792
|
+
});
|
|
697
793
|
});
|
|
698
794
|
}
|
|
795
|
+
function getCommandFailureMessage(pm, err) {
|
|
796
|
+
if (!isMissingCommandError(err)) return "Failed to install dependencies.";
|
|
797
|
+
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.";
|
|
798
|
+
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.";
|
|
799
|
+
if (pm === "bun") return "Bun is required to install dependencies with the selected package manager. Install Bun, then run the setup commands below.";
|
|
800
|
+
return "npm is required to install dependencies. Install npm, then run the setup commands below.";
|
|
801
|
+
}
|
|
699
802
|
const CREATE_NEW_ORG = "__create_new__";
|
|
700
803
|
async function selectOrCreateOrganization(token) {
|
|
701
804
|
const orgs = await listOrganizations(token);
|
|
@@ -833,7 +936,7 @@ async function init() {
|
|
|
833
936
|
pkg.name = project.slug;
|
|
834
937
|
delete pkg.version;
|
|
835
938
|
pkg.dependencies.camox = `^${ownPkg.version}`;
|
|
836
|
-
|
|
939
|
+
pkg.packageManager = packageManagerVersions[pm];
|
|
837
940
|
fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
838
941
|
if (pm === "pnpm") fs.writeFileSync(path.join(targetDir, "pnpm-workspace.yaml"), PNPM_WORKSPACE);
|
|
839
942
|
fs.writeFileSync(path.join(targetDir, ".env"), `CAMOX_SYNC_SECRET=${project.syncSecret}\n`);
|
|
@@ -860,25 +963,26 @@ src/routeTree.gen.ts
|
|
|
860
963
|
`);
|
|
861
964
|
s.stop("Project scaffolded!");
|
|
862
965
|
const { install: installCmd, dev: devCmd } = pmCommands[pm];
|
|
863
|
-
const [installBin, ...installArgs] = installCmd.split(" ");
|
|
864
966
|
const s2 = p.spinner();
|
|
865
|
-
s2.start(`Running ${installCmd}...`);
|
|
967
|
+
s2.start(`Running ${installCmd.display}...`);
|
|
866
968
|
try {
|
|
867
|
-
await
|
|
969
|
+
await runPackageManagerCommand(installCmd, targetDir);
|
|
868
970
|
s2.stop("Dependencies installed!");
|
|
869
|
-
} catch {
|
|
971
|
+
} catch (err) {
|
|
870
972
|
s2.stop("Install failed.");
|
|
871
|
-
p.log.error(
|
|
872
|
-
p.outro(`To finish setup:\n cd ${resolvedPath}\n ${installCmd}\n ${devCmd}`);
|
|
973
|
+
p.log.error(getCommandFailureMessage(pm, err));
|
|
974
|
+
p.outro(`To finish setup:\n cd ${resolvedPath}\n ${installCmd.display}\n ${devCmd.display}`);
|
|
873
975
|
process.exit(1);
|
|
874
976
|
}
|
|
875
977
|
p.log.info(`Starting dev server... (Ctrl+C to stop)`);
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
978
|
+
let child;
|
|
979
|
+
try {
|
|
980
|
+
child = await startPackageManagerCommand(devCmd, targetDir);
|
|
981
|
+
} catch (err) {
|
|
982
|
+
p.log.error(getCommandFailureMessage(pm, err));
|
|
983
|
+
p.outro(`To start the dev server:\n cd ${resolvedPath}\n ${devCmd.display}`);
|
|
984
|
+
process.exit(1);
|
|
985
|
+
}
|
|
882
986
|
const sigintHandler = () => {
|
|
883
987
|
if (child.pid) try {
|
|
884
988
|
process.kill(-child.pid, "SIGTERM");
|
|
@@ -889,7 +993,7 @@ src/routeTree.gen.ts
|
|
|
889
993
|
child.on("close", () => {
|
|
890
994
|
process.removeListener("SIGINT", sigintHandler);
|
|
891
995
|
process.removeListener("exit", sigintHandler);
|
|
892
|
-
p.outro(`To restart the dev server:\n cd ${resolvedPath}\n ${devCmd}`);
|
|
996
|
+
p.outro(`To restart the dev server:\n cd ${resolvedPath}\n ${devCmd.display}`);
|
|
893
997
|
process.exit(0);
|
|
894
998
|
});
|
|
895
999
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@camox/cli",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.4",
|
|
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.4"
|
|
30
30
|
},
|
|
31
31
|
"nx": {
|
|
32
32
|
"tags": [
|