@capawesome/cli 0.0.5 → 0.0.7

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/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
4
4
 
5
+ ## [0.0.7](https://github.com/capawesome-team/cli/compare/v0.0.6...v0.0.7) (2024-05-27)
6
+
7
+
8
+ ### Features
9
+
10
+ * add `apps:bundles:update` command ([9dbad37](https://github.com/capawesome-team/cli/commit/9dbad377bebf4ea9b2a04194c3cda73aafcae067))
11
+ * add `rollout` argument to `apps:bundles:create` command ([30b892c](https://github.com/capawesome-team/cli/commit/30b892cd3aabfc62178420d516c162abacd1b757))
12
+
13
+ ## [0.0.6](https://github.com/capawesome-team/cli/compare/v0.0.5...v0.0.6) (2024-05-04)
14
+
15
+
16
+ ### Features
17
+
18
+ * **bundles:** add new min and max options ([#1](https://github.com/capawesome-team/cli/issues/1)) ([41d4bad](https://github.com/capawesome-team/cli/commit/41d4badadafc4b5989d22200e58f09efe01ebeec))
19
+
5
20
  ## [0.0.5](https://github.com/capawesome-team/cli/compare/v0.0.4...v0.0.5) (2024-05-02)
6
21
 
7
22
 
@@ -27,9 +27,13 @@ exports.default = (0, citty_1.defineCommand)({
27
27
  description: 'Create a new app bundle.',
28
28
  },
29
29
  args: {
30
- path: {
30
+ androidMax: {
31
31
  type: 'string',
32
- description: 'Path to the bundle to upload. Must be a folder (e.g. `www` or `dist`) or a zip file.',
32
+ description: 'The maximum Android version code (`versionCode`) that the bundle supports.',
33
+ },
34
+ androidMin: {
35
+ type: 'string',
36
+ description: 'The minimum Android version code (`versionCode`) that the bundle supports.',
33
37
  },
34
38
  appId: {
35
39
  type: 'string',
@@ -39,6 +43,22 @@ exports.default = (0, citty_1.defineCommand)({
39
43
  type: 'string',
40
44
  description: 'Channel to associate the bundle with.',
41
45
  },
46
+ path: {
47
+ type: 'string',
48
+ description: 'Path to the bundle to upload. Must be a folder (e.g. `www` or `dist`) or a zip file.',
49
+ },
50
+ rollout: {
51
+ type: 'string',
52
+ description: 'The percentage of devices to deploy the bundle to. Must be a number between 0 and 1 (e.g. 0.5).',
53
+ },
54
+ iosMax: {
55
+ type: 'string',
56
+ description: 'The maximum iOS bundle version (`CFBundleVersion`) that the bundle supports.',
57
+ },
58
+ iosMin: {
59
+ type: 'string',
60
+ description: 'The minimum iOS bundle version (`CFBundleVersion`) that the bundle supports.',
61
+ },
42
62
  },
43
63
  run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
44
64
  var _a, _b, _c;
@@ -46,8 +66,9 @@ exports.default = (0, citty_1.defineCommand)({
46
66
  consola_1.default.error('You must be logged in to run this command.');
47
67
  return;
48
68
  }
49
- let path = ctx.args.path;
69
+ const { androidMax, androidMin, rollout, iosMax, iosMin } = ctx.args;
50
70
  let appId = ctx.args.appId;
71
+ let path = ctx.args.path;
51
72
  let channelName = ctx.args.channel;
52
73
  if (!path) {
53
74
  path = yield (0, prompt_1.prompt)('Enter the path to the app bundle:', {
@@ -86,6 +107,26 @@ exports.default = (0, citty_1.defineCommand)({
86
107
  if (channelName) {
87
108
  formData.append('channelName', channelName);
88
109
  }
110
+ if (androidMax) {
111
+ formData.append('maxAndroidAppVersionCode', androidMax);
112
+ }
113
+ if (androidMin) {
114
+ formData.append('minAndroidAppVersionCode', androidMin);
115
+ }
116
+ if (rollout) {
117
+ const rolloutAsNumber = parseFloat(rollout);
118
+ if (isNaN(rolloutAsNumber) || rolloutAsNumber < 0 || rolloutAsNumber > 1) {
119
+ consola_1.default.error('Rollout percentage must be a number between 0 and 1 (e.g. 0.5).');
120
+ return;
121
+ }
122
+ formData.append('rolloutPercentage', rolloutAsNumber);
123
+ }
124
+ if (iosMax) {
125
+ formData.append('maxIosAppVersionCode', iosMax);
126
+ }
127
+ if (iosMin) {
128
+ formData.append('minIosAppVersionCode', iosMin);
129
+ }
89
130
  consola_1.default.start('Uploading...');
90
131
  // Upload the bundle
91
132
  try {
@@ -34,7 +34,9 @@ exports.default = (0, citty_1.defineCommand)({
34
34
  },
35
35
  run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
36
36
  var _a;
37
+ // Prompt for missing arguments
37
38
  let appId = ctx.args.appId;
39
+ let bundleId = ctx.args.bundleId;
38
40
  if (!appId) {
39
41
  const apps = yield apps_1.default.findAll();
40
42
  // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
@@ -43,18 +45,19 @@ exports.default = (0, citty_1.defineCommand)({
43
45
  options: apps.map((app) => ({ label: app.name, value: app.id })),
44
46
  });
45
47
  }
46
- let bundleId = ctx.args.bundleId;
47
48
  if (!bundleId) {
48
49
  bundleId = yield (0, prompt_1.prompt)('Enter the bundle ID:', {
49
50
  type: 'text',
50
51
  });
51
52
  }
53
+ // Confirm deletion
52
54
  const confirmed = yield (0, prompt_1.prompt)('Are you sure you want to delete this bundle?', {
53
55
  type: 'confirm',
54
56
  });
55
57
  if (!confirmed) {
56
58
  return;
57
59
  }
60
+ // Delete bundle
58
61
  try {
59
62
  yield app_bundle_1.default.delete({
60
63
  appId,
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const citty_1 = require("citty");
16
+ const consola_1 = __importDefault(require("consola"));
17
+ const prompt_1 = require("../../../utils/prompt");
18
+ const axios_1 = require("axios");
19
+ const authorization_service_1 = __importDefault(require("../../../services/authorization-service"));
20
+ const apps_1 = __importDefault(require("../../../services/apps"));
21
+ const app_bundle_1 = __importDefault(require("../../../services/app-bundle"));
22
+ exports.default = (0, citty_1.defineCommand)({
23
+ meta: {
24
+ description: 'Update an app bundle.',
25
+ },
26
+ args: {
27
+ androidMax: {
28
+ type: 'string',
29
+ description: 'The maximum Android version code (`versionCode`) that the bundle supports.',
30
+ },
31
+ androidMin: {
32
+ type: 'string',
33
+ description: 'The minimum Android version code (`versionCode`) that the bundle supports.',
34
+ },
35
+ appId: {
36
+ type: 'string',
37
+ description: 'ID of the app.',
38
+ },
39
+ bundleId: {
40
+ type: 'string',
41
+ description: 'ID of the bundle.',
42
+ },
43
+ rollout: {
44
+ type: 'string',
45
+ description: 'The percentage of devices to deploy the bundle to. Must be a number between 0 and 1 (e.g. 0.5).',
46
+ },
47
+ iosMax: {
48
+ type: 'string',
49
+ description: 'The maximum iOS bundle version (`CFBundleVersion`) that the bundle supports.',
50
+ },
51
+ iosMin: {
52
+ type: 'string',
53
+ description: 'The minimum iOS bundle version (`CFBundleVersion`) that the bundle supports.',
54
+ },
55
+ },
56
+ run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
57
+ var _a;
58
+ if (!authorization_service_1.default.hasAuthorizationToken()) {
59
+ consola_1.default.error('You must be logged in to run this command.');
60
+ return;
61
+ }
62
+ // Prompt for missing arguments
63
+ const { androidMax, androidMin, rollout, iosMax, iosMin } = ctx.args;
64
+ let appId = ctx.args.appId;
65
+ let bundleId = ctx.args.bundleId;
66
+ if (!appId) {
67
+ const apps = yield apps_1.default.findAll();
68
+ // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
69
+ appId = yield (0, prompt_1.prompt)('Which app do you want to update the bundle for?', {
70
+ type: 'select',
71
+ options: apps.map((app) => ({ label: app.name, value: app.id })),
72
+ });
73
+ }
74
+ if (!bundleId) {
75
+ bundleId = yield (0, prompt_1.prompt)('Enter the bundle ID:', {
76
+ type: 'text',
77
+ });
78
+ }
79
+ // Update bundle
80
+ try {
81
+ const rolloutAsNumber = parseFloat(rollout);
82
+ yield app_bundle_1.default.update({
83
+ appId,
84
+ bundleId,
85
+ maxAndroidAppVersionCode: androidMax,
86
+ maxIosAppVersionCode: iosMax,
87
+ minAndroidAppVersionCode: androidMin,
88
+ minIosAppVersionCode: iosMin,
89
+ rolloutPercentage: rolloutAsNumber,
90
+ });
91
+ consola_1.default.success('Bundle updated successfully.');
92
+ }
93
+ catch (error) {
94
+ if (error instanceof axios_1.AxiosError && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
95
+ consola_1.default.error('Your token is no longer valid. Please sign in again.');
96
+ }
97
+ else {
98
+ consola_1.default.error('Failed to delete bundle.');
99
+ }
100
+ }
101
+ }),
102
+ });
package/dist/index.js CHANGED
@@ -43,6 +43,7 @@ const main = (0, citty_1.defineCommand)({
43
43
  'apps:delete': Promise.resolve().then(() => __importStar(require('./commands/apps/delete'))).then((mod) => mod.default),
44
44
  'apps:bundles:create': Promise.resolve().then(() => __importStar(require('./commands/apps/bundles/create'))).then((mod) => mod.default),
45
45
  'apps:bundles:delete': Promise.resolve().then(() => __importStar(require('./commands/apps/bundles/delete'))).then((mod) => mod.default),
46
+ 'apps:bundles:update': Promise.resolve().then(() => __importStar(require('./commands/apps/bundles/update'))).then((mod) => mod.default),
46
47
  'apps:channels:create': Promise.resolve().then(() => __importStar(require('./commands/apps/channels/create'))).then((mod) => mod.default),
47
48
  'apps:channels:delete': Promise.resolve().then(() => __importStar(require('./commands/apps/channels/delete'))).then((mod) => mod.default),
48
49
  'apps:devices:delete': Promise.resolve().then(() => __importStar(require('./commands/apps/devices/delete'))).then((mod) => mod.default),
@@ -29,6 +29,19 @@ class AppBundlesServiceImpl {
29
29
  return response.data;
30
30
  });
31
31
  }
32
+ update(data) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ const response = yield this.httpClient.patch(`/apps/${data.appId}/bundles/${data.bundleId}`, data, {
35
+ headers: {
36
+ Authorization: `Bearer ${authorization_service_1.default.getCurrentAuthorizationToken()}`,
37
+ },
38
+ });
39
+ if (!response.success) {
40
+ throw response.error;
41
+ }
42
+ return response.data;
43
+ });
44
+ }
32
45
  delete(data) {
33
46
  return __awaiter(this, void 0, void 0, function* () {
34
47
  const response = yield this.httpClient.delete(`/apps/${data.appId}/bundles/${data.bundleId}`, {
@@ -53,6 +53,25 @@ class HttpClientImpl {
53
53
  }
54
54
  });
55
55
  }
56
+ patch(url, data, config) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ try {
59
+ const res = yield axios_1.default.patch(config_1.API_URL + url, data, config);
60
+ return {
61
+ success: true,
62
+ status: res.status,
63
+ data: res.data,
64
+ };
65
+ }
66
+ catch (e) {
67
+ return {
68
+ success: false,
69
+ status: e.response.status,
70
+ error: e,
71
+ };
72
+ }
73
+ });
74
+ }
56
75
  post(url, data, config) {
57
76
  return __awaiter(this, void 0, void 0, function* () {
58
77
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capawesome/cli",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "The Capawesome Cloud Command Line Interface (CLI) to manage Live Updates and more.",
5
5
  "scripts": {
6
6
  "build": "rimraf ./dist && tsc",