@capawesome/cli
Version:
The Capawesome Cloud Command Line Interface (CLI) to manage Live Updates and more.
103 lines (102 loc) • 4.45 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const citty_1 = require("citty");
const consola_1 = __importDefault(require("consola"));
const app_bundles_1 = __importDefault(require("../../../services/app-bundles"));
const apps_1 = __importDefault(require("../../../services/apps"));
const authorization_service_1 = __importDefault(require("../../../services/authorization-service"));
const error_1 = require("../../../utils/error");
const prompt_1 = require("../../../utils/prompt");
exports.default = (0, citty_1.defineCommand)({
meta: {
description: 'Update an app bundle.',
},
args: {
androidMax: {
type: 'string',
description: 'The maximum Android version code (`versionCode`) that the bundle supports.',
},
androidMin: {
type: 'string',
description: 'The minimum Android version code (`versionCode`) that the bundle supports.',
},
appId: {
type: 'string',
description: 'ID of the app.',
},
bundleId: {
type: 'string',
description: 'ID of the bundle.',
},
rollout: {
type: 'string',
description: 'The percentage of devices to deploy the bundle to. Must be a number between 0 and 1 (e.g. 0.5).',
},
iosMax: {
type: 'string',
description: 'The maximum iOS bundle version (`CFBundleVersion`) that the bundle supports.',
},
iosMin: {
type: 'string',
description: 'The minimum iOS bundle version (`CFBundleVersion`) that the bundle supports.',
},
},
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
if (!authorization_service_1.default.hasAuthorizationToken()) {
consola_1.default.error('You must be logged in to run this command.');
process.exit(1);
}
// Prompt for missing arguments
const { androidMax, androidMin, rollout, iosMax, iosMin } = ctx.args;
let appId = ctx.args.appId;
let bundleId = ctx.args.bundleId;
if (!appId) {
const apps = yield apps_1.default.findAll();
if (!apps.length) {
consola_1.default.error('You must create an app before updating a bundle.');
process.exit(1);
}
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
appId = yield (0, prompt_1.prompt)('Which app do you want to update the bundle for?', {
type: 'select',
options: apps.map((app) => ({ label: app.name, value: app.id })),
});
}
if (!bundleId) {
bundleId = yield (0, prompt_1.prompt)('Enter the bundle ID:', {
type: 'text',
});
}
// Update bundle
try {
const rolloutAsNumber = parseFloat(rollout);
yield app_bundles_1.default.update({
appId,
appBundleId: bundleId,
maxAndroidAppVersionCode: androidMax,
maxIosAppVersionCode: iosMax,
minAndroidAppVersionCode: androidMin,
minIosAppVersionCode: iosMin,
rolloutPercentage: rolloutAsNumber,
});
consola_1.default.success('Bundle updated successfully.');
}
catch (error) {
const message = (0, error_1.getMessageFromUnknownError)(error);
consola_1.default.error(message);
process.exit(1);
}
}),
});