Skip to content

Commit f17de8e

Browse files
Merge pull request #120 from AlexandrLi/update-stack
feat: Update application dependencies
2 parents ae039bb + e10d6a8 commit f17de8e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+9995
-1905
lines changed

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
public
3+
vite.config.ts
4+
serverless.yml

.eslintrc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"parserOptions": {
5+
"project": "./tsconfig.json"
6+
},
7+
"extends": [
8+
"plugin:@typescript-eslint/recommended",
9+
"plugin:react/recommended",
10+
"plugin:react/jsx-runtime",
11+
"plugin:prettier/recommended",
12+
"prettier"
13+
],
14+
"plugins": ["@typescript-eslint", "react", "prettier"],
15+
"env": {
16+
"browser": true,
17+
"node": true
18+
},
19+
"settings": {
20+
"react": {
21+
"version": "detect"
22+
}
23+
}
24+
}

.gitignore

100755100644
Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
29

3-
# dependencies
410
node_modules
5-
/.pnp
6-
.pnp.js
7-
8-
# testing
9-
/coverage
10-
11-
# production
12-
build
1311
.serverless
12+
coverage
13+
dist
14+
dist-ssr
15+
*.local
1416

15-
# misc
17+
# Editor directories and files
18+
.vscode/*
19+
!.vscode/extensions.json
20+
.idea
1621
.DS_Store
17-
.env.local
18-
.env.development.local
19-
.env.test.local
20-
.env.production.local
21-
22-
npm-debug.log*
23-
yarn-debug.log*
24-
yarn-error.log*
25-
26-
/.idea
27-
.vscode
22+
*.suo
23+
*.ntvs*
24+
*.njsproj
25+
*.sln
26+
*.sw?
Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,36 @@
1-
'use strict';
1+
"use strict";
22

3-
const spawnSync = require('child_process').spawnSync;
3+
const spawnSync = require("child_process").spawnSync;
44

55
class ServerlessPlugin {
66
constructor(serverless, options) {
77
this.serverless = serverless;
88
this.options = options;
99
this.commands = {
1010
syncToS3: {
11-
usage: 'Deploys the `app` directory to your bucket',
12-
lifecycleEvents: [
13-
'sync',
14-
],
11+
usage: "Deploys the `app` directory to your bucket",
12+
lifecycleEvents: ["sync"],
1513
},
1614
domainInfo: {
17-
usage: 'Fetches and prints out the deployed CloudFront domain names',
18-
lifecycleEvents: [
19-
'domainInfo',
20-
],
15+
usage: "Fetches and prints out the deployed CloudFront domain names",
16+
lifecycleEvents: ["domainInfo"],
2117
},
2218
invalidateCloudFrontCache: {
23-
usage: 'Invalidates CloudFront cache',
24-
lifecycleEvents: [
25-
'invalidateCache',
26-
],
19+
usage: "Invalidates CloudFront cache",
20+
lifecycleEvents: ["invalidateCache"],
2721
},
2822
};
2923

3024
this.hooks = {
31-
'syncToS3:sync': this.syncDirectory.bind(this),
32-
'domainInfo:domainInfo': this.domainInfo.bind(this),
33-
'invalidateCloudFrontCache:invalidateCache': this.invalidateCache.bind(
34-
this,
35-
),
25+
"syncToS3:sync": this.syncDirectory.bind(this),
26+
"domainInfo:domainInfo": this.domainInfo.bind(this),
27+
"invalidateCloudFrontCache:invalidateCache":
28+
this.invalidateCache.bind(this),
3629
};
3730
}
3831

3932
runAwsCommand(args) {
40-
let command = 'aws';
33+
let command = "aws";
4134
if (this.serverless.variables.service.provider.region) {
4235
command = `${command} --region ${this.serverless.variables.service.provider.region}`;
4336
}
@@ -60,84 +53,85 @@ class ServerlessPlugin {
6053
// syncs the `app` directory to the provided bucket
6154
syncDirectory() {
6255
const s3Bucket = this.serverless.variables.service.custom.s3Bucket;
63-
const buildFolder = this.serverless.variables.service.custom.client.distributionFolder;
56+
const buildFolder =
57+
this.serverless.variables.service.custom.client.distributionFolder;
6458
const args = [
65-
's3',
66-
'sync',
59+
"s3",
60+
"sync",
6761
`${buildFolder}/`,
6862
`s3://${s3Bucket}/`,
69-
'--delete',
63+
"--delete",
7064
];
7165
const { sterr } = this.runAwsCommand(args);
7266
if (!sterr) {
73-
this.serverless.cli.log('Successfully synced to the S3 bucket');
67+
this.serverless.cli.log("Successfully synced to the S3 bucket");
7468
} else {
75-
throw new Error('Failed syncing to the S3 bucket');
69+
throw new Error("Failed syncing to the S3 bucket");
7670
}
7771
}
7872

7973
// fetches the domain name from the CloudFront outputs and prints it out
8074
async domainInfo() {
81-
const provider = this.serverless.getProvider('aws');
75+
const provider = this.serverless.getProvider("aws");
8276
const stackName = provider.naming.getStackName(this.options.stage);
8377
const result = await provider.request(
84-
'CloudFormation',
85-
'describeStacks',
78+
"CloudFormation",
79+
"describeStacks",
8680
{ StackName: stackName },
8781
this.options.stage,
88-
this.options.region,
82+
this.options.region
8983
);
9084

9185
const outputs = result.Stacks[0].Outputs;
9286
const output = outputs.find(
93-
entry => entry.OutputKey === 'WebAppCloudFrontDistributionOutput',
87+
(entry) => entry.OutputKey === "WebAppCloudFrontDistributionOutput"
9488
);
9589

9690
if (output && output.OutputValue) {
9791
this.serverless.cli.log(`Web App Domain: ${output.OutputValue}`);
9892
return output.OutputValue;
9993
}
10094

101-
this.serverless.cli.log('Web App Domain: Not Found');
102-
const error = new Error('Could not extract Web App Domain');
95+
this.serverless.cli.log("Web App Domain: Not Found");
96+
const error = new Error("Could not extract Web App Domain");
10397
throw error;
10498
}
10599

106100
async invalidateCache() {
107-
const provider = this.serverless.getProvider('aws');
101+
const provider = this.serverless.getProvider("aws");
108102

109103
const domain = await this.domainInfo();
110104

111105
const result = await provider.request(
112-
'CloudFront',
113-
'listDistributions',
106+
"CloudFront",
107+
"listDistributions",
114108
{},
115109
this.options.stage,
116-
this.options.region,
110+
this.options.region
117111
);
118112

119113
const distributions = result.DistributionList.Items;
120114
const distribution = distributions.find(
121-
entry => entry.DomainName === domain,
115+
(entry) => entry.DomainName === domain
122116
);
123117

124118
if (distribution) {
125119
this.serverless.cli.log(
126-
`Invalidating CloudFront distribution with id: ${distribution.Id}`,
120+
`Invalidating CloudFront distribution with id: ${distribution.Id}`
127121
);
128122
const args = [
129-
'cloudfront',
130-
'create-invalidation',
131-
'--distribution-id',
123+
"cloudfront",
124+
"create-invalidation",
125+
"--distribution-id",
132126
distribution.Id,
133-
'--paths',
127+
"--paths",
134128
'"/*"',
135129
];
136130
const { sterr } = this.runAwsCommand(args);
137131
if (!sterr) {
138-
this.serverless.cli.log('Successfully invalidated CloudFront cache');
132+
this.serverless.cli.log("Successfully invalidated CloudFront cache");
139133
} else {
140-
throw new Error('Failed invalidating CloudFront cache');
134+
throw new Error("Failed invalidating CloudFront cache");
141135
}
142136
} else {
143137
const message = `Could not find distribution with domain ${domain}`;
@@ -148,4 +142,4 @@ class ServerlessPlugin {
148142
}
149143
}
150144

151-
module.exports = ServerlessPlugin;
145+
module.exports = ServerlessPlugin;

README.md

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,71 @@
1-
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
1+
# React-shop-cloudfront
2+
3+
This is frontend starter project for nodejs-aws mentoring program. It uses the following technologies:
4+
5+
- [Vite](https://vitejs.dev/) as a project bundler
6+
- [React](https://beta.reactjs.org/) as a frontend framework
7+
- [React-router-dom](https://reactrouterdotcom.fly.dev/) as a routing library
8+
- [MUI](https://mui.com/) as a UI framework
9+
- [React-query](https://react-query-v3.tanstack.com/) as a data fetching library
10+
- [Formik](https://formik.org/) as a form library
11+
- [Yup](https://github.com/jquense/yup) as a validation schema
12+
- [Serverless](https://serverless.com/) as a serverless framework
13+
- [Vitest](https://vitest.dev/) as a test runner
14+
- [MSW](https://mswjs.io/) as an API mocking library
15+
- [Eslint](https://eslint.org/) as a code linting tool
16+
- [Prettier](https://prettier.io/) as a code formatting tool
17+
- [TypeScript](https://www.typescriptlang.org/) as a type checking tool
218

319
## Available Scripts
420

5-
In the project directory, you can run:
6-
You can use NPM instead of YARN (Up to you)
21+
### `start`
722

8-
### `yarn start` OR `npm run start`
23+
Starts the project in dev mode with mocked API on local environment.
924

10-
Runs the app in the development mode.<br />
11-
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
25+
### `build`
1226

13-
The page will reload if you make edits.<br />
14-
You will also see any lint errors in the console.
27+
Builds the project for production in `dist` folder.
1528

16-
### `yarn test` OR `npm run test`
29+
### `preview`
1730

18-
Launches the test runner in the interactive watch mode.<br />
19-
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
31+
Starts the project in production mode on local environment.
2032

21-
### `yarn build` OR `npm run build`
33+
### `test`, `test:ui`, `test:coverage`
2234

23-
Builds the app for production to the `build` folder.<br />
24-
It correctly bundles React in production mode and optimizes the build for the best performance.
35+
Runs tests in console, in browser or with coverage.
2536

26-
The build is minified and the filenames include the hashes.<br />
27-
Your app is ready to be deployed!
37+
### `lint`, `prettier`
2838

29-
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
39+
Runs linting and formatting for all files in `src` folder.
3040

31-
### `yarn eject` OR `npm run eject`
41+
### `client:deploy`, `client:deploy:nc`
3242

33-
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
43+
Deploy the project build from `dist` folder to configured in `serverless.yml` AWS S3 bucket with or without confirmation.
3444

35-
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
45+
### `client:build:deploy`, `client:build:deploy:nc`
3646

37-
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
47+
Combination of `build` and `client:deploy` commands with or without confirmation.
3848

39-
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
49+
### `cloudfront:setup`
4050

41-
## Learn More
51+
Deploy configured in `serverless.yml` stack via CloudFormation.
4252

43-
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
53+
### `cloudfront:domainInfo`
4454

45-
To learn React, check out the [React documentation](https://reactjs.org/).
55+
Display cloudfront domain information in console.
56+
57+
### `cloudfront:invalidateCache`
58+
59+
Invalidate cloudfront cache.
60+
61+
### `cloudfront:build:deploy`, `cloudfront:build:deploy:nc`
62+
63+
Combination of `client:build:deploy` and `cloudfront:invalidateCache` commands with or without confirmation.
64+
65+
### `cloudfront:update:build:deploy`, `cloudfront:update:build:deploy:nc`
66+
67+
Combination of `cloudfront:setup` and `cloudfront:build:deploy` commands with or without confirmation.
68+
69+
### `serverless:remove`
70+
71+
Remove an entire stack configured in `serverless.yml` via CloudFormation.

index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>My shop</title>
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
<script type="module" src="/src/index.tsx"></script>
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)