pwrdrvr 0.4.0-alpha.13

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 (82) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +241 -0
  3. package/bin/run +5 -0
  4. package/dist/commands/delete.d.ts +18 -0
  5. package/dist/commands/delete.d.ts.map +1 -0
  6. package/dist/commands/delete.js +125 -0
  7. package/dist/commands/delete.js.map +1 -0
  8. package/dist/commands/nextjs-version-restore.d.ts +14 -0
  9. package/dist/commands/nextjs-version-restore.d.ts.map +1 -0
  10. package/dist/commands/nextjs-version-restore.js +53 -0
  11. package/dist/commands/nextjs-version-restore.js.map +1 -0
  12. package/dist/commands/nextjs-version.d.ts +18 -0
  13. package/dist/commands/nextjs-version.d.ts.map +1 -0
  14. package/dist/commands/nextjs-version.js +103 -0
  15. package/dist/commands/nextjs-version.js.map +1 -0
  16. package/dist/commands/preflight.d.ts +19 -0
  17. package/dist/commands/preflight.d.ts.map +1 -0
  18. package/dist/commands/preflight.js +135 -0
  19. package/dist/commands/preflight.js.map +1 -0
  20. package/dist/commands/publish-static.d.ts +25 -0
  21. package/dist/commands/publish-static.d.ts.map +1 -0
  22. package/dist/commands/publish-static.js +361 -0
  23. package/dist/commands/publish-static.js.map +1 -0
  24. package/dist/commands/publish.d.ts +39 -0
  25. package/dist/commands/publish.d.ts.map +1 -0
  26. package/dist/commands/publish.js +565 -0
  27. package/dist/commands/publish.js.map +1 -0
  28. package/dist/config/Application.d.ts +26 -0
  29. package/dist/config/Application.d.ts.map +1 -0
  30. package/dist/config/Application.js +99 -0
  31. package/dist/config/Application.js.map +1 -0
  32. package/dist/config/Config.d.ts +18 -0
  33. package/dist/config/Config.d.ts.map +1 -0
  34. package/dist/config/Config.js +71 -0
  35. package/dist/config/Config.js.map +1 -0
  36. package/dist/config/Deployer.d.ts +10 -0
  37. package/dist/config/Deployer.d.ts.map +1 -0
  38. package/dist/config/Deployer.js +17 -0
  39. package/dist/config/Deployer.js.map +1 -0
  40. package/dist/index.d.ts +2 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +6 -0
  43. package/dist/index.js.map +1 -0
  44. package/dist/lib/DeployClient.d.ts +102 -0
  45. package/dist/lib/DeployClient.d.ts.map +1 -0
  46. package/dist/lib/DeployClient.js +233 -0
  47. package/dist/lib/DeployClient.js.map +1 -0
  48. package/dist/lib/FilesExist.d.ts +5 -0
  49. package/dist/lib/FilesExist.d.ts.map +1 -0
  50. package/dist/lib/FilesExist.js +26 -0
  51. package/dist/lib/FilesExist.js.map +1 -0
  52. package/dist/lib/S3TransferUtility.d.ts +19 -0
  53. package/dist/lib/S3TransferUtility.d.ts.map +1 -0
  54. package/dist/lib/S3TransferUtility.js +94 -0
  55. package/dist/lib/S3TransferUtility.js.map +1 -0
  56. package/dist/lib/S3Uploader.d.ts +27 -0
  57. package/dist/lib/S3Uploader.d.ts.map +1 -0
  58. package/dist/lib/S3Uploader.js +77 -0
  59. package/dist/lib/S3Uploader.js.map +1 -0
  60. package/dist/lib/Versions.d.ts +33 -0
  61. package/dist/lib/Versions.d.ts.map +1 -0
  62. package/dist/lib/Versions.js +76 -0
  63. package/dist/lib/Versions.js.map +1 -0
  64. package/package.json +83 -0
  65. package/src/commands/delete.ts +135 -0
  66. package/src/commands/nextjs-version-restore.ts +70 -0
  67. package/src/commands/nextjs-version.ts +123 -0
  68. package/src/commands/preflight.ts +148 -0
  69. package/src/commands/publish-static.ts +416 -0
  70. package/src/commands/publish.ts +662 -0
  71. package/src/commands-deprecated/nextjs-docker-auto.skip +590 -0
  72. package/src/config/Application.ts +98 -0
  73. package/src/config/Config.ts +81 -0
  74. package/src/config/Deployer.ts +17 -0
  75. package/src/index.ts +1 -0
  76. package/src/lib/DeployClient.ts +334 -0
  77. package/src/lib/FilesExist.ts +25 -0
  78. package/src/lib/S3TransferUtility.spec.ts +15 -0
  79. package/src/lib/S3TransferUtility.ts +113 -0
  80. package/src/lib/S3Uploader.ts +94 -0
  81. package/src/lib/Versions.ts +101 -0
  82. package/src/lib/__snapshots__/S3TransferUtility.spec.ts.snap +12 -0
@@ -0,0 +1,19 @@
1
+ import type { IDeployVersionPreflightResponse } from '@pwrdrvr/microapps-deployer-lib';
2
+ export declare class S3TransferUtility {
3
+ /**
4
+ * @deprecated 2021-11-27
5
+ *
6
+ * @param s3Path
7
+ * @param destPrefixPath
8
+ * @param bucketName
9
+ * @param preflightResponse
10
+ */
11
+ static UploadDir(s3Path: string, destPrefixPath: string, bucketName: string, preflightResponse: IDeployVersionPreflightResponse): Promise<void>;
12
+ /**
13
+ * Resursively enumerate the files to be uploaded
14
+ * @param dir
15
+ * @returns
16
+ */
17
+ static GetFiles(dir: string): string[];
18
+ }
19
+ //# sourceMappingURL=S3TransferUtility.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"S3TransferUtility.d.ts","sourceRoot":"","sources":["../../src/lib/S3TransferUtility.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,iCAAiC,CAAC;AAIvF,qBAAa,iBAAiB;IAC5B;;;;;;;OAOG;WACiB,SAAS,CAC3B,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,iBAAiB,EAAE,+BAA+B,GACjD,OAAO,CAAC,IAAI,CAAC;IAqDhB;;;;OAIG;WACW,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE;CA4B9C"}
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ //
3
+ // From: https://stackoverflow.com/a/65862128/878903
4
+ //
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.S3TransferUtility = void 0;
7
+ const tslib_1 = require("tslib");
8
+ const fs_1 = require("fs");
9
+ const path = tslib_1.__importStar(require("path"));
10
+ const s3 = tslib_1.__importStar(require("@aws-sdk/client-s3"));
11
+ const lib_storage_1 = require("@aws-sdk/lib-storage");
12
+ const mime_types_1 = require("mime-types");
13
+ const p_map_1 = tslib_1.__importDefault(require("p-map"));
14
+ class S3TransferUtility {
15
+ /**
16
+ * @deprecated 2021-11-27
17
+ *
18
+ * @param s3Path
19
+ * @param destPrefixPath
20
+ * @param bucketName
21
+ * @param preflightResponse
22
+ */
23
+ static async UploadDir(s3Path, destPrefixPath, bucketName, preflightResponse) {
24
+ // Use temp credentials for S3
25
+ const s3Client = new s3.S3Client({
26
+ maxAttempts: 16,
27
+ credentials: {
28
+ accessKeyId: preflightResponse.awsCredentials.accessKeyId,
29
+ secretAccessKey: preflightResponse.awsCredentials.secretAccessKey,
30
+ sessionToken: preflightResponse.awsCredentials.sessionToken,
31
+ },
32
+ });
33
+ // console.log('Uploading files to S3');
34
+ const files = S3TransferUtility.GetFiles(s3Path);
35
+ // const pathWithoutAppAndVer = path.join(s3Path, destPrefixPath);
36
+ // for (const filePath of files) {
37
+ // const relFilePath = path.relative(pathWithoutAppAndVer, filePath);
38
+ // console.log(` ${relFilePath}`);
39
+ // }
40
+ // Use p-map to limit upload parallelism
41
+ await (0, p_map_1.default)(files, async (filePath) => {
42
+ // Use 4 multi-part parallel uploads for items > 5 MB
43
+ const upload = new lib_storage_1.Upload({
44
+ client: s3Client,
45
+ leavePartsOnError: false,
46
+ params: {
47
+ Bucket: bucketName,
48
+ Key: path.relative(s3Path, filePath),
49
+ Body: (0, fs_1.createReadStream)(filePath),
50
+ ContentType: (0, mime_types_1.contentType)(path.basename(filePath)) || 'application/octet-stream',
51
+ CacheControl: 'max-age=86400; public',
52
+ },
53
+ });
54
+ await upload.done();
55
+ }, {
56
+ concurrency: 10,
57
+ });
58
+ }
59
+ // Recursive getFiles from
60
+ // https://stackoverflow.com/a/45130990/831465
61
+ /**
62
+ * Resursively enumerate the files to be uploaded
63
+ * @param dir
64
+ * @returns
65
+ */
66
+ static GetFiles(dir) {
67
+ const dirents = (0, fs_1.readdirSync)(dir, { withFileTypes: true });
68
+ const files = [];
69
+ const toScan = dirents.map((dirent) => ({
70
+ path: path.resolve(dir, dirent.name),
71
+ isDirectory: dirent.isDirectory(),
72
+ }));
73
+ // Iteratively collect all the files in the directories
74
+ // Do not use function call recursion
75
+ while (toScan.length > 0) {
76
+ const dirOrFile = toScan.pop();
77
+ if (dirOrFile.isDirectory) {
78
+ const direntsChild = (0, fs_1.readdirSync)(dirOrFile.path, { withFileTypes: true });
79
+ const toScanChild = direntsChild.map((dirent) => ({
80
+ path: path.resolve(dirOrFile.path, dirent.name),
81
+ isDirectory: dirent.isDirectory(),
82
+ }));
83
+ Array.prototype.push.apply(toScan, toScanChild);
84
+ }
85
+ else {
86
+ files.push(dirOrFile.path);
87
+ }
88
+ }
89
+ // Reverse the array so that the files are in the same order as the original
90
+ return files.reverse();
91
+ }
92
+ }
93
+ exports.S3TransferUtility = S3TransferUtility;
94
+ //# sourceMappingURL=S3TransferUtility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"S3TransferUtility.js","sourceRoot":"","sources":["../../src/lib/S3TransferUtility.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,oDAAoD;AACpD,EAAE;;;;AAEF,2BAAmD;AACnD,mDAA6B;AAC7B,+DAAyC;AACzC,sDAA8C;AAE9C,2CAAyC;AACzC,0DAAyB;AAEzB,MAAa,iBAAiB;IAC5B;;;;;;;OAOG;IACI,MAAM,CAAC,KAAK,CAAC,SAAS,CAC3B,MAAc,EACd,cAAsB,EACtB,UAAkB,EAClB,iBAAkD;QAElD,8BAA8B;QAC9B,MAAM,QAAQ,GAAG,IAAI,EAAE,CAAC,QAAQ,CAAC;YAC/B,WAAW,EAAE,EAAE;YACf,WAAW,EAAE;gBACX,WAAW,EAAE,iBAAiB,CAAC,cAAc,CAAC,WAAW;gBACzD,eAAe,EAAE,iBAAiB,CAAC,cAAc,CAAC,eAAe;gBACjE,YAAY,EAAE,iBAAiB,CAAC,cAAc,CAAC,YAAY;aAC5D;SACF,CAAC,CAAC;QAEH,wCAAwC;QACxC,MAAM,KAAK,GAAG,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M,CAAC,MAAM,GAAG,CAAC,EAAE;YACxB,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC;YAE/B,IAAI,SAAS,CAAC,WAAW,EAAE;gBACzB,MAAM,YAAY,GAAG,IAAA,gBAAW,EAAC,SAAS,CAAC,IAAI,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC1E,MAAM,WAAW,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;oBAChD,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC;oBAC/C,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE;iBAClC,CAAC,CAAC,CAAC;gBACJ,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;aACjD;iBAAM;gBACL,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;aAC5B;SACF;QAED,4EAA4E;QAC5E,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACF;AApGD,8CAoGC"}
@@ -0,0 +1,27 @@
1
+ import type { IDeployVersionPreflightResponse } from '@pwrdrvr/microapps-deployer-lib';
2
+ import { IConfig } from '../config/Config';
3
+ export declare class S3Uploader {
4
+ /**
5
+ * Copy files to local upload directory
6
+ * @param config
7
+ * @param s3UploadPath
8
+ * @param preflightResponse
9
+ */
10
+ static CopyToUploadDir(config: IConfig, s3UploadPath: string): Promise<void>;
11
+ static ParseUploadPath(s3UploadPath: string): {
12
+ bucketName: string;
13
+ destinationPrefix: string;
14
+ };
15
+ /**
16
+ * Upload files to S3
17
+ * @deprecated 2021-11-27
18
+ * @param config
19
+ * @param s3UploadPath
20
+ * @param preflightResponse
21
+ */
22
+ static Upload(config: IConfig, s3UploadPath: string, preflightResponse: IDeployVersionPreflightResponse): Promise<void>;
23
+ static removeTempDirIfExists(): Promise<void>;
24
+ private static readonly _tempDir;
25
+ static get TempDir(): string;
26
+ }
27
+ //# sourceMappingURL=S3Uploader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"S3Uploader.d.ts","sourceRoot":"","sources":["../../src/lib/S3Uploader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,iCAAiC,CAAC;AAEvF,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAG3C,qBAAa,UAAU;IACrB;;;;;OAKG;WACiB,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WAa3E,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG;QACnD,UAAU,EAAE,MAAM,CAAC;QACnB,iBAAiB,EAAE,MAAM,CAAC;KAC3B;IASD;;;;;;OAMG;WACiB,MAAM,CACxB,MAAM,EAAE,OAAO,EACf,YAAY,EAAE,MAAM,EACpB,iBAAiB,EAAE,+BAA+B,GACjD,OAAO,CAAC,IAAI,CAAC;WA2BI,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;IAa1D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAuB;IACvD,WAAkB,OAAO,IAAI,MAAM,CAElC;CACF"}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.S3Uploader = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path = tslib_1.__importStar(require("path"));
6
+ const fs = tslib_1.__importStar(require("fs-extra"));
7
+ const S3TransferUtility_1 = require("./S3TransferUtility");
8
+ class S3Uploader {
9
+ /**
10
+ * Copy files to local upload directory
11
+ * @param config
12
+ * @param s3UploadPath
13
+ * @param preflightResponse
14
+ */
15
+ static async CopyToUploadDir(config, s3UploadPath) {
16
+ const { destinationPrefix } = S3Uploader.ParseUploadPath(s3UploadPath);
17
+ // Make a local root dir for the upload
18
+ const tempUploadPath = path.join(S3Uploader._tempDir, destinationPrefix);
19
+ await S3Uploader.removeTempDirIfExists();
20
+ await fs.mkdir(tempUploadPath, { recursive: true });
21
+ // Copy the files in the source dir to the root dir
22
+ // Note: It would be faster to move the files, then move them back
23
+ await fs.copy(config.app.staticAssetsPath, tempUploadPath);
24
+ }
25
+ static ParseUploadPath(s3UploadPath) {
26
+ // Parse the S3 Source URI
27
+ const uri = new URL(s3UploadPath);
28
+ const bucketName = uri.host;
29
+ const destinationPrefix = uri.pathname.length >= 1 ? uri.pathname.slice(1) : '';
30
+ return { bucketName, destinationPrefix };
31
+ }
32
+ /**
33
+ * Upload files to S3
34
+ * @deprecated 2021-11-27
35
+ * @param config
36
+ * @param s3UploadPath
37
+ * @param preflightResponse
38
+ */
39
+ static async Upload(config, s3UploadPath, preflightResponse) {
40
+ try {
41
+ const { destinationPrefix, bucketName } = S3Uploader.ParseUploadPath(s3UploadPath);
42
+ // Make a local root dir for the upload
43
+ const tempUploadPath = path.join(S3Uploader._tempDir, destinationPrefix);
44
+ await S3Uploader.removeTempDirIfExists();
45
+ await fs.mkdir(tempUploadPath, { recursive: true });
46
+ // Copy the files in the source dir to the root dir
47
+ // Note: It would be faster to move the files, then move them back
48
+ // FIXME: Use p-map for controlled parallelism
49
+ await fs.copy(config.app.staticAssetsPath, tempUploadPath);
50
+ // Do the upload
51
+ await S3TransferUtility_1.S3TransferUtility.UploadDir(this._tempDir, destinationPrefix, bucketName, preflightResponse);
52
+ }
53
+ finally {
54
+ // Delete the directory, now that it's uploaded or if we failed
55
+ await S3Uploader.removeTempDirIfExists();
56
+ }
57
+ }
58
+ static async removeTempDirIfExists() {
59
+ try {
60
+ const stats = await fs.stat(S3Uploader._tempDir);
61
+ if (stats.isDirectory()) {
62
+ await fs.rm(S3Uploader._tempDir, { recursive: true });
63
+ }
64
+ }
65
+ catch (_a) {
66
+ // Don't care
67
+ // fs.stat will throw if file/dir does not exist
68
+ // Since we want the directory deleted this is ok
69
+ }
70
+ }
71
+ static get TempDir() {
72
+ return S3Uploader._tempDir;
73
+ }
74
+ }
75
+ exports.S3Uploader = S3Uploader;
76
+ S3Uploader._tempDir = './deploytool-temp';
77
+ //# sourceMappingURL=S3Uploader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"S3Uploader.js","sourceRoot":"","sources":["../../src/lib/S3Uploader.ts"],"names":[],"mappings":";;;;AAAA,mDAA6B;AAE7B,qDAA+B;AAE/B,2DAAwD;AAExD,MAAa,UAAU;IACrB;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,MAAe,EAAE,YAAoB;QACvE,MAAM,EAAE,iBAAiB,EAAE,GAAG,UAAU,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;QAEvE,uCAAuC;QACvC,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;QACzE,MAAM,UAAU,CAAC,qBAAqB,EAAE,CAAC;QACzC,MAAM,EAAE,CAAC,KAAK,CAAC,cAAc,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAEpD,mDAAmD;QACnD,kEAAkE;QAClE,MAAM,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;IAC7D,CAAC;IAEM,MAAM,CAAC,eAAe,CAAC,YAAoB;QAIhD,0BAA0B;QAC1B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;QAClC,MAAM,UAAU,GAAG,GAAG,CAAC,IAAI,CAAC;QAC5B,MAAM,iBAAiB,GAAG,GAAG,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAEhF,OAAO,EAAE,UAAU,EAAE,iBAAi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,CAAC;IAC7B,CAAC;;AAtFH,gCAuFC;AAJyB,mBAAQ,GAAG,mBAAmB,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Represents a File To Modify
3
+ */
4
+ export interface IFileToModify {
5
+ path: string;
6
+ versions: IVersions;
7
+ }
8
+ /**
9
+ * Write new versions into specified config file
10
+ * @param path
11
+ * @param requiredVersions
12
+ * @param leaveFiles
13
+ * @returns
14
+ */
15
+ export declare function writeNewVersions(path: string, requiredVersions: IVersions, leaveFiles: boolean): Promise<boolean>;
16
+ /**
17
+ * Restore files that the version was patched into
18
+ */
19
+ export declare function restoreFiles(filesToModify: IFileToModify[]): Promise<void>;
20
+ /**
21
+ * Represents a Versions
22
+ */
23
+ export interface IVersions {
24
+ version: string;
25
+ alias?: string;
26
+ }
27
+ /**
28
+ * Setup version and alias strings
29
+ * @param version
30
+ * @returns
31
+ */
32
+ export declare function createVersions(version: string): Required<IVersions>;
33
+ //# sourceMappingURL=Versions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Versions.d.ts","sourceRoot":"","sources":["../../src/lib/Versions.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,SAAS,CAAC;CACrB;AAOD;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,MAAM,EACZ,gBAAgB,EAAE,SAAS,EAC3B,UAAU,EAAE,OAAO,GAClB,OAAO,CAAC,OAAO,CAAC,CAoClB;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,aAAa,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBhF;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,CAEnE"}
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createVersions = exports.restoreFiles = exports.writeNewVersions = void 0;
4
+ const fs_extra_1 = require("fs-extra");
5
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
6
+ function escapeRegExp(value) {
7
+ return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
8
+ }
9
+ /**
10
+ * Write new versions into specified config file
11
+ * @param path
12
+ * @param requiredVersions
13
+ * @param leaveFiles
14
+ * @returns
15
+ */
16
+ async function writeNewVersions(path, requiredVersions, leaveFiles) {
17
+ const stats = await fs_extra_1.promises.stat(path);
18
+ if (!stats.isFile) {
19
+ return false;
20
+ }
21
+ // Make a backup of the file
22
+ await fs_extra_1.promises.copyFile(path, `${path}.original`);
23
+ // File exists, check that it has the required version strings
24
+ let fileText = await fs_extra_1.promises.readFile(path, 'utf8');
25
+ for (const key of Object.keys(requiredVersions)) {
26
+ const placeHolder = key === 'version' ? '0.0.0' : 'v0_0_0';
27
+ if (fileText.indexOf(placeHolder) === -1) {
28
+ // The required placeholder is missing
29
+ return false;
30
+ }
31
+ else {
32
+ const regExp = new RegExp(escapeRegExp(placeHolder), 'g');
33
+ fileText = fileText.replace(regExp, key === 'version' ? requiredVersions.version : requiredVersions.alias);
34
+ }
35
+ }
36
+ // Write the updated file contents
37
+ await fs_extra_1.promises.writeFile(path, fileText, 'utf8');
38
+ // Leave a copy of the modified file if requested
39
+ if (leaveFiles) {
40
+ // This copy will overwrite an existing file
41
+ await fs_extra_1.promises.copyFile(path, `${path}.modified`);
42
+ }
43
+ return true;
44
+ }
45
+ exports.writeNewVersions = writeNewVersions;
46
+ /**
47
+ * Restore files that the version was patched into
48
+ */
49
+ async function restoreFiles(filesToModify) {
50
+ // Put the old files back when succeeded or failed
51
+ for (const fileToModify of filesToModify) {
52
+ try {
53
+ const stats = await fs_extra_1.promises.stat(`${fileToModify.path}.original`);
54
+ if (stats.isFile()) {
55
+ // Remove the possibly modified file
56
+ await fs_extra_1.promises.unlink(fileToModify.path);
57
+ // Move the original file back
58
+ await fs_extra_1.promises.rename(`${fileToModify.path}.original`, fileToModify.path);
59
+ }
60
+ }
61
+ catch (_a) {
62
+ // don't care... if the file doesn't exist we can't do anything
63
+ }
64
+ }
65
+ }
66
+ exports.restoreFiles = restoreFiles;
67
+ /**
68
+ * Setup version and alias strings
69
+ * @param version
70
+ * @returns
71
+ */
72
+ function createVersions(version) {
73
+ return { version, alias: `v${version.replace(/\./g, '_')}` };
74
+ }
75
+ exports.createVersions = createVersions;
76
+ //# sourceMappingURL=Versions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Versions.js","sourceRoot":"","sources":["../../src/lib/Versions.ts"],"names":[],"mappings":";;;AAAA,uCAA0C;AAU1C,6FAA6F;AAC7F,SAAS,YAAY,CAAC,KAAa;IACjC,OAAO,KAAK,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC,CAAC,oCAAoC;AAC3F,CAAC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,gBAAgB,CACpC,IAAY,EACZ,gBAA2B,EAC3B,UAAmB;IAEnB,MAAM,KAAK,GAAG,MAAM,mBAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;QACjB,OAAO,KAAK,CAAC;KACd;IAED,4BAA4B;IAC5B,MAAM,mBAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,IAAI,WAAW,CAAC,CAAC;IAE5C,8DAA8D;IAC9D,IAAI,QAAQ,GAAG,MAAM,mBAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAE/C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAAE;QAC/C,MAAM,WAAW,GAAG,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;YACN,+DAA+D;SAChE;KACF;AACH,CAAC;AAhBD,oCAgBC;AAUD;;;;GAIG;AACH,SAAgB,cAAc,CAAC,OAAe;IAC5C,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC;AAC/D,CAAC;AAFD,wCAEC"}
package/package.json ADDED
@@ -0,0 +1,83 @@
1
+ {
2
+ "name": "pwrdrvr",
3
+ "version": "0.4.0-alpha.13",
4
+ "description": "Publish tool for deploying apps and updates",
5
+ "main": "dist/index.js",
6
+ "source": "src/index.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "bin": {
11
+ "microapps-publish": "./bin/run",
12
+ "pwrdrvr": "./bin/run"
13
+ },
14
+ "engineStrict": true,
15
+ "engine": {
16
+ "node": ">= 12.0.0"
17
+ },
18
+ "scripts": {
19
+ "test": "echo \"Error: no test specified\" && exit 1"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "src",
24
+ "package.json",
25
+ "LICENSE",
26
+ "README.md"
27
+ ],
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/pwrdrvr/microapps-core.git"
31
+ },
32
+ "author": "PwrDrvr LLC",
33
+ "license": "MIT",
34
+ "bugs": {
35
+ "url": "https://github.com/pwrdrvr/microapps-core/issues"
36
+ },
37
+ "homepage": "https://github.com/pwrdrvr/microapps-core#readme",
38
+ "dependencies": {
39
+ "@aws-sdk/client-lambda": "^3.78.0",
40
+ "@aws-sdk/client-s3": "^3.78.0",
41
+ "@aws-sdk/client-sts": "^3.78.0",
42
+ "@aws-sdk/lib-storage": "^3.78.0",
43
+ "@oclif/command": "^1.8.4",
44
+ "@oclif/config": "^1.17.1",
45
+ "@oclif/core": "^1.0.4",
46
+ "@oclif/errors": "^1.3.5",
47
+ "@oclif/plugin-help": "^3.2.7",
48
+ "chalk": "^4.1.2",
49
+ "convict": "^6.1.0",
50
+ "convict-format-with-validator": "^6.0.1",
51
+ "fs-extra": "^9.1.0",
52
+ "js-yaml": "^4.1.0",
53
+ "listr2": "^3.13.5",
54
+ "mime-types": "^2.1.30",
55
+ "p-map": "^4.0.0",
56
+ "reflect-metadata": "^0.1.13",
57
+ "source-map-support": "0.5.21",
58
+ "ts-convict": "^1.1.0",
59
+ "tslib": "^2.1.0"
60
+ },
61
+ "peerDependencies": {
62
+ "@aws-sdk/client-lambda": "^3.78.0",
63
+ "@aws-sdk/client-s3": "^3.78.0",
64
+ "@aws-sdk/client-sts": "^3.78.0",
65
+ "@aws-sdk/lib-storage": "^3.78.0"
66
+ },
67
+ "devDependencies": {
68
+ "@types/convict": "^6.0.2",
69
+ "@types/convict-format-with-validator": "^6.0.2",
70
+ "@types/fs-extra": "^9.0.11",
71
+ "@types/js-yaml": "^4.0.1",
72
+ "@types/mime-types": "^2.1.0",
73
+ "@types/source-map-support": "0.5.6",
74
+ "type-fest": "^0.20.2"
75
+ },
76
+ "oclif": {
77
+ "commands": "./dist/commands/",
78
+ "bin": "pwrdrvr",
79
+ "plugins": [
80
+ "@oclif/plugin-help"
81
+ ]
82
+ }
83
+ }
@@ -0,0 +1,135 @@
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 DeleteCommand extends Command {
9
+ static description = 'Delete app/version';
10
+
11
+ static examples = [
12
+ `$ pwrdrvr delete -d microapps-deployer-dev -a release -n 0.0.13
13
+ ✔ App/Version deleted: release/0.0.13 [1.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
+ };
59
+
60
+ async run(): Promise<void> {
61
+ const config = Config.instance;
62
+
63
+ // const RUNNING_TEXT = ' RUNS ';
64
+ // const RUNNING = chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
65
+ const RUNNING = ''; //chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
66
+
67
+ const { flags: parsedFlags } = this.parse(DeleteCommand);
68
+ const semVer = parsedFlags.newVersion ?? parsedFlags['new-version'] ?? config.app.semVer;
69
+ const appName = parsedFlags.appName ?? parsedFlags['app-name'] ?? config.app.name;
70
+ const deployerLambdaName =
71
+ parsedFlags.deployerLambdaName ??
72
+ parsedFlags['deployer-lambda-name'] ??
73
+ config.deployer.lambdaName;
74
+
75
+ // Override the config value
76
+ config.deployer.lambdaName = deployerLambdaName;
77
+ config.app.name = appName;
78
+ config.app.semVer = semVer;
79
+
80
+ // TODO: Pick and validate the appname/semver from the config and flags
81
+
82
+ // Get the account ID and region from STS
83
+ // TODO: Move this to the right place
84
+ if (config.app.awsAccountID === '' || config.app.awsRegion === '') {
85
+ const stsClient = new sts.STSClient({
86
+ maxAttempts: 8,
87
+ });
88
+ const stsResponse = await stsClient.send(new sts.GetCallerIdentityCommand({}));
89
+ if (config.app.awsAccountID === '') {
90
+ config.app.awsAccountID = stsResponse.Account;
91
+ }
92
+ if (config.app.awsRegion === '') {
93
+ config.app.awsRegion = stsClient.config.region as string;
94
+ }
95
+ }
96
+
97
+ //
98
+ // Setup Tasks
99
+ //
100
+
101
+ const tasks = new Listr(
102
+ [
103
+ {
104
+ title: 'Deleting Version',
105
+ task: async (ctx, task) => {
106
+ const origTitle = task.title;
107
+ task.title = RUNNING + origTitle;
108
+
109
+ // Confirm the Version Does Not Exist in Published State
110
+ task.output = `Deleting app/version ${config.app.name}/${semVer}`;
111
+ const result = await DeployClient.DeleteVersion({
112
+ config,
113
+ output: (message: string) => (task.output = message),
114
+ });
115
+ if (result.statusCode === 200) {
116
+ task.title = `App/Version deleted: ${config.app.name}/${config.app.semVer}`;
117
+ } else if (result.statusCode === 404) {
118
+ task.title = `App/Version does not exist: ${config.app.name}/${config.app.semVer}`;
119
+ } else {
120
+ task.title = `App/Version delete failed: ${config.app.name}/${config.app.semVer}`;
121
+ throw new Error(`App/Version delete failed: ${config.app.name}/${config.app.semVer}`);
122
+ }
123
+ },
124
+ },
125
+ ],
126
+ {
127
+ rendererOptions: {
128
+ showTimer: true,
129
+ },
130
+ },
131
+ );
132
+
133
+ await tasks.run();
134
+ }
135
+ }
@@ -0,0 +1,70 @@
1
+ import 'reflect-metadata';
2
+ import { Command, flags as flagsParser } from '@oclif/command';
3
+ import { Listr } from 'listr2';
4
+ import { createVersions, IVersions, restoreFiles } from '../lib/Versions';
5
+
6
+ export class NextJSVersionRestoreCommand extends Command {
7
+ static description = 'Restore next.config.js';
8
+
9
+ static examples = [
10
+ `$ pwrdrvr nextjs-version-restore
11
+ ✔ Restoring Modified Config Files [0.0s]
12
+ `,
13
+ ];
14
+
15
+ static flags = {
16
+ version: flagsParser.version({
17
+ char: 'v',
18
+ }),
19
+ help: flagsParser.help(),
20
+ };
21
+
22
+ private VersionAndAlias: IVersions;
23
+ private FILES_TO_MODIFY: {
24
+ path: string;
25
+ versions: IVersions;
26
+ }[];
27
+
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
+ // const { flags: parsedFlags } =
34
+ this.parse(NextJSVersionRestoreCommand);
35
+
36
+ this.VersionAndAlias = createVersions('0.0.0');
37
+ const versionOnly = { version: this.VersionAndAlias.version };
38
+
39
+ this.FILES_TO_MODIFY = [{ path: 'next.config.js', versions: versionOnly }];
40
+
41
+ // TODO: Pick and validate the appname/semver from the config and flags
42
+
43
+ //
44
+ // Setup Tasks
45
+ //
46
+
47
+ const tasks = new Listr(
48
+ [
49
+ {
50
+ title: 'Restoring Modified Config Files',
51
+ task: async (ctx, task) => {
52
+ const origTitle = task.title;
53
+ task.title = RUNNING + origTitle;
54
+
55
+ await restoreFiles(this.FILES_TO_MODIFY);
56
+
57
+ task.title = origTitle;
58
+ },
59
+ },
60
+ ],
61
+ {
62
+ rendererOptions: {
63
+ showTimer: true,
64
+ },
65
+ },
66
+ );
67
+
68
+ await tasks.run();
69
+ }
70
+ }