clever-tools 4.4.1 → 4.5.0
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/bin/clever.js +208 -2125
- package/package.json +33 -25
- package/src/commands/README.md +65 -0
- package/src/commands/accesslogs/accesslogs.command.js +158 -0
- package/src/commands/accesslogs/accesslogs.docs.md +20 -0
- package/src/commands/{activity.js → activity/activity.command.js} +74 -44
- package/src/commands/activity/activity.docs.md +19 -0
- package/src/commands/addon/addon.args.js +14 -0
- package/src/commands/addon/addon.command.js +7 -0
- package/src/commands/addon/addon.create.command.js +236 -0
- package/src/commands/addon/addon.delete.command.js +32 -0
- package/src/commands/addon/addon.docs.md +156 -0
- package/src/commands/addon/addon.env.command.js +50 -0
- package/src/commands/addon/addon.list.command.js +55 -0
- package/src/commands/addon/addon.providers.command.js +45 -0
- package/src/commands/addon/addon.providers.show.command.js +99 -0
- package/src/commands/addon/addon.rename.command.js +24 -0
- package/src/commands/applications/applications.command.js +59 -0
- package/src/commands/applications/applications.docs.md +31 -0
- package/src/commands/applications/applications.list.command.js +100 -0
- package/src/commands/cancel-deploy/cancel-deploy.command.js +30 -0
- package/src/commands/cancel-deploy/cancel-deploy.docs.md +16 -0
- package/src/commands/config/config.args.js +10 -0
- package/src/commands/config/config.command.js +20 -0
- package/src/commands/config/config.docs.md +86 -0
- package/src/commands/config/config.get.command.js +21 -0
- package/src/commands/config/config.set.command.js +38 -0
- package/src/commands/config/config.update.command.js +88 -0
- package/src/commands/console/console.command.js +31 -0
- package/src/commands/console/console.docs.md +16 -0
- package/src/commands/create/create.command.js +173 -0
- package/src/commands/create/create.docs.md +27 -0
- package/src/commands/{curl.js → curl/curl.command.js} +10 -3
- package/src/commands/curl/curl.docs.md +9 -0
- package/src/commands/database/database.args.js +8 -0
- package/src/commands/database/database.backups.command.js +60 -0
- package/src/commands/database/database.backups.download.command.js +55 -0
- package/src/commands/database/database.command.js +10 -0
- package/src/commands/database/database.docs.md +52 -0
- package/src/commands/delete/delete.command.js +43 -0
- package/src/commands/delete/delete.docs.md +17 -0
- package/src/commands/deploy/deploy.command.js +166 -0
- package/src/commands/deploy/deploy.docs.md +22 -0
- package/src/commands/diag/diag.command.js +136 -0
- package/src/commands/diag/diag.docs.md +15 -0
- package/src/commands/domain/domain.add.command.js +25 -0
- package/src/commands/domain/domain.args.js +8 -0
- package/src/commands/domain/domain.command.js +38 -0
- package/src/commands/domain/domain.diag.command.js +204 -0
- package/src/commands/domain/domain.docs.md +143 -0
- package/src/commands/domain/domain.favourite.command.js +35 -0
- package/src/commands/domain/domain.favourite.set.command.js +24 -0
- package/src/commands/domain/domain.favourite.unset.command.js +23 -0
- package/src/commands/domain/domain.overview.command.js +157 -0
- package/src/commands/domain/domain.rm.command.js +25 -0
- package/src/commands/drain/drain.args.js +8 -0
- package/src/commands/drain/drain.command.js +56 -0
- package/src/commands/drain/drain.create.command.js +128 -0
- package/src/commands/drain/drain.disable.command.js +27 -0
- package/src/commands/drain/drain.docs.md +129 -0
- package/src/commands/drain/drain.enable.command.js +27 -0
- package/src/commands/drain/drain.get.command.js +38 -0
- package/src/commands/drain/drain.remove.command.js +26 -0
- package/src/commands/emails/emails.add.command.js +32 -0
- package/src/commands/emails/emails.args.js +8 -0
- package/src/commands/emails/emails.command.js +35 -0
- package/src/commands/emails/emails.docs.md +79 -0
- package/src/commands/emails/emails.open.command.js +15 -0
- package/src/commands/emails/emails.primary.command.js +29 -0
- package/src/commands/emails/emails.remove-all.command.js +54 -0
- package/src/commands/emails/emails.remove.command.js +25 -0
- package/src/commands/env/env.command.js +77 -0
- package/src/commands/env/env.docs.md +99 -0
- package/src/commands/env/env.import-vars.command.js +45 -0
- package/src/commands/env/env.import.command.js +29 -0
- package/src/commands/env/env.rm.command.js +25 -0
- package/src/commands/env/env.set.command.js +32 -0
- package/src/commands/features/features.args.js +9 -0
- package/src/commands/features/features.command.js +7 -0
- package/src/commands/features/features.disable.command.js +25 -0
- package/src/commands/features/features.docs.md +71 -0
- package/src/commands/features/features.enable.command.js +32 -0
- package/src/commands/features/features.info.command.js +27 -0
- package/src/commands/features/features.list.command.js +49 -0
- package/src/commands/global.args.js +45 -0
- package/src/commands/global.commands.js +461 -0
- package/src/commands/global.options.js +186 -0
- package/src/commands/help/help.command.js +9 -0
- package/src/commands/help/help.docs.md +9 -0
- package/src/commands/k8s/k8s.add-persistent-storage.command.js +39 -0
- package/src/commands/k8s/k8s.args.js +9 -0
- package/src/commands/k8s/k8s.command.js +12 -0
- package/src/commands/k8s/k8s.create.command.js +86 -0
- package/src/commands/k8s/k8s.delete.command.js +40 -0
- package/src/commands/k8s/k8s.docs.md +131 -0
- package/src/commands/k8s/k8s.get-kubeconfig.command.js +32 -0
- package/src/commands/k8s/k8s.get.command.js +43 -0
- package/src/commands/k8s/k8s.list.command.js +38 -0
- package/src/commands/keycloak/keycloak.command.js +17 -0
- package/src/commands/keycloak/keycloak.disable-ng.command.js +13 -0
- package/src/commands/keycloak/keycloak.docs.md +197 -0
- package/src/commands/keycloak/keycloak.enable-ng.command.js +13 -0
- package/src/commands/keycloak/keycloak.get.command.js +17 -0
- package/src/commands/keycloak/keycloak.open.command.js +13 -0
- package/src/commands/keycloak/keycloak.open.logs.command.js +13 -0
- package/src/commands/keycloak/keycloak.open.webui.command.js +13 -0
- package/src/commands/keycloak/keycloak.rebuild.command.js +13 -0
- package/src/commands/keycloak/keycloak.restart.command.js +13 -0
- package/src/commands/keycloak/keycloak.version.check.command.js +17 -0
- package/src/commands/keycloak/keycloak.version.command.js +17 -0
- package/src/commands/keycloak/keycloak.version.update.command.js +17 -0
- package/src/commands/kv/kv.command.js +99 -0
- package/src/commands/kv/kv.docs.md +27 -0
- package/src/commands/link/link.command.js +31 -0
- package/src/commands/link/link.docs.md +22 -0
- package/src/commands/{login.js → login/login.command.js} +44 -22
- package/src/commands/login/login.docs.md +16 -0
- package/src/commands/logout/logout.command.js +15 -0
- package/src/commands/logout/logout.docs.md +9 -0
- package/src/commands/logs/logs.command.js +81 -0
- package/src/commands/logs/logs.docs.md +22 -0
- package/src/commands/make-default/make-default.command.js +17 -0
- package/src/commands/make-default/make-default.docs.md +15 -0
- package/src/commands/matomo/matomo.command.js +17 -0
- package/src/commands/matomo/matomo.docs.md +109 -0
- package/src/commands/matomo/matomo.get.command.js +17 -0
- package/src/commands/matomo/matomo.open.command.js +13 -0
- package/src/commands/matomo/matomo.open.logs.command.js +13 -0
- package/src/commands/matomo/matomo.open.webui.command.js +13 -0
- package/src/commands/matomo/matomo.rebuild.command.js +13 -0
- package/src/commands/matomo/matomo.restart.command.js +13 -0
- package/src/commands/metabase/metabase.command.js +17 -0
- package/src/commands/metabase/metabase.docs.md +169 -0
- package/src/commands/metabase/metabase.get.command.js +17 -0
- package/src/commands/metabase/metabase.open.command.js +13 -0
- package/src/commands/metabase/metabase.open.logs.command.js +13 -0
- package/src/commands/metabase/metabase.open.webui.command.js +13 -0
- package/src/commands/metabase/metabase.rebuild.command.js +13 -0
- package/src/commands/metabase/metabase.restart.command.js +13 -0
- package/src/commands/metabase/metabase.version.check.command.js +17 -0
- package/src/commands/metabase/metabase.version.command.js +17 -0
- package/src/commands/metabase/metabase.version.update.command.js +17 -0
- package/src/commands/ng/ng.args.js +27 -0
- package/src/commands/ng/ng.command.js +45 -0
- package/src/commands/ng/ng.create.command.js +60 -0
- package/src/commands/ng/ng.create.external.command.js +44 -0
- package/src/commands/ng/ng.delete.command.js +22 -0
- package/src/commands/ng/ng.delete.external.command.js +25 -0
- package/src/commands/ng/ng.docs.md +214 -0
- package/src/commands/ng/ng.get-config.command.js +32 -0
- package/src/commands/ng/ng.get.command.js +22 -0
- package/src/commands/ng/ng.link.command.js +25 -0
- package/src/commands/ng/ng.options.js +9 -0
- package/src/commands/ng/ng.search.command.js +22 -0
- package/src/commands/ng/ng.unlink.command.js +25 -0
- package/src/commands/notify-email/notify-email.add.command.js +65 -0
- package/src/commands/notify-email/notify-email.command.js +61 -0
- package/src/commands/notify-email/notify-email.docs.md +60 -0
- package/src/commands/notify-email/notify-email.remove.command.js +24 -0
- package/src/commands/open/open.command.js +24 -0
- package/src/commands/open/open.docs.md +16 -0
- package/src/commands/otoroshi/otoroshi.command.js +17 -0
- package/src/commands/otoroshi/otoroshi.disable-ng.command.js +13 -0
- package/src/commands/otoroshi/otoroshi.docs.md +211 -0
- package/src/commands/otoroshi/otoroshi.enable-ng.command.js +13 -0
- package/src/commands/otoroshi/otoroshi.get-config.command.js +13 -0
- package/src/commands/otoroshi/otoroshi.get.command.js +17 -0
- package/src/commands/otoroshi/otoroshi.open.command.js +13 -0
- package/src/commands/otoroshi/otoroshi.open.logs.command.js +13 -0
- package/src/commands/otoroshi/otoroshi.open.webui.command.js +13 -0
- package/src/commands/otoroshi/otoroshi.rebuild.command.js +13 -0
- package/src/commands/otoroshi/otoroshi.restart.command.js +13 -0
- package/src/commands/otoroshi/otoroshi.version.check.command.js +17 -0
- package/src/commands/otoroshi/otoroshi.version.command.js +17 -0
- package/src/commands/otoroshi/otoroshi.version.update.command.js +17 -0
- package/src/commands/profile/profile.command.js +60 -0
- package/src/commands/profile/profile.docs.md +23 -0
- package/src/commands/profile/profile.open.command.js +12 -0
- package/src/commands/published-config/published-config.command.js +40 -0
- package/src/commands/published-config/published-config.docs.md +77 -0
- package/src/commands/published-config/published-config.import.command.js +29 -0
- package/src/commands/published-config/published-config.rm.command.js +27 -0
- package/src/commands/published-config/published-config.set.command.js +34 -0
- package/src/commands/restart/restart.command.js +77 -0
- package/src/commands/restart/restart.docs.md +21 -0
- package/src/commands/scale/scale.command.js +121 -0
- package/src/commands/scale/scale.docs.md +23 -0
- package/src/commands/service/service.command.js +91 -0
- package/src/commands/service/service.docs.md +104 -0
- package/src/commands/service/service.link-addon.command.js +24 -0
- package/src/commands/service/service.link-app.command.js +23 -0
- package/src/commands/service/service.unlink-addon.command.js +24 -0
- package/src/commands/service/service.unlink-app.command.js +23 -0
- package/src/commands/ssh/ssh.command.js +40 -0
- package/src/commands/ssh/ssh.docs.md +17 -0
- package/src/commands/ssh-keys/ssh-keys.add.command.js +41 -0
- package/src/commands/ssh-keys/ssh-keys.args.js +8 -0
- package/src/commands/ssh-keys/ssh-keys.command.js +50 -0
- package/src/commands/ssh-keys/ssh-keys.docs.md +66 -0
- package/src/commands/ssh-keys/ssh-keys.open.command.js +12 -0
- package/src/commands/ssh-keys/ssh-keys.remove-all.command.js +54 -0
- package/src/commands/ssh-keys/ssh-keys.remove.command.js +26 -0
- package/src/commands/status/status.command.js +122 -0
- package/src/commands/status/status.docs.md +17 -0
- package/src/commands/stop/stop.command.js +23 -0
- package/src/commands/stop/stop.docs.md +16 -0
- package/src/commands/tcp-redirs/tcp-redirs.add.command.js +24 -0
- package/src/commands/tcp-redirs/tcp-redirs.command.js +41 -0
- package/src/commands/tcp-redirs/tcp-redirs.docs.md +71 -0
- package/src/commands/tcp-redirs/tcp-redirs.list-namespaces.command.js +48 -0
- package/src/commands/tcp-redirs/tcp-redirs.options.js +11 -0
- package/src/commands/tcp-redirs/tcp-redirs.remove.command.js +34 -0
- package/src/commands/tokens/tokens.command.js +43 -0
- package/src/commands/tokens/tokens.create.command.js +108 -0
- package/src/commands/tokens/tokens.docs.md +50 -0
- package/src/commands/tokens/tokens.revoke.command.js +25 -0
- package/src/commands/unlink/unlink.command.js +21 -0
- package/src/commands/unlink/unlink.docs.md +15 -0
- package/src/commands/version/version.command.js +13 -0
- package/src/commands/version/version.docs.md +9 -0
- package/src/commands/webhooks/webhooks.add.command.js +51 -0
- package/src/commands/webhooks/webhooks.command.js +57 -0
- package/src/commands/webhooks/webhooks.docs.md +61 -0
- package/src/commands/webhooks/webhooks.remove.command.js +24 -0
- package/src/lib/cliparse-patched.js +192 -0
- package/src/lib/define-argument.js +7 -0
- package/src/lib/define-argument.types.d.ts +23 -0
- package/src/lib/define-command.js +7 -0
- package/src/lib/define-command.types.d.ts +85 -0
- package/src/lib/define-common.types.d.ts +18 -0
- package/src/lib/define-option.js +7 -0
- package/src/lib/define-option.types.d.ts +29 -0
- package/src/lib/get-command-info.js +86 -0
- package/src/lib/get-command-info.types.d.ts +42 -0
- package/src/lib/zod-utils.js +66 -0
- package/src/models/addon.js +2 -3
- package/src/models/application.js +4 -5
- package/src/models/application_configuration.js +5 -23
- package/src/models/domain.js +34 -2
- package/src/models/exit-strategy-option.js +0 -9
- package/src/models/git.js +1 -4
- package/src/models/log-v4.js +5 -0
- package/src/models/log.js +5 -0
- package/src/models/namespaces.js +1 -2
- package/src/models/notification.js +1 -7
- package/src/parsers.js +33 -92
- package/src/command-options.js +0 -55
- package/src/command-promise-handler.js +0 -16
- package/src/commands/accesslogs.js +0 -138
- package/src/commands/addon.js +0 -391
- package/src/commands/applications.js +0 -123
- package/src/commands/cancel-deploy.js +0 -19
- package/src/commands/config.js +0 -47
- package/src/commands/console.js +0 -20
- package/src/commands/create.js +0 -129
- package/src/commands/database.js +0 -73
- package/src/commands/delete.js +0 -24
- package/src/commands/deploy.js +0 -133
- package/src/commands/diag.js +0 -126
- package/src/commands/domain.js +0 -445
- package/src/commands/drain.js +0 -164
- package/src/commands/emails.js +0 -156
- package/src/commands/env.js +0 -124
- package/src/commands/features.js +0 -87
- package/src/commands/k8s.js +0 -193
- package/src/commands/keycloak.js +0 -138
- package/src/commands/kv.js +0 -93
- package/src/commands/link.js +0 -20
- package/src/commands/logout.js +0 -8
- package/src/commands/logs.js +0 -45
- package/src/commands/makeDefault.js +0 -11
- package/src/commands/matomo.js +0 -85
- package/src/commands/metabase.js +0 -112
- package/src/commands/ng.js +0 -202
- package/src/commands/notify-email.js +0 -99
- package/src/commands/open.js +0 -13
- package/src/commands/otoroshi.js +0 -149
- package/src/commands/profile.js +0 -55
- package/src/commands/published-config.js +0 -70
- package/src/commands/restart.js +0 -52
- package/src/commands/scale.js +0 -66
- package/src/commands/service.js +0 -105
- package/src/commands/ssh-keys.js +0 -144
- package/src/commands/ssh.js +0 -20
- package/src/commands/status.js +0 -115
- package/src/commands/stop.js +0 -12
- package/src/commands/tcp-redirs.js +0 -80
- package/src/commands/tokens.js +0 -144
- package/src/commands/unlink.js +0 -14
- package/src/commands/version.js +0 -6
- package/src/commands/webhooks.js +0 -74
package/src/commands/create.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { styleText } from '../lib/style-text.js';
|
|
3
|
-
import { Logger } from '../logger.js';
|
|
4
|
-
import * as AppConfig from '../models/app_configuration.js';
|
|
5
|
-
import * as Application from '../models/application.js';
|
|
6
|
-
import { conf } from '../models/configuration.js';
|
|
7
|
-
import { isGitWorkingDirectoryClean, isInsideGitRepo } from '../models/git.js';
|
|
8
|
-
|
|
9
|
-
export async function create(params) {
|
|
10
|
-
const { type: typeName } = params.options;
|
|
11
|
-
const [rawName] = params.args;
|
|
12
|
-
const { org: orgaIdOrName, alias, region, github: githubOwnerRepo, format, task: taskCommand } = params.options;
|
|
13
|
-
const { apps } = await AppConfig.loadApplicationConf();
|
|
14
|
-
|
|
15
|
-
// Application name is optionnal, use current directory name if not specified (empty string)
|
|
16
|
-
const name = rawName !== '' ? rawName : getCurrentDirectoryName();
|
|
17
|
-
|
|
18
|
-
const isTask = taskCommand != null;
|
|
19
|
-
const envVars = isTask ? { CC_RUN_COMMAND: taskCommand } : {};
|
|
20
|
-
|
|
21
|
-
AppConfig.checkAlreadyLinked(apps, name, alias);
|
|
22
|
-
|
|
23
|
-
const github = getGithubDetails(githubOwnerRepo);
|
|
24
|
-
const app = await Application.create(name, typeName, region, orgaIdOrName, github, isTask, envVars);
|
|
25
|
-
await AppConfig.addLinkedApplication(app, alias);
|
|
26
|
-
|
|
27
|
-
switch (format) {
|
|
28
|
-
case 'json': {
|
|
29
|
-
Logger.printJson({
|
|
30
|
-
id: app.id,
|
|
31
|
-
name: app.name,
|
|
32
|
-
executedAs: app.instance.lifetime,
|
|
33
|
-
env: app.env,
|
|
34
|
-
deployUrl: app.deployUrl,
|
|
35
|
-
});
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
case 'human':
|
|
40
|
-
default:
|
|
41
|
-
await displayAppCreation(app, alias, github, taskCommand);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function getGithubDetails(githubOwnerRepo) {
|
|
46
|
-
if (githubOwnerRepo != null) {
|
|
47
|
-
const [owner, name] = githubOwnerRepo.split('/');
|
|
48
|
-
return { owner, name };
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function getCurrentDirectoryName() {
|
|
53
|
-
return path.basename(process.cwd());
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Display the application creation message in a human-readable format
|
|
58
|
-
* @param {Object} app - The application object
|
|
59
|
-
* @param {string} alias - The alias of the application
|
|
60
|
-
* @param {Object} github - The GitHub details
|
|
61
|
-
* @param {string} taskCommand - The task command
|
|
62
|
-
*/
|
|
63
|
-
async function displayAppCreation(app, alias, github, taskCommand) {
|
|
64
|
-
Logger.printSuccess(`Application ${styleText('green', app.name)} successfully created!`);
|
|
65
|
-
|
|
66
|
-
const hasDistinctAlias = alias != null && alias !== app.name;
|
|
67
|
-
const isTask = app.instance.lifetime === 'TASK';
|
|
68
|
-
|
|
69
|
-
Logger.println();
|
|
70
|
-
printFieldsAsTable(2, {
|
|
71
|
-
Type: styleText('blue', `⬢ ${app.instance.variant.name}`),
|
|
72
|
-
ID: app.id,
|
|
73
|
-
'Organisation ID': app.ownerId,
|
|
74
|
-
Name: app.name,
|
|
75
|
-
GitHub: github != null && `${github.owner}/${github.name}`,
|
|
76
|
-
Alias: hasDistinctAlias && alias,
|
|
77
|
-
Zone: app.zone,
|
|
78
|
-
Task: isTask && `"${taskCommand}"`,
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
Logger.println();
|
|
82
|
-
Logger.println(' ' + styleText('bold', 'Next steps:'));
|
|
83
|
-
|
|
84
|
-
if (!github) {
|
|
85
|
-
const isInsideGit = await isInsideGitRepo();
|
|
86
|
-
if (!isInsideGit) {
|
|
87
|
-
Logger.println(` ${styleText('yellow', '!')} Initialize a git repository first, for example:`);
|
|
88
|
-
Logger.println(` ${shellCommand('git init')}`);
|
|
89
|
-
Logger.println(` ${shellCommand('git add .')}`);
|
|
90
|
-
Logger.println(` ${shellCommand('git commit -m "Initial commit"')}`);
|
|
91
|
-
Logger.println();
|
|
92
|
-
} else {
|
|
93
|
-
const isClean = await isGitWorkingDirectoryClean();
|
|
94
|
-
if (!isClean) {
|
|
95
|
-
Logger.println(` ${styleText('yellow', '!')} Commit your changes first:`);
|
|
96
|
-
Logger.println(` ${shellCommand('git add .')}`);
|
|
97
|
-
Logger.println(` ${shellCommand('git commit -m "My changes"')}`);
|
|
98
|
-
Logger.println();
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (github) {
|
|
104
|
-
Logger.println(
|
|
105
|
-
` ${styleText('blue', '→')} Push changes to ${styleText('blue', `${github.owner}/${github.name}`)} GitHub repository to trigger a deployment, or ${styleText('blue', 'clever restart')} the latest pushed commit`,
|
|
106
|
-
);
|
|
107
|
-
} else {
|
|
108
|
-
Logger.println(
|
|
109
|
-
` ${styleText('blue', '→')} Run ${styleText('blue', 'clever deploy')} ${isTask ? 'to execute your task' : 'to deploy your application'}`,
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
Logger.println(
|
|
114
|
-
` ${styleText('blue', '→')} Manage your application at: ${styleText('underline', `${conf.GOTO_URL}/${app.id}`)}`,
|
|
115
|
-
);
|
|
116
|
-
Logger.println('');
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function shellCommand(command) {
|
|
120
|
-
return `${styleText('grey', '$')} ${styleText('yellow', command)}`;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function printFieldsAsTable(indent, fields) {
|
|
124
|
-
const fieldsWithValues = Object.fromEntries(Object.entries(fields).filter(([_, value]) => typeof value === 'string'));
|
|
125
|
-
const labelMaxWidth = Math.max(...Object.keys(fieldsWithValues).map((label) => label.length));
|
|
126
|
-
return Object.entries(fieldsWithValues).forEach(([label, value]) => {
|
|
127
|
-
Logger.println(`${' '.repeat(indent)}${label.padEnd(labelMaxWidth, ' ')} ${styleText('grey', value)}`);
|
|
128
|
-
});
|
|
129
|
-
}
|
package/src/commands/database.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { getBackups } from '@clevercloud/client/esm/api/v2/backups.js';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import { Writable } from 'node:stream';
|
|
4
|
-
import { formatTable } from '../format-table.js';
|
|
5
|
-
import { Logger } from '../logger.js';
|
|
6
|
-
import { findOwnerId } from '../models/addon.js';
|
|
7
|
-
import { resolveAddonId, resolveRealId } from '../models/ids-resolver.js';
|
|
8
|
-
import { sendToApi } from '../models/send-to-api.js';
|
|
9
|
-
|
|
10
|
-
export async function listBackups(params) {
|
|
11
|
-
const { org, format } = params.options;
|
|
12
|
-
const [addonIdOrRealId] = params.args;
|
|
13
|
-
|
|
14
|
-
const realId = await resolveRealId(addonIdOrRealId);
|
|
15
|
-
const addonId = await resolveAddonId(addonIdOrRealId);
|
|
16
|
-
const ownerId = await findOwnerId(org, realId);
|
|
17
|
-
|
|
18
|
-
const backups = await getBackups({ ownerId, ref: realId }).then(sendToApi);
|
|
19
|
-
|
|
20
|
-
if (backups.length === 0 && format === 'human') {
|
|
21
|
-
Logger.println('There are no backups yet');
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const sortedBackups = backups.sort((a, b) => a.creation_date.localeCompare(b.creation_date));
|
|
26
|
-
|
|
27
|
-
switch (format) {
|
|
28
|
-
case 'json': {
|
|
29
|
-
const formattedBackups = sortedBackups.map((backup) => {
|
|
30
|
-
return {
|
|
31
|
-
addonId: addonId,
|
|
32
|
-
backupId: backup.backup_id,
|
|
33
|
-
creationDate: backup.creation_date,
|
|
34
|
-
downloadUrl: backup.download_url,
|
|
35
|
-
ownerId: ownerId,
|
|
36
|
-
realId: realId,
|
|
37
|
-
status: backup.status,
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
Logger.printJson(formattedBackups);
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
case 'human': {
|
|
44
|
-
const formattedLines = sortedBackups.map((backup) => [backup.backup_id, backup.creation_date, backup.status]);
|
|
45
|
-
|
|
46
|
-
const head = ['BACKUP ID', 'CREATION DATE', 'STATUS'];
|
|
47
|
-
|
|
48
|
-
Logger.println(formatTable([head, ...formattedLines]));
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export async function downloadBackups(params) {
|
|
54
|
-
const { org, output } = params.options;
|
|
55
|
-
const [addonIdOrRealId, backupId] = params.args;
|
|
56
|
-
|
|
57
|
-
const addonId = await resolveRealId(addonIdOrRealId);
|
|
58
|
-
const ownerId = await findOwnerId(org, addonId);
|
|
59
|
-
|
|
60
|
-
const backups = await getBackups({ ownerId, ref: addonId }).then(sendToApi);
|
|
61
|
-
const backup = backups.find((backup) => backup.backup_id === backupId);
|
|
62
|
-
|
|
63
|
-
if (backup == null) {
|
|
64
|
-
throw new Error('no backup with this ID');
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const response = await globalThis.fetch(backup.download_url);
|
|
68
|
-
if (!response.ok) {
|
|
69
|
-
throw new Error('Failed to download backup');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
await response.body.pipeTo(Writable.toWeb(output ? fs.createWriteStream(output) : process.stdout));
|
|
73
|
-
}
|
package/src/commands/delete.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { styleText } from '../lib/style-text.js';
|
|
2
|
-
import { Logger } from '../logger.js';
|
|
3
|
-
import * as AppConfig from '../models/app_configuration.js';
|
|
4
|
-
import * as Application from '../models/application.js';
|
|
5
|
-
|
|
6
|
-
export async function deleteApp(params) {
|
|
7
|
-
const { alias, app: appIdOrName, yes: skipConfirmation } = params.options;
|
|
8
|
-
const { ownerId, appId } = await Application.resolveId(appIdOrName, alias);
|
|
9
|
-
|
|
10
|
-
const app = await Application.get(ownerId, appId);
|
|
11
|
-
if (app == null) {
|
|
12
|
-
throw new Error("The application doesn't exist");
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// delete app
|
|
16
|
-
await Application.deleteApp(app, skipConfirmation);
|
|
17
|
-
Logger.printSuccess(`Application ${styleText('green', styleText('bold', `${app.name}`))} successfully deleted!`);
|
|
18
|
-
Logger.println(` ${styleText('grey', '•')} Application ID: ${styleText('grey', app.id)}`);
|
|
19
|
-
|
|
20
|
-
const wasUnlinked = await AppConfig.removeLinkedApplication({ appId, alias });
|
|
21
|
-
if (wasUnlinked) {
|
|
22
|
-
Logger.println(` ${styleText('blue', '→')} Local alias ${styleText('blue', alias || app.name)} unlinked`);
|
|
23
|
-
}
|
|
24
|
-
}
|
package/src/commands/deploy.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { getAllDeployments } from '@clevercloud/client/esm/api/v2/application.js';
|
|
2
|
-
import dedent from 'dedent';
|
|
3
|
-
import { styleText } from '../lib/style-text.js';
|
|
4
|
-
import { Logger } from '../logger.js';
|
|
5
|
-
import * as AppConfig from '../models/app_configuration.js';
|
|
6
|
-
import * as Application from '../models/application.js';
|
|
7
|
-
import * as ExitStrategy from '../models/exit-strategy-option.js';
|
|
8
|
-
import * as git from '../models/git.js';
|
|
9
|
-
import * as Log from '../models/log-v4.js';
|
|
10
|
-
import { sendToApi } from '../models/send-to-api.js';
|
|
11
|
-
|
|
12
|
-
// Once the API call to redeploy() has been triggered successfully,
|
|
13
|
-
// the rest (waiting for deployment state to evolve and displaying logs) is done with auto retry (resilient to network failures)
|
|
14
|
-
export async function deploy(params) {
|
|
15
|
-
const {
|
|
16
|
-
alias,
|
|
17
|
-
branch: branchName,
|
|
18
|
-
tag: tagName,
|
|
19
|
-
quiet,
|
|
20
|
-
force,
|
|
21
|
-
follow,
|
|
22
|
-
'same-commit-policy': sameCommitPolicy,
|
|
23
|
-
'exit-on': exitOnDeploy,
|
|
24
|
-
} = params.options;
|
|
25
|
-
|
|
26
|
-
const exitStrategy = ExitStrategy.get(follow, exitOnDeploy);
|
|
27
|
-
|
|
28
|
-
const appData = await AppConfig.getAppDetails({ alias });
|
|
29
|
-
const { ownerId, appId } = appData;
|
|
30
|
-
|
|
31
|
-
const branchRefspec = await getBranchToDeploy(branchName, tagName);
|
|
32
|
-
const commitIdToPush = await git.getBranchCommit(branchRefspec);
|
|
33
|
-
const remoteHeadCommitId = await git.getRemoteCommit(appData.deployUrl);
|
|
34
|
-
const deployedCommitId = await Application.get(ownerId, appId).then(({ commitId }) => commitId);
|
|
35
|
-
|
|
36
|
-
await git.addRemote(appData.alias, appData.deployUrl);
|
|
37
|
-
|
|
38
|
-
if (commitIdToPush === remoteHeadCommitId) {
|
|
39
|
-
switch (sameCommitPolicy) {
|
|
40
|
-
case 'ignore':
|
|
41
|
-
Logger.printSuccess(`The application is up-to-date (${styleText('grey', remoteHeadCommitId)})`);
|
|
42
|
-
return;
|
|
43
|
-
case 'restart':
|
|
44
|
-
return restartOnSameCommit(ownerId, appId, commitIdToPush, quiet, false, exitStrategy);
|
|
45
|
-
case 'rebuild':
|
|
46
|
-
return restartOnSameCommit(ownerId, appId, commitIdToPush, quiet, true, exitStrategy);
|
|
47
|
-
case 'error':
|
|
48
|
-
default: {
|
|
49
|
-
const restartCommand =
|
|
50
|
-
commitIdToPush !== deployedCommitId ? `clever restart --commit ${commitIdToPush}` : 'clever restart';
|
|
51
|
-
throw new Error(dedent`
|
|
52
|
-
Remote HEAD has the same commit as the one to push ${styleText('grey', `(${remoteHeadCommitId})`)}, your application is up-to-date.
|
|
53
|
-
Create a new commit, use ${styleText('blue', restartCommand)} or the ${styleText('blue', '--same-commit-policy')} option.
|
|
54
|
-
`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// It's sometimes tricky to figure out the deployment ID for the current git push.
|
|
60
|
-
// We on have the commit ID but there in a situation where the last deployment was cancelled, it may have the same commit ID.
|
|
61
|
-
// So before pushing, we get the last deployments so we can after the push figure out which deployment is new…
|
|
62
|
-
const knownDeployments = await getAllDeployments({ id: ownerId, appId, limit: 5 }).then(sendToApi);
|
|
63
|
-
|
|
64
|
-
Logger.println(dedent`
|
|
65
|
-
${styleText('bold', `🚀 Deploying ${styleText('green', appData.name)}`)}
|
|
66
|
-
Application ID ${styleText('grey', `${appId}`)}
|
|
67
|
-
Organisation ID ${styleText('grey', `${ownerId}`)}
|
|
68
|
-
`);
|
|
69
|
-
|
|
70
|
-
Logger.println();
|
|
71
|
-
|
|
72
|
-
Logger.println(styleText('bold', '🔀 Git information'));
|
|
73
|
-
if (remoteHeadCommitId == null || deployedCommitId == null) {
|
|
74
|
-
Logger.println(` ${styleText('yellow', '!')} App is brand new, no commits on remote yet`);
|
|
75
|
-
} else {
|
|
76
|
-
Logger.println(` Remote head ${styleText('yellow', remoteHeadCommitId)} (${branchRefspec})`);
|
|
77
|
-
Logger.println(` Deployed commit ${styleText('yellow', deployedCommitId)}`);
|
|
78
|
-
}
|
|
79
|
-
Logger.println(
|
|
80
|
-
` Local commit ${styleText('yellow', commitIdToPush)} ${styleText('blue', '[will be deployed]')}`,
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
Logger.println();
|
|
84
|
-
|
|
85
|
-
Logger.println(dedent`
|
|
86
|
-
${styleText('bold', '🔄 Deployment progress')}
|
|
87
|
-
${styleText('blue', '→ Pushing source code to Clever Cloud…')}
|
|
88
|
-
`);
|
|
89
|
-
|
|
90
|
-
await git.push(appData.deployUrl, commitIdToPush, force).catch(async (e) => {
|
|
91
|
-
const isShallow = await git.isShallow();
|
|
92
|
-
if (isShallow) {
|
|
93
|
-
throw new Error(
|
|
94
|
-
'Failed to push your source code because your repository is shallow and therefore cannot be pushed to the Clever Cloud remote.',
|
|
95
|
-
);
|
|
96
|
-
} else {
|
|
97
|
-
throw e;
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
await Logger.println(` ${styleText('green', '✓ Code pushed to Clever Cloud')}`);
|
|
102
|
-
|
|
103
|
-
return Log.watchDeploymentAndDisplayLogs({
|
|
104
|
-
ownerId,
|
|
105
|
-
appId,
|
|
106
|
-
commitId: commitIdToPush,
|
|
107
|
-
knownDeployments,
|
|
108
|
-
quiet,
|
|
109
|
-
exitStrategy,
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
async function restartOnSameCommit(ownerId, appId, commitIdToPush, quiet, withoutCache, exitStrategy) {
|
|
114
|
-
const cacheSuffix = withoutCache ? ' without using cache' : '';
|
|
115
|
-
Logger.println(`🔄 Restarting ${styleText('bold', appId)}${cacheSuffix} ${styleText('grey', `(${commitIdToPush})`)}`);
|
|
116
|
-
|
|
117
|
-
const restart = await Application.redeploy(ownerId, appId, commitIdToPush, withoutCache);
|
|
118
|
-
return Log.watchDeploymentAndDisplayLogs({ ownerId, appId, deploymentId: restart.deploymentId, quiet, exitStrategy });
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async function getBranchToDeploy(branchName, tagName) {
|
|
122
|
-
if (tagName) {
|
|
123
|
-
const useTag = await git.isExistingTag(tagName);
|
|
124
|
-
if (useTag) {
|
|
125
|
-
const tagRefspec = await git.getFullBranch(tagName);
|
|
126
|
-
return tagRefspec;
|
|
127
|
-
} else {
|
|
128
|
-
throw new Error(`Tag ${tagName} doesn't exist locally`);
|
|
129
|
-
}
|
|
130
|
-
} else {
|
|
131
|
-
return await git.getFullBranch(branchName);
|
|
132
|
-
}
|
|
133
|
-
}
|
package/src/commands/diag.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { releaseInfo as getLinuxInfos } from 'linux-release-info';
|
|
2
|
-
import os from 'node:os';
|
|
3
|
-
import pkg from '../../package.json' with { type: 'json' };
|
|
4
|
-
import { styleText } from '../lib/style-text.js';
|
|
5
|
-
import { Logger } from '../logger.js';
|
|
6
|
-
import { conf, loadOAuthConf } from '../models/configuration.js';
|
|
7
|
-
import * as User from '../models/user.js';
|
|
8
|
-
|
|
9
|
-
export async function diag(params) {
|
|
10
|
-
const { format } = params.options;
|
|
11
|
-
|
|
12
|
-
/** @type {string} */
|
|
13
|
-
const userId = await User.getCurrentId().catch(() => null);
|
|
14
|
-
const authDetails = await loadOAuthConf();
|
|
15
|
-
|
|
16
|
-
function getAuthState() {
|
|
17
|
-
if (authDetails.token == null) {
|
|
18
|
-
return 'not connected';
|
|
19
|
-
}
|
|
20
|
-
if (userId == null) {
|
|
21
|
-
return 'authentication failed';
|
|
22
|
-
}
|
|
23
|
-
return 'authenticated';
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const formattedDiag = {
|
|
27
|
-
version: pkg.version,
|
|
28
|
-
commitId: pkg.commitId,
|
|
29
|
-
nodeVersion: process.version,
|
|
30
|
-
platform: os.platform(),
|
|
31
|
-
release: os.release(),
|
|
32
|
-
arch: process.arch,
|
|
33
|
-
shell: getShell(),
|
|
34
|
-
terminal: getTerminal(),
|
|
35
|
-
isPackaged: process.pkg != null,
|
|
36
|
-
execPath: process.execPath,
|
|
37
|
-
configFile: conf.CONFIGURATION_FILE,
|
|
38
|
-
authSource: authDetails.source,
|
|
39
|
-
oAuthToken: authDetails.token,
|
|
40
|
-
authState: getAuthState(),
|
|
41
|
-
userId,
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const linuxInfos = await getLinuxInfos()
|
|
45
|
-
.then(({ pretty_name, name, id }) => pretty_name || name || id)
|
|
46
|
-
.catch(() => null);
|
|
47
|
-
if (linuxInfos != null) {
|
|
48
|
-
formattedDiag.linuxInfos = linuxInfos;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
switch (format) {
|
|
52
|
-
case 'json': {
|
|
53
|
-
Logger.printJson(formattedDiag);
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
case 'human':
|
|
57
|
-
default: {
|
|
58
|
-
Logger.println('clever-tools ' + styleText('green', formattedDiag.version));
|
|
59
|
-
// Only available in built binaries
|
|
60
|
-
if (formattedDiag.commitId) {
|
|
61
|
-
Logger.println('Commit ' + styleText('green', formattedDiag.commitId));
|
|
62
|
-
}
|
|
63
|
-
Logger.println('Node.js ' + styleText('green', formattedDiag.nodeVersion));
|
|
64
|
-
Logger.println('Platform ' + styleText('green', formattedDiag.platform));
|
|
65
|
-
Logger.println('Release ' + styleText('green', formattedDiag.release));
|
|
66
|
-
Logger.println('Architecture ' + styleText('green', formattedDiag.arch));
|
|
67
|
-
if (formattedDiag.linuxInfos != null) {
|
|
68
|
-
Logger.println('Linux ' + styleText('green', formattedDiag.linuxInfos));
|
|
69
|
-
}
|
|
70
|
-
Logger.println('Shell ' + styleText('green', formattedDiag.shell));
|
|
71
|
-
Logger.println('Terminal ' + styleText('green', formattedDiag.terminal));
|
|
72
|
-
Logger.println('Packaged ' + styleText('green', formattedDiag.isPackaged));
|
|
73
|
-
Logger.println('Exec path ' + styleText('green', formattedDiag.execPath));
|
|
74
|
-
Logger.println('Config file ' + styleText('green', formattedDiag.configFile));
|
|
75
|
-
|
|
76
|
-
Logger.println('Auth source ' + styleText('green', formattedDiag.authSource));
|
|
77
|
-
|
|
78
|
-
const token =
|
|
79
|
-
formattedDiag.oAuthToken == null ? styleText('red', '(none)') : styleText('green', formattedDiag.oAuthToken);
|
|
80
|
-
Logger.println('oAuth token ' + token);
|
|
81
|
-
|
|
82
|
-
switch (formattedDiag.authState) {
|
|
83
|
-
case 'authenticated': {
|
|
84
|
-
Logger.println('User ID ' + styleText('green', formattedDiag.userId));
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
case 'authentication failed': {
|
|
88
|
-
Logger.println('User ID ' + styleText('red', 'Authentication failed'));
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
case 'not connected': {
|
|
92
|
-
Logger.println('User ID ' + styleText('red', 'Not connected'));
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function getShell() {
|
|
100
|
-
const platform = os.platform();
|
|
101
|
-
|
|
102
|
-
if (platform === 'win32') {
|
|
103
|
-
if (process.env.PSModulePath) {
|
|
104
|
-
if (process.env.WT_SESSION) {
|
|
105
|
-
return 'PowerShell (Windows Terminal)';
|
|
106
|
-
}
|
|
107
|
-
if (process.env.PSVersionTable || process.env.POWERSHELL_DISTRIBUTION_CHANNEL) {
|
|
108
|
-
return 'PowerShell Core';
|
|
109
|
-
}
|
|
110
|
-
return 'Windows PowerShell';
|
|
111
|
-
}
|
|
112
|
-
if (process.env.WT_SESSION) {
|
|
113
|
-
return 'Windows Terminal (cmd)';
|
|
114
|
-
}
|
|
115
|
-
return process.env.ComSpec || 'cmd.exe';
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return process.env.SHELL || 'unknown';
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function getTerminal() {
|
|
122
|
-
if (process.env.WT_SESSION) {
|
|
123
|
-
return 'Windows Terminal';
|
|
124
|
-
}
|
|
125
|
-
return process.env.TERM_PROGRAM || process.env.TERMINAL_EMULATOR || process.env.TERM;
|
|
126
|
-
}
|