@goldstack/template-nextjs 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,9 @@
1
- import { NextjsDeployment } from './types/NextJsPackage';
2
- import { DeploymentState } from '@goldstack/infra';
3
- interface DeployLambdaParams {
4
- deployment: NextjsDeployment;
5
- deploymentState: DeploymentState;
6
- }
7
- export declare const deployEdgeLambda: (params: DeployLambdaParams) => Promise<void>;
8
- export {};
1
+ import { NextjsDeployment } from './types/NextJsPackage';
2
+ import { DeploymentState } from '@goldstack/infra';
3
+ interface DeployLambdaParams {
4
+ deployment: NextjsDeployment;
5
+ deploymentState: DeploymentState;
6
+ }
7
+ export declare const deployEdgeLambda: (params: DeployLambdaParams) => Promise<void>;
8
+ export {};
9
9
  //# sourceMappingURL=edgeLambdaDeploy.d.ts.map
@@ -1,100 +1,100 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.deployEdgeLambda = void 0;
7
- const infra_aws_1 = require("@goldstack/infra-aws");
8
- const infra_1 = require("@goldstack/infra");
9
- const utils_sh_1 = require("@goldstack/utils-sh");
10
- const utils_aws_cli_1 = require("@goldstack/utils-aws-cli");
11
- const util_1 = __importDefault(require("util"));
12
- const glob_1 = __importDefault(require("glob"));
13
- const edgeLambdaPackage_1 = require("./edgeLambdaPackage");
14
- const utils_aws_lambda_1 = require("@goldstack/utils-aws-lambda");
15
- const glob = util_1.default.promisify(glob_1.default);
16
- const deployEdgeLambda = async (params) => {
17
- const targetArchive = 'lambda.zip';
18
- const lambdaSourceDir = './src/utils/routing/';
19
- const lambdaCompiledDir = './dist/src/utils/routing/';
20
- const lambdaPackageDir = './dist/edgeLambda/';
21
- // Getting the latest manifest containing Next js dynamic routes
22
- const routesManifest = JSON.parse((0, utils_sh_1.read)('./.next/routes-manifest.json'));
23
- // adding in statically rendered pages
24
- const dynamicRoutes = routesManifest.dynamicRoutes;
25
- const htmlPagePaths = await glob('webDist/**/*.html');
26
- const htmlPagePathsWithoutRootDir = htmlPagePaths.map((match) => {
27
- const els = match.split('/');
28
- els.shift();
29
- const withoutRootDir = els.join('/');
30
- return withoutRootDir;
31
- });
32
- const htmlPagePathsWithoutExtension = htmlPagePathsWithoutRootDir.map((match) => {
33
- const comps = match.split('.');
34
- comps.pop();
35
- const withoutExtension = comps.join('.');
36
- return withoutExtension;
37
- });
38
- const staticRoutes = htmlPagePathsWithoutExtension.map((match) => ({
39
- page: '/' + match,
40
- regex: `^\\/${match.replace(/\//g, '\\/')}$`,
41
- }));
42
- routesManifest.dynamicRoutes = [...staticRoutes, ...dynamicRoutes];
43
- // Making sure there are no linting errors with copied file
44
- await (0, utils_sh_1.rmSafe)(`${lambdaSourceDir}routes-manifest.json`);
45
- (0, utils_sh_1.write)(JSON.stringify(routesManifest, null, 2), `${lambdaSourceDir}routes-manifest.json`);
46
- await (0, utils_sh_1.rmSafe)(`${lambdaCompiledDir}routes-manifest.json`);
47
- (0, utils_sh_1.cp)('-f', `${lambdaSourceDir}routes-manifest.json`, `${lambdaCompiledDir}routes-manifest.json`);
48
- // pack source for Lambda Node.js runtime
49
- await (0, utils_sh_1.rmSafe)(lambdaPackageDir);
50
- (0, utils_sh_1.mkdir)('-p', lambdaPackageDir);
51
- await (0, edgeLambdaPackage_1.packageEdgeLambda)({
52
- sourceFile: `${lambdaCompiledDir}lambda.js`,
53
- destFile: `${lambdaPackageDir}lambda.js`,
54
- });
55
- const functionName = (0, infra_1.readTerraformStateVariable)(params.deploymentState, 'edge_function_name');
56
- const credentials = await (0, infra_aws_1.getAWSUser)(params.deployment.awsUser);
57
- const deployResult = await (0, utils_aws_lambda_1.deployFunction)({
58
- targetArchiveName: targetArchive,
59
- lambdaPackageDir,
60
- functionName,
61
- awsCredentials: credentials,
62
- region: 'us-east-1',
63
- });
64
- const { FunctionArn } = deployResult;
65
- const publishResults = await (0, utils_aws_cli_1.awsCli)({
66
- credentials,
67
- region: 'us-east-1',
68
- command: `lambda publish-version --function-name ${functionName}`,
69
- });
70
- const { Version } = JSON.parse(publishResults);
71
- const qualifiedArn = `${FunctionArn}:${Version}`;
72
- // Add a wait since there sometimes appear to be race conditions
73
- // CF thinking the lambda is not in active state
74
- // notwithstanding the above check
75
- await new Promise((resolve) => {
76
- setTimeout(() => resolve(), 10000);
77
- });
78
- const cfDistributionResult = await (0, utils_aws_cli_1.awsCli)({
79
- credentials,
80
- region: 'us-east-1',
81
- command: `cloudfront get-distribution-config --id ${(0, infra_1.readTerraformStateVariable)(params.deploymentState, 'website_cdn_root_id')}`,
82
- options: { silent: true },
83
- });
84
- const cfDistribution = JSON.parse(cfDistributionResult);
85
- const eTag = cfDistribution.ETag;
86
- const lambdaFunctionAssociations = cfDistribution.DistributionConfig.DefaultCacheBehavior
87
- .LambdaFunctionAssociations.Items;
88
- lambdaFunctionAssociations[0].LambdaFunctionARN = `${qualifiedArn}`;
89
- await (0, utils_sh_1.rmSafe)('./dist/cf.json');
90
- (0, utils_sh_1.write)(JSON.stringify(cfDistribution.DistributionConfig, null, 2), './dist/cf.json');
91
- await (0, utils_aws_cli_1.awsCli)({
92
- credentials: credentials,
93
- region: 'us-east-1',
94
- command: `cloudfront update-distribution --id ${(0, infra_1.readTerraformStateVariable)(params.deploymentState, 'website_cdn_root_id')} --distribution-config file://dist/cf.json --if-match ${eTag}`,
95
- options: { silent: true },
96
- });
97
- await (0, utils_sh_1.rmSafe)('./dist/cf.json');
98
- };
99
- exports.deployEdgeLambda = deployEdgeLambda;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.deployEdgeLambda = void 0;
7
+ const infra_aws_1 = require("@goldstack/infra-aws");
8
+ const infra_1 = require("@goldstack/infra");
9
+ const utils_sh_1 = require("@goldstack/utils-sh");
10
+ const utils_aws_cli_1 = require("@goldstack/utils-aws-cli");
11
+ const util_1 = __importDefault(require("util"));
12
+ const glob_1 = __importDefault(require("glob"));
13
+ const edgeLambdaPackage_1 = require("./edgeLambdaPackage");
14
+ const utils_aws_lambda_1 = require("@goldstack/utils-aws-lambda");
15
+ const glob = util_1.default.promisify(glob_1.default);
16
+ const deployEdgeLambda = async (params) => {
17
+ const targetArchive = 'lambda.zip';
18
+ const lambdaSourceDir = './src/utils/routing/';
19
+ const lambdaCompiledDir = './dist/src/utils/routing/';
20
+ const lambdaPackageDir = './dist/edgeLambda/';
21
+ // Getting the latest manifest containing Next js dynamic routes
22
+ const routesManifest = JSON.parse((0, utils_sh_1.read)('./.next/routes-manifest.json'));
23
+ // adding in statically rendered pages
24
+ const dynamicRoutes = routesManifest.dynamicRoutes;
25
+ const htmlPagePaths = await glob('webDist/**/*.html');
26
+ const htmlPagePathsWithoutRootDir = htmlPagePaths.map((match) => {
27
+ const els = match.split('/');
28
+ els.shift();
29
+ const withoutRootDir = els.join('/');
30
+ return withoutRootDir;
31
+ });
32
+ const htmlPagePathsWithoutExtension = htmlPagePathsWithoutRootDir.map((match) => {
33
+ const comps = match.split('.');
34
+ comps.pop();
35
+ const withoutExtension = comps.join('.');
36
+ return withoutExtension;
37
+ });
38
+ const staticRoutes = htmlPagePathsWithoutExtension.map((match) => ({
39
+ page: '/' + match,
40
+ regex: `^\\/${match.replace(/\//g, '\\/')}$`,
41
+ }));
42
+ routesManifest.dynamicRoutes = [...staticRoutes, ...dynamicRoutes];
43
+ // Making sure there are no linting errors with copied file
44
+ await (0, utils_sh_1.rmSafe)(`${lambdaSourceDir}routes-manifest.json`);
45
+ (0, utils_sh_1.write)(JSON.stringify(routesManifest, null, 2), `${lambdaSourceDir}routes-manifest.json`);
46
+ await (0, utils_sh_1.rmSafe)(`${lambdaCompiledDir}routes-manifest.json`);
47
+ (0, utils_sh_1.cp)('-f', `${lambdaSourceDir}routes-manifest.json`, `${lambdaCompiledDir}routes-manifest.json`);
48
+ // pack source for Lambda Node.js runtime
49
+ await (0, utils_sh_1.rmSafe)(lambdaPackageDir);
50
+ (0, utils_sh_1.mkdir)('-p', lambdaPackageDir);
51
+ await (0, edgeLambdaPackage_1.packageEdgeLambda)({
52
+ sourceFile: `${lambdaCompiledDir}lambda.js`,
53
+ destFile: `${lambdaPackageDir}lambda.js`,
54
+ });
55
+ const functionName = (0, infra_1.readTerraformStateVariable)(params.deploymentState, 'edge_function_name');
56
+ const credentials = await (0, infra_aws_1.getAWSUser)(params.deployment.awsUser);
57
+ const deployResult = await (0, utils_aws_lambda_1.deployFunction)({
58
+ targetArchiveName: targetArchive,
59
+ lambdaPackageDir,
60
+ functionName,
61
+ awsCredentials: credentials,
62
+ region: 'us-east-1',
63
+ });
64
+ const { FunctionArn } = deployResult;
65
+ const publishResults = await (0, utils_aws_cli_1.awsCli)({
66
+ credentials,
67
+ region: 'us-east-1',
68
+ command: `lambda publish-version --function-name ${functionName}`,
69
+ });
70
+ const { Version } = JSON.parse(publishResults);
71
+ const qualifiedArn = `${FunctionArn}:${Version}`;
72
+ // Add a wait since there sometimes appear to be race conditions
73
+ // CF thinking the lambda is not in active state
74
+ // notwithstanding the above check
75
+ await new Promise((resolve) => {
76
+ setTimeout(() => resolve(), 10000);
77
+ });
78
+ const cfDistributionResult = await (0, utils_aws_cli_1.awsCli)({
79
+ credentials,
80
+ region: 'us-east-1',
81
+ command: `cloudfront get-distribution-config --id ${(0, infra_1.readTerraformStateVariable)(params.deploymentState, 'website_cdn_root_id')}`,
82
+ options: { silent: true },
83
+ });
84
+ const cfDistribution = JSON.parse(cfDistributionResult);
85
+ const eTag = cfDistribution.ETag;
86
+ const lambdaFunctionAssociations = cfDistribution.DistributionConfig.DefaultCacheBehavior
87
+ .LambdaFunctionAssociations.Items;
88
+ lambdaFunctionAssociations[0].LambdaFunctionARN = `${qualifiedArn}`;
89
+ await (0, utils_sh_1.rmSafe)('./dist/cf.json');
90
+ (0, utils_sh_1.write)(JSON.stringify(cfDistribution.DistributionConfig, null, 2), './dist/cf.json');
91
+ await (0, utils_aws_cli_1.awsCli)({
92
+ credentials: credentials,
93
+ region: 'us-east-1',
94
+ command: `cloudfront update-distribution --id ${(0, infra_1.readTerraformStateVariable)(params.deploymentState, 'website_cdn_root_id')} --distribution-config file://dist/cf.json --if-match ${eTag}`,
95
+ options: { silent: true },
96
+ });
97
+ await (0, utils_sh_1.rmSafe)('./dist/cf.json');
98
+ };
99
+ exports.deployEdgeLambda = deployEdgeLambda;
100
100
  //# sourceMappingURL=edgeLambdaDeploy.js.map
