Skip to content

Commit cefd826

Browse files
committed
[release] cli + helpers: --generate works without creds, --updateFunctionSpec returns, --schemaOutDir resolves from cwd
1 parent 953e3bd commit cefd826

3 files changed

Lines changed: 27 additions & 14 deletions

File tree

packages/appwrite-utils-cli/src/main.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ interface CliOptions {
8282
autoSync?: boolean;
8383
selectBuckets?: boolean;
8484
// New schema/constant CLI flags
85-
generateSchemas?: boolean;
8685
schemaFormat?: string;
8786
schemaOutDir?: string;
8887
constantsInclude?: string;
@@ -384,7 +383,7 @@ const argv = yargs(hideBin(process.argv))
384383
description: "Prefer loading from appwrite.config.json instead of config.yaml",
385384
})
386385
.option("it", {
387-
alias: ["interactive", "i"],
386+
alias: ["interactive"],
388387
type: "boolean",
389388
description: "Launch interactive CLI mode with guided prompts",
390389
})
@@ -610,10 +609,6 @@ const argv = yargs(hideBin(process.argv))
610609
description:
611610
"Comma-separated categories to include: databases,collections,buckets,functions",
612611
})
613-
.option("generateSchemas", {
614-
type: "boolean",
615-
description: "Generate schemas/models without interactive prompts",
616-
})
617612
.option("schemaFormat", {
618613
type: "string",
619614
description:
@@ -750,6 +745,15 @@ async function main() {
750745
MessageFormatter.info("Debug logging enabled (helpers logs → console at debug level)", { prefix: "CLI" });
751746
}
752747

748+
if ((argv.schemaFormat || argv.schemaOutDir) && !argv.generate) {
749+
MessageFormatter.error(
750+
"--schemaFormat / --schemaOutDir require --generate",
751+
undefined,
752+
{ prefix: "CLI" }
753+
);
754+
process.exit(1);
755+
}
756+
753757
if (argv.it) {
754758
const cli = new InteractiveCLI(process.cwd(), {
755759
useSession: argv.useSession,
@@ -785,7 +789,7 @@ async function main() {
785789
if (error instanceof AuthenticationError) {
786790
// --init / --upgradeConfig / --passthrough can legitimately run without a fully wired config.
787791
// Defer auth handling to those flows; otherwise surface the error and exit.
788-
if (!argv.init && !argv.upgradeConfig && !argv.passthrough && !argv.regen && !argv.syncExtensions && !argv.pullSelective) {
792+
if (!argv.init && !argv.upgradeConfig && !argv.passthrough && !argv.regen && !argv.syncExtensions && !argv.pullSelective && !argv.generate) {
789793
MessageFormatter.error(error.getFormattedMessage(), undefined, { prefix: "Auth" });
790794
process.exit(1);
791795
}
@@ -870,8 +874,10 @@ async function main() {
870874
return;
871875
}
872876

873-
// After init, check if we have a valid config (from file OR CLI overrides)
874-
if (!controller.config) {
877+
// After init, check if we have a valid config (from file OR CLI overrides).
878+
// --generate is allowed through with no controller.config; controller.generateSchemas()
879+
// lazy-loads via ConfigManager so local schema generation works without Appwrite creds.
880+
if (!controller.config && !argv.generate) {
875881
MessageFormatter.error("No Appwrite configuration available", undefined, { prefix: "CLI" });
876882
MessageFormatter.info("Provide credentials via CLI flags (--endpoint, --projectId, --apiKey or --session)", { prefix: "CLI" });
877883
MessageFormatter.info("Or create a config file using --setup", { prefix: "CLI" });
@@ -1157,6 +1163,8 @@ async function main() {
11571163
buildSpec as Specification,
11581164
runtimeSpec as Specification
11591165
);
1166+
operationStats.updatedFunctionSpec = 1;
1167+
return;
11601168
}
11611169

11621170
// Add default databases if not specified (only if we need them for operations)

packages/appwrite-utils-cli/src/utilsController.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -733,13 +733,12 @@ export class UtilsController {
733733
MessageFormatter.info("Config loaded successfully from ConfigManager", { prefix: "Config" });
734734
} catch (error) {
735735
MessageFormatter.error("Failed to load config", error instanceof Error ? error : undefined, { prefix: "Config" });
736-
return;
736+
throw error instanceof Error ? error : new Error(String(error));
737737
}
738738
}
739739

740740
if (!this.appwriteFolderPath) {
741-
MessageFormatter.error("Failed to get appwriteFolderPath", undefined, { prefix: "Controller" });
742-
return;
741+
throw new Error("Failed to get appwriteFolderPath");
743742
}
744743

745744
await generateSchemas(this.config, this.appwriteFolderPath, {

packages/appwrite-utils-helpers/src/schemas/schemaGenerator.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,10 @@ export default appwriteConfig;
405405
let schemasPath: string;
406406
if (path.isAbsolute(configuredDir)) {
407407
schemasPath = configuredDir;
408+
} else if (outputDir) {
409+
// Caller passed an explicit relative override → resolve from the invocation CWD,
410+
// not the config folder. Matches the natural shell expectation for `--schemaOutDir`.
411+
schemasPath = path.resolve(process.cwd(), configuredDir);
408412
} else if (configuredDir === "schemas") {
409413
schemasPath = resolveSchemaDir(this.appwriteFolderPath);
410414
} else {
@@ -430,12 +434,14 @@ export default appwriteConfig;
430434
});
431435
}
432436

433-
// Generate JSON schemas (all at once)
437+
// Generate JSON schemas (all at once). Pass the already-resolved absolute schemasPath
438+
// so JsonSchemaGenerator lands files in the same dir as zod/pydantic instead of
439+
// re-resolving relative paths against appwriteFolderPath.
434440
if (formats.has("json")) {
435441
const jsonSchemaGenerator = new JsonSchemaGenerator(this.config, this.appwriteFolderPath);
436442
jsonSchemaGenerator.generateJsonSchemas({
437443
outputFormat: formats.has("zod") ? "both" : "json",
438-
outputDirectory: configuredDir,
444+
outputDirectory: schemasPath,
439445
verbose: verbose
440446
});
441447
}

0 commit comments

Comments
 (0)