clever-tools 3.8.2 → 3.9.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.
Files changed (79) hide show
  1. package/bin/clever.js +177 -426
  2. package/package.json +11 -5
  3. package/src/command-options.js +4 -10
  4. package/src/command-promise-handler.js +5 -7
  5. package/src/commands/accesslogs.js +9 -13
  6. package/src/commands/activity.js +10 -14
  7. package/src/commands/addon.js +82 -36
  8. package/src/commands/applications.js +9 -16
  9. package/src/commands/cancel-deploy.js +5 -9
  10. package/src/commands/config.js +7 -11
  11. package/src/commands/console.js +5 -9
  12. package/src/commands/create.js +5 -9
  13. package/src/commands/curl.js +7 -11
  14. package/src/commands/database.js +13 -16
  15. package/src/commands/delete.js +4 -8
  16. package/src/commands/deploy.js +10 -14
  17. package/src/commands/diag.js +9 -11
  18. package/src/commands/domain.js +348 -17
  19. package/src/commands/drain.js +10 -20
  20. package/src/commands/env.js +13 -17
  21. package/src/commands/link.js +3 -7
  22. package/src/commands/login.js +13 -15
  23. package/src/commands/logout.js +3 -7
  24. package/src/commands/logs.js +9 -13
  25. package/src/commands/makeDefault.js +3 -7
  26. package/src/commands/notify-email.js +9 -19
  27. package/src/commands/open.js +5 -9
  28. package/src/commands/profile.js +21 -12
  29. package/src/commands/published-config.js +11 -15
  30. package/src/commands/restart.js +7 -11
  31. package/src/commands/scale.js +3 -7
  32. package/src/commands/service.js +8 -18
  33. package/src/commands/ssh.js +4 -8
  34. package/src/commands/status.js +7 -11
  35. package/src/commands/stop.js +5 -9
  36. package/src/commands/tcp-redirs.js +11 -15
  37. package/src/commands/unlink.js +4 -8
  38. package/src/commands/version.js +4 -6
  39. package/src/commands/webhooks.js +8 -16
  40. package/src/format-table.js +4 -8
  41. package/src/initial-setup.js +49 -0
  42. package/src/load-package-json.cjs +5 -0
  43. package/src/logger.js +5 -8
  44. package/src/models/activity.js +3 -7
  45. package/src/models/addon.js +52 -54
  46. package/src/models/app_configuration.js +18 -31
  47. package/src/models/application.js +37 -61
  48. package/src/models/application_configuration.js +11 -15
  49. package/src/models/configuration.js +11 -15
  50. package/src/models/deployments.js +6 -10
  51. package/src/models/domain.js +6 -10
  52. package/src/models/drain.js +5 -13
  53. package/src/models/exit-strategy-option.js +4 -8
  54. package/src/models/fs-utils.js +3 -7
  55. package/src/models/git.js +19 -34
  56. package/src/models/ids-resolver.js +6 -12
  57. package/src/models/interact.js +2 -6
  58. package/src/models/isomorphic-http-with-agent.js +3 -9
  59. package/src/models/json-array.js +1 -3
  60. package/src/models/log-v4.js +10 -12
  61. package/src/models/log.js +11 -15
  62. package/src/models/namespaces.js +7 -13
  63. package/src/models/node-dns-resolver.js +43 -0
  64. package/src/models/notification.js +8 -17
  65. package/src/models/organisation.js +4 -10
  66. package/src/models/send-to-api.js +17 -13
  67. package/src/models/user.js +16 -9
  68. package/src/models/utils.js +2 -6
  69. package/src/models/variables.js +4 -10
  70. package/src/parsers.js +21 -71
  71. package/src/commands/networkgroups/commands.js +0 -7
  72. package/src/commands/networkgroups/index.js +0 -67
  73. package/src/commands/networkgroups/members.js +0 -80
  74. package/src/commands/networkgroups/peers.js +0 -83
  75. package/src/models/format-ng-table.js +0 -115
  76. package/src/models/format-string.js +0 -44
  77. package/src/models/networkgroup.js +0 -64
  78. package/src/models/wireguard-conf.js +0 -95
  79. package/src/models/wireguard.js +0 -75
@@ -1,9 +1,7 @@
1
- 'use strict';
1
+ import cliparse from 'cliparse';
2
+ import colors from 'colors/safe.js';
2
3
 
3
- const cliparse = require('cliparse');
4
- const colors = require('colors/safe');
5
-
6
- const Logger = require('../logger.js');
4
+ import { Logger } from '../logger.js';
7
5
 
8
6
  const CONFIG_KEYS = [
9
7
  { id: 'name', name: 'name', displayName: 'Name', kind: 'string' },
@@ -14,11 +12,11 @@ const CONFIG_KEYS = [
14
12
  { id: 'force-https', name: 'forceHttps', displayName: 'Force redirection of HTTP to HTTPS', kind: 'force-https' },
15
13
  ];
16
14
 
17
- function listAvailableIds () {
15
+ export function listAvailableIds () {
18
16
  return CONFIG_KEYS.map((config) => config.id);
19
17
  }
20
18
 
21
- function getById (id) {
19
+ export function getById (id) {
22
20
  const config = CONFIG_KEYS.find((config) => config.id === id);
23
21
  if (config == null) {
24
22
  Logger.error(`Invalid configuration name: ${id}.`);
@@ -44,7 +42,7 @@ function display (config, value) {
44
42
  }
45
43
  }
46
44
 
47
- function parse (config, value) {
45
+ export function parse (config, value) {
48
46
  switch (config.kind) {
49
47
  case 'bool': {
50
48
  return (value !== 'false');
@@ -61,7 +59,7 @@ function parse (config, value) {
61
59
  }
62
60
  }
63
61
 
64
- function getUpdateOptions () {
62
+ export function getUpdateOptions () {
65
63
  return CONFIG_KEYS
66
64
  .map((config) => getConfigOptions(config))
67
65
  .reduce((a, b) => [...a, ...b], []);
@@ -85,7 +83,7 @@ function getConfigOptions (config) {
85
83
  }
86
84
  }
87
85
 
88
- function parseOptions (options) {
86
+ export function parseOptions (options) {
89
87
  const newOptions = CONFIG_KEYS
90
88
  .map((config) => parseConfigOption(config, options))
91
89
  .filter((a) => a != null);
@@ -143,22 +141,20 @@ function printConfig (app, config) {
143
141
  }
144
142
  }
145
143
 
146
- function printById (app, id) {
144
+ export function printById (app, id) {
147
145
  const config = getById(id);
148
146
  if (config != null) {
149
147
  printConfig(app, config);
150
148
  }
151
149
  }
152
150
 
153
- function printByName (app, name) {
151
+ export function printByName (app, name) {
154
152
  const config = CONFIG_KEYS.find((config) => config.name === name);
155
153
  printConfig(app, config);
156
154
  }
157
155
 
158
- function print (app) {
156
+ export function print (app) {
159
157
  for (const config of CONFIG_KEYS) {
160
158
  printConfig(app, config);
161
159
  }
162
160
  }
163
-
164
- module.exports = { listAvailableIds, getById, getUpdateOptions, parse, parseOptions, printById, printByName, print };
@@ -1,13 +1,11 @@
1
- 'use strict';
1
+ import { promises as fs } from 'node:fs';
2
+ import path from 'node:path';
2
3
 
3
- const { promises: fs } = require('fs');
4
- const path = require('path');
4
+ import commonEnv from 'common-env';
5
+ import mkdirp from 'mkdirp';
6
+ import xdg from 'xdg';
5
7
 
6
- const commonEnv = require('common-env');
7
- const mkdirp = require('mkdirp');
8
- const xdg = require('xdg');
9
-
10
- const Logger = require('../logger.js');
8
+ import { Logger } from '../logger.js';
11
9
  const env = commonEnv(Logger);
12
10
 
13
11
  const CONFIG_FILES = {
@@ -22,7 +20,7 @@ function getConfigPath (configFile) {
22
20
  return path.resolve(configDir, configFile);
23
21
  }
24
22
 
25
- async function loadOAuthConf () {
23
+ export async function loadOAuthConf () {
26
24
  Logger.debug('Load configuration from environment variables');
27
25
  if (process.env.CLEVER_TOKEN != null && process.env.CLEVER_SECRET != null) {
28
26
  return {
@@ -49,7 +47,7 @@ async function loadOAuthConf () {
49
47
  }
50
48
  }
51
49
 
52
- async function writeOAuthConf (oauthData) {
50
+ export async function writeOAuthConf (oauthData) {
53
51
  Logger.debug('Write the tokens in the configuration file…');
54
52
  const configDir = path.dirname(conf.CONFIGURATION_FILE);
55
53
  try {
@@ -61,7 +59,7 @@ async function writeOAuthConf (oauthData) {
61
59
  }
62
60
  }
63
61
 
64
- async function loadIdsCache () {
62
+ export async function loadIdsCache () {
65
63
  const cachePath = getConfigPath(CONFIG_FILES.IDS_CACHE);
66
64
  try {
67
65
  const rawFile = await fs.readFile(cachePath);
@@ -76,7 +74,7 @@ async function loadIdsCache () {
76
74
  }
77
75
  }
78
76
 
79
- async function writeIdsCache (ids) {
77
+ export async function writeIdsCache (ids) {
80
78
  const cachePath = getConfigPath(CONFIG_FILES.IDS_CACHE);
81
79
  const idsJson = JSON.stringify(ids);
82
80
  try {
@@ -87,7 +85,7 @@ async function writeIdsCache (ids) {
87
85
  }
88
86
  }
89
87
 
90
- const conf = env.getOrElseAll({
88
+ export const conf = env.getOrElseAll({
91
89
  API_HOST: 'https://api.clever-cloud.com',
92
90
  // API_HOST: 'https://ccapi-preprod.cleverapps.io',
93
91
  LOG_WS_URL: 'wss://api.clever-cloud.com/v2/logs/logs-socket/<%- appId %>?since=<%- timestamp %>',
@@ -106,5 +104,3 @@ const conf = env.getOrElseAll({
106
104
  CLEVER_CONFIGURATION_DIR: path.resolve('.', 'clevercloud'),
107
105
  APP_CONFIGURATION_FILE: path.resolve('.', '.clever.json'),
108
106
  });
109
-
110
- module.exports = { conf, loadOAuthConf, writeOAuthConf, loadIdsCache, writeIdsCache };
@@ -1,18 +1,16 @@
1
- 'use strict';
1
+ import { promisify } from 'node:util';
2
+ import { Logger } from '../logger.js';
3
+ import { getDeployment, getAllDeployments } from '@clevercloud/client/esm/api/v2/application.js';
4
+ import { sendToApi } from './send-to-api.js';
2
5
 
3
- const { promisify } = require('util');
4
6
  const delay = promisify(setTimeout);
5
7
 
6
- const Logger = require('../logger.js');
7
- const { getDeployment, getAllDeployments } = require('@clevercloud/client/cjs/api/v2/application.js');
8
- const { sendToApi } = require('./send-to-api.js');
9
-
10
8
  const DEPLOYMENT_POLLING_DELAY = 5000;
11
9
  const BACKOFF_FACTOR = 1.25;
12
10
  const INIT_RETRY_TIMEOUT = 1500;
13
11
  const MAX_RETRY_COUNT = 5;
14
12
 
15
- async function waitForDeploymentStart ({ ownerId, appId, deploymentId, commitId, knownDeployments }) {
13
+ export async function waitForDeploymentStart ({ ownerId, appId, deploymentId, commitId, knownDeployments }) {
16
14
 
17
15
  return waitFor(async () => {
18
16
  try {
@@ -45,7 +43,7 @@ async function waitForDeploymentStart ({ ownerId, appId, deploymentId, commitId,
45
43
  });
46
44
  }
47
45
 
48
- async function waitForDeploymentEnd ({ ownerId, appId, deploymentId }) {
46
+ export async function waitForDeploymentEnd ({ ownerId, appId, deploymentId }) {
49
47
  return waitFor(async () => {
50
48
  try {
51
49
  const deployment = await getDeployment({ id: ownerId, appId, deploymentId }).then(sendToApi);
@@ -103,5 +101,3 @@ async function waitFor (fetchResult) {
103
101
  }
104
102
  }
105
103
  }
106
-
107
- module.exports = { waitForDeploymentStart, waitForDeploymentEnd };
@@ -1,12 +1,10 @@
1
- 'use strict';
1
+ import _ from 'lodash';
2
2
 
3
- const _ = require('lodash');
3
+ import { Logger } from '../logger.js';
4
+ import { getAllDomains, getFavouriteDomain } from '@clevercloud/client/esm/api/v2/application.js';
5
+ import { sendToApi } from '../models/send-to-api.js';
4
6
 
5
- const Logger = require('../logger.js');
6
- const { getAllDomains, getFavouriteDomain } = require('@clevercloud/client/cjs/api/v2/application.js');
7
- const { sendToApi } = require('../models/send-to-api.js');
8
-
9
- async function getBest (appId, orgaId) {
7
+ export async function getBest (appId, orgaId) {
10
8
  Logger.debug('Trying to get the favourite vhost for ' + appId);
11
9
  return getFavouriteDomain({ id: orgaId, appId }).then(sendToApi)
12
10
  .catch(async (e) => {
@@ -27,7 +25,7 @@ async function getBest (appId, orgaId) {
27
25
  });
28
26
  }
29
27
 
30
- function selectBest (vhosts) {
28
+ export function selectBest (vhosts) {
31
29
  const customVhost = _.find(vhosts, (vhost) => {
32
30
  return !vhost.fqdn.endsWith('.cleverapps.io');
33
31
  });
@@ -36,5 +34,3 @@ function selectBest (vhosts) {
36
34
  });
37
35
  return customVhost || withoutDefaultDomain || vhosts[0];
38
36
  }
39
-
40
- module.exports = { getBest, selectBest };
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- const autocomplete = require('cliparse').autocomplete;
1
+ import cliparse from 'cliparse';
4
2
 
5
3
  const DRAIN_TYPES = [
6
4
  { id: 'TCPSyslog', structuredDataParameters: 'OPTIONAL' },
@@ -11,7 +9,7 @@ const DRAIN_TYPES = [
11
9
  { id: 'NewRelicHTTP', apiKey: 'MANDATORY' },
12
10
  ];
13
11
 
14
- function createDrainBody (appId, drainTargetURL, drainTargetType, drainTargetCredentials, drainTargetConfig) {
12
+ export function createDrainBody (appId, drainTargetURL, drainTargetType, drainTargetCredentials, drainTargetConfig) {
15
13
 
16
14
  if (!authorizeDrainCreation(drainTargetType, drainTargetCredentials, drainTargetConfig)) {
17
15
  throw new Error("Credentials are: optional for HTTP, mandatory for ElasticSearch, NewRelicHTTP and TCPSyslog/UDPSyslog don't need them.");
@@ -39,7 +37,7 @@ function createDrainBody (appId, drainTargetURL, drainTargetType, drainTargetCre
39
37
  return body;
40
38
  }
41
39
 
42
- function authorizeDrainCreation (drainTargetType, drainTargetCredentials, drainTargetConfig) {
40
+ export function authorizeDrainCreation (drainTargetType, drainTargetCredentials, drainTargetConfig) {
43
41
  if (drainTypeExists(drainTargetType)) {
44
42
  // retrieve field for drain type ('mandatory', 'optional', undefined)
45
43
  const credStatus = fieldStatus(drainTargetType).credentials;
@@ -129,12 +127,6 @@ function keyEmpty ({ apiKey }) {
129
127
  return apiKey == null;
130
128
  }
131
129
 
132
- function listDrainTypes () {
133
- return autocomplete.words(DRAIN_TYPES.map((type) => type.id));
130
+ export function listDrainTypes () {
131
+ return cliparse.autocomplete.words(DRAIN_TYPES.map((type) => type.id));
134
132
  }
135
-
136
- module.exports = {
137
- createDrainBody,
138
- authorizeDrainCreation,
139
- listDrainTypes,
140
- };
@@ -1,9 +1,7 @@
1
- 'use strict';
1
+ import colors from 'colors/safe.js';
2
+ import { Logger } from '../logger.js';
2
3
 
3
- const colors = require('colors/safe');
4
- const Logger = require('../logger.js');
5
-
6
- function get (follow, exitOnDeploy) {
4
+ export function get (follow, exitOnDeploy) {
7
5
  if (follow) {
8
6
  if (exitOnDeploy === 'deploy-start') {
9
7
  throw new Error('The `follow` and `exit-on` set to "deploy-start" options are not compatible');
@@ -15,10 +13,8 @@ function get (follow, exitOnDeploy) {
15
13
  }
16
14
 
17
15
  // plotQuietWarning: If in quiet mode and exitStrategy set to never plot a warning to indicate that the command will end
18
- function plotQuietWarning (exitStrategy, quiet) {
16
+ export function plotQuietWarning (exitStrategy, quiet) {
19
17
  if (exitStrategy === 'never' && quiet) {
20
18
  Logger.println(colors.bold.yellow('The "never" exit-on strategy is not compatible with the "quiet" mode, it will exit once the deployment ends'));
21
19
  }
22
20
  }
23
-
24
- module.exports = { get, plotQuietWarning };
@@ -1,9 +1,7 @@
1
- 'use strict';
1
+ import { join } from 'node:path';
2
+ import { promises as fs } from 'node:fs';
2
3
 
3
- const { join } = require('path');
4
- const { promises: fs } = require('fs');
5
-
6
- function findPath (dir, name) {
4
+ export function findPath (dir, name) {
7
5
  const fullPath = join(dir, name);
8
6
  return fs.stat(fullPath)
9
7
  .then(() => dir)
@@ -15,5 +13,3 @@ function findPath (dir, name) {
15
13
  throw e;
16
14
  });
17
15
  }
18
-
19
- module.exports = { findPath };
package/src/models/git.js CHANGED
@@ -1,16 +1,13 @@
1
- 'use strict';
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
2
3
 
3
- const fs = require('fs');
4
- const path = require('path');
5
-
6
- const _ = require('lodash');
7
- const git = require('isomorphic-git');
8
- const http = require('./isomorphic-http-with-agent.js');
9
- const { autocomplete } = require('cliparse');
10
-
11
- const slugify = require('slugify');
12
- const { findPath } = require('./fs-utils.js');
13
- const { loadOAuthConf } = require('./configuration.js');
4
+ import _ from 'lodash';
5
+ import git from 'isomorphic-git';
6
+ import * as http from './isomorphic-http-with-agent.js';
7
+ import cliparse from 'cliparse';
8
+ import slugify from 'slugify';
9
+ import { findPath } from './fs-utils.js';
10
+ import { loadOAuthConf } from './configuration.js';
14
11
 
15
12
  async function getRepo () {
16
13
  try {
@@ -30,7 +27,7 @@ async function onAuth () {
30
27
  };
31
28
  }
32
29
 
33
- async function addRemote (remoteName, url) {
30
+ export async function addRemote (remoteName, url) {
34
31
  const repo = await getRepo();
35
32
  const safeRemoteName = slugify(remoteName);
36
33
  const allRemotes = await git.listRemotes({ ...repo });
@@ -41,7 +38,7 @@ async function addRemote (remoteName, url) {
41
38
  }
42
39
  }
43
40
 
44
- async function resolveFullCommitId (commitId) {
41
+ export async function resolveFullCommitId (commitId) {
45
42
  if (commitId == null) {
46
43
  return null;
47
44
  }
@@ -57,7 +54,7 @@ async function resolveFullCommitId (commitId) {
57
54
  }
58
55
  }
59
56
 
60
- async function getRemoteCommit (remoteUrl) {
57
+ export async function getRemoteCommit (remoteUrl) {
61
58
  const repo = await getRepo();
62
59
  const remoteInfos = await git.getRemoteInfo({
63
60
  ...repo,
@@ -67,7 +64,7 @@ async function getRemoteCommit (remoteUrl) {
67
64
  return _.get(remoteInfos, 'refs.heads.master');
68
65
  }
69
66
 
70
- async function getFullBranch (branchName) {
67
+ export async function getFullBranch (branchName) {
71
68
  const repo = await getRepo();
72
69
  if (branchName === '') {
73
70
  const currentBranch = await git.currentBranch({ ...repo, fullname: true });
@@ -76,7 +73,7 @@ async function getFullBranch (branchName) {
76
73
  return git.expandRef({ ...repo, ref: branchName });
77
74
  };
78
75
 
79
- async function getBranchCommit (refspec) {
76
+ export async function getBranchCommit (refspec) {
80
77
  const repo = await getRepo();
81
78
  const oid = await git.resolveRef({ ...repo, ref: refspec });
82
79
  // When a refspec refers to an annotated tag, the OID ref represents the annotation and not the commit directly,
@@ -85,7 +82,7 @@ async function getBranchCommit (refspec) {
85
82
  return res.oid;
86
83
  }
87
84
 
88
- async function isExistingTag (tag) {
85
+ export async function isExistingTag (tag) {
89
86
  const repo = await getRepo();
90
87
  const tags = await git.listTags({
91
88
  ...repo,
@@ -93,7 +90,7 @@ async function isExistingTag (tag) {
93
90
  return tags.includes(tag);
94
91
  }
95
92
 
96
- async function push (remoteUrl, branchRefspec, force) {
93
+ export async function push (remoteUrl, branchRefspec, force) {
97
94
  const repo = await getRepo();
98
95
  try {
99
96
  const push = await git.push({
@@ -117,13 +114,13 @@ async function push (remoteUrl, branchRefspec, force) {
117
114
  }
118
115
  }
119
116
 
120
- function completeBranches () {
117
+ export function completeBranches () {
121
118
  return getRepo()
122
119
  .then((repo) => git.listBranches(repo))
123
- .then(autocomplete.words);
120
+ .then(cliparse.autocomplete.words);
124
121
  }
125
122
 
126
- async function isShallow () {
123
+ export async function isShallow () {
127
124
  const { dir } = await getRepo();
128
125
  try {
129
126
  await fs.promises.access(path.join(dir, '.git', 'shallow'));
@@ -133,15 +130,3 @@ async function isShallow () {
133
130
  return false;
134
131
  }
135
132
  }
136
-
137
- module.exports = {
138
- addRemote,
139
- resolveFullCommitId,
140
- getRemoteCommit,
141
- getFullBranch,
142
- getBranchCommit,
143
- push,
144
- completeBranches,
145
- isShallow,
146
- isExistingTag,
147
- };
@@ -1,6 +1,6 @@
1
- const { getSummary } = require('@clevercloud/client/cjs/api/v2/user.js');
2
- const { sendToApi } = require('./send-to-api.js');
3
- const { loadIdsCache, writeIdsCache } = require('./configuration.js');
1
+ import { getSummary } from '@clevercloud/client/esm/api/v2/user.js';
2
+ import { sendToApi } from './send-to-api.js';
3
+ import { loadIdsCache, writeIdsCache } from './configuration.js';
4
4
 
5
5
  /*
6
6
  This system uses a simplified representation of the summary to expose IDs links:
@@ -24,11 +24,11 @@ This system uses a simplified representation of the summary to expose IDs links:
24
24
  }
25
25
  */
26
26
 
27
- async function resolveOwnerId (id) {
27
+ export async function resolveOwnerId (id) {
28
28
  return getIdFromCacheOrSummary((ids) => ids.owners[id]);
29
29
  }
30
30
 
31
- async function resolveAddonId (id) {
31
+ export async function resolveAddonId (id) {
32
32
 
33
33
  const addonId = await getIdFromCacheOrSummary((ids) => {
34
34
  return (ids.addons[id] != null) ? ids.addons[id].addonId : null;
@@ -41,7 +41,7 @@ async function resolveAddonId (id) {
41
41
  throw new Error(`Add-on ${id} does not exist`);
42
42
  }
43
43
 
44
- async function resolveRealId (id) {
44
+ export async function resolveRealId (id) {
45
45
 
46
46
  const realId = await getIdFromCacheOrSummary((ids) => {
47
47
  return (ids.addons[id] != null) ? ids.addons[id].realId : null;
@@ -102,9 +102,3 @@ async function getIdsFromSummary () {
102
102
 
103
103
  return ids;
104
104
  }
105
-
106
- module.exports = {
107
- resolveOwnerId,
108
- resolveAddonId,
109
- resolveRealId,
110
- };
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- const readline = require('readline');
1
+ import readline from 'node:readline';
4
2
 
5
3
  function ask (question) {
6
4
 
@@ -17,12 +15,10 @@ function ask (question) {
17
15
  });
18
16
  }
19
17
 
20
- async function confirm (question, rejectionMessage, expectedAnswers = ['yes', 'y']) {
18
+ export async function confirm (question, rejectionMessage, expectedAnswers = ['yes', 'y']) {
21
19
  const answer = await ask(question);
22
20
  if (!expectedAnswers.includes(answer)) {
23
21
  throw new Error(rejectionMessage);
24
22
  }
25
23
  return true;
26
24
  }
27
-
28
- module.exports = { confirm };
@@ -1,7 +1,5 @@
1
- 'use strict';
2
-
3
- const isomotphicHttp = require('isomorphic-git/http/node');
4
- const https = require('https');
1
+ import isomotphicHttp from 'isomorphic-git/http/node/index.js';
2
+ import https from 'node:https';
5
3
 
6
4
  // We use our own HTTP plugin, so we can customize the agent used for requests and configure a long timeout (default is 5 seconds).
7
5
 
@@ -10,10 +8,6 @@ const agent = new https.Agent({
10
8
  timeout: 10 * 60 * 1000,
11
9
  });
12
10
 
13
- function request (params) {
11
+ export function request (params) {
14
12
  return isomotphicHttp.request({ ...params, agent });
15
13
  }
16
-
17
- module.exports = {
18
- request,
19
- };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Helper to print a real JSON array with starting `[` and ending `]`
3
3
  */
4
- class JsonArray {
4
+ export class JsonArray {
5
5
  constructor () {
6
6
  this._isFirst = true;
7
7
  }
@@ -24,5 +24,3 @@ class JsonArray {
24
24
  process.stdout.write('\n]');
25
25
  }
26
26
  }
27
-
28
- module.exports = { JsonArray };
@@ -1,11 +1,11 @@
1
- const { getHostAndTokens, processError } = require('./send-to-api.js');
2
- const colors = require('colors/safe');
3
- const { Deferred } = require('./utils.js');
4
- const Logger = require('../logger.js');
5
- const { waitForDeploymentEnd, waitForDeploymentStart } = require('./deployments.js');
6
- const { ApplicationLogStream } = require('@clevercloud/client/cjs/streams/application-logs.js');
7
- const { JsonArray } = require('./json-array.js');
8
- const ExitStrategy = require('../models/exit-strategy-option.js');
1
+ import { getHostAndTokens, processError } from './send-to-api.js';
2
+ import colors from 'colors/safe.js';
3
+ import { Deferred } from './utils.js';
4
+ import { Logger } from '../logger.js';
5
+ import { waitForDeploymentEnd, waitForDeploymentStart } from './deployments.js';
6
+ import { ApplicationLogStream } from '@clevercloud/client/esm/streams/application-logs.js';
7
+ import { JsonArray } from './json-array.js';
8
+ import * as ExitStrategy from '../models/exit-strategy-option.js';
9
9
 
10
10
  // 2000 logs per 100ms maximum
11
11
  const THROTTLE_ELEMENTS = 2000;
@@ -16,7 +16,7 @@ const retryConfiguration = {
16
16
  maxRetryCount: 6,
17
17
  };
18
18
 
19
- async function displayLogs (params) {
19
+ export async function displayLogs (params) {
20
20
 
21
21
  const deferred = params.deferred || new Deferred();
22
22
  const { apiHost, tokens } = await getHostAndTokens();
@@ -83,7 +83,7 @@ async function displayLogs (params) {
83
83
  return logStream;
84
84
  }
85
85
 
86
- async function watchDeploymentAndDisplayLogs (options) {
86
+ export async function watchDeploymentAndDisplayLogs (options) {
87
87
 
88
88
  const {
89
89
  ownerId,
@@ -171,5 +171,3 @@ function isDeploymentFailedMessage (log) {
171
171
  function isBuildSucessMessage (log) {
172
172
  return isCleverMessage(log) && log.message.toLowerCase().startsWith('build succeeded in');
173
173
  };
174
-
175
- module.exports = { displayLogs, watchDeploymentAndDisplayLogs };
package/src/models/log.js CHANGED
@@ -1,15 +1,13 @@
1
- 'use strict';
1
+ import _ from 'lodash';
2
+ import colors from 'colors/safe.js';
2
3
 
3
- const _ = require('lodash');
4
- const colors = require('colors/safe');
5
-
6
- const Logger = require('../logger.js');
7
- const { Deferred } = require('./utils.js');
8
- const { getOldLogs } = require('@clevercloud/client/cjs/api/v2/log.js');
9
- const { LogsStream } = require('@clevercloud/client/cjs/streams/logs.node.js');
10
- const { sendToApi, getHostAndTokens } = require('./send-to-api.js');
11
- const { waitForDeploymentEnd, waitForDeploymentStart } = require('./deployments.js');
12
- const ExitStrategy = require('../models/exit-strategy-option.js');
4
+ import { Logger } from '../logger.js';
5
+ import { Deferred } from './utils.js';
6
+ import { getOldLogs } from '@clevercloud/client/esm/api/v2/log.js';
7
+ import { LogsStream } from '@clevercloud/client/esm/streams/logs.node.js';
8
+ import { sendToApi, getHostAndTokens } from './send-to-api.js';
9
+ import { waitForDeploymentEnd, waitForDeploymentStart } from './deployments.js';
10
+ import * as ExitStrategy from '../models/exit-strategy-option.js';
13
11
 
14
12
  function isCleverMessage (line) {
15
13
  return line._source.syslog_program === '/home/bas/rubydeployer/deployer.rb';
@@ -69,7 +67,7 @@ async function displayLiveLogs ({ appId, filter, until, deploymentId }, deferred
69
67
  return logsStream;
70
68
  }
71
69
 
72
- async function displayLogs ({ appAddonId, until, since, filter, deploymentId }) {
70
+ export async function displayLogs ({ appAddonId, until, since, filter, deploymentId }) {
73
71
 
74
72
  const now = new Date();
75
73
 
@@ -101,7 +99,7 @@ async function displayLogs ({ appAddonId, until, since, filter, deploymentId })
101
99
  return deferred.promise;
102
100
  }
103
101
 
104
- async function watchDeploymentAndDisplayLogs ({ ownerId, appId, deploymentId, commitId, knownDeployments, quiet, exitStrategy }) {
102
+ export async function watchDeploymentAndDisplayLogs ({ ownerId, appId, deploymentId, commitId, knownDeployments, quiet, exitStrategy }) {
105
103
 
106
104
  ExitStrategy.plotQuietWarning(exitStrategy, quiet);
107
105
  // If in quiet mode, we only log start/finished deployment messages
@@ -148,5 +146,3 @@ async function watchDeploymentAndDisplayLogs ({ ownerId, appId, deploymentId, co
148
146
  throw new Error('Deployment failed. Please check the logs');
149
147
  }
150
148
  }
151
-
152
- module.exports = { displayLogs, watchDeploymentAndDisplayLogs };
@@ -1,20 +1,14 @@
1
- const Application = require('./application.js');
2
- const organisation = require('@clevercloud/client/cjs/api/v2/organisation.js');
3
- const { sendToApi } = require('./send-to-api.js');
4
- const { autocomplete } = require('cliparse');
5
-
6
- async function getNamespaces (ownerId) {
1
+ import * as Application from './application.js';
2
+ import * as organisation from '@clevercloud/client/esm/api/v2/organisation.js';
3
+ import { sendToApi } from './send-to-api.js';
4
+ import cliparse from 'cliparse';
5
+ export async function getNamespaces (ownerId) {
7
6
  return organisation.getNamespaces({ id: ownerId }).then(sendToApi);
8
7
  }
9
8
 
10
- async function completeNamespaces () {
9
+ export async function completeNamespaces () {
11
10
  // Sadly we do not have access to current params in complete as of now
12
11
  const { ownerId } = await Application.resolveId(null, null);
13
12
 
14
- return getNamespaces(ownerId).then(autocomplete.words);
13
+ return getNamespaces(ownerId).then(cliparse.autocomplete.words);
15
14
  }
16
-
17
- module.exports = {
18
- getNamespaces,
19
- completeNamespaces,
20
- };