@pwrdrvr/microapps-publish 0.0.21 → 0.0.25
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.
- package/dist/commands/nextjs-docker-auto.d.ts +6 -0
- package/dist/commands/nextjs-docker-auto.d.ts.map +1 -1
- package/dist/commands/nextjs-docker-auto.js +87 -26
- package/dist/commands/nextjs-docker-auto.js.map +1 -1
- package/dist/commands/nextjs-version-restore.d.ts.map +1 -1
- package/dist/commands/nextjs-version-restore.js +4 -10
- package/dist/commands/nextjs-version-restore.js.map +1 -1
- package/dist/commands/nextjs-version.d.ts.map +1 -1
- package/dist/commands/nextjs-version.js +4 -10
- package/dist/commands/nextjs-version.js.map +1 -1
- package/dist/commands/preflight.d.ts +1 -0
- package/dist/commands/preflight.d.ts.map +1 -1
- package/dist/commands/preflight.js +21 -14
- package/dist/commands/preflight.js.map +1 -1
- package/dist/commands/publish-static.d.ts +20 -0
- package/dist/commands/publish-static.d.ts.map +1 -0
- package/dist/commands/publish-static.js +281 -0
- package/dist/commands/publish-static.js.map +1 -0
- package/dist/commands/publish.d.ts +4 -0
- package/dist/commands/publish.d.ts.map +1 -1
- package/dist/commands/publish.js +61 -17
- package/dist/commands/publish.js.map +1 -1
- package/dist/lib/DeployClient.d.ts +10 -2
- package/dist/lib/DeployClient.d.ts.map +1 -1
- package/dist/lib/DeployClient.js +9 -4
- package/dist/lib/DeployClient.js.map +1 -1
- package/package.json +1 -2
- package/src/commands/nextjs-docker-auto.ts +91 -26
- package/src/commands/nextjs-version-restore.ts +5 -9
- package/src/commands/nextjs-version.ts +5 -9
- package/src/commands/preflight.ts +23 -16
- package/src/commands/publish-static.ts +322 -0
- package/src/commands/publish.ts +64 -16
- package/src/lib/DeployClient.ts +15 -7
|
@@ -5,7 +5,6 @@ import * as lambda from '@aws-sdk/client-lambda';
|
|
|
5
5
|
import * as s3 from '@aws-sdk/client-s3';
|
|
6
6
|
import * as sts from '@aws-sdk/client-sts';
|
|
7
7
|
import { Command, flags as flagsParser } from '@oclif/command';
|
|
8
|
-
import * as chalk from 'chalk';
|
|
9
8
|
import * as path from 'path';
|
|
10
9
|
import { promises as fs, pathExists, createReadStream } from 'fs-extra';
|
|
11
10
|
import { Listr, ListrTask } from 'listr2';
|
|
@@ -81,11 +80,49 @@ export class DockerAutoCommand extends Command {
|
|
|
81
80
|
description: 'Name (not URI) of the Docker repo for the app',
|
|
82
81
|
}),
|
|
83
82
|
leaveCopy: flagsParser.boolean({
|
|
84
|
-
char: '
|
|
83
|
+
char: 'f',
|
|
85
84
|
default: false,
|
|
86
85
|
required: false,
|
|
87
86
|
description: 'Leave a copy of the modifed files as .modified',
|
|
88
87
|
}),
|
|
88
|
+
appLambdaName: flagsParser.string({
|
|
89
|
+
char: 'l',
|
|
90
|
+
multiple: false,
|
|
91
|
+
required: false,
|
|
92
|
+
description: 'Name of the application lambda function',
|
|
93
|
+
}),
|
|
94
|
+
appName: flagsParser.string({
|
|
95
|
+
char: 'a',
|
|
96
|
+
multiple: false,
|
|
97
|
+
required: false,
|
|
98
|
+
description: 'MicroApps app name',
|
|
99
|
+
}),
|
|
100
|
+
staticAssetsPath: flagsParser.string({
|
|
101
|
+
char: 's',
|
|
102
|
+
multiple: false,
|
|
103
|
+
required: false,
|
|
104
|
+
description:
|
|
105
|
+
'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.',
|
|
106
|
+
}),
|
|
107
|
+
defaultFile: flagsParser.string({
|
|
108
|
+
char: 'i',
|
|
109
|
+
multiple: false,
|
|
110
|
+
required: false,
|
|
111
|
+
description:
|
|
112
|
+
'Default file to return when the app is loaded via the router without a version (e.g. when app/ is requested).',
|
|
113
|
+
}),
|
|
114
|
+
overwrite: flagsParser.boolean({
|
|
115
|
+
char: 'o',
|
|
116
|
+
required: false,
|
|
117
|
+
default: false,
|
|
118
|
+
description:
|
|
119
|
+
'Allow overwrite - Warn but do not fail if version exists. Discouraged outside of test envs if cacheable static files have changed.',
|
|
120
|
+
}),
|
|
121
|
+
noCache: flagsParser.boolean({
|
|
122
|
+
required: false,
|
|
123
|
+
default: false,
|
|
124
|
+
description: 'Force revalidation of CloudFront and browser caching of static assets',
|
|
125
|
+
}),
|
|
89
126
|
};
|
|
90
127
|
|
|
91
128
|
private VersionAndAlias: IVersions;
|
|
@@ -95,19 +132,31 @@ export class DockerAutoCommand extends Command {
|
|
|
95
132
|
private _restoreFilesStarted = false;
|
|
96
133
|
|
|
97
134
|
async run(): Promise<void> {
|
|
98
|
-
const
|
|
99
|
-
|
|
135
|
+
const config = Config.instance;
|
|
136
|
+
|
|
137
|
+
// const RUNNING_TEXT = ' RUNS ';
|
|
138
|
+
// const RUNNING = chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
|
|
139
|
+
const RUNNING = ''; //chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
|
|
100
140
|
|
|
101
141
|
const { flags: parsedFlags } = this.parse(DockerAutoCommand);
|
|
102
|
-
const
|
|
142
|
+
const appLambdaName = parsedFlags.appLambdaName ?? config.app.lambdaName;
|
|
143
|
+
const appName = parsedFlags.appName ?? config.app.name;
|
|
103
144
|
const leaveFiles = parsedFlags.leaveCopy;
|
|
104
|
-
const
|
|
105
|
-
const
|
|
145
|
+
const deployerLambdaName = parsedFlags.deployerLambdaName ?? config.deployer.lambdaName;
|
|
146
|
+
const semVer = parsedFlags.newVersion ?? config.app.semVer;
|
|
147
|
+
const ecrRepo = parsedFlags.repoName ?? config.app.ecrRepoName;
|
|
148
|
+
const staticAssetsPath = parsedFlags.staticAssetsPath ?? config.app.staticAssetsPath;
|
|
149
|
+
const defaultFile = parsedFlags.defaultFile ?? config.app.defaultFile;
|
|
150
|
+
const overwrite = parsedFlags.overwrite;
|
|
151
|
+
const noCache = parsedFlags.noCache;
|
|
106
152
|
|
|
107
153
|
// Override the config value
|
|
108
|
-
|
|
109
|
-
config.
|
|
110
|
-
config.app.
|
|
154
|
+
config.deployer.lambdaName = deployerLambdaName;
|
|
155
|
+
config.app.lambdaName = appLambdaName;
|
|
156
|
+
config.app.name = appName;
|
|
157
|
+
config.app.semVer = semVer;
|
|
158
|
+
config.app.staticAssetsPath = staticAssetsPath;
|
|
159
|
+
config.app.defaultFile = defaultFile;
|
|
111
160
|
|
|
112
161
|
// Get the account ID and region from STS
|
|
113
162
|
// TODO: Move this to the right place
|
|
@@ -132,7 +181,7 @@ export class DockerAutoCommand extends Command {
|
|
|
132
181
|
config.app.ecrRepoName = `microapps-app-${config.app.name}${Config.envLevel}-repo`;
|
|
133
182
|
}
|
|
134
183
|
|
|
135
|
-
this.VersionAndAlias = createVersions(
|
|
184
|
+
this.VersionAndAlias = createVersions(semVer);
|
|
136
185
|
const versionOnly = { version: this.VersionAndAlias.version };
|
|
137
186
|
|
|
138
187
|
this.FILES_TO_MODIFY = [
|
|
@@ -153,11 +202,8 @@ export class DockerAutoCommand extends Command {
|
|
|
153
202
|
await restoreFiles(this.FILES_TO_MODIFY);
|
|
154
203
|
});
|
|
155
204
|
|
|
156
|
-
if (config === undefined) {
|
|
157
|
-
this.error('Failed to load the config file');
|
|
158
|
-
}
|
|
159
205
|
if (config.app.staticAssetsPath === undefined) {
|
|
160
|
-
this.error('
|
|
206
|
+
this.error('staticAssetsPath must be specified');
|
|
161
207
|
}
|
|
162
208
|
|
|
163
209
|
//
|
|
@@ -201,16 +247,23 @@ export class DockerAutoCommand extends Command {
|
|
|
201
247
|
task.title = RUNNING + origTitle;
|
|
202
248
|
|
|
203
249
|
// Confirm the Version Does Not Exist in Published State
|
|
204
|
-
task.output = `Checking if deployed app/version already exists for ${config.app.name}/${
|
|
250
|
+
task.output = `Checking if deployed app/version already exists for ${config.app.name}/${semVer}`;
|
|
205
251
|
ctx.preflightResult = await DeployClient.DeployVersionPreflight({
|
|
206
252
|
config,
|
|
253
|
+
overwrite,
|
|
207
254
|
output: (message: string) => (task.output = message),
|
|
208
255
|
});
|
|
209
256
|
if (ctx.preflightResult.exists) {
|
|
210
|
-
|
|
257
|
+
if (!overwrite) {
|
|
258
|
+
throw new Error(
|
|
259
|
+
`App/Version already exists: ${config.app.name}/${config.app.semVer}`,
|
|
260
|
+
);
|
|
261
|
+
} else {
|
|
262
|
+
task.title = `Warning: App/Version already exists: ${config.app.name}/${config.app.semVer}`;
|
|
263
|
+
}
|
|
264
|
+
} else {
|
|
265
|
+
task.title = `App/Version does not exist: ${config.app.name}/${config.app.semVer}`;
|
|
211
266
|
}
|
|
212
|
-
|
|
213
|
-
task.title = origTitle;
|
|
214
267
|
},
|
|
215
268
|
},
|
|
216
269
|
{
|
|
@@ -219,7 +272,7 @@ export class DockerAutoCommand extends Command {
|
|
|
219
272
|
const origTitle = task.title;
|
|
220
273
|
task.title = RUNNING + origTitle;
|
|
221
274
|
|
|
222
|
-
task.output = `Invoking serverless next.js build for ${config.app.name}/${
|
|
275
|
+
task.output = `Invoking serverless next.js build for ${config.app.name}/${semVer}`;
|
|
223
276
|
|
|
224
277
|
// Run the serverless next.js build
|
|
225
278
|
await asyncExec('serverless');
|
|
@@ -317,6 +370,16 @@ export class DockerAutoCommand extends Command {
|
|
|
317
370
|
},
|
|
318
371
|
});
|
|
319
372
|
|
|
373
|
+
// Setup caching on static assets
|
|
374
|
+
// NoCache - Only used for test deploys, requires browser and CloudFront to refetch every time
|
|
375
|
+
// Overwrite - Reduces default cache time period from 24 hours to 15 minutes
|
|
376
|
+
// Default - 24 hours
|
|
377
|
+
const CacheControl = noCache
|
|
378
|
+
? 'max-age=0, must-revalidate, public'
|
|
379
|
+
: overwrite
|
|
380
|
+
? `max-age=${15 * 60}, public`
|
|
381
|
+
: `max-age=${24 * 60 * 60}, public`;
|
|
382
|
+
|
|
320
383
|
const pathWithoutAppAndVer = path.join(S3Uploader.TempDir, destinationPrefix);
|
|
321
384
|
|
|
322
385
|
const tasks: ListrTask<IContext>[] = ctx.files.map((filePath) => ({
|
|
@@ -334,7 +397,7 @@ export class DockerAutoCommand extends Command {
|
|
|
334
397
|
Key: path.relative(S3Uploader.TempDir, filePath),
|
|
335
398
|
Body: createReadStream(filePath),
|
|
336
399
|
ContentType: contentType(path.basename(filePath)) || 'application/octet-stream',
|
|
337
|
-
CacheControl
|
|
400
|
+
CacheControl,
|
|
338
401
|
},
|
|
339
402
|
});
|
|
340
403
|
await upload.done();
|
|
@@ -362,7 +425,7 @@ export class DockerAutoCommand extends Command {
|
|
|
362
425
|
task.title = RUNNING + origTitle;
|
|
363
426
|
|
|
364
427
|
// Call Deployer to Create App if Not Exists
|
|
365
|
-
await DeployClient.CreateApp(config);
|
|
428
|
+
await DeployClient.CreateApp({ config });
|
|
366
429
|
|
|
367
430
|
task.title = origTitle;
|
|
368
431
|
},
|
|
@@ -374,7 +437,12 @@ export class DockerAutoCommand extends Command {
|
|
|
374
437
|
task.title = RUNNING + origTitle;
|
|
375
438
|
|
|
376
439
|
// Call Deployer to Deploy AppName/Version
|
|
377
|
-
await DeployClient.DeployVersion(
|
|
440
|
+
await DeployClient.DeployVersion({
|
|
441
|
+
config,
|
|
442
|
+
appType: 'lambda',
|
|
443
|
+
overwrite,
|
|
444
|
+
output: (message: string) => (task.output = message),
|
|
445
|
+
});
|
|
378
446
|
|
|
379
447
|
task.title = origTitle;
|
|
380
448
|
},
|
|
@@ -389,9 +457,6 @@ export class DockerAutoCommand extends Command {
|
|
|
389
457
|
|
|
390
458
|
try {
|
|
391
459
|
await tasks.run();
|
|
392
|
-
// this.log(`Published: ${config.app.name}/${config.app.semVer}`);
|
|
393
|
-
} catch (error) {
|
|
394
|
-
this.log(`Caught exception: ${error.message}`);
|
|
395
460
|
} finally {
|
|
396
461
|
await S3Uploader.removeTempDirIfExists();
|
|
397
462
|
await restoreFiles(this.FILES_TO_MODIFY);
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { Command, flags as flagsParser } from '@oclif/command';
|
|
3
|
-
import * as chalk from 'chalk';
|
|
4
3
|
import { Listr } from 'listr2';
|
|
5
4
|
import { createVersions, IVersions, restoreFiles } from '../lib/Versions';
|
|
6
5
|
|
|
7
|
-
const RUNNING_TEXT = ' RUNS ';
|
|
8
|
-
const RUNNING = chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
|
|
9
|
-
|
|
10
6
|
export class NextJSVersionRestoreCommand extends Command {
|
|
11
7
|
static description = 'Restore next.config.js';
|
|
12
8
|
|
|
@@ -30,6 +26,10 @@ export class NextJSVersionRestoreCommand extends Command {
|
|
|
30
26
|
}[];
|
|
31
27
|
|
|
32
28
|
async run(): Promise<void> {
|
|
29
|
+
// const RUNNING_TEXT = ' RUNS ';
|
|
30
|
+
// const RUNNING = chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
|
|
31
|
+
const RUNNING = ''; //chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
|
|
32
|
+
|
|
33
33
|
const { flags: parsedFlags } = this.parse(NextJSVersionRestoreCommand);
|
|
34
34
|
|
|
35
35
|
this.VersionAndAlias = createVersions('0.0.0');
|
|
@@ -64,10 +64,6 @@ export class NextJSVersionRestoreCommand extends Command {
|
|
|
64
64
|
},
|
|
65
65
|
);
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
await tasks.run();
|
|
69
|
-
} catch (error) {
|
|
70
|
-
this.log(`Caught exception: ${error.message}`);
|
|
71
|
-
}
|
|
67
|
+
await tasks.run();
|
|
72
68
|
}
|
|
73
69
|
}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { Command, flags as flagsParser } from '@oclif/command';
|
|
3
|
-
import * as chalk from 'chalk';
|
|
4
3
|
import { Listr } from 'listr2';
|
|
5
4
|
import { Config } from '../config/Config';
|
|
6
5
|
import { createVersions, IVersions, restoreFiles, writeNewVersions } from '../lib/Versions';
|
|
7
6
|
|
|
8
|
-
const RUNNING_TEXT = ' RUNS ';
|
|
9
|
-
const RUNNING = chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
|
|
10
|
-
|
|
11
7
|
export class NextJSVersionCommand extends Command {
|
|
12
8
|
static description = 'Apply version to next.config.js overtop of 0.0.0 placeholder';
|
|
13
9
|
|
|
@@ -43,6 +39,10 @@ export class NextJSVersionCommand extends Command {
|
|
|
43
39
|
}[];
|
|
44
40
|
|
|
45
41
|
async run(): Promise<void> {
|
|
42
|
+
// const RUNNING_TEXT = ' RUNS ';
|
|
43
|
+
// const RUNNING = chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
|
|
44
|
+
const RUNNING = ''; //chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
|
|
45
|
+
|
|
46
46
|
const { flags: parsedFlags } = this.parse(NextJSVersionCommand);
|
|
47
47
|
const version = parsedFlags.newVersion;
|
|
48
48
|
const leaveFiles = parsedFlags.leaveCopy;
|
|
@@ -104,10 +104,6 @@ export class NextJSVersionCommand extends Command {
|
|
|
104
104
|
},
|
|
105
105
|
);
|
|
106
106
|
|
|
107
|
-
|
|
108
|
-
await tasks.run();
|
|
109
|
-
} catch (error) {
|
|
110
|
-
this.log(`Caught exception: ${error.message}`);
|
|
111
|
-
}
|
|
107
|
+
await tasks.run();
|
|
112
108
|
}
|
|
113
109
|
}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import * as sts from '@aws-sdk/client-sts';
|
|
3
3
|
import { Command, flags as flagsParser } from '@oclif/command';
|
|
4
|
-
import * as chalk from 'chalk';
|
|
5
4
|
import { Listr } from 'listr2';
|
|
6
5
|
import { Config } from '../config/Config';
|
|
7
6
|
import DeployClient from '../lib/DeployClient';
|
|
8
7
|
|
|
9
|
-
const RUNNING_TEXT = ' RUNS ';
|
|
10
|
-
const RUNNING = chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
|
|
11
|
-
|
|
12
8
|
export class PreflightCommand extends Command {
|
|
13
9
|
static description = 'Check if app/version are available';
|
|
14
10
|
|
|
@@ -41,16 +37,28 @@ export class PreflightCommand extends Command {
|
|
|
41
37
|
required: true,
|
|
42
38
|
description: 'Name of the deployer lambda function',
|
|
43
39
|
}),
|
|
40
|
+
overwrite: flagsParser.boolean({
|
|
41
|
+
char: 'o',
|
|
42
|
+
required: false,
|
|
43
|
+
default: false,
|
|
44
|
+
description:
|
|
45
|
+
'Allow overwrite - Warn but do not fail if version exists. Discouraged outside of test envs if cacheable static files have changed.',
|
|
46
|
+
}),
|
|
44
47
|
};
|
|
45
48
|
|
|
46
49
|
async run(): Promise<void> {
|
|
47
50
|
const config = Config.instance;
|
|
48
51
|
|
|
52
|
+
// const RUNNING_TEXT = ' RUNS ';
|
|
53
|
+
// const RUNNING = chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
|
|
54
|
+
const RUNNING = ''; //chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
|
|
55
|
+
|
|
49
56
|
const { flags: parsedFlags } = this.parse(PreflightCommand);
|
|
50
57
|
const version = parsedFlags.newVersion;
|
|
51
58
|
const appName = parsedFlags.appName ?? config.app.name;
|
|
52
59
|
const deployerLambdaName = parsedFlags.deployerLambdaName ?? config.deployer.lambdaName;
|
|
53
60
|
const semVer = parsedFlags.newVersion ?? config.app.semVer;
|
|
61
|
+
const overwrite = parsedFlags.overwrite;
|
|
54
62
|
|
|
55
63
|
// Override the config value
|
|
56
64
|
config.deployer.lambdaName = deployerLambdaName;
|
|
@@ -74,10 +82,6 @@ export class PreflightCommand extends Command {
|
|
|
74
82
|
}
|
|
75
83
|
}
|
|
76
84
|
|
|
77
|
-
if (config === undefined) {
|
|
78
|
-
this.error('Failed to load the config file');
|
|
79
|
-
}
|
|
80
|
-
|
|
81
85
|
//
|
|
82
86
|
// Setup Tasks
|
|
83
87
|
//
|
|
@@ -95,13 +99,20 @@ export class PreflightCommand extends Command {
|
|
|
95
99
|
const preflightResult = await DeployClient.DeployVersionPreflight({
|
|
96
100
|
config,
|
|
97
101
|
needS3Creds: false,
|
|
102
|
+
overwrite,
|
|
98
103
|
output: (message: string) => (task.output = message),
|
|
99
104
|
});
|
|
100
105
|
if (preflightResult.exists) {
|
|
101
|
-
|
|
106
|
+
if (!overwrite) {
|
|
107
|
+
throw new Error(
|
|
108
|
+
`App/Version already exists: ${config.app.name}/${config.app.semVer}`,
|
|
109
|
+
);
|
|
110
|
+
} else {
|
|
111
|
+
task.title = `Warning: App/Version already exists: ${config.app.name}/${config.app.semVer}`;
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
task.title = `App/Version does not exist: ${config.app.name}/${config.app.semVer}`;
|
|
102
115
|
}
|
|
103
|
-
|
|
104
|
-
task.title = origTitle;
|
|
105
116
|
},
|
|
106
117
|
},
|
|
107
118
|
],
|
|
@@ -112,10 +123,6 @@ export class PreflightCommand extends Command {
|
|
|
112
123
|
},
|
|
113
124
|
);
|
|
114
125
|
|
|
115
|
-
|
|
116
|
-
await tasks.run();
|
|
117
|
-
} catch (error) {
|
|
118
|
-
this.log(`Caught exception: ${error.message}`);
|
|
119
|
-
}
|
|
126
|
+
await tasks.run();
|
|
120
127
|
}
|
|
121
128
|
}
|