@boostercloud/cli
Version:
CLI of the Booster Framework, the next level of abstraction for cloud-native applications
52 lines (51 loc) • 2.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.assertNameIsCorrect = assertNameIsCorrect;
exports.deployToCloudProvider = deployToCloudProvider;
exports.synthToProvider = synthToProvider;
exports.nukeCloudProviderResources = nukeCloudProviderResources;
exports.startProvider = startProvider;
function assertNameIsCorrect(name) {
// Current characters max length: 37
// Lambda name limit is 64 characters
// `-subscriptions-notifier` lambda is 23 characters
// `-app` prefix is added to application stack
// which is 64 - 23 - 4 = 37
const maxProjectNameLength = 37;
if (name.length > maxProjectNameLength)
throw new ForbiddenProjectName(name, `be longer than ${maxProjectNameLength} characters`);
if (name.includes(' '))
throw new ForbiddenProjectName(name, 'contain spaces');
if (name.toLowerCase() !== name)
throw new ForbiddenProjectName(name, 'contain uppercase letters');
if (name.includes('_'))
throw new ForbiddenProjectName(name, 'contain underscore');
}
class ForbiddenProjectName extends Error {
constructor(name, restrictionText) {
super(`Project name cannot ${restrictionText}:\n\n Found: '${name}'`);
this.name = name;
this.restrictionText = restrictionText;
}
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function supportedInfrastructureMethodOrDie(methodName, config) {
assertNameIsCorrect(config.appName);
const method = config.provider.infrastructure()[methodName];
if (!method) {
throw new Error(`Attempted to perform the '${methodName}' operation with a provider that does not support this feature, please check your environment configuration.`);
}
return method;
}
function deployToCloudProvider(config) {
return supportedInfrastructureMethodOrDie('deploy', config)(config);
}
function synthToProvider(config) {
return supportedInfrastructureMethodOrDie('synth', config)(config);
}
function nukeCloudProviderResources(config) {
return supportedInfrastructureMethodOrDie('nuke', config)(config);
}
async function startProvider(port, config) {
return supportedInfrastructureMethodOrDie('start', config)(config, port);
}