Skip to content

Commit f78b4a0

Browse files
Jefiozieyannickglt
andauthored
Beta (#357)
* fix(subfolder): get subfolder config work (#356) * Release 3.0.1-beta.0 Co-authored-by: Yannick Galatol <[email protected]>
1 parent efc755c commit f78b4a0

File tree

7 files changed

+17
-11
lines changed

7 files changed

+17
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
5. Due to security risk we have made the decision to never add any options to the `angular.json`. You should set the environments variable during the `ng deploy` command. Below a example on how you could do this.
4848

4949
```bash
50-
npx cross-env NG_DEPLOY_AWS_ACCESS_KEY_ID=1234 NG_DEPLOY_AWS_SECRET_ACCESS_KEY=321ACCESS NG_DEPLOY_AWS_BUCKET=mys3bucket NG_DEPLOY_AWS_REGION=eu-1-region ng deploy
50+
npx cross-env NG_DEPLOY_AWS_ACCESS_KEY_ID=1234 NG_DEPLOY_AWS_SECRET_ACCESS_KEY=321ACCESS NG_DEPLOY_AWS_BUCKET=mys3bucket NG_DEPLOY_AWS_REGION=eu-1-region NG_DEPLOY_AWS_SUB_FOLDER=path/on/bucker ng deploy
5151
```
5252
6. Run `ng deploy` to deploy your application to Amazon S3.
5353

libs/ngx-aws-deploy/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jefiozie/ngx-aws-deploy",
3-
"version": "3.0.0",
3+
"version": "3.0.1-beta.0",
44
"description": "Deploy rou Angular app to Amazon S3 directly from the Angular CLI",
55
"main": "index.js",
66
"builders": "./builders.json",

libs/ngx-aws-deploy/src/lib/deploy/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ export const getBucket = (builderConfig: Schema): string => {
1515
export const getRegion = (builderConfig: Schema): string => {
1616
return process.env.NG_DEPLOY_AWS_REGION || (builderConfig.region as string);
1717
};
18+
19+
export const getSubFolder = (builderConfig: Schema): string => {
20+
return process.env.NG_DEPLOY_AWS_SUB_FOLDER || (builderConfig.subFolder as string);
21+
};

libs/ngx-aws-deploy/src/lib/deploy/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ export default createBuilder(
3636
};
3737

3838
let targetString = `${context.target.project}:deploy`;
39-
// Providing `region` and `bucket` through configuration is actually deprecated.
39+
// Providing `region`, `bucket` and `subFolder` through configuration is actually deprecated.
4040
// By default `ng add` command doesn't generate any additional configuration inside
4141
// the builder configuration thus `context.target.configuration` defaults to an empty string.
4242
if (context.target.configuration) {
4343
targetString += `:${context.target.configuration}`;
4444
}
4545

46-
const { bucket, region } = await context.getTargetOptions(
46+
const { bucket, region, subFolder } = await context.getTargetOptions(
4747
targetFromTargetString(targetString)
4848
);
4949

50-
const deployConfig = { bucket, region } as Pick<
50+
const deployConfig = { bucket, region, subFolder } as Pick<
5151
Schema,
52-
'bucket' | 'region'
52+
'bucket' | 'region' | 'subFolder'
5353
>;
5454

5555
let buildResult: BuilderOutput;

libs/ngx-aws-deploy/src/lib/deploy/uploader.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@ import {
99
getAccessKeyId,
1010
getBucket,
1111
getRegion,
12-
getSecretAccessKey,
12+
getSecretAccessKey, getSubFolder
1313
} from './config';
1414

1515
export class Uploader {
1616
private _context: BuilderContext;
1717
private _s3: AWS.S3;
1818
private _bucket: string;
1919
private _region: string;
20+
private _subFolder: string;
2021
private _builderConfig: Schema;
2122

2223
constructor(context: BuilderContext, builderConfig: Schema) {
2324
this._context = context;
2425
this._builderConfig = builderConfig;
2526
this._bucket = getBucket(this._builderConfig);
2627
this._region = getRegion(this._builderConfig);
28+
this._subFolder = getSubFolder(this._builderConfig);
2729

2830
AWS.config.update({ region: this._region });
2931
this._s3 = new AWS.S3({
@@ -81,8 +83,8 @@ export class Uploader {
8183

8284
const params: PutObjectRequest = {
8385
Bucket: this._bucket,
84-
Key: this._builderConfig.subFolder
85-
? `${this._builderConfig.subFolder}/${originFilePath}`
86+
Key: this._subFolder
87+
? `${this._subFolder}/${originFilePath}`
8688
: originFilePath,
8789
Body: body,
8890
ContentType: mimeTypes.lookup(fileName) || undefined,

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aws-deploy",
3-
"version": "3.0.0",
3+
"version": "3.0.1-beta.0",
44
"license": "MIT",
55
"scripts": {
66
"ng": "nx",

0 commit comments

Comments
 (0)