@pwrdrvr/microapps-publish 0.4.0-alpha.9 → 1.0.2

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.
Files changed (81) hide show
  1. package/README.md +25 -25
  2. package/package.json +5 -52
  3. package/bin/run +0 -5
  4. package/dist/commands/delete.d.ts +0 -18
  5. package/dist/commands/delete.d.ts.map +0 -1
  6. package/dist/commands/delete.js +0 -125
  7. package/dist/commands/delete.js.map +0 -1
  8. package/dist/commands/nextjs-version-restore.d.ts +0 -14
  9. package/dist/commands/nextjs-version-restore.d.ts.map +0 -1
  10. package/dist/commands/nextjs-version-restore.js +0 -53
  11. package/dist/commands/nextjs-version-restore.js.map +0 -1
  12. package/dist/commands/nextjs-version.d.ts +0 -18
  13. package/dist/commands/nextjs-version.d.ts.map +0 -1
  14. package/dist/commands/nextjs-version.js +0 -103
  15. package/dist/commands/nextjs-version.js.map +0 -1
  16. package/dist/commands/preflight.d.ts +0 -19
  17. package/dist/commands/preflight.d.ts.map +0 -1
  18. package/dist/commands/preflight.js +0 -135
  19. package/dist/commands/preflight.js.map +0 -1
  20. package/dist/commands/publish-static.d.ts +0 -25
  21. package/dist/commands/publish-static.d.ts.map +0 -1
  22. package/dist/commands/publish-static.js +0 -361
  23. package/dist/commands/publish-static.js.map +0 -1
  24. package/dist/commands/publish.d.ts +0 -39
  25. package/dist/commands/publish.d.ts.map +0 -1
  26. package/dist/commands/publish.js +0 -565
  27. package/dist/commands/publish.js.map +0 -1
  28. package/dist/config/Application.d.ts +0 -26
  29. package/dist/config/Application.d.ts.map +0 -1
  30. package/dist/config/Application.js +0 -99
  31. package/dist/config/Application.js.map +0 -1
  32. package/dist/config/Config.d.ts +0 -18
  33. package/dist/config/Config.d.ts.map +0 -1
  34. package/dist/config/Config.js +0 -71
  35. package/dist/config/Config.js.map +0 -1
  36. package/dist/config/Deployer.d.ts +0 -10
  37. package/dist/config/Deployer.d.ts.map +0 -1
  38. package/dist/config/Deployer.js +0 -17
  39. package/dist/config/Deployer.js.map +0 -1
  40. package/dist/index.d.ts +0 -2
  41. package/dist/index.d.ts.map +0 -1
  42. package/dist/index.js +0 -6
  43. package/dist/index.js.map +0 -1
  44. package/dist/lib/DeployClient.d.ts +0 -102
  45. package/dist/lib/DeployClient.d.ts.map +0 -1
  46. package/dist/lib/DeployClient.js +0 -233
  47. package/dist/lib/DeployClient.js.map +0 -1
  48. package/dist/lib/FilesExist.d.ts +0 -5
  49. package/dist/lib/FilesExist.d.ts.map +0 -1
  50. package/dist/lib/FilesExist.js +0 -26
  51. package/dist/lib/FilesExist.js.map +0 -1
  52. package/dist/lib/S3TransferUtility.d.ts +0 -19
  53. package/dist/lib/S3TransferUtility.d.ts.map +0 -1
  54. package/dist/lib/S3TransferUtility.js +0 -94
  55. package/dist/lib/S3TransferUtility.js.map +0 -1
  56. package/dist/lib/S3Uploader.d.ts +0 -27
  57. package/dist/lib/S3Uploader.d.ts.map +0 -1
  58. package/dist/lib/S3Uploader.js +0 -77
  59. package/dist/lib/S3Uploader.js.map +0 -1
  60. package/dist/lib/Versions.d.ts +0 -33
  61. package/dist/lib/Versions.d.ts.map +0 -1
  62. package/dist/lib/Versions.js +0 -76
  63. package/dist/lib/Versions.js.map +0 -1
  64. package/src/commands/delete.ts +0 -135
  65. package/src/commands/nextjs-version-restore.ts +0 -70
  66. package/src/commands/nextjs-version.ts +0 -123
  67. package/src/commands/preflight.ts +0 -148
  68. package/src/commands/publish-static.ts +0 -416
  69. package/src/commands/publish.ts +0 -662
  70. package/src/commands-deprecated/nextjs-docker-auto.skip +0 -590
  71. package/src/config/Application.ts +0 -98
  72. package/src/config/Config.ts +0 -81
  73. package/src/config/Deployer.ts +0 -17
  74. package/src/index.ts +0 -1
  75. package/src/lib/DeployClient.ts +0 -334
  76. package/src/lib/FilesExist.ts +0 -25
  77. package/src/lib/S3TransferUtility.spec.ts +0 -15
  78. package/src/lib/S3TransferUtility.ts +0 -113
  79. package/src/lib/S3Uploader.ts +0 -94
  80. package/src/lib/Versions.ts +0 -101
  81. package/src/lib/__snapshots__/S3TransferUtility.spec.ts.snap +0 -12
@@ -1,123 +0,0 @@
1
- import 'reflect-metadata';
2
- import { Command, flags as flagsParser } from '@oclif/command';
3
- import { Listr } from 'listr2';
4
- import { createVersions, IVersions, restoreFiles, writeNewVersions } from '../lib/Versions';
5
- import { Config } from '../config/Config';
6
-
7
- export class NextJSVersionCommand extends Command {
8
- static description = 'Apply version to next.config.js overtop of 0.0.0 placeholder';
9
-
10
- static examples = [
11
- `$ microapps-publish nextjs-version -n 0.0.13
12
- ✔ Modifying Config Files [0.0s]
13
- `,
14
- ];
15
-
16
- static flags = {
17
- version: flagsParser.version({
18
- char: 'v',
19
- }),
20
- help: flagsParser.help(),
21
- // Deprecated
22
- newVersion: flagsParser.string({
23
- multiple: false,
24
- required: false,
25
- hidden: true,
26
- }),
27
- 'new-version': flagsParser.string({
28
- char: 'n',
29
- multiple: false,
30
- exactlyOne: ['new-version', 'newVersion'],
31
- description: 'New semantic version to apply',
32
- }),
33
- // Deprecated
34
- leaveCopy: flagsParser.boolean({
35
- char: 'l',
36
- default: false,
37
- required: false,
38
- hidden: true,
39
- exclusive: ['leave-copy'],
40
- }),
41
- 'leave-copy': flagsParser.boolean({
42
- char: 'l',
43
- default: false,
44
- required: false,
45
- description: 'Leave a copy of the modifed files as .modified',
46
- }),
47
- };
48
-
49
- private VersionAndAlias: IVersions;
50
- private FILES_TO_MODIFY: {
51
- path: string;
52
- versions: IVersions;
53
- }[];
54
-
55
- async run(): Promise<void> {
56
- // const RUNNING_TEXT = ' RUNS ';
57
- // const RUNNING = chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
58
- const RUNNING = ''; //chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
59
-
60
- const { flags: parsedFlags } = this.parse(NextJSVersionCommand);
61
- const semVer = parsedFlags.newVersion ?? parsedFlags['new-version'];
62
- const leaveFiles = parsedFlags.leaveCopy ?? parsedFlags['leave-copy'];
63
-
64
- // Override the config value
65
- const config = Config.instance;
66
- config.app.semVer = semVer;
67
-
68
- this.VersionAndAlias = createVersions(semVer);
69
- const versionOnly = { version: this.VersionAndAlias.version };
70
-
71
- this.FILES_TO_MODIFY = [{ path: 'next.config.js', versions: versionOnly }];
72
-
73
- // TODO: Pick and validate the appname/semver from the config and flags
74
-
75
- if (config === undefined) {
76
- this.error('Failed to load the config file');
77
- }
78
-
79
- //
80
- // Setup Tasks
81
- //
82
-
83
- const tasks = new Listr(
84
- [
85
- {
86
- title: 'Restoring Modified Config Files',
87
- task: async (ctx, task) => {
88
- const origTitle = task.title;
89
- task.title = RUNNING + origTitle;
90
-
91
- await restoreFiles(this.FILES_TO_MODIFY);
92
-
93
- task.title = origTitle;
94
- },
95
- },
96
- {
97
- title: 'Modifying Config Files',
98
- task: async (ctx, task) => {
99
- const origTitle = task.title;
100
- task.title = RUNNING + origTitle;
101
-
102
- // Modify the existing files with the new version
103
- for (const fileToModify of this.FILES_TO_MODIFY) {
104
- task.output = `Patching version (${this.VersionAndAlias.version}) into ${fileToModify.path}`;
105
- if (!(await writeNewVersions(fileToModify.path, fileToModify.versions, leaveFiles))) {
106
- task.output = `Failed modifying file: ${fileToModify.path}`;
107
- }
108
- }
109
-
110
- task.title = origTitle;
111
- },
112
- },
113
- ],
114
- {
115
- rendererOptions: {
116
- showTimer: true,
117
- },
118
- },
119
- );
120
-
121
- await tasks.run();
122
- }
123
- }
@@ -1,148 +0,0 @@
1
- import 'reflect-metadata';
2
- import * as sts from '@aws-sdk/client-sts';
3
- import { Command, flags as flagsParser } from '@oclif/command';
4
- import { Listr } from 'listr2';
5
- import { Config } from '../config/Config';
6
- import DeployClient from '../lib/DeployClient';
7
-
8
- export class PreflightCommand extends Command {
9
- static description = 'Check if app/version are available';
10
-
11
- static examples = [
12
- `$ microapps-publish preflight -d microapps-deployer-dev -a release -n 0.0.13
13
- ✔ Preflight Version Check [0.2s]
14
- `,
15
- ];
16
-
17
- static flags = {
18
- version: flagsParser.version({
19
- char: 'v',
20
- }),
21
- help: flagsParser.help(),
22
- // Deprecated
23
- appName: flagsParser.string({
24
- multiple: false,
25
- required: false,
26
- hidden: true,
27
- }),
28
- 'app-name': flagsParser.string({
29
- char: 'a',
30
- multiple: false,
31
- exactlyOne: ['app-name', 'appName'],
32
- description: 'MicroApps app name (this becomes the path the app is rooted at)',
33
- }),
34
- // Deprecated
35
- newVersion: flagsParser.string({
36
- multiple: false,
37
- required: false,
38
- hidden: true,
39
- }),
40
- 'new-version': flagsParser.string({
41
- char: 'n',
42
- multiple: false,
43
- exactlyOne: ['new-version', 'newVersion'],
44
- description: 'New semantic version to apply',
45
- }),
46
- // Deprecated
47
- deployerLambdaName: flagsParser.string({
48
- multiple: false,
49
- required: false,
50
- hidden: true,
51
- }),
52
- 'deployer-lambda-name': flagsParser.string({
53
- char: 'd',
54
- multiple: false,
55
- exactlyOne: ['deployer-lambda-name', 'deployerLambdaName'],
56
- description: 'Name of the deployer lambda function',
57
- }),
58
- overwrite: flagsParser.boolean({
59
- char: 'o',
60
- required: false,
61
- default: false,
62
- description:
63
- 'Allow overwrite - Warn but do not fail if version exists. Discouraged outside of test envs if cacheable static files have changed.',
64
- }),
65
- };
66
-
67
- async run(): Promise<void> {
68
- const config = Config.instance;
69
-
70
- // const RUNNING_TEXT = ' RUNS ';
71
- // const RUNNING = chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
72
- const RUNNING = ''; //chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
73
-
74
- const { flags: parsedFlags } = this.parse(PreflightCommand);
75
- const appName = parsedFlags.appName ?? parsedFlags['app-name'] ?? config.app.name;
76
- const deployerLambdaName =
77
- parsedFlags.deployerLambdaName ??
78
- parsedFlags['deployer-lambda-name'] ??
79
- config.deployer.lambdaName;
80
- const semVer = parsedFlags.newVersion ?? parsedFlags['new-version'] ?? config.app.semVer;
81
- const overwrite = parsedFlags.overwrite;
82
-
83
- // Override the config value
84
- config.deployer.lambdaName = deployerLambdaName;
85
- config.app.name = appName;
86
- config.app.semVer = semVer;
87
-
88
- // TODO: Pick and validate the appname/semver from the config and flags
89
-
90
- // Get the account ID and region from STS
91
- // TODO: Move this to the right place
92
- if (config.app.awsAccountID === '' || config.app.awsRegion === '') {
93
- const stsClient = new sts.STSClient({
94
- maxAttempts: 8,
95
- });
96
- const stsResponse = await stsClient.send(new sts.GetCallerIdentityCommand({}));
97
- if (config.app.awsAccountID === '') {
98
- config.app.awsAccountID = stsResponse.Account;
99
- }
100
- if (config.app.awsRegion === '') {
101
- config.app.awsRegion = stsClient.config.region as string;
102
- }
103
- }
104
-
105
- //
106
- // Setup Tasks
107
- //
108
-
109
- const tasks = new Listr(
110
- [
111
- {
112
- title: 'Preflight Version Check',
113
- task: async (ctx, task) => {
114
- const origTitle = task.title;
115
- task.title = RUNNING + origTitle;
116
-
117
- // Confirm the Version Does Not Exist in Published State
118
- task.output = `Checking if deployed app/version already exists for ${config.app.name}/${semVer}`;
119
- const preflightResult = await DeployClient.DeployVersionPreflight({
120
- config,
121
- needS3Creds: false,
122
- overwrite,
123
- output: (message: string) => (task.output = message),
124
- });
125
- if (preflightResult.exists) {
126
- if (!overwrite) {
127
- throw new Error(
128
- `App/Version already exists: ${config.app.name}/${config.app.semVer}`,
129
- );
130
- } else {
131
- task.title = `Warning: App/Version already exists: ${config.app.name}/${config.app.semVer}`;
132
- }
133
- } else {
134
- task.title = `App/Version does not exist: ${config.app.name}/${config.app.semVer}`;
135
- }
136
- },
137
- },
138
- ],
139
- {
140
- rendererOptions: {
141
- showTimer: true,
142
- },
143
- },
144
- );
145
-
146
- await tasks.run();
147
- }
148
- }
@@ -1,416 +0,0 @@
1
- import 'reflect-metadata';
2
- import * as s3 from '@aws-sdk/client-s3';
3
- import * as sts from '@aws-sdk/client-sts';
4
- import { Upload } from '@aws-sdk/lib-storage';
5
- import { Command, flags as flagsParser } from '@oclif/command';
6
- // eslint-disable-next-line @typescript-eslint/no-var-requires
7
- const pMap = require('p-map');
8
- import * as path from 'path';
9
- import { pathExists, createReadStream } from 'fs-extra';
10
- import { Listr, ListrTask } from 'listr2';
11
- import { contentType } from 'mime-types';
12
- import { Config } from '../config/Config';
13
- import DeployClient, {
14
- DeployVersionArgs,
15
- IDeployVersionPreflightResult,
16
- } from '../lib/DeployClient';
17
- import { S3Uploader } from '../lib/S3Uploader';
18
- import { S3TransferUtility } from '../lib/S3TransferUtility';
19
-
20
- interface IContext {
21
- preflightResult: IDeployVersionPreflightResult;
22
- files: string[];
23
- }
24
-
25
- export class PublishCommand extends Command {
26
- static description = 'Publish arbitrary framework static app - deploy static assets to S3 only.';
27
-
28
- static examples = [
29
- `$ microapps-publish publish-static -d microapps-deployer-dev -l microapps-app-release-dev -a release -n 0.0.21
30
- ✔ Get S3 Temp Credentials [1s]
31
- ✔ Confirm Static Assets Folder Exists [0.0s]
32
- ✔ Copy Static Files to Local Upload Dir [0.0s]
33
- ✔ Enumerate Files to Upload to S3 [0.0s]
34
- ✔ Upload Static Files to S3 [1s]
35
- ✔ Creating MicroApp Application: release [0.0s]
36
- ✔ Creating MicroApp Version: 0.0.21 [1s]
37
- `,
38
- ];
39
-
40
- static flags = {
41
- version: flagsParser.version({
42
- char: 'v',
43
- }),
44
- help: flagsParser.help(),
45
- // Deprecated
46
- deployerLambdaName: flagsParser.string({
47
- multiple: false,
48
- required: false,
49
- hidden: true,
50
- }),
51
- 'deployer-lambda-name': flagsParser.string({
52
- char: 'd',
53
- multiple: false,
54
- exactlyOne: ['deployer-lambda-name', 'deployerLambdaName'],
55
- description: 'Name of the deployer lambda function',
56
- }),
57
- // Deprecated
58
- newVersion: flagsParser.string({
59
- multiple: false,
60
- required: false,
61
- hidden: true,
62
- }),
63
- 'new-version': flagsParser.string({
64
- char: 'n',
65
- multiple: false,
66
- exactlyOne: ['new-version', 'newVersion'],
67
- description: 'New semantic version to apply',
68
- }),
69
- // Deprecated
70
- appName: flagsParser.string({
71
- multiple: false,
72
- required: false,
73
- hidden: true,
74
- }),
75
- 'app-name': flagsParser.string({
76
- char: 'a',
77
- multiple: false,
78
- exactlyOne: ['app-name', 'appName'],
79
- description: 'MicroApps app name (this becomes the path the app is rooted at)',
80
- }),
81
- // Deprecated
82
- staticAssetsPath: flagsParser.string({
83
- multiple: false,
84
- required: false,
85
- hidden: true,
86
- }),
87
- 'static-assets-path': flagsParser.string({
88
- char: 's',
89
- multiple: false,
90
- required: false,
91
- exactlyOne: ['static-assets-path', 'staticAssetsPath'],
92
- description:
93
- 'Path to files to be uploaded to S3 static bucket at app/version/ path. Do include app/version/ in path if files are already "rooted" under that path locally.',
94
- }),
95
- // Deprecated
96
- defaultFile: flagsParser.string({
97
- multiple: false,
98
- required: false,
99
- hidden: true,
100
- exclusive: ['default-file'],
101
- }),
102
- 'default-file': flagsParser.string({
103
- char: 'i',
104
- multiple: false,
105
- required: false,
106
- description:
107
- 'Default file to return when the app is loaded via the router without a version (e.g. when app/ is requested).',
108
- }),
109
- overwrite: flagsParser.boolean({
110
- char: 'o',
111
- required: false,
112
- default: false,
113
- description:
114
- 'Allow overwrite - Warn but do not fail if version exists. Discouraged outside of test envs if cacheable static files have changed.',
115
- }),
116
- // Deprecated
117
- noCache: flagsParser.boolean({
118
- required: false,
119
- default: false,
120
- hidden: true,
121
- }),
122
- 'no-cache': flagsParser.boolean({
123
- required: false,
124
- default: false,
125
- description: 'Force revalidation of CloudFront and browser caching of static assets',
126
- }),
127
- };
128
-
129
- async run(): Promise<void> {
130
- const config = Config.instance;
131
-
132
- // const RUNNING_TEXT = ' RUNS ';
133
- // const RUNNING = chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
134
- const RUNNING = ''; //chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
135
-
136
- const { flags: parsedFlags } = this.parse(PublishCommand);
137
- const appName = parsedFlags.appName ?? parsedFlags['app-name'] ?? config.app.name;
138
- const deployerLambdaName =
139
- parsedFlags.deployerLambdaName ??
140
- parsedFlags['deployer-lambda-name'] ??
141
- config.deployer.lambdaName;
142
- const semVer = parsedFlags.newVersion ?? parsedFlags['new-version'] ?? config.app.semVer;
143
- const staticAssetsPath =
144
- parsedFlags.staticAssetsPath ??
145
- parsedFlags['static-assets-path'] ??
146
- config.app.staticAssetsPath;
147
- const defaultFile =
148
- parsedFlags.defaultFile ?? parsedFlags['default-file'] ?? config.app.defaultFile;
149
- const overwrite = parsedFlags.overwrite;
150
- const noCache = parsedFlags.noCache ?? parsedFlags['no-cache'];
151
-
152
- // Override the config value
153
- config.deployer.lambdaName = deployerLambdaName;
154
- delete config.app.lambdaName;
155
- config.app.name = appName;
156
- config.app.semVer = semVer;
157
- config.app.staticAssetsPath = staticAssetsPath;
158
- config.app.defaultFile = defaultFile;
159
-
160
- // Get the account ID and region from STS
161
- // TODO: Move this to the right place
162
- if (config.app.awsAccountID === '' || config.app.awsRegion === '') {
163
- const stsClient = new sts.STSClient({
164
- maxAttempts: 8,
165
- });
166
- const stsResponse = await stsClient.send(new sts.GetCallerIdentityCommand({}));
167
- if (config.app.awsAccountID === '') {
168
- config.app.awsAccountID = stsResponse.Account;
169
- }
170
- if (config.app.awsRegion === '') {
171
- config.app.awsRegion = stsClient.config.region as string;
172
- }
173
- }
174
-
175
- if (config.app.staticAssetsPath === undefined) {
176
- this.error('staticAssetsPath must be specified');
177
- }
178
- if (config.app.defaultFile === undefined || config.app.defaultFile === '') {
179
- this.error('defaultFile must be specified');
180
- }
181
-
182
- //
183
- // Setup Tasks
184
- //
185
-
186
- const tasks = new Listr<IContext>(
187
- [
188
- {
189
- // TODO: Disable this task if no static assets path
190
- title: 'Confirm Static Assets Folder Exists',
191
- task: async (ctx, task) => {
192
- const origTitle = task.title;
193
- task.title = RUNNING + origTitle;
194
-
195
- // Check that Static Assets Folder exists
196
- if (!(await pathExists(config.app.staticAssetsPath))) {
197
- this.error(`Static asset path does not exist: ${config.app.staticAssetsPath}`);
198
- }
199
-
200
- task.title = origTitle;
201
- },
202
- },
203
- {
204
- // TODO: Disable this task if no static assets path
205
- title: 'Get S3 Temp Credentials',
206
- task: async (ctx, task) => {
207
- const origTitle = task.title;
208
- task.title = RUNNING + origTitle;
209
-
210
- // Confirm the Version Does Not Exist in Published State
211
- task.output = `Checking if deployed app/version already exists for ${config.app.name}/${semVer}`;
212
- ctx.preflightResult = await DeployClient.DeployVersionPreflight({
213
- config,
214
- overwrite,
215
- output: (message: string) => (task.output = message),
216
- });
217
- if (ctx.preflightResult.exists) {
218
- if (!overwrite) {
219
- throw new Error(
220
- `App/Version already exists: ${config.app.name}/${config.app.semVer}`,
221
- );
222
- } else {
223
- task.title = `Warning: App/Version already exists: ${config.app.name}/${config.app.semVer}`;
224
- }
225
- } else {
226
- task.title = `App/Version does not exist: ${config.app.name}/${config.app.semVer}`;
227
- }
228
- },
229
- },
230
- {
231
- // TODO: Disable this task if no static assets path
232
- title: 'Copy Static Files to Local Upload Dir',
233
- task: async (ctx, task) => {
234
- const origTitle = task.title;
235
- task.title = RUNNING + origTitle;
236
-
237
- // Copy files to local dir to be uploaded
238
- await S3Uploader.CopyToUploadDir(config, ctx.preflightResult.response.s3UploadUrl);
239
-
240
- task.title = origTitle;
241
- },
242
- },
243
- {
244
- // TODO: Disable this task if no static assets path
245
- title: 'Enumerate Files to Upload to S3',
246
- task: (ctx, task) => {
247
- const origTitle = task.title;
248
- task.title = RUNNING + origTitle;
249
-
250
- ctx.files = S3TransferUtility.GetFiles(S3Uploader.TempDir);
251
-
252
- task.title = origTitle;
253
- },
254
- },
255
- {
256
- // TODO: Disable this task if no static assets path
257
- title: 'Upload Static Files to S3',
258
- task: async (ctx, task) => {
259
- const origTitle = task.title;
260
- task.title = RUNNING + origTitle;
261
-
262
- const { bucketName, destinationPrefix } = S3Uploader.ParseUploadPath(
263
- ctx.preflightResult.response.s3UploadUrl,
264
- );
265
-
266
- // Use temp credentials for S3
267
- const s3Client = new s3.S3Client({
268
- maxAttempts: 16,
269
- credentials: {
270
- accessKeyId: ctx.preflightResult.response.awsCredentials.accessKeyId,
271
- secretAccessKey: ctx.preflightResult.response.awsCredentials.secretAccessKey,
272
- sessionToken: ctx.preflightResult.response.awsCredentials.sessionToken,
273
- },
274
- });
275
-
276
- // Setup caching on static assets
277
- // NoCache - Only used for test deploys, requires browser and CloudFront to refetch every time
278
- // Default - 24 hours
279
- const CacheControl = noCache
280
- ? 'max-age=0, must-revalidate, public'
281
- : `max-age=${24 * 60 * 60}, public`;
282
-
283
- const pathWithoutAppAndVer = path.join(S3Uploader.TempDir, destinationPrefix);
284
- // Listr causes OOM if passes a list of, say, 5,000 to 20,000 files
285
- if (ctx.files.length > 200) {
286
- const fileCountMsgInterval = Math.floor(ctx.files.length / 10);
287
- let filesPublished = 0;
288
-
289
- await pMap(
290
- ctx.files,
291
- async (filePath: string) => {
292
- // Can't use tasks for each file
293
- const relFilePath = path.relative(pathWithoutAppAndVer, filePath);
294
-
295
- if (
296
- ctx.files.length > 1000 &&
297
- (filesPublished % fileCountMsgInterval === 0 ||
298
- filesPublished === ctx.files.length)
299
- ) {
300
- task.output = `Uploaded ${filesPublished} of ${ctx.files.length} files`;
301
- } else if (ctx.files.length <= 1000) {
302
- task.output = `Uploading ${relFilePath}`;
303
- }
304
-
305
- const upload = new Upload({
306
- client: s3Client,
307
- leavePartsOnError: false,
308
- params: {
309
- Bucket: bucketName,
310
- Key: path.relative(S3Uploader.TempDir, filePath),
311
- Body: createReadStream(filePath),
312
- ContentType:
313
- contentType(path.basename(filePath)) || 'application/octet-stream',
314
- CacheControl,
315
- },
316
- });
317
- await upload.done();
318
- filesPublished++;
319
- },
320
- { concurrency: 40 },
321
- );
322
- } else {
323
- const tasks: ListrTask<IContext>[] = ctx.files.map((filePath) => ({
324
- task: async (ctx: IContext, subtask) => {
325
- const relFilePath = path.relative(pathWithoutAppAndVer, filePath);
326
-
327
- const origTitle = relFilePath;
328
- subtask.title = RUNNING + origTitle;
329
-
330
- const upload = new Upload({
331
- client: s3Client,
332
- leavePartsOnError: false,
333
- params: {
334
- Bucket: bucketName,
335
- Key: path.relative(S3Uploader.TempDir, filePath),
336
- Body: createReadStream(filePath),
337
- ContentType:
338
- contentType(path.basename(filePath)) || 'application/octet-stream',
339
- CacheControl,
340
- },
341
- });
342
- await upload.done();
343
-
344
- subtask.title = origTitle;
345
- },
346
- }));
347
-
348
- task.title = origTitle;
349
-
350
- return task.newListr(tasks, {
351
- concurrent: 8,
352
- rendererOptions: {
353
- clearOutput: false,
354
- showErrorMessage: true,
355
- showTimer: true,
356
- },
357
- });
358
- }
359
- },
360
- },
361
- {
362
- title: `Creating MicroApp Application: ${config.app.name}`,
363
- task: async (ctx, task) => {
364
- const origTitle = task.title;
365
- task.title = RUNNING + origTitle;
366
-
367
- // Call Deployer to Create App if Not Exists
368
- await DeployClient.CreateApp({ config });
369
-
370
- task.title = origTitle;
371
- },
372
- },
373
- {
374
- title: `Creating MicroApp Version: ${config.app.semVer}`,
375
- task: async (ctx, task) => {
376
- const origTitle = task.title;
377
- task.title = RUNNING + origTitle;
378
-
379
- const request: DeployVersionArgs = {
380
- appName: config.app.name,
381
- semVer: config.app.semVer,
382
- deployerLambdaName: config.deployer.lambdaName,
383
- defaultFile: config.app.defaultFile,
384
- appType: 'static',
385
- overwrite,
386
- output: (message: string) => (task.output = message),
387
- };
388
-
389
- // Use DeployVersionLite if createAlias is supported
390
- if (ctx.preflightResult.response.capabilities?.['createAlias'] === 'true') {
391
- task.output = 'Using DeployVersionLite';
392
- await DeployClient.DeployVersionLite(request);
393
- } else {
394
- // Use legacy DeployVersion if createAlias is not supported
395
- task.output = 'Using DeployVersion';
396
- await DeployClient.DeployVersion(request);
397
- }
398
-
399
- task.title = origTitle;
400
- },
401
- },
402
- ],
403
- {
404
- rendererOptions: {
405
- showTimer: true,
406
- },
407
- },
408
- );
409
-
410
- try {
411
- await tasks.run();
412
- } finally {
413
- await S3Uploader.removeTempDirIfExists();
414
- }
415
- }
416
- }