@@ -1,6 +1,6 @@
1
- export interface PackageEdgeLambdaParams {
2
- sourceFile: string;
3
- destFile: string;
4
- }
5
- export declare const packageEdgeLambda: (params: PackageEdgeLambdaParams) => Promise<void>;
1
+ export interface PackageEdgeLambdaParams {
2
+ sourceFile: string;
3
+ destFile: string;
4
+ }
5
+ export declare const packageEdgeLambda: (params: PackageEdgeLambdaParams) => Promise<void>;
6
6
  //# sourceMappingURL=edgeLambdaPackage.d.ts.map
@@ -1,33 +1,33 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.packageEdgeLambda = void 0;
7
- const webpack_1 = __importDefault(require("webpack"));
8
- const path_1 = __importDefault(require("path"));
9
- const utils_sh_1 = require("@goldstack/utils-sh");
10
- const packageEdgeLambda = async (params) => {
11
- (0, utils_sh_1.assertFileExists)(params.sourceFile);
12
- await new Promise((resolve, reject) => {
13
- (0, webpack_1.default)({
14
- mode: 'production',
15
- entry: `${params.sourceFile}`,
16
- target: 'node',
17
- output: {
18
- libraryTarget: 'commonjs2',
19
- path: path_1.default.dirname(path_1.default.resolve(params.destFile)),
20
- filename: `${path_1.default.relative(path_1.default.dirname(params.destFile), params.destFile)}`,
21
- },
22
- }, (err, stats) => {
23
- if (err || stats.hasErrors()) {
24
- reject();
25
- return;
26
- }
27
- resolve();
28
- });
29
- });
30
- (0, utils_sh_1.assertFileExists)(path_1.default.resolve(params.destFile));
31
- };
32
- exports.packageEdgeLambda = packageEdgeLambda;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.packageEdgeLambda = void 0;
7
+ const webpack_1 = __importDefault(require("webpack"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const utils_sh_1 = require("@goldstack/utils-sh");
10
+ const packageEdgeLambda = async (params) => {
11
+ (0, utils_sh_1.assertFileExists)(params.sourceFile);
12
+ await new Promise((resolve, reject) => {
13
+ (0, webpack_1.default)({
14
+ mode: 'production',
15
+ entry: `${params.sourceFile}`,
16
+ target: 'node',
17
+ output: {
18
+ libraryTarget: 'commonjs2',
19
+ path: path_1.default.dirname(path_1.default.resolve(params.destFile)),
20
+ filename: `${path_1.default.relative(path_1.default.dirname(params.destFile), params.destFile)}`,
21
+ },
22
+ }, (err, stats) => {
23
+ if (err || stats.hasErrors()) {
24
+ reject();
25
+ return;
26
+ }
27
+ resolve();
28
+ });
29
+ });
30
+ (0, utils_sh_1.assertFileExists)(path_1.default.resolve(params.destFile));
31
+ };
32
+ exports.packageEdgeLambda = packageEdgeLambda;
33
33
  //# sourceMappingURL=edgeLambdaPackage.js.map
@@ -1,3 +1,3 @@
1
- import { NextjsDeployment } from './types/NextJsPackage';
2
- export declare const setNextjsEnvironmentVariables: (deployment: NextjsDeployment) => Promise<void>;
1
+ import { NextjsDeployment } from './types/NextJsPackage';
2
+ export declare const setNextjsEnvironmentVariables: (deployment: NextjsDeployment) => Promise<void>;
3
3
  //# sourceMappingURL=nextjsEnvironment.d.ts.map
@@ -1,18 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setNextjsEnvironmentVariables = void 0;
4
- const utils_sh_1 = require("@goldstack/utils-sh");
5
- const setNextjsEnvironmentVariables = async (deployment) => {
6
- const vars = (deployment === null || deployment === void 0 ? void 0 : deployment.configuration.environmentVariables) || [];
7
- vars.push({
8
- name: 'NEXT_PUBLIC_GOLDSTACK_DEPLOYMENT',
9
- value: deployment.name,
10
- });
11
- console.log('Set production environment variables', vars);
12
- const envContent = vars
13
- .map((envVar) => `${envVar.name}=${envVar.value}\n`)
14
- .join('');
15
- (0, utils_sh_1.write)(envContent, '.env.production');
16
- };
17
- exports.setNextjsEnvironmentVariables = setNextjsEnvironmentVariables;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setNextjsEnvironmentVariables = void 0;
4
+ const utils_sh_1 = require("@goldstack/utils-sh");
5
+ const setNextjsEnvironmentVariables = async (deployment) => {
6
+ const vars = (deployment === null || deployment === void 0 ? void 0 : deployment.configuration.environmentVariables) || [];
7
+ vars.push({
8
+ name: 'NEXT_PUBLIC_GOLDSTACK_DEPLOYMENT',
9
+ value: deployment.name,
10
+ });
11
+ console.log('Set production environment variables', vars);
12
+ const envContent = vars
13
+ .map((envVar) => `${envVar.name}=${envVar.value}\n`)
14
+ .join('');
15
+ (0, utils_sh_1.write)(envContent, '.env.production');
16
+ };
17
+ exports.setNextjsEnvironmentVariables = setNextjsEnvironmentVariables;
18
18
  //# sourceMappingURL=nextjsEnvironment.js.map
@@ -1,217 +1,217 @@
1
- {
2
- "$ref": "#/definitions/NextjsPackage",
3
- "$schema": "http://json-schema.org/draft-07/schema#",
4
- "definitions": {
5
- "AWSDeploymentRegion": {
6
- "description": "AWS region that infrastructure should be deployed to.",
7
- "enum": [
8
- "us-east-1",
9
- "us-west-1",
10
- "us-west-2",
11
- "af-south-1",
12
- "ap-east-1",
13
- "ap-south-1",
14
- "ap-northeast-3",
15
- "ap-northeast-2",
16
- "ap-southeast-1",
17
- "ap-southeast-2",
18
- "ap-northeast-1",
19
- "ca-central-1",
20
- "eu-central-1",
21
- "eu-west-1",
22
- "eu-west-2",
23
- "eu-south-1",
24
- "eu-west-3",
25
- "eu-north-1",
26
- "me-south-1",
27
- "sa-east-1"
28
- ],
29
- "title": "AWS Deployment Region",
30
- "type": "string"
31
- },
32
- "AWSUserName": {
33
- "description": "Name of the AWS user that is used to perform the deployment.",
34
- "title": "AWS User Name",
35
- "type": "string"
36
- },
37
- "DefaultCacheDuration": {
38
- "description": "Seconds resources will be cached for by default. For development sites, a good value is around 10 seconds and for production sites 60-100 seconds.",
39
- "exclusiveMinimum": 0,
40
- "title": "Default Cache Duraction",
41
- "type": "number"
42
- },
43
- "DeploymentName": {
44
- "description": "Identifier for this deployment. No spaces allowed in name.",
45
- "pattern": "^[^\\s]*$",
46
- "title": "Deployment Name",
47
- "type": "string"
48
- },
49
- "HostedZoneDomain": {
50
- "description": "The domain name of the Route 53 hosted zone that this website should be added to.",
51
- "title": "Hosted Zone Domain",
52
- "type": "string"
53
- },
54
- "Name": {
55
- "description": "Name of this package.",
56
- "title": "Package Name",
57
- "type": "string"
58
- },
59
- "NextJsInfrastructureConfiguration": {
60
- "additionalProperties": false,
61
- "description": "Configure NextJs infrastructure",
62
- "properties": {
63
- "deployments": {
64
- "items": {
65
- "$ref": "#/definitions/NextjsDeployment"
66
- },
67
- "type": "array"
68
- }
69
- },
70
- "required": [
71
- "deployments"
72
- ],
73
- "title": "NextJs App Infrastructure",
74
- "type": "object"
75
- },
76
- "NextjsConfiguration": {
77
- "description": "Configure NextJS application",
78
- "properties": {
79
- "infrastructure": {
80
- "$ref": "#/definitions/NextJsInfrastructureConfiguration"
81
- }
82
- },
83
- "required": [
84
- "infrastructure"
85
- ],
86
- "title": "NextJs Configuration",
87
- "type": "object"
88
- },
89
- "NextjsDeployment": {
90
- "description": "Configure NextJs deployment",
91
- "properties": {
92
- "awsRegion": {
93
- "$ref": "#/definitions/AWSDeploymentRegion"
94
- },
95
- "awsUser": {
96
- "$ref": "#/definitions/AWSUserName"
97
- },
98
- "defaultCacheDuration": {
99
- "$ref": "#/definitions/DefaultCacheDuration"
100
- },
101
- "environmentVariables": {
102
- "items": {
103
- "$ref": "#/definitions/NextjsEnvironmentVariable"
104
- },
105
- "type": "array"
106
- },
107
- "hostedZoneDomain": {
108
- "$ref": "#/definitions/HostedZoneDomain"
109
- },
110
- "name": {
111
- "$ref": "#/definitions/DeploymentName"
112
- },
113
- "terraformVariables": {
114
- "$ref": "#/definitions/TerraformVariables"
115
- },
116
- "websiteDomain": {
117
- "$ref": "#/definitions/PrimaryWebsiteDomain"
118
- },
119
- "websiteDomainRedirect": {
120
- "$ref": "#/definitions/RedirectWebsiteDomain"
121
- }
122
- },
123
- "required": [
124
- "awsRegion",
125
- "awsUser",
126
- "hostedZoneDomain",
127
- "name",
128
- "websiteDomain",
129
- "websiteDomainRedirect"
130
- ],
131
- "title": "NextJs Deployment",
132
- "type": "object"
133
- },
134
- "NextjsEnvironmentVariable": {
135
- "additionalProperties": false,
136
- "description": "NextJs public environment variable for web application (see https://nextjs.org/docs/basic-features/environment-variables)",
137
- "properties": {
138
- "name": {
139
- "description": "Environment variable name",
140
- "title": "Name",
141
- "type": "string"
142
- },
143
- "value": {
144
- "description": "Environment variable value",
145
- "title": "Value",
146
- "type": "string"
147
- }
148
- },
149
- "required": [
150
- "name",
151
- "value"
152
- ],
153
- "title": "NextJs Environment Variable",
154
- "type": "object"
155
- },
156
- "NextjsPackage": {
157
- "additionalProperties": false,
158
- "description": "A NextJs application",
159
- "properties": {
160
- "configuration": {
161
- "$ref": "#/definitions/NextjsConfiguration"
162
- },
163
- "name": {
164
- "$ref": "#/definitions/Name"
165
- },
166
- "template": {
167
- "$ref": "#/definitions/Template"
168
- },
169
- "templateVersion": {
170
- "$ref": "#/definitions/TemplateVersion"
171
- }
172
- },
173
- "required": [
174
- "configuration",
175
- "name",
176
- "template",
177
- "templateVersion"
178
- ],
179
- "title": "NextJs Package",
180
- "type": "object"
181
- },
182
- "PrimaryWebsiteDomain": {
183
- "description": "The domain name your users should use (e.g. mysite.com)",
184
- "title": "Primary Website Domain",
185
- "type": "string"
186
- },
187
- "RedirectWebsiteDomain": {
188
- "description": "A domain name that users are redirected from to your Primary Website Domain (e.g. www.mysite.com)",
189
- "title": "Redirect Website Domain",
190
- "type": "string"
191
- },
192
- "Template": {
193
- "description": "Name of the template used for creating this package.",
194
- "pattern": "^[^\\s]*$",
195
- "title": "Template",
196
- "type": "string"
197
- },
198
- "TemplateVersion": {
199
- "description": "Latest template version that was applied to this package.",
200
- "title": "Template Version",
201
- "type": "string"
202
- },
203
- "TerraformVariable": {
204
- "description": "Name of the property that should be converted into a Terraform variable.",
205
- "title": "Terraform Variable",
206
- "type": "string"
207
- },
208
- "TerraformVariables": {
209
- "description": "Define which of the deployment variables will be made available for terraform.",
210
- "items": {
211
- "$ref": "#/definitions/TerraformVariable"
212
- },
213
- "title": "Terraform Variables",
214
- "type": "array"
215
- }
216
- }
217
- }
1
+ {
2
+ "$ref": "#/definitions/NextjsPackage",
3
+ "$schema": "http://json-schema.org/draft-07/schema#",
4
+ "definitions": {
5
+ "AWSDeploymentRegion": {
6
+ "description": "AWS region that infrastructure should be deployed to.",
7
+ "enum": [
8
+ "us-east-1",
9
+ "us-west-1",
10
+ "us-west-2",
11
+ "af-south-1",
12
+ "ap-east-1",
13
+ "ap-south-1",
14
+ "ap-northeast-3",
15
+ "ap-northeast-2",
16
+ "ap-southeast-1",
17
+ "ap-southeast-2",
18
+ "ap-northeast-1",
19
+ "ca-central-1",
20
+ "eu-central-1",
21
+ "eu-west-1",
22
+ "eu-west-2",
23
+ "eu-south-1",
24
+ "eu-west-3",
25
+ "eu-north-1",
26
+ "me-south-1",
27
+ "sa-east-1"
28
+ ],
29
+ "title": "AWS Deployment Region",
30
+ "type": "string"
31
+ },
32
+ "AWSUserName": {
33
+ "description": "Name of the AWS user that is used to perform the deployment.",
34
+ "title": "AWS User Name",
35
+ "type": "string"
36
+ },
37
+ "DefaultCacheDuration": {
38
+ "description": "Seconds resources will be cached for by default. For development sites, a good value is around 10 seconds and for production sites 60-100 seconds.",
39
+ "exclusiveMinimum": 0,
40
+ "title": "Default Cache Duraction",
41
+ "type": "number"
42
+ },
43
+ "DeploymentName": {
44
+ "description": "Identifier for this deployment. No spaces allowed in name.",
45
+ "pattern": "^[^\\s]*$",
46
+ "title": "Deployment Name",
47
+ "type": "string"
48
+ },
49
+ "HostedZoneDomain": {
50
+ "description": "The domain name of the Route 53 hosted zone that this website should be added to.",
51
+ "title": "Hosted Zone Domain",
52
+ "type": "string"
53
+ },
54
+ "Name": {
55
+ "description": "Name of this package.",
56
+ "title": "Package Name",
57
+ "type": "string"
58
+ },
59
+ "NextJsInfrastructureConfiguration": {
60
+ "additionalProperties": false,
61
+ "description": "Configure NextJs infrastructure",
62
+ "properties": {
63
+ "deployments": {
64
+ "items": {
65
+ "$ref": "#/definitions/NextjsDeployment"
66
+ },
67
+ "type": "array"
68
+ }
69
+ },
70
+ "required": [
71
+ "deployments"
72
+ ],
73
+ "title": "NextJs App Infrastructure",
74
+ "type": "object"
75
+ },
76
+ "NextjsConfiguration": {
77
+ "description": "Configure NextJS application",
78
+ "properties": {
79
+ "infrastructure": {
80
+ "$ref": "#/definitions/NextJsInfrastructureConfiguration"
81
+ }
82
+ },
83
+ "required": [
84
+ "infrastructure"
85
+ ],
86
+ "title": "NextJs Configuration",
87
+ "type": "object"
88
+ },
89
+ "NextjsDeployment": {
90
+ "description": "Configure NextJs deployment",
91
+ "properties": {
92
+ "awsRegion": {
93
+ "$ref": "#/definitions/AWSDeploymentRegion"
94
+ },
95
+ "awsUser": {
96
+ "$ref": "#/definitions/AWSUserName"
97
+ },
98
+ "defaultCacheDuration": {
99
+ "$ref": "#/definitions/DefaultCacheDuration"
100
+ },
101
+ "environmentVariables": {
102
+ "items": {
103
+ "$ref": "#/definitions/NextjsEnvironmentVariable"
104
+ },
105
+ "type": "array"
106
+ },
107
+ "hostedZoneDomain": {
108
+ "$ref": "#/definitions/HostedZoneDomain"
109
+ },
110
+ "name": {
111
+ "$ref": "#/definitions/DeploymentName"
112
+ },
113
+ "terraformVariables": {
114
+ "$ref": "#/definitions/TerraformVariables"
115
+ },
116
+ "websiteDomain": {
117
+ "$ref": "#/definitions/PrimaryWebsiteDomain"
118
+ },
119
+ "websiteDomainRedirect": {
120
+ "$ref": "#/definitions/RedirectWebsiteDomain"
121
+ }
122
+ },
123
+ "required": [
124
+ "awsRegion",
125
+ "awsUser",
126
+ "hostedZoneDomain",
127
+ "name",
128
+ "websiteDomain",
129
+ "websiteDomainRedirect"
130
+ ],
131
+ "title": "NextJs Deployment",
132
+ "type": "object"
133
+ },
134
+ "NextjsEnvironmentVariable": {
135
+ "additionalProperties": false,
136
+ "description": "NextJs public environment variable for web application (see https://nextjs.org/docs/basic-features/environment-variables)",
137
+ "properties": {
138
+ "name": {
139
+ "description": "Environment variable name",
140
+ "title": "Name",
141
+ "type": "string"
142
+ },
143
+ "value": {
144
+ "description": "Environment variable value",
145
+ "title": "Value",
146
+ "type": "string"
147
+ }
148
+ },
149
+ "required": [
150
+ "name",
151
+ "value"
152
+ ],
153
+ "title": "NextJs Environment Variable",
154
+ "type": "object"
155
+ },
156
+ "NextjsPackage": {
157
+ "additionalProperties": false,
158
+ "description": "A NextJs application",
159
+ "properties": {
160
+ "configuration": {
161
+ "$ref": "#/definitions/NextjsConfiguration"
162
+ },
163
+ "name": {
164
+ "$ref": "#/definitions/Name"
165
+ },
166
+ "template": {
167
+ "$ref": "#/definitions/Template"
168
+ },
169
+ "templateVersion": {
170
+ "$ref": "#/definitions/TemplateVersion"
171
+ }
172
+ },
173
+ "required": [
174
+ "configuration",
175
+ "name",
176
+ "template",
177
+ "templateVersion"
178
+ ],
179
+ "title": "NextJs Package",
180
+ "type": "object"
181
+ },
182
+ "PrimaryWebsiteDomain": {
183
+ "description": "The domain name your users should use (e.g. mysite.com)",
184
+ "title": "Primary Website Domain",
185
+ "type": "string"
186
+ },
187
+ "RedirectWebsiteDomain": {
188
+ "description": "A domain name that users are redirected from to your Primary Website Domain (e.g. www.mysite.com)",
189
+ "title": "Redirect Website Domain",
190
+ "type": "string"
191
+ },
192
+ "Template": {
193
+ "description": "Name of the template used for creating this package.",
194
+ "pattern": "^[^\\s]*$",
195
+ "title": "Template",
196
+ "type": "string"
197
+ },
198
+ "TemplateVersion": {
199
+ "description": "Latest template version that was applied to this package.",
200
+ "title": "Template Version",
201
+ "type": "string"
202
+ },
203
+ "TerraformVariable": {
204
+ "description": "Name of the property that should be converted into a Terraform variable.",
205
+ "title": "Terraform Variable",
206
+ "type": "string"
207
+ },
208
+ "TerraformVariables": {
209
+ "description": "Define which of the deployment variables will be made available for terraform.",
210
+ "items": {
211
+ "$ref": "#/definitions/TerraformVariable"
212
+ },
213
+ "title": "Terraform Variables",
214
+ "type": "array"
215
+ }
216
+ }
217
+ }
@@ -1,4 +1,4 @@
1
- import { NextjsPackage } from './types/NextJsPackage';
2
- export type { NextjsPackage };
3
- export declare const run: (args: string[]) => Promise<void>;
1
+ import { NextjsPackage } from './types/NextJsPackage';
2
+ export type { NextjsPackage };
3
+ export declare const run: (args: string[]) => Promise<void>;
4
4
  //# sourceMappingURL=templateNextjs.d.ts.map
@@ -1,62 +1,62 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.run = void 0;
7
- const utils_cli_1 = require("@goldstack/utils-cli");
8
- const utils_log_1 = require("@goldstack/utils-log");
9
- const template_static_website_aws_1 = require("@goldstack/template-static-website-aws");
10
- const yargs_1 = __importDefault(require("yargs"));
11
- const utils_package_1 = require("@goldstack/utils-package");
12
- const infra_1 = require("@goldstack/infra");
13
- const utils_terraform_1 = require("@goldstack/utils-terraform");
14
- const utils_package_config_1 = require("@goldstack/utils-package-config");
15
- const nextjsEnvironment_1 = require("./nextjsEnvironment");
16
- const edgeLambdaDeploy_1 = require("./edgeLambdaDeploy");
17
- const run = async (args) => {
18
- await (0, utils_cli_1.wrapCli)(async () => {
19
- const argv = await (0, utils_package_1.buildCli)({
20
- yargs: yargs_1.default,
21
- deployCommands: (0, utils_package_1.buildDeployCommands)(),
22
- infraCommands: (0, utils_terraform_1.infraCommands)(),
23
- })
24
- .command('set-nextjs-env <deployment>', 'Set NextJs environment variables', () => {
25
- return yargs_1.default.positional('deployment', {
26
- type: 'string',
27
- describe: 'Name of the deployment this command should be applied to',
28
- demandOption: true,
29
- });
30
- })
31
- .help()
32
- .parse();
33
- const packageConfig = new utils_package_config_1.PackageConfig({
34
- packagePath: './',
35
- });
36
- const config = packageConfig.getConfig();
37
- const command = argv._[0];
38
- const [, , , ...opArgs] = args;
39
- if (command === 'set-nextjs-env') {
40
- await (0, nextjsEnvironment_1.setNextjsEnvironmentVariables)(packageConfig.getDeployment(opArgs[0]));
41
- return;
42
- }
43
- if (command === 'infra') {
44
- await (0, template_static_website_aws_1.infraAwsStaticWebsiteCli)(config, opArgs);
45
- return;
46
- }
47
- if (command === 'deploy') {
48
- await (0, template_static_website_aws_1.infraAwsStaticWebsiteCli)(config, ['deploy', ...opArgs]);
49
- const deployment = packageConfig.getDeployment(opArgs[0]);
50
- const deploymentState = (0, infra_1.readDeploymentState)('./', deployment.name);
51
- await (0, edgeLambdaDeploy_1.deployEdgeLambda)({
52
- deployment,
53
- deploymentState: deploymentState,
54
- });
55
- return;
56
- }
57
- (0, utils_log_1.fatal)('Unknown command: ' + command);
58
- throw new Error();
59
- });
60
- };
61
- exports.run = run;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.run = void 0;
7
+ const utils_cli_1 = require("@goldstack/utils-cli");
8
+ const utils_log_1 = require("@goldstack/utils-log");
9
+ const template_static_website_aws_1 = require("@goldstack/template-static-website-aws");
10
+ const yargs_1 = __importDefault(require("yargs"));
11
+ const utils_package_1 = require("@goldstack/utils-package");
12
+ const infra_1 = require("@goldstack/infra");
13
+ const utils_terraform_1 = require("@goldstack/utils-terraform");
14
+ const utils_package_config_1 = require("@goldstack/utils-package-config");
15
+ const nextjsEnvironment_1 = require("./nextjsEnvironment");
16
+ const edgeLambdaDeploy_1 = require("./edgeLambdaDeploy");
17
+ const run = async (args) => {
18
+ await (0, utils_cli_1.wrapCli)(async () => {
19
+ const argv = await (0, utils_package_1.buildCli)({
20
+ yargs: yargs_1.default,
21
+ deployCommands: (0, utils_package_1.buildDeployCommands)(),
22
+ infraCommands: (0, utils_terraform_1.infraCommands)(),
23
+ })
24
+ .command('set-nextjs-env <deployment>', 'Set NextJs environment variables', () => {
25
+ return yargs_1.default.positional('deployment', {
26
+ type: 'string',
27
+ describe: 'Name of the deployment this command should be applied to',
28
+ demandOption: true,
29
+ });
30
+ })
31
+ .help()
32
+ .parse();
33
+ const packageConfig = new utils_package_config_1.PackageConfig({
34
+ packagePath: './',
35
+ });
36
+ const config = packageConfig.getConfig();
37
+ const command = argv._[0];
38
+ const [, , , ...opArgs] = args;
39
+ if (command === 'set-nextjs-env') {
40
+ await (0, nextjsEnvironment_1.setNextjsEnvironmentVariables)(packageConfig.getDeployment(opArgs[0]));
41
+ return;
42
+ }
43
+ if (command === 'infra') {
44
+ await (0, template_static_website_aws_1.infraAwsStaticWebsiteCli)(config, opArgs);
45
+ return;
46
+ }
47
+ if (command === 'deploy') {
48
+ await (0, template_static_website_aws_1.infraAwsStaticWebsiteCli)(config, ['deploy', ...opArgs]);
49
+ const deployment = packageConfig.getDeployment(opArgs[0]);
50
+ const deploymentState = (0, infra_1.readDeploymentState)('./', deployment.name);
51
+ await (0, edgeLambdaDeploy_1.deployEdgeLambda)({
52
+ deployment,
53
+ deploymentState: deploymentState,
54
+ });
55
+ return;
56
+ }
57
+ (0, utils_log_1.fatal)('Unknown command: ' + command);
58
+ throw new Error();
59
+ });
60
+ };
61
+ exports.run = run;
62
62
  //# sourceMappingURL=templateNextjs.js.map
@@ -1,53 +1,53 @@
1
- import { AWSStaticWebsiteDeployment, AWSStaticWebsitePackage, AWSStaticWebsiteConfiguration, AWSStaticWebsiteDeploymentConfiguration } from '@goldstack/template-static-website-aws';
2
- /**
3
- * Define the name and value for the environment variable.
4
- *
5
- * @title NextJs Environment Variable
6
- */
7
- export interface NextjsEnvironmentVariable {
8
- /**
9
- * Environment variable name
10
- *
11
- * @title Name
12
- */
13
- name: string;
14
- /**
15
- * Environment variable value
16
- *
17
- * @title Value
18
- */
19
- value: string;
20
- }
21
- export interface NextjsDeploymentConfiguration extends AWSStaticWebsiteDeploymentConfiguration {
22
- /**
23
- * Define environment variables for the NextJs application.
24
- *
25
- * @title Environment Variables
26
- */
27
- environmentVariables?: NextjsEnvironmentVariable[];
28
- }
29
- /**
30
- * Configure NextJs deployment
31
- *
32
- * @title NextJs Deployment
33
- */
34
- export interface NextjsDeployment extends AWSStaticWebsiteDeployment {
35
- configuration: NextjsDeploymentConfiguration;
36
- }
37
- /**
38
- * Configure NextJS application
39
- *
40
- * @title NextJs Configuration
41
- *
42
- */
43
- export declare type NextjsPackageConfiguration = AWSStaticWebsiteConfiguration;
44
- /**
45
- * A NextJs application
46
- *
47
- * @title NextJs Package
48
- */
49
- export interface NextjsPackage extends AWSStaticWebsitePackage {
50
- configuration: NextjsPackageConfiguration;
51
- deployments: NextjsDeployment[];
52
- }
1
+ import { AWSStaticWebsiteDeployment, AWSStaticWebsitePackage, AWSStaticWebsiteConfiguration, AWSStaticWebsiteDeploymentConfiguration } from '@goldstack/template-static-website-aws';
2
+ /**
3
+ * Define the name and value for the environment variable.
4
+ *
5
+ * @title NextJs Environment Variable
6
+ */
7
+ export interface NextjsEnvironmentVariable {
8
+ /**
9
+ * Environment variable name
10
+ *
11
+ * @title Name
12
+ */
13
+ name: string;
14
+ /**
15
+ * Environment variable value
16
+ *
17
+ * @title Value
18
+ */
19
+ value: string;
20
+ }
21
+ export interface NextjsDeploymentConfiguration extends AWSStaticWebsiteDeploymentConfiguration {
22
+ /**
23
+ * Define environment variables for the NextJs application.
24
+ *
25
+ * @title Environment Variables
26
+ */
27
+ environmentVariables?: NextjsEnvironmentVariable[];
28
+ }
29
+ /**
30
+ * Configure NextJs deployment
31
+ *
32
+ * @title NextJs Deployment
33
+ */
34
+ export interface NextjsDeployment extends AWSStaticWebsiteDeployment {
35
+ configuration: NextjsDeploymentConfiguration;
36
+ }
37
+ /**
38
+ * Configure NextJS application
39
+ *
40
+ * @title NextJs Configuration
41
+ *
42
+ */
43
+ export declare type NextjsPackageConfiguration = AWSStaticWebsiteConfiguration;
44
+ /**
45
+ * A NextJs application
46
+ *
47
+ * @title NextJs Package
48
+ */
49
+ export interface NextjsPackage extends AWSStaticWebsitePackage {
50
+ configuration: NextjsPackageConfiguration;
51
+ deployments: NextjsDeployment[];
52
+ }
53
53
  //# sourceMappingURL=NextJsPackage.d.ts.map
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=NextJsPackage.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goldstack/template-nextjs",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Building blocks for deploying Next.js applications to AWS using S3 and CloudFront",
5
5
  "keywords": [
6
6
  "goldstack",
@@ -48,19 +48,19 @@
48
48
  "version:apply:force": "yarn version $@ && yarn version apply"
49
49
  },
50
50
  "dependencies": {
51
- "@goldstack/infra": "0.4.0",
52
- "@goldstack/infra-aws": "0.4.0",
53
- "@goldstack/template-static-website-aws": "0.5.0",
54
- "@goldstack/utils-aws-cli": "0.4.0",
55
- "@goldstack/utils-aws-lambda": "0.3.0",
56
- "@goldstack/utils-cli": "0.3.0",
57
- "@goldstack/utils-config": "0.4.0",
58
- "@goldstack/utils-log": "0.3.0",
59
- "@goldstack/utils-package": "0.4.0",
60
- "@goldstack/utils-package-config": "0.4.0",
61
- "@goldstack/utils-sh": "0.5.0",
62
- "@goldstack/utils-template": "0.4.0",
63
- "@goldstack/utils-terraform": "0.4.0",
51
+ "@goldstack/infra": "0.4.1",
52
+ "@goldstack/infra-aws": "0.4.1",
53
+ "@goldstack/template-static-website-aws": "0.5.1",
54
+ "@goldstack/utils-aws-cli": "0.4.1",
55
+ "@goldstack/utils-aws-lambda": "0.3.1",
56
+ "@goldstack/utils-cli": "0.3.1",
57
+ "@goldstack/utils-config": "0.4.1",
58
+ "@goldstack/utils-log": "0.3.1",
59
+ "@goldstack/utils-package": "0.4.1",
60
+ "@goldstack/utils-package-config": "0.4.1",
61
+ "@goldstack/utils-sh": "0.5.1",
62
+ "@goldstack/utils-template": "0.4.1",
63
+ "@goldstack/utils-terraform": "0.4.1",
64
64
  "glob": "^7.1.6",
65
65
  "source-map-support": "^0.5.21",
66
66
  "webpack": "4.43.0",
@@ -68,8 +68,8 @@
68
68
  },
69
69
  "devDependencies": {
70
70
  "@goldstack/utils-docs-cli": "0.3.11",
71
- "@goldstack/utils-git": "0.2.0",
72
- "@goldstack/utils-package-config-generate": "0.3.0",
71
+ "@goldstack/utils-git": "0.2.1",
72
+ "@goldstack/utils-package-config-generate": "0.3.1",
73
73
  "@types/glob": "^7.1.3",
74
74
  "@types/jest": "^28.1.8",
75
75
  "@types/node": "^18.7.13",