@pwrdrvr/microapps-publish 0.4.0-alpha.2 → 0.4.0-alpha.4

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.
@@ -19,22 +19,40 @@ export class PreflightCommand extends Command {
19
19
  char: 'v',
20
20
  }),
21
21
  help: flagsParser.help(),
22
+ // Deprecated
22
23
  appName: flagsParser.string({
23
- char: 'a',
24
24
  multiple: false,
25
25
  required: false,
26
- description: 'Name of the MicroApp',
26
+ hidden: true,
27
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
28
35
  newVersion: flagsParser.string({
36
+ multiple: false,
37
+ required: false,
38
+ hidden: true,
39
+ }),
40
+ 'new-version': flagsParser.string({
29
41
  char: 'n',
30
42
  multiple: false,
31
- required: true,
43
+ exactlyOne: ['new-version', 'newVersion'],
32
44
  description: 'New semantic version to apply',
33
45
  }),
46
+ // Deprecated
34
47
  deployerLambdaName: flagsParser.string({
48
+ multiple: false,
49
+ required: false,
50
+ hidden: true,
51
+ }),
52
+ 'deployer-lambda-name': flagsParser.string({
35
53
  char: 'd',
36
54
  multiple: false,
37
- required: true,
55
+ exactlyOne: ['deployer-lambda-name', 'deployerLambdaName'],
38
56
  description: 'Name of the deployer lambda function',
39
57
  }),
40
58
  overwrite: flagsParser.boolean({
@@ -54,10 +72,12 @@ export class PreflightCommand extends Command {
54
72
  const RUNNING = ''; //chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
55
73
 
56
74
  const { flags: parsedFlags } = this.parse(PreflightCommand);
57
- const version = parsedFlags.newVersion;
58
- const appName = parsedFlags.appName ?? config.app.name;
59
- const deployerLambdaName = parsedFlags.deployerLambdaName ?? config.deployer.lambdaName;
60
- const semVer = parsedFlags.newVersion ?? config.app.semVer;
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;
61
81
  const overwrite = parsedFlags.overwrite;
62
82
 
63
83
  // Override the config value
@@ -95,7 +115,7 @@ export class PreflightCommand extends Command {
95
115
  task.title = RUNNING + origTitle;
96
116
 
97
117
  // Confirm the Version Does Not Exist in Published State
98
- task.output = `Checking if deployed app/version already exists for ${config.app.name}/${version}`;
118
+ task.output = `Checking if deployed app/version already exists for ${config.app.name}/${semVer}`;
99
119
  const preflightResult = await DeployClient.DeployVersionPreflight({
100
120
  config,
101
121
  needS3Creds: false,
@@ -1,19 +1,21 @@
1
1
  import 'reflect-metadata';
2
2
  import * as s3 from '@aws-sdk/client-s3';
3
3
  import * as sts from '@aws-sdk/client-sts';
4
+ import { Upload } from '@aws-sdk/lib-storage';
4
5
  import { Command, flags as flagsParser } from '@oclif/command';
5
6
  // eslint-disable-next-line @typescript-eslint/no-var-requires
6
7
  const pMap = require('p-map');
7
8
  import * as path from 'path';
8
9
  import { pathExists, createReadStream } from 'fs-extra';
9
10
  import { Listr, ListrTask } from 'listr2';
10
- import { createVersions, IVersions } from '../lib/Versions';
11
+ import { contentType } from 'mime-types';
11
12
  import { Config } from '../config/Config';
12
- import DeployClient, { IDeployVersionPreflightResult } from '../lib/DeployClient';
13
+ import DeployClient, {
14
+ DeployVersionArgs,
15
+ IDeployVersionPreflightResult,
16
+ } from '../lib/DeployClient';
13
17
  import { S3Uploader } from '../lib/S3Uploader';
14
18
  import { S3TransferUtility } from '../lib/S3TransferUtility';
15
- import { Upload } from '@aws-sdk/lib-storage';
16
- import { contentType } from 'mime-types';
17
19
 
18
20
  interface IContext {
19
21
  preflightResult: IDeployVersionPreflightResult;
@@ -40,32 +42,64 @@ export class PublishCommand extends Command {
40
42
  char: 'v',
41
43
  }),
42
44
  help: flagsParser.help(),
45
+ // Deprecated
43
46
  deployerLambdaName: flagsParser.string({
47
+ multiple: false,
48
+ required: false,
49
+ hidden: true,
50
+ }),
51
+ 'deployer-lambda-name': flagsParser.string({
44
52
  char: 'd',
45
53
  multiple: false,
46
- required: true,
54
+ exactlyOne: ['deployer-lambda-name', 'deployerLambdaName'],
47
55
  description: 'Name of the deployer lambda function',
48
56
  }),
57
+ // Deprecated
49
58
  newVersion: flagsParser.string({
59
+ multiple: false,
60
+ required: false,
61
+ hidden: true,
62
+ }),
63
+ 'new-version': flagsParser.string({
50
64
  char: 'n',
51
65
  multiple: false,
52
- required: true,
66
+ exactlyOne: ['new-version', 'newVersion'],
53
67
  description: 'New semantic version to apply',
54
68
  }),
69
+ // Deprecated
55
70
  appName: flagsParser.string({
56
- char: 'a',
57
71
  multiple: false,
58
72
  required: false,
59
- description: 'MicroApps app name',
73
+ hidden: true,
60
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
61
82
  staticAssetsPath: flagsParser.string({
83
+ multiple: false,
84
+ required: false,
85
+ hidden: true,
86
+ }),
87
+ 'static-assets-path': flagsParser.string({
62
88
  char: 's',
63
89
  multiple: false,
64
90
  required: false,
91
+ exactlyOne: ['static-assets-path', 'staticAssetsPath'],
65
92
  description:
66
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.',
67
94
  }),
95
+ // Deprecated
68
96
  defaultFile: flagsParser.string({
97
+ multiple: false,
98
+ required: false,
99
+ hidden: true,
100
+ exclusive: ['default-file'],
101
+ }),
102
+ 'default-file': flagsParser.string({
69
103
  char: 'i',
70
104
  multiple: false,
71
105
  required: false,
@@ -79,15 +113,19 @@ export class PublishCommand extends Command {
79
113
  description:
80
114
  'Allow overwrite - Warn but do not fail if version exists. Discouraged outside of test envs if cacheable static files have changed.',
81
115
  }),
116
+ // Deprecated
82
117
  noCache: flagsParser.boolean({
118
+ required: false,
119
+ default: false,
120
+ hidden: true,
121
+ }),
122
+ 'no-cache': flagsParser.boolean({
83
123
  required: false,
84
124
  default: false,
85
125
  description: 'Force revalidation of CloudFront and browser caching of static assets',
86
126
  }),
87
127
  };
88
128
 
89
- private VersionAndAlias: IVersions;
90
-
91
129
  async run(): Promise<void> {
92
130
  const config = Config.instance;
93
131
 
@@ -96,11 +134,18 @@ export class PublishCommand extends Command {
96
134
  const RUNNING = ''; //chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
97
135
 
98
136
  const { flags: parsedFlags } = this.parse(PublishCommand);
99
- const appName = parsedFlags.appName ?? config.app.name;
100
- const deployerLambdaName = parsedFlags.deployerLambdaName ?? config.deployer.lambdaName;
101
- const semVer = parsedFlags.newVersion ?? config.app.semVer;
102
- const staticAssetsPath = parsedFlags.staticAssetsPath ?? config.app.staticAssetsPath;
103
- const defaultFile = parsedFlags.defaultFile ?? config.app.defaultFile;
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;
104
149
  const overwrite = parsedFlags.overwrite;
105
150
  const noCache = parsedFlags.noCache;
106
151
 
@@ -127,8 +172,6 @@ export class PublishCommand extends Command {
127
172
  }
128
173
  }
129
174
 
130
- this.VersionAndAlias = createVersions(semVer);
131
-
132
175
  if (config.app.staticAssetsPath === undefined) {
133
176
  this.error('staticAssetsPath must be specified');
134
177
  }
@@ -232,12 +275,9 @@ export class PublishCommand extends Command {
232
275
 
233
276
  // Setup caching on static assets
234
277
  // NoCache - Only used for test deploys, requires browser and CloudFront to refetch every time
235
- // Overwrite - Reduces default cache time period from 24 hours to 15 minutes
236
278
  // Default - 24 hours
237
279
  const CacheControl = noCache
238
280
  ? 'max-age=0, must-revalidate, public'
239
- : overwrite
240
- ? `max-age=${15 * 60}, public`
241
281
  : `max-age=${24 * 60 * 60}, public`;
242
282
 
243
283
  const pathWithoutAppAndVer = path.join(S3Uploader.TempDir, destinationPrefix);
@@ -336,8 +376,7 @@ export class PublishCommand extends Command {
336
376
  const origTitle = task.title;
337
377
  task.title = RUNNING + origTitle;
338
378
 
339
- // Call Deployer to Deploy AppName/Version
340
- await DeployClient.DeployVersion({
379
+ const request: DeployVersionArgs = {
341
380
  appName: config.app.name,
342
381
  semVer: config.app.semVer,
343
382
  deployerLambdaName: config.deployer.lambdaName,
@@ -345,7 +384,17 @@ export class PublishCommand extends Command {
345
384
  appType: 'static',
346
385
  overwrite,
347
386
  output: (message: string) => (task.output = message),
348
- });
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
+ }
349
398
 
350
399
  task.title = origTitle;
351
400
  },
@@ -11,7 +11,10 @@ import { pathExists, createReadStream } from 'fs-extra';
11
11
  import { Listr, ListrTask } from 'listr2';
12
12
  import { createVersions, IVersions } from '../lib/Versions';
13
13
  import { Config, IConfig } from '../config/Config';
14
- import DeployClient, { IDeployVersionPreflightResult } from '../lib/DeployClient';
14
+ import DeployClient, {
15
+ DeployVersionArgs,
16
+ IDeployVersionPreflightResult,
17
+ } from '../lib/DeployClient';
15
18
  import { S3Uploader } from '../lib/S3Uploader';
16
19
  import { S3TransferUtility } from '../lib/S3TransferUtility';
17
20
  import { Upload } from '@aws-sdk/lib-storage';
@@ -24,8 +27,6 @@ const lambdaClient = new lambda.LambdaClient({
24
27
  maxAttempts: 8,
25
28
  });
26
29
 
27
- type DeployVersionArgs = Parameters<typeof DeployClient.DeployVersionLite>[0];
28
-
29
30
  interface IContext {
30
31
  preflightResult: IDeployVersionPreflightResult;
31
32
  files: string[];
@@ -68,38 +69,78 @@ export class PublishCommand extends Command {
68
69
  char: 'v',
69
70
  }),
70
71
  help: flagsParser.help(),
72
+ // Deprecated
71
73
  deployerLambdaName: flagsParser.string({
74
+ multiple: false,
75
+ required: false,
76
+ hidden: true,
77
+ }),
78
+ 'deployer-lambda-name': flagsParser.string({
72
79
  char: 'd',
73
80
  multiple: false,
74
- required: true,
81
+ exactlyOne: ['deployer-lambda-name', 'deployerLambdaName'],
75
82
  description: 'Name of the deployer lambda function',
76
83
  }),
84
+ // Deprecated
77
85
  newVersion: flagsParser.string({
86
+ multiple: false,
87
+ required: false,
88
+ hidden: true,
89
+ }),
90
+ 'new-version': flagsParser.string({
78
91
  char: 'n',
79
92
  multiple: false,
80
- required: true,
93
+ exactlyOne: ['new-version', 'newVersion'],
81
94
  description: 'New semantic version to apply',
82
95
  }),
96
+ // Deprecated
83
97
  appLambdaName: flagsParser.string({
98
+ multiple: false,
99
+ required: false,
100
+ hidden: true,
101
+ exclusive: ['app-lambda-name'],
102
+ }),
103
+ 'app-lambda-name': flagsParser.string({
84
104
  char: 'l',
85
105
  multiple: false,
86
106
  required: false,
87
107
  description: 'ARN of lambda version, alias, or function (name or ARN) to deploy',
88
108
  }),
109
+ // Deprecated
89
110
  appName: flagsParser.string({
90
- char: 'a',
91
111
  multiple: false,
92
112
  required: false,
113
+ hidden: true,
114
+ exclusive: ['app-name'],
115
+ }),
116
+ 'app-name': flagsParser.string({
117
+ char: 'a',
118
+ multiple: false,
119
+ exactlyOne: ['app-name', 'appName'],
93
120
  description: 'MicroApps app name (this becomes the path the app is rooted at)',
94
121
  }),
122
+ // Deprecated
95
123
  staticAssetsPath: flagsParser.string({
124
+ multiple: false,
125
+ required: false,
126
+ hidden: true,
127
+ exclusive: ['static-assets-path'],
128
+ }),
129
+ 'static-assets-path': flagsParser.string({
96
130
  char: 's',
97
131
  multiple: false,
98
132
  required: false,
99
133
  description:
100
134
  '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.',
101
135
  }),
136
+ // Deprecated
102
137
  defaultFile: flagsParser.string({
138
+ multiple: false,
139
+ required: false,
140
+ hidden: true,
141
+ exclusive: ['default-file'],
142
+ }),
143
+ 'default-file': flagsParser.string({
103
144
  char: 'i',
104
145
  multiple: false,
105
146
  required: false,
@@ -113,7 +154,13 @@ export class PublishCommand extends Command {
113
154
  description:
114
155
  'Allow overwrite - Warn but do not fail if version exists. Discouraged outside of test envs if cacheable static files have changed.',
115
156
  }),
157
+ // Deprecated
116
158
  noCache: flagsParser.boolean({
159
+ required: false,
160
+ default: false,
161
+ hidden: true,
162
+ }),
163
+ 'no-cache': flagsParser.boolean({
117
164
  required: false,
118
165
  default: false,
119
166
  description: 'Force revalidation of CloudFront and browser caching of static assets',
@@ -151,14 +198,22 @@ export class PublishCommand extends Command {
151
198
  const RUNNING = ''; //chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
152
199
 
153
200
  const { flags: parsedFlags } = this.parse(PublishCommand);
154
- const appLambdaName = parsedFlags.appLambdaName ?? config.app.lambdaName;
155
- const appName = parsedFlags.appName ?? config.app.name;
156
- const deployerLambdaName = parsedFlags.deployerLambdaName ?? config.deployer.lambdaName;
157
- const semVer = parsedFlags.newVersion ?? config.app.semVer;
158
- const staticAssetsPath = parsedFlags.staticAssetsPath ?? config.app.staticAssetsPath;
159
- const defaultFile = parsedFlags.defaultFile ?? config.app.defaultFile;
201
+ const appLambdaName =
202
+ parsedFlags.appLambdaName ?? parsedFlags['app-lambda-name'] ?? config.app.lambdaName;
203
+ const appName = parsedFlags.appName ?? parsedFlags['app-name'] ?? config.app.name;
204
+ const deployerLambdaName =
205
+ parsedFlags.deployerLambdaName ??
206
+ parsedFlags['deployer-lambda-name'] ??
207
+ config.deployer.lambdaName;
208
+ const semVer = parsedFlags.newVersion ?? parsedFlags['new-version'] ?? config.app.semVer;
209
+ const staticAssetsPath =
210
+ parsedFlags.staticAssetsPath ??
211
+ parsedFlags['static-assets-path'] ??
212
+ config.app.staticAssetsPath;
213
+ const defaultFile =
214
+ parsedFlags.defaultFile ?? parsedFlags['default-file'] ?? config.app.defaultFile;
160
215
  const overwrite = parsedFlags.overwrite;
161
- const noCache = parsedFlags.noCache;
216
+ const noCache = parsedFlags.noCache ?? parsedFlags['no-cache'];
162
217
 
163
218
  // Override the config value
164
219
  config.deployer.lambdaName = deployerLambdaName;
@@ -365,12 +420,9 @@ export class PublishCommand extends Command {
365
420
 
366
421
  // Setup caching on static assets
367
422
  // NoCache - Only used for test deploys, requires browser and CloudFront to refetch every time
368
- // Overwrite - Reduces default cache time period from 24 hours to 15 minutes
369
423
  // Default - 24 hours
370
424
  const CacheControl = noCache
371
425
  ? 'max-age=0, must-revalidate, public'
372
- : overwrite
373
- ? `max-age=${15 * 60}, public`
374
426
  : `max-age=${24 * 60 * 60}, public`;
375
427
 
376
428
  const pathWithoutAppAndVer = path.join(S3Uploader.TempDir, destinationPrefix);
@@ -19,7 +19,7 @@ export interface IDeployVersionPreflightResult {
19
19
  response: IDeployVersionPreflightResponse;
20
20
  }
21
21
 
22
- export type DeployVersionArgs = Parameters<typeof DeployClient.DeployVersionLite>;
22
+ export type DeployVersionArgs = Parameters<typeof DeployClient.DeployVersionLite>[0];
23
23
 
24
24
  export default class DeployClient {
25
25
  static readonly _client = new lambda.LambdaClient({