@hexclave/cli 1.0.51 → 1.0.53
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 +9 -8
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/commands/config-file.test.ts +17 -7
- package/src/commands/config-file.ts +25 -15
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ import { Command } from "commander";
|
|
|
17
17
|
import { StackClientApp } from "@hexclave/js";
|
|
18
18
|
import { hexclaveDevEnvStatePath } from "@hexclave/shared/dist/utils/dev-env-state-path";
|
|
19
19
|
import { createHash, randomBytes } from "crypto";
|
|
20
|
-
import { replaceConfigObject
|
|
20
|
+
import { replaceConfigObject } from "@hexclave/shared-backend";
|
|
21
21
|
import { detectImportPackageFromDir } from "@hexclave/shared/dist/config-eval";
|
|
22
22
|
import { isValidConfig } from "@hexclave/shared/dist/config/format";
|
|
23
23
|
import { ALL_APPS } from "@hexclave/shared/dist/apps/apps-config";
|
|
@@ -682,20 +682,21 @@ function resolveConfigFilePathForPull(opts, cwd) {
|
|
|
682
682
|
if (fs.statSync(candidate).isDirectory()) throw new CliError(`Default config path points to a directory instead of a file: ${candidate}`);
|
|
683
683
|
return candidate;
|
|
684
684
|
}
|
|
685
|
-
function
|
|
686
|
-
|
|
685
|
+
function assertConfigPullTarget(filePath, opts) {
|
|
686
|
+
if (opts.overwrite === true) return;
|
|
687
|
+
if (fs.existsSync(filePath)) throw new CliError(`A config file already exists at ${filePath}. Pass --overwrite to replace it with the pulled config, or remove the file first.`);
|
|
687
688
|
}
|
|
688
689
|
function registerConfigCommand(program) {
|
|
689
690
|
const config = program.command("config").description("Manage project configuration files");
|
|
690
|
-
config.command("pull").description("Pull branch config to a local file").option("--cloud-project-id <id>", "Cloud project ID to pull config from (defaults to the STACK_PROJECT_ID env var)").option("--config-file <path>", "Path to write config file (.ts); defaults to ./hexclave.config.ts in the current directory").option("--overwrite", "
|
|
691
|
+
config.command("pull").description("Pull branch config to a local file").option("--cloud-project-id <id>", "Cloud project ID to pull config from (defaults to the STACK_PROJECT_ID env var)").option("--config-file <path>", "Path to write config file (.ts); defaults to ./hexclave.config.ts in the current directory").option("--overwrite", "Replace the config file if one already exists at the target path").action(async (opts) => {
|
|
691
692
|
const auth = resolveAuth(resolveProjectId(opts.cloudProjectId));
|
|
692
693
|
if (!isProjectAuthWithRefreshToken(auth)) throw new CliError("`hexclave config pull` requires `hexclave login`. Remove STACK_SECRET_SERVER_KEY and try again.");
|
|
693
|
-
const configOverride = await (await getAdminProject(auth)).getConfigOverride("branch");
|
|
694
|
-
if (!isValidConfig(configOverride)) throw new CliError("Pulled branch config is not a valid local config object.");
|
|
695
694
|
const filePath = resolveConfigFilePathForPull(opts, process.cwd());
|
|
696
695
|
if (path.extname(filePath) !== ".ts") throw new CliError("Config file must have a .ts extension. Typed config files require TypeScript.");
|
|
697
|
-
|
|
698
|
-
|
|
696
|
+
assertConfigPullTarget(filePath, opts);
|
|
697
|
+
const configOverride = await (await getAdminProject(auth)).getConfigOverride("branch");
|
|
698
|
+
if (!isValidConfig(configOverride)) throw new CliError("Pulled branch config is not a valid local config object.");
|
|
699
|
+
await replaceConfigObject(filePath, configOverride);
|
|
699
700
|
console.log(`Config written to ${filePath}`);
|
|
700
701
|
});
|
|
701
702
|
config.command("push").description("Push a local config file to branch config").option("--cloud-project-id <id>", "Cloud project ID to push config to (defaults to the STACK_PROJECT_ID env var)").requiredOption("--config-file <path>", "Path to config file (.js or .ts)").option("--source <type>", "Explicit source type for this push. Only 'github' is supported.").option("--source-repo <owner/repo>", "GitHub repository in 'owner/repo' format. Only allowed with --source github.").option("--source-path <path>", "Path to the config file within the source repository. Only allowed with --source github.").option("--source-workflow-path <path>", "Path to the syncing workflow file within the source repository. Only allowed with --source github.").action(async (opts) => {
|