bdy 1.16.8-dev → 1.16.9-dev

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.16.8-dev",
4
+ "version": "1.16.9-dev",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {
@@ -181,7 +181,7 @@ class AgentSystem {
181
181
  downloadBinaryArchive() {
182
182
  const archivePath = this.getBinaryArchivePath();
183
183
  const env = (0, utils_1.getVersionEnv)();
184
- const version = (0, utils_1.getVersionWithoutEnv)();
184
+ const version = (0, utils_1.getCurrentVersionWithoutEnv)();
185
185
  const archive = this.getBinaryArchive();
186
186
  return this.downloadFile(`https://es.buddy.works/bdy/${env}/${version}/${archive}`, archivePath);
187
187
  }
@@ -304,7 +304,7 @@ class AgentSystem {
304
304
  token,
305
305
  port,
306
306
  standalone,
307
- debug
307
+ debug,
308
308
  }), 'utf-8');
309
309
  return true;
310
310
  }
@@ -31,6 +31,7 @@ const commandPre = async (_, command) => {
31
31
  // do nothing
32
32
  }
33
33
  command.currentVersion = (0, utils_1.getVersion)();
34
+ command.env = (0, utils_1.getVersionEnv)();
34
35
  try {
35
36
  command.latestVersion = await (0, utils_1.getLatestVersion)();
36
37
  }
@@ -6,8 +6,103 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const utils_1 = require("../utils");
7
7
  const output_1 = __importDefault(require("../output"));
8
8
  const utils_2 = require("../utils");
9
+ const updateMessage = (currentVersion, latestVersion, instructions) => {
10
+ output_1.default.normal('Current version: ', false);
11
+ output_1.default.gray(currentVersion);
12
+ output_1.default.normal('Latest version: ', false);
13
+ output_1.default.gray(latestVersion);
14
+ output_1.default.normal('Update bdy CLI to newest version:');
15
+ output_1.default.gray(instructions);
16
+ output_1.default.exitNormal('');
17
+ };
18
+ const updateByBrew = (currentVersion, latestVersion, env) => {
19
+ let instructions = 'brew tap buddy/bdy\n';
20
+ if (env === 'prod')
21
+ instructions += 'brew install bdy';
22
+ else
23
+ instructions += `brew install bdy@${env}`;
24
+ updateMessage(currentVersion, latestVersion, instructions);
25
+ };
26
+ const updateByChoco = (currentVersion, latestVersion, env) => {
27
+ const latestWithoutEnv = (0, utils_1.getVersionWithoutEnv)(latestVersion);
28
+ const instructions = `choco install bdy --version=${latestWithoutEnv}-${env} --pre`;
29
+ updateMessage(currentVersion, latestVersion, instructions);
30
+ };
31
+ const updateByApt = (currentVersion, latestVersion) => {
32
+ const instructions = 'sudo apt-get update && sudo apt-get install -y bdy';
33
+ updateMessage(currentVersion, latestVersion, instructions);
34
+ };
35
+ const updateByNpm = (isWin, currentVersion, latestVersion, env) => {
36
+ let instructions = '';
37
+ if (!isWin)
38
+ instructions = 'sudo ';
39
+ instructions += 'npm i -g bdy';
40
+ if (env !== 'prod')
41
+ instructions += `@${env}`;
42
+ updateMessage(currentVersion, latestVersion, instructions);
43
+ };
44
+ const updateByDownload = (platform, currentVersion, latestVersion, env) => {
45
+ const isMac = platform === 'darwin';
46
+ const isWin = platform === 'win32';
47
+ const x64 = process.arch === 'x64';
48
+ const latestWithoutEnv = (0, utils_1.getVersionWithoutEnv)(latestVersion);
49
+ let packageName;
50
+ if (isWin)
51
+ packageName = 'win-x64.zip';
52
+ else if (isMac)
53
+ packageName = 'darwin-arm64.tar.gz';
54
+ else if (x64)
55
+ packageName = 'linux-x64.tar.gz';
56
+ else
57
+ packageName = 'linux-arm64.tar.gz';
58
+ let instructions = `curl https://es.buddy.works/bdy/${env}/${latestWithoutEnv}/${packageName}`;
59
+ if (isWin)
60
+ instructions += ' -o bdy.zip\ntar -xf bdy.zip';
61
+ else
62
+ instructions += ' -o bdy.tar.gz\nsudo tar -zxf bdy.tar.gz -C /usr/local/bin/';
63
+ updateMessage(currentVersion, latestVersion, instructions);
64
+ };
9
65
  const commandVersion = (0, utils_2.newCommand)('version');
10
- commandVersion.action(() => {
11
- output_1.default.exitNormal((0, utils_1.getVersion)());
66
+ commandVersion.hideVersionUpdate = true;
67
+ commandVersion.action(async () => {
68
+ const currVersion = commandVersion.currentVersion || '';
69
+ const lastVersion = commandVersion.latestVersion || '';
70
+ const env = commandVersion.env || '';
71
+ if (currVersion !== lastVersion) {
72
+ const platform = (0, utils_1.getPlatform)();
73
+ const isMac = platform === 'darwin';
74
+ const isWin = platform === 'win32';
75
+ if (isMac) {
76
+ const isInstalled = await (0, utils_1.isInstalledByBrew)();
77
+ if (isInstalled) {
78
+ updateByBrew(currVersion, lastVersion, env);
79
+ return;
80
+ }
81
+ }
82
+ else if (isWin) {
83
+ const isInstalled = await (0, utils_1.isInstalledByChoco)();
84
+ if (isInstalled) {
85
+ updateByChoco(currVersion, lastVersion, env);
86
+ return;
87
+ }
88
+ }
89
+ else {
90
+ const isInstalled = await (0, utils_1.isInstalledByApt)();
91
+ if (isInstalled) {
92
+ updateByApt(currVersion, lastVersion);
93
+ return;
94
+ }
95
+ }
96
+ const isInstalled = await (0, utils_1.isInstalledByNpm)();
97
+ if (isInstalled) {
98
+ updateByNpm(isWin, currVersion, lastVersion, env);
99
+ return;
100
+ }
101
+ else {
102
+ updateByDownload(platform, currVersion, lastVersion, env);
103
+ return;
104
+ }
105
+ }
106
+ output_1.default.exitNormal(currVersion);
12
107
  });
13
108
  exports.default = commandVersion;
@@ -35,6 +35,12 @@ class Output {
35
35
  msg += '\n';
36
36
  terminal(msg);
37
37
  }
38
+ static gray(txt, newLine = true) {
39
+ let msg = txt;
40
+ if (newLine)
41
+ msg += '\n';
42
+ terminal.gray(msg);
43
+ }
38
44
  static warning(txt, newLine = true) {
39
45
  let msg = txt;
40
46
  if (newLine)
@@ -219,7 +219,7 @@ exports.OPTION_UPLOAD_REPORT_FORMAT = 'Format of the reports';
219
219
  exports.OPTION_UPLOAD_DRY_RUN = 'Run command without uploading reports';
220
220
  const TXT_NEW_CLI_DOCKER_VERSION = (version) => `A new version of bdy Docker image is available! (${version})\n\n`;
221
221
  exports.TXT_NEW_CLI_DOCKER_VERSION = TXT_NEW_CLI_DOCKER_VERSION;
222
- const TXT_NEW_CLI_VERSION = (version) => `A new version of bdy is available! (${version})\n\n`;
222
+ const TXT_NEW_CLI_VERSION = (version) => `A new version of bdy is available! (${version}). Run bdy version for more info\n\n`;
223
223
  exports.TXT_NEW_CLI_VERSION = TXT_NEW_CLI_VERSION;
224
224
  exports.TXT_NEW_AGENT_VERSION = 'Agent upgrade required. Update the agent by running:\n`bdy agent update`\n\n';
225
225
  exports.TXT_ENABLING_AGENT = 'Installing agent...';
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.getBasicCommandTls = exports.getBasicCommandHttp = exports.getBasicCommandTcp = exports.createSshHostKey = exports.getRealTargetHost = exports.isWindows = exports.isLinux = exports.isOsx = exports.isDocker = exports.sleep = exports.getLatestVersion = exports.getVersionEnv = exports.getVersionWithoutEnv = exports.getVersion = exports.getHomeDirectory = exports.newCommand = exports.formatHelp = exports.getPlatform = exports.getHostname = exports.isStringRegExp = exports.getRootDir = exports.TARGET_ONLY_PORT_REGEX = exports.TARGET_HTTP_REGEX = exports.TARGET_TCP_TLS_REGEX = exports.ApiErrorTunnelsDisabled = exports.ApiErrorWorkspaceFlagged = exports.ApiErrorTunnelLimitReached = exports.ApiErrorAgentLimitReached = exports.ApiErrorDomainRestricted = exports.ApiErrorTargetInvalid = exports.ApiErrorWrongToken = exports.ApiErrorFailedToConnect = exports.ApiErrorAgentNotFound = exports.SUGGESTED_BROWSER_VERSION = exports.DEFAULT_TIMEOUT = exports.TUNNEL_HTTP_CB_MIN_REQUESTS = exports.TUNNEL_HTTP_CB_WINDOW = exports.TUNNEL_MAX_REQUEST_SIZE_TO_SYNC = exports.TUNNEL_HTTP_LOG_MAX_REQUESTS = exports.TUNNEL_HTTP_LOG_MAX_BODY = exports.TUNNEL_HTTP_RATE_WINDOW = exports.TUNNEL_HTTP_RATE_LIMIT = void 0;
39
+ exports.getBasicCommandTls = exports.getBasicCommandHttp = exports.getBasicCommandTcp = exports.createSshHostKey = exports.getRealTargetHost = exports.isWindows = exports.isLinux = exports.isOsx = exports.isDocker = exports.sleep = exports.getLatestVersion = exports.getVersionEnv = exports.getCurrentVersionWithoutEnv = exports.getVersionWithoutEnv = exports.getVersion = exports.isInstalledByChoco = exports.isInstalledByApt = exports.isInstalledByBrew = exports.isInstalledByNpm = exports.execLocally = exports.getHomeDirectory = exports.newCommand = exports.formatHelp = exports.getPlatform = exports.getHostname = exports.isStringRegExp = exports.getRootDir = exports.TARGET_ONLY_PORT_REGEX = exports.TARGET_HTTP_REGEX = exports.TARGET_TCP_TLS_REGEX = exports.ApiErrorTunnelsDisabled = exports.ApiErrorWorkspaceFlagged = exports.ApiErrorTunnelLimitReached = exports.ApiErrorAgentLimitReached = exports.ApiErrorDomainRestricted = exports.ApiErrorTargetInvalid = exports.ApiErrorWrongToken = exports.ApiErrorFailedToConnect = exports.ApiErrorAgentNotFound = exports.SUGGESTED_BROWSER_VERSION = exports.DEFAULT_TIMEOUT = exports.TUNNEL_HTTP_CB_MIN_REQUESTS = exports.TUNNEL_HTTP_CB_WINDOW = exports.TUNNEL_MAX_REQUEST_SIZE_TO_SYNC = exports.TUNNEL_HTTP_LOG_MAX_REQUESTS = exports.TUNNEL_HTTP_LOG_MAX_BODY = exports.TUNNEL_HTTP_RATE_WINDOW = exports.TUNNEL_HTTP_RATE_LIMIT = void 0;
40
40
  exports.apiErrorCodeToClass = apiErrorCodeToClass;
41
41
  exports.isFile = isFile;
42
42
  exports.asyncWait = asyncWait;
@@ -48,6 +48,7 @@ const node_sea_1 = require("node:sea");
48
48
  const commander_1 = require("commander");
49
49
  const texts_2 = require("./texts");
50
50
  const node_os_1 = __importStar(require("node:os"));
51
+ const node_child_process_1 = require("node:child_process");
51
52
  exports.TUNNEL_HTTP_RATE_LIMIT = 2000;
52
53
  exports.TUNNEL_HTTP_RATE_WINDOW = 60000;
53
54
  exports.TUNNEL_HTTP_LOG_MAX_BODY = 5242880; // 5MB
@@ -239,6 +240,57 @@ const getHomeDirectory = () => {
239
240
  return p;
240
241
  };
241
242
  exports.getHomeDirectory = getHomeDirectory;
243
+ const execLocally = async (cmd) => {
244
+ return new Promise((resolve, reject) => {
245
+ (0, node_child_process_1.exec)(cmd, (err, stdout, stderr) => {
246
+ if (err)
247
+ reject(err);
248
+ else
249
+ resolve(`${stdout}\n${stderr}`);
250
+ });
251
+ });
252
+ };
253
+ exports.execLocally = execLocally;
254
+ const isInstalledByNpm = async () => {
255
+ try {
256
+ const out = await (0, exports.execLocally)('npm -g list');
257
+ return (out || '').includes('bdy@');
258
+ }
259
+ catch {
260
+ return false;
261
+ }
262
+ };
263
+ exports.isInstalledByNpm = isInstalledByNpm;
264
+ const isInstalledByBrew = async () => {
265
+ try {
266
+ const out = await (0, exports.execLocally)('brew list');
267
+ return (out || '').includes('bdy');
268
+ }
269
+ catch {
270
+ return false;
271
+ }
272
+ };
273
+ exports.isInstalledByBrew = isInstalledByBrew;
274
+ const isInstalledByApt = async () => {
275
+ try {
276
+ const out = await (0, exports.execLocally)('apt list --installed');
277
+ return (out || '').includes('bdy/');
278
+ }
279
+ catch {
280
+ return false;
281
+ }
282
+ };
283
+ exports.isInstalledByApt = isInstalledByApt;
284
+ const isInstalledByChoco = async () => {
285
+ try {
286
+ const out = await (0, exports.execLocally)('choco list');
287
+ return (out || '').includes('bdy');
288
+ }
289
+ catch {
290
+ return false;
291
+ }
292
+ };
293
+ exports.isInstalledByChoco = isInstalledByChoco;
242
294
  const getVersion = () => {
243
295
  if (!cachedVersion) {
244
296
  let packageJson;
@@ -254,14 +306,21 @@ const getVersion = () => {
254
306
  return cachedVersion;
255
307
  };
256
308
  exports.getVersion = getVersion;
257
- const getVersionWithoutEnv = () => {
309
+ const getVersionWithoutEnv = (version) => {
310
+ const m = version.match(/^\d+\.\d+\.\d+/);
311
+ if (m)
312
+ return m[0];
313
+ return '0.0.0';
314
+ };
315
+ exports.getVersionWithoutEnv = getVersionWithoutEnv;
316
+ const getCurrentVersionWithoutEnv = () => {
258
317
  const v = (0, exports.getVersion)();
259
318
  const m = v.match(/^\d+\.\d+\.\d+/);
260
319
  if (m)
261
320
  return m[0];
262
321
  return '0.0.0';
263
322
  };
264
- exports.getVersionWithoutEnv = getVersionWithoutEnv;
323
+ exports.getCurrentVersionWithoutEnv = getCurrentVersionWithoutEnv;
265
324
  const getVersionEnv = () => {
266
325
  const v = (0, exports.getVersion)();
267
326
  if (/dev/.test(v))
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.16.8-dev",
4
+ "version": "1.16.9-dev",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {