balena-cli
Version:
The official balena Command Line Interface
31 lines • 1.62 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.applicationCreateBase = applicationCreateBase;
const errors_1 = require("../errors");
const lazy_1 = require("./lazy");
async function applicationCreateBase(resource, options, params) {
var _a;
const deviceType = options.type || (await (await Promise.resolve().then(() => require('./patterns'))).selectDeviceType());
const organization = ((_a = options.organization) === null || _a === void 0 ? void 0 : _a.toLowerCase()) ||
(await (await Promise.resolve().then(() => require('./patterns'))).getAndSelectOrganization());
try {
const application = await (0, lazy_1.getBalenaSdk)().models.application.create({
name: params.name,
deviceType,
organization,
applicationClass: resource,
});
const { capitalize } = await Promise.resolve().then(() => require('lodash'));
console.log(`${capitalize(resource)} created: slug "${application.slug}", device type "${deviceType}"`);
}
catch (err) {
if ((err.message || '').toLowerCase().includes('unique')) {
throw new errors_1.ExpectedError(`Error: An app or block or fleet with the name "${params.name}" already exists in organization "${organization}".`);
}
else if ((err.message || '').toLowerCase().includes('unauthorized')) {
throw new errors_1.ExpectedError(`Error: You are not authorized to create ${resource}s in organization "${organization}".`);
}
throw err;
}
}
//# sourceMappingURL=application-create.js.map
;