@goldstack/template-static-website-aws
Version:
Utilities for deploying a website to CloudFront and S3
71 lines • 2.97 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.infraAwsStaticWebsiteCli = exports.deploy = void 0;
const utils_log_1 = require("@goldstack/utils-log");
const utils_s3_deployment_1 = require("@goldstack/utils-s3-deployment");
const utils_sh_1 = require("@goldstack/utils-sh");
const utils_terraform_aws_1 = require("@goldstack/utils-terraform-aws");
const path_1 = __importDefault(require("path"));
/**
* @description Retrieves the deployment configuration by name from the package config.
* @param config - The AWS Static Website package configuration.
* @param args - Command line arguments containing the deployment name.
* @returns The deployment configuration.
*/
const getDeployment = (config, args) => {
if (args.length < 1) {
(0, utils_log_1.fatal)('Please specify the name of the deployment.');
}
const name = args[0];
const deployment = config.deployments.find((deployment) => deployment.name === name);
if (!deployment) {
(0, utils_log_1.fatal)(`Cannot find configuration for deployment '${name}''`);
throw new Error('Cannot parse configuration.');
}
return deployment;
};
/**
* @description Deploys the static website artifacts to AWS S3.
* @param config - The AWS Static Website package configuration.
* @param args - Command line arguments.
*/
const deploy = async (config, args) => {
const deployment = getDeployment(config, args);
const webDistDir = path_1.default.resolve('./webDist');
(0, utils_sh_1.assertDirectoryExists)(webDistDir, 'Cannot upload website artifacts.');
await (0, utils_s3_deployment_1.upload)({
userName: deployment.awsUser,
bucket: `${deployment.configuration.websiteDomain}-root`,
region: deployment.awsRegion,
bucketPath: '/',
localPath: webDistDir,
});
};
exports.deploy = deploy;
/**
* @description Main CLI handler for AWS Static Website infrastructure operations.
* @param config - The AWS Static Website package configuration.
* @param params - CLI parameters.
*/
const infraAwsStaticWebsiteCli = async (config, params) => {
var _a;
if (params.operation === 'deploy') {
await (0, exports.deploy)(config, [params.deploymentName]);
return;
}
await (0, utils_terraform_aws_1.terraformAwsCli)({
infraOperation: params.operation,
deploymentName: params.deploymentName,
targetVersion: params.targetVersion,
confirm: params.confirm,
commandArguments: params.commandArgs,
ignoreMissingDeployments: false,
skipConfirmations: (_a = params.skipConfirmations) !== null && _a !== void 0 ? _a : false,
options: undefined,
});
};
exports.infraAwsStaticWebsiteCli = infraAwsStaticWebsiteCli;
//# sourceMappingURL=infraAwsStaticWebsite.js.map