|
1 | | -#! /usr/bin/env node |
2 | | - |
3 | | -/** Required to set max width of the help commands */ |
4 | | -const oldWidth = process.stdout.columns; |
5 | | -process.stdout.columns = 100; |
6 | | -/** ---------------------------------------------- */ |
| 1 | +/** |
| 2 | + * Library exports for programmatic use of the Appwrite CLI |
| 3 | + * |
| 4 | + * For CLI usage, run the 'appwrite' command directly. |
| 5 | + */ |
7 | 6 |
|
8 | | -import { program } from "commander"; |
9 | | -import chalk from "chalk"; |
10 | | -import packageJson from "./package.json" with { type: "json" }; |
11 | | -const { version } = packageJson; |
12 | | -import { commandDescriptions, cliConfig } from "./lib/parser.js"; |
13 | | -import { client } from "./lib/commands/generic.js"; |
14 | | -import { getLatestVersion, compareVersions } from "./lib/utils.js"; |
15 | | -import inquirer from "inquirer"; |
16 | | -import { |
17 | | - login, |
18 | | - logout, |
19 | | - whoami, |
20 | | - migrate, |
21 | | - register, |
22 | | -} from "./lib/commands/generic.js"; |
23 | | -import { init } from "./lib/commands/init.js"; |
24 | | -import { types } from "./lib/commands/types.js"; |
25 | | -import { pull } from "./lib/commands/pull.js"; |
26 | | -import { run } from "./lib/commands/run.js"; |
27 | | -import { push, deploy } from "./lib/commands/push.js"; |
28 | | -import { update } from "./lib/commands/update.js"; |
29 | | -import { account } from "./lib/commands/services/account.js"; |
30 | | -import { console } from "./lib/commands/services/console.js"; |
31 | | -import { databases } from "./lib/commands/services/databases.js"; |
32 | | -import { functions } from "./lib/commands/services/functions.js"; |
33 | | -import { graphql } from "./lib/commands/services/graphql.js"; |
34 | | -import { health } from "./lib/commands/services/health.js"; |
35 | | -import { locale } from "./lib/commands/services/locale.js"; |
36 | | -import { messaging } from "./lib/commands/services/messaging.js"; |
37 | | -import { migrations } from "./lib/commands/services/migrations.js"; |
38 | | -import { project } from "./lib/commands/services/project.js"; |
39 | | -import { projects } from "./lib/commands/services/projects.js"; |
40 | | -import { proxy } from "./lib/commands/services/proxy.js"; |
41 | | -import { sites } from "./lib/commands/services/sites.js"; |
42 | | -import { storage } from "./lib/commands/services/storage.js"; |
43 | | -import { tablesdb } from "./lib/commands/services/tablesdb.js"; |
44 | | -import { teams } from "./lib/commands/services/teams.js"; |
45 | | -import { tokens } from "./lib/commands/services/tokens.js"; |
46 | | -import { users } from "./lib/commands/services/users.js"; |
47 | | -import { vcs } from "./lib/commands/services/vcs.js"; |
48 | | -import searchList from "inquirer-search-list"; |
49 | 7 | import { Push } from "./lib/commands/push.js"; |
50 | 8 | import { Pull } from "./lib/commands/pull.js"; |
51 | 9 | import { Schema } from "./lib/commands/schema.js"; |
52 | 10 |
|
53 | | -inquirer.registerPrompt("search-list", searchList); |
54 | | - |
55 | | -/** |
56 | | - * Check for updates and show version information |
57 | | - */ |
58 | | -async function checkVersion(): Promise<void> { |
59 | | - process.stdout.write(chalk.bold(`appwrite version ${version}`) + "\n"); |
60 | | - |
61 | | - try { |
62 | | - const latestVersion = await getLatestVersion(); |
63 | | - const comparison = compareVersions(version, latestVersion); |
64 | | - |
65 | | - if (comparison > 0) { |
66 | | - // Current version is older than latest |
67 | | - process.stdout.write( |
68 | | - chalk.yellow( |
69 | | - `\n⚠️ A newer version is available: ${chalk.bold(latestVersion)}`, |
70 | | - ) + "\n", |
71 | | - ); |
72 | | - process.stdout.write( |
73 | | - chalk.cyan( |
74 | | - `💡 Run '${chalk.bold("appwrite update")}' to update to the latest version.`, |
75 | | - ) + "\n", |
76 | | - ); |
77 | | - } else if (comparison === 0) { |
78 | | - process.stdout.write( |
79 | | - chalk.green("\n✅ You are running the latest version!") + "\n", |
80 | | - ); |
81 | | - } else { |
82 | | - // Current version is newer than latest (pre-release/dev) |
83 | | - process.stdout.write( |
84 | | - chalk.blue( |
85 | | - "\n🚀 You are running a pre-release or development version.", |
86 | | - ) + "\n", |
87 | | - ); |
88 | | - } |
89 | | - } catch (error) { |
90 | | - // Silently fail version check, just show current version |
91 | | - process.stdout.write(chalk.gray("\n(Unable to check for updates)") + "\n"); |
92 | | - } |
93 | | -} |
94 | | - |
95 | | -// Intercept version flag before Commander.js processes it |
96 | | -if (process.argv.includes("-v") || process.argv.includes("--version")) { |
97 | | - (async () => { |
98 | | - await checkVersion(); |
99 | | - process.exit(0); |
100 | | - })(); |
101 | | -} else { |
102 | | - program |
103 | | - .description(commandDescriptions["main"]) |
104 | | - .configureHelp({ |
105 | | - helpWidth: process.stdout.columns || 80, |
106 | | - sortSubcommands: true, |
107 | | - }) |
108 | | - .helpOption("-h, --help", "Display help for command") |
109 | | - .version(version, "-v, --version", "Output the version number") |
110 | | - .option("-V, --verbose", "Show complete error log") |
111 | | - .option("-j, --json", "Output in JSON format") |
112 | | - .hook("preAction", migrate) |
113 | | - .option("-f,--force", "Flag to confirm all warnings") |
114 | | - .option("-a,--all", "Flag to push all resources") |
115 | | - .option("--id [id...]", "Flag to pass a list of ids for a given action") |
116 | | - .option("--report", "Enable reporting in case of CLI errors") |
117 | | - .on("option:json", () => { |
118 | | - cliConfig.json = true; |
119 | | - }) |
120 | | - .on("option:verbose", () => { |
121 | | - cliConfig.verbose = true; |
122 | | - }) |
123 | | - .on("option:report", function () { |
124 | | - cliConfig.report = true; |
125 | | - cliConfig.reportData = { data: this }; |
126 | | - }) |
127 | | - .on("option:force", () => { |
128 | | - cliConfig.force = true; |
129 | | - }) |
130 | | - .on("option:all", () => { |
131 | | - cliConfig.all = true; |
132 | | - }) |
133 | | - .on("option:id", function () { |
134 | | - cliConfig.ids = (this as any).opts().id; |
135 | | - }) |
136 | | - .showSuggestionAfterError() |
137 | | - .addCommand(whoami) |
138 | | - .addCommand(register) |
139 | | - .addCommand(login) |
140 | | - .addCommand(init) |
141 | | - .addCommand(pull) |
142 | | - .addCommand(push) |
143 | | - .addCommand(types) |
144 | | - .addCommand(deploy) |
145 | | - .addCommand(run) |
146 | | - .addCommand(update) |
147 | | - .addCommand(logout) |
148 | | - .addCommand(account) |
149 | | - .addCommand(console) |
150 | | - .addCommand(databases) |
151 | | - .addCommand(functions) |
152 | | - .addCommand(graphql) |
153 | | - .addCommand(health) |
154 | | - .addCommand(locale) |
155 | | - .addCommand(messaging) |
156 | | - .addCommand(migrations) |
157 | | - .addCommand(project) |
158 | | - .addCommand(projects) |
159 | | - .addCommand(proxy) |
160 | | - .addCommand(sites) |
161 | | - .addCommand(storage) |
162 | | - .addCommand(tablesdb) |
163 | | - .addCommand(teams) |
164 | | - .addCommand(tokens) |
165 | | - .addCommand(users) |
166 | | - .addCommand(vcs) |
167 | | - .addCommand(client) |
168 | | - .parse(process.argv); |
169 | | - |
170 | | - process.stdout.columns = oldWidth; |
171 | | -} |
172 | | - |
173 | 11 | export { Schema, Push, Pull }; |
174 | 12 | export type { |
175 | 13 | ConfigType, |
|
0 commit comments