Skip to content

Commit 87523cf

Browse files
committed
Add eslint and prettier configs
1 parent 6260f76 commit 87523cf

File tree

18 files changed

+1312
-145
lines changed

18 files changed

+1312
-145
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
vite.config.ts
3+
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+
}
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo
33
## Available Scripts
44

55
In the project directory, you can run:
6-
You can use NPM instead of YARN (Up to you)
6+
You can use NPM instead of YARN (Up to you)
77

88
### `yarn start` OR `npm run start`
99

0 commit comments

Comments
 (0)