Skip to content

Commit 0a26d6b

Browse files
committed
fix package
1 parent c3cf582 commit 0a26d6b

File tree

4 files changed

+183
-176
lines changed

4 files changed

+183
-176
lines changed

cli.ts

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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+
/** ---------------------------------------------- */
7+
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+
50+
inquirer.registerPrompt("search-list", searchList);
51+
52+
/**
53+
* Check for updates and show version information
54+
*/
55+
async function checkVersion(): Promise<void> {
56+
process.stdout.write(chalk.bold(`appwrite version ${version}`) + "\n");
57+
58+
try {
59+
const latestVersion = await getLatestVersion();
60+
const comparison = compareVersions(version, latestVersion);
61+
62+
if (comparison > 0) {
63+
// Current version is older than latest
64+
process.stdout.write(
65+
chalk.yellow(
66+
`\n⚠️ A newer version is available: ${chalk.bold(latestVersion)}`,
67+
) + "\n",
68+
);
69+
process.stdout.write(
70+
chalk.cyan(
71+
`💡 Run '${chalk.bold("appwrite update")}' to update to the latest version.`,
72+
) + "\n",
73+
);
74+
} else if (comparison === 0) {
75+
process.stdout.write(
76+
chalk.green("\n✅ You are running the latest version!") + "\n",
77+
);
78+
} else {
79+
// Current version is newer than latest (pre-release/dev)
80+
process.stdout.write(
81+
chalk.blue(
82+
"\n🚀 You are running a pre-release or development version.",
83+
) + "\n",
84+
);
85+
}
86+
} catch (error) {
87+
// Silently fail version check, just show current version
88+
process.stdout.write(chalk.gray("\n(Unable to check for updates)") + "\n");
89+
}
90+
}
91+
92+
// Intercept version flag before Commander.js processes it
93+
if (process.argv.includes("-v") || process.argv.includes("--version")) {
94+
(async () => {
95+
await checkVersion();
96+
process.exit(0);
97+
})();
98+
} else {
99+
program
100+
.description(commandDescriptions["main"])
101+
.configureHelp({
102+
helpWidth: process.stdout.columns || 80,
103+
sortSubcommands: true,
104+
})
105+
.helpOption("-h, --help", "Display help for command")
106+
.version(version, "-v, --version", "Output the version number")
107+
.option("-V, --verbose", "Show complete error log")
108+
.option("-j, --json", "Output in JSON format")
109+
.hook("preAction", migrate)
110+
.option("-f,--force", "Flag to confirm all warnings")
111+
.option("-a,--all", "Flag to push all resources")
112+
.option("--id [id...]", "Flag to pass a list of ids for a given action")
113+
.option("--report", "Enable reporting in case of CLI errors")
114+
.on("option:json", () => {
115+
cliConfig.json = true;
116+
})
117+
.on("option:verbose", () => {
118+
cliConfig.verbose = true;
119+
})
120+
.on("option:report", function () {
121+
cliConfig.report = true;
122+
cliConfig.reportData = { data: this };
123+
})
124+
.on("option:force", () => {
125+
cliConfig.force = true;
126+
})
127+
.on("option:all", () => {
128+
cliConfig.all = true;
129+
})
130+
.on("option:id", function () {
131+
cliConfig.ids = (this as any).opts().id;
132+
})
133+
.showSuggestionAfterError()
134+
.addCommand(whoami)
135+
.addCommand(register)
136+
.addCommand(login)
137+
.addCommand(init)
138+
.addCommand(pull)
139+
.addCommand(push)
140+
.addCommand(types)
141+
.addCommand(deploy)
142+
.addCommand(run)
143+
.addCommand(update)
144+
.addCommand(logout)
145+
.addCommand(account)
146+
.addCommand(console)
147+
.addCommand(databases)
148+
.addCommand(functions)
149+
.addCommand(graphql)
150+
.addCommand(health)
151+
.addCommand(locale)
152+
.addCommand(messaging)
153+
.addCommand(migrations)
154+
.addCommand(project)
155+
.addCommand(projects)
156+
.addCommand(proxy)
157+
.addCommand(sites)
158+
.addCommand(storage)
159+
.addCommand(tablesdb)
160+
.addCommand(teams)
161+
.addCommand(tokens)
162+
.addCommand(users)
163+
.addCommand(vcs)
164+
.addCommand(client)
165+
.parse(process.argv);
166+
167+
process.stdout.columns = oldWidth;
168+
}

index.ts

Lines changed: 5 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -1,175 +1,13 @@
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+
*/
76

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";
497
import { Push } from "./lib/commands/push.js";
508
import { Pull } from "./lib/commands/pull.js";
519
import { Schema } from "./lib/commands/schema.js";
5210

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-
17311
export { Schema, Push, Pull };
17412
export type {
17513
ConfigType,

lib/commands/utils/deployment.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs from "fs";
22
import path from "path";
33
import tar from "tar";
44
import { Client, AppwriteException } from "@appwrite.io/console";
5+
import { error } from "../../parser.js";
56

67
const POLL_DEBOUNCE = 2000; // Milliseconds
78

@@ -59,7 +60,7 @@ export async function downloadDeploymentCode(params: {
5960
}
6061
} catch (e: unknown) {
6162
if (e instanceof AppwriteException) {
62-
this.error(e.message);
63+
error(e.message);
6364
return;
6465
} else {
6566
throw e;

0 commit comments

Comments
 (0)