@goldstack/template-static-website-aws
Version:
Utilities for deploying a website to CloudFront and S3
100 lines • 4.15 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = exports.getDeploymentConfig = exports.infraAwsStaticWebsiteCli = void 0;
const utils_cli_1 = require("@goldstack/utils-cli");
const utils_log_1 = require("@goldstack/utils-log");
const infraAwsStaticWebsite_1 = require("./infraAwsStaticWebsite");
Object.defineProperty(exports, "infraAwsStaticWebsiteCli", { enumerable: true, get: function () { return infraAwsStaticWebsite_1.infraAwsStaticWebsiteCli; } });
const utils_package_1 = require("@goldstack/utils-package");
const utils_package_config_1 = require("@goldstack/utils-package-config");
const utils_terraform_1 = require("@goldstack/utils-terraform");
const yargs_1 = __importDefault(require("yargs"));
/**
* @description Gets the deployment configuration for a given deployment name.
* @param deploymentName - The name of the deployment.
* @returns The deployment configuration.
*/
const getDeploymentConfig = (deploymentName) => {
const packageConfig = new utils_package_config_1.PackageConfig({
packagePath: './',
});
return packageConfig.getDeployment(deploymentName);
};
exports.getDeploymentConfig = getDeploymentConfig;
/**
* @description Runs the CLI command for the AWS Static Website template.
* @param args - Command line arguments.
*/
const run = async (args) => {
await (0, utils_cli_1.wrapCli)(async () => {
const argv = await (0, utils_package_1.buildCli)({
yargs: yargs_1.default,
deployCommands: (0, utils_package_1.buildDeployCommands)(),
infraCommands: (0, utils_terraform_1.infraCommands)(),
})
.help()
.parse();
const [, , , ...opArgs] = args;
const packageConfig = new utils_package_config_1.PackageConfig({
packagePath: './',
});
const config = packageConfig.getConfig();
const command = argv._[0];
// console.log(JSON.stringify(argv, null, 2));
if (command === 'infra') {
const infraOperation = argv._[1];
const deploymentName = argv.deployment;
let targetVersion;
let confirm;
let skipConfirmations;
let commandArgs;
if (infraOperation === 'upgrade') {
targetVersion = argv.targetVersion;
}
else if (infraOperation === 'terraform') {
commandArgs = opArgs.slice(2);
}
else if (infraOperation === 'destroy') {
confirm = argv.yes;
}
else if (infraOperation === 'destroy-state') {
skipConfirmations = argv.yes;
}
const params = {
operation: infraOperation,
deploymentName,
targetVersion,
confirm,
skipConfirmations,
commandArgs,
};
await (0, infraAwsStaticWebsite_1.infraAwsStaticWebsiteCli)(config, params);
return;
}
if (command === 'deploy') {
const deploymentName = argv.deployment;
if (!packageConfig.hasDeployment(deploymentName)) {
if (argv['ignore-missing-deployments']) {
(0, utils_log_1.warn)(`Deployment '${deploymentName}' does not exist. Skipping deploy due to --ignore-missing-deployments flag.`);
return;
}
else {
throw new Error(`Cannot find configuration for deployment '${deploymentName}'`);
}
}
const params = {
operation: 'deploy',
deploymentName,
};
await (0, infraAwsStaticWebsite_1.infraAwsStaticWebsiteCli)(config, params);
return;
}
(0, utils_log_1.fatal)(`Unknown command: ${command}`);
throw new Error();
});
};
exports.run = run;
//# sourceMappingURL=templateStaticWebsiteAws.js.map