@onivoro/onix 20.5.4 → 20.5.6
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/executors.json +5 -0
- package/package.json +1 -1
- package/src/executors/deploy-s3-react/executor.d.ts +3 -0
- package/src/executors/deploy-s3-react/executor.js +58 -0
- package/src/executors/deploy-s3-react/executor.js.map +1 -0
- package/src/executors/deploy-s3-react/schema.d.ts +7 -0
- package/src/executors/deploy-s3-react/schema.json +34 -0
- package/src/functions/add-cdn-prefix-to-key.function.d.ts +1 -0
- package/src/functions/add-cdn-prefix-to-key.function.js +9 -0
- package/src/functions/add-cdn-prefix-to-key.function.js.map +1 -0
- package/src/functions/resolve-aws-credentials.function.js +13 -1
- package/src/functions/resolve-aws-credentials.function.js.map +1 -1
- package/src/functions/to-cdn-path.function.d.ts +1 -0
- package/src/functions/to-cdn-path.function.js +8 -0
- package/src/functions/to-cdn-path.function.js.map +1 -0
package/executors.json
CHANGED
|
@@ -25,6 +25,11 @@
|
|
|
25
25
|
"schema": "./src/executors/deploy-ecs/schema.json",
|
|
26
26
|
"description": "deploy-ecs"
|
|
27
27
|
},
|
|
28
|
+
"deploy-s3-react": {
|
|
29
|
+
"implementation": "./src/executors/deploy-s3-react/executor",
|
|
30
|
+
"schema": "./src/executors/deploy-s3-react/schema.json",
|
|
31
|
+
"description": "deploy-s3-react"
|
|
32
|
+
},
|
|
28
33
|
"openapi-gen": {
|
|
29
34
|
"implementation": "./src/executors/openapi-gen/executor",
|
|
30
35
|
"schema": "./src/executors/openapi-gen/schema.json",
|
package/package.json
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const extract_project_build_outputs_function_1 = require("../../functions/extract-project-build-outputs.function");
|
|
5
|
+
const pmx_function_1 = require("../../functions/pmx.function");
|
|
6
|
+
const executor_factory_function_1 = require("../../functions/executor-factory.function");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const promises_1 = require("fs/promises");
|
|
9
|
+
const to_cdn_path_function_1 = require("../../functions/to-cdn-path.function");
|
|
10
|
+
const fs_1 = require("fs");
|
|
11
|
+
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
12
|
+
const resolve_aws_credentials_function_1 = require("../../functions/resolve-aws-credentials.function");
|
|
13
|
+
exports.default = (0, executor_factory_function_1.executorFactory)((options, context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
const { region, bucket, omitAcl, version, profile } = options;
|
|
15
|
+
const [projectOutput] = (0, extract_project_build_outputs_function_1.extractProjectBuildOutputs)(context, context.projectName);
|
|
16
|
+
const app = context.projectName;
|
|
17
|
+
(0, pmx_function_1.pmxSpawn)(context, `nx build ${context.projectName}`);
|
|
18
|
+
const jsAndCssAssets = yield getAssetListFromDirectory(projectOutput);
|
|
19
|
+
const indexHtml = yield getIndexHtmlContent(projectOutput);
|
|
20
|
+
const assetRoot = (0, path_1.resolve)(projectOutput, 'assets');
|
|
21
|
+
const fileMappings = jsAndCssAssets.map(original => {
|
|
22
|
+
const [name, hash, ext] = original.split('.');
|
|
23
|
+
const key = `${app}/${version}/${name}.${ext}`;
|
|
24
|
+
const modified = (0, to_cdn_path_function_1.toCdnPath)(bucket, region, app, name, ext);
|
|
25
|
+
return {
|
|
26
|
+
original,
|
|
27
|
+
modified,
|
|
28
|
+
key,
|
|
29
|
+
ext,
|
|
30
|
+
contentType: (ext === 'js' ? 'text/javascript' : 'text/css')
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
let html = fileMappings.reduce((acc, { modified, original }) => acc.replace(original, modified), indexHtml);
|
|
34
|
+
const ACL = omitAcl ? undefined : 'public-read';
|
|
35
|
+
const s3Client = new client_s3_1.S3Client({ region, credentials: (0, resolve_aws_credentials_function_1.resolveAwsCredentials)(profile) });
|
|
36
|
+
yield Promise.all(fileMappings.map((_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ contentType, original, key }) {
|
|
37
|
+
return yield s3Client.send(new client_s3_1.PutObjectCommand({
|
|
38
|
+
Bucket: bucket,
|
|
39
|
+
ContentType: contentType,
|
|
40
|
+
Body: (0, fs_1.createReadStream)(`${assetRoot}/${original}`, 'utf-8'),
|
|
41
|
+
Key: key,
|
|
42
|
+
ACL
|
|
43
|
+
}));
|
|
44
|
+
})));
|
|
45
|
+
}));
|
|
46
|
+
function getAssetListFromDirectory(assetDirectory) {
|
|
47
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const allAssets = yield (0, promises_1.readdir)(assetDirectory);
|
|
49
|
+
const assets = allAssets.filter(a => ['.js', '.css'].includes((0, path_1.parse)(a).ext));
|
|
50
|
+
return assets;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function getIndexHtmlContent(projectOutput) {
|
|
54
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
return yield (0, promises_1.readFile)((0, path_1.resolve)(projectOutput, 'index.html'), { encoding: 'utf-8' });
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../onix/src/executors/deploy-s3-react/executor.ts"],"names":[],"mappings":";;;AAEA,mHAAoG;AACpG,+DAAwD;AACxD,yFAA4E;AAC5E,+BAAsC;AACtC,0CAAgD;AAChD,+EAAiE;AACjE,2BAAsC;AACtC,kDAAgE;AAChE,uGAAyF;AAEzF,kBAAe,IAAA,2CAAe,EAAC,CAC7B,OAAuB,EACvB,OAAwB,EACxB,EAAE;IACF,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC9D,MAAM,CAAC,aAAa,CAAC,GAAG,IAAA,mEAA0B,EAAC,OA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|
+
"properties": {
|
|
8
|
+
"bucket": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "Name of the S3 bucket to use for uploading artifacts"
|
|
11
|
+
},
|
|
12
|
+
"profile": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "AWS profile name (which must be defined in the ~/.aws/credentials file) if AWS keys aren't defined as env vars"
|
|
15
|
+
},
|
|
16
|
+
"region": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "AWS region"
|
|
19
|
+
},
|
|
20
|
+
"version": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "AWS region"
|
|
23
|
+
},
|
|
24
|
+
"omitAcl": {
|
|
25
|
+
"type": "boolean",
|
|
26
|
+
"description": "Whether to use acl public-read for S3 push"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"required": [
|
|
30
|
+
"bucket",
|
|
31
|
+
"region",
|
|
32
|
+
"version"
|
|
33
|
+
]
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function addCdnPrefixToKey(bucket: string, region: string, key: string): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addCdnPrefixToKey = addCdnPrefixToKey;
|
|
4
|
+
function addCdnPrefixToKey(bucket, region, key) {
|
|
5
|
+
return bucket.includes('.')
|
|
6
|
+
? `https://s3.${region}.amazonaws.com/${bucket}/${key}`
|
|
7
|
+
: `https://${bucket}.s3.${region}.amazonaws.com/${key}`;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=add-cdn-prefix-to-key.function.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-cdn-prefix-to-key.function.js","sourceRoot":"","sources":["../../../../onix/src/functions/add-cdn-prefix-to-key.function.ts"],"names":[],"mappings":";;AAAA,8CAIC;AAJD,SAAgB,iBAAiB,CAAC,MAAc,EAAE,MAAc,EAAE,GAAW;IACzE,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC;QACvB,CAAC,CAAC,cAAc,MAAM,kBAAkB,MAAM,IAAI,GAAG,EAAE;QACvD,CAAC,CAAC,WAAW,MAAM,OAAO,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAChE,CAAC"}
|
|
@@ -2,14 +2,26 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveAwsCredentials = resolveAwsCredentials;
|
|
4
4
|
const credential_providers_1 = require("@aws-sdk/credential-providers");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
6
|
const AWS_ACCESS_KEY_ID = 'AWS_ACCESS_KEY_ID';
|
|
6
7
|
const AWS_SECRET_ACCESS_KEY = 'AWS_SECRET_ACCESS_KEY';
|
|
7
8
|
function resolveAwsCredentials(profile) {
|
|
9
|
+
if (profile) {
|
|
10
|
+
try {
|
|
11
|
+
devkit_1.logger.warn(`using AWS profile "${profile}"`);
|
|
12
|
+
const resolved = (0, credential_providers_1.fromIni)({ profile });
|
|
13
|
+
if (resolved) {
|
|
14
|
+
return resolved;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
devkit_1.logger.warn(`failed to load AWS profile "${profile}"... ensure that ${[AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY].map(_ => `"${_.toLowerCase()}"`).join(' and ')} are lowercase in your ~/.aws/credentials file`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
8
21
|
if ((process.env[AWS_ACCESS_KEY_ID] && process.env[AWS_SECRET_ACCESS_KEY])
|
|
9
22
|
||
|
|
10
23
|
(process.env[AWS_ACCESS_KEY_ID.toLowerCase()] && process.env[AWS_SECRET_ACCESS_KEY.toLowerCase()])) {
|
|
11
24
|
return undefined;
|
|
12
25
|
}
|
|
13
|
-
return profile ? (0, credential_providers_1.fromIni)({ profile }) : undefined;
|
|
14
26
|
}
|
|
15
27
|
//# sourceMappingURL=resolve-aws-credentials.function.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-aws-credentials.function.js","sourceRoot":"","sources":["../../../../onix/src/functions/resolve-aws-credentials.function.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"resolve-aws-credentials.function.js","sourceRoot":"","sources":["../../../../onix/src/functions/resolve-aws-credentials.function.ts"],"names":[],"mappings":";;AAMA,sDAsBC;AA5BD,wEAAwD;AACxD,uCAAoC;AAEpC,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAC9C,MAAM,qBAAqB,GAAG,uBAAuB,CAAC;AAEtD,SAAgB,qBAAqB,CAAC,OAA4B;IAC9D,IAAI,OAAO,EAAE,CAAC;QACV,IAAI,CAAC;YACD,eAAM,CAAC,IAAI,CAAC,sBAAsB,OAAO,GAAG,CAAC,CAAC;YAE9C,MAAM,QAAQ,GAAG,IAAA,8BAAO,EAAC,EAAE,OAAO,EAAE,CAAC,CAAC;YAEtC,IAAI,QAAQ,EAAE,CAAC;gBACX,OAAO,QAAQ,CAAC;YACpB,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,eAAM,CAAC,IAAI,CAAC,+BAA+B,OAAO,oBAAoB,CAAC,iBAAiB,EAAE,qBAAqB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,gDAAgD,CAAC,CAAC;QACrN,CAAC;IACL,CAAC;IAED,IACI,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;;YAEtE,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,WAAW,EAAE,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,WAAW,EAAE,CAAC,CAAC,EACpG,CAAC;QACC,OAAO,SAAS,CAAC;IACrB,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function toCdnPath(bucket: string, region: string, folder: string, name: string, ext: string): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toCdnPath = toCdnPath;
|
|
4
|
+
const add_cdn_prefix_to_key_function_1 = require("./add-cdn-prefix-to-key.function");
|
|
5
|
+
function toCdnPath(bucket, region, folder, name, ext) {
|
|
6
|
+
return (0, add_cdn_prefix_to_key_function_1.addCdnPrefixToKey)(bucket, region, `${folder}/${name}.${ext}`);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=to-cdn-path.function.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-cdn-path.function.js","sourceRoot":"","sources":["../../../../onix/src/functions/to-cdn-path.function.ts"],"names":[],"mappings":";;AAEA,8BAEC;AAJD,qFAAqE;AAErE,SAAgB,SAAS,CAAC,MAAc,EAAE,MAAc,EAAE,MAAc,EAAE,IAAY,EAAE,GAAW;IAC/F,OAAO,IAAA,kDAAiB,EAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,IAAI,IAAI,GAAG,EAAE,CAAC,CAAA;AACxE,CAAC"}
|