UNPKG

@goldstack/template-static-website-aws

Version:

Utilities for deploying a website to CloudFront and S3

50 lines 2.16 kB
"use strict"; 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_terraform_aws_1 = require("@goldstack/utils-terraform-aws"); const utils_sh_1 = require("@goldstack/utils-sh"); const path_1 = __importDefault(require("path")); 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; }; 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; const infraAwsStaticWebsiteCli = async (config, args) => { if (args.length < 1) { (0, utils_log_1.fatal)('Please provide the operation in the arguments: "up", "init", "plan", "apply", "deploy", "destroy", "upgrade", "terraform".'); throw new Error(); } const [operation, ...opArgs] = args; if (operation === 'deploy') { await (0, exports.deploy)(config, opArgs); return; } await (0, utils_terraform_aws_1.terraformAwsCli)(args); }; exports.infraAwsStaticWebsiteCli = infraAwsStaticWebsiteCli; //# sourceMappingURL=infraAwsStaticWebsite.js.map