Skip to content

Commit

Permalink
refactor: reorganize files
Browse files Browse the repository at this point in the history
- move all code into lib folder
- move unit tests next to lib code
- rename files in kebab-case
- sort some requires
- remove utilities folder since there was only one file
  • Loading branch information
mikejpeters authored and Shereef committed Mar 1, 2022
1 parent 0df330a commit 4667b99
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .nycrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"all": true,
"include": ["index.js", "lib/**/*.js"],
"include": ["lib/**/*.js"],
"exclude": ["**/*.test.js"],
"reporter": ["lcov", "html", "text-summary"]
}
11 changes: 6 additions & 5 deletions lib/bucketUtils.js → lib/bucket-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,18 @@ function emptyBucket(aws, bucketName, keyPrefix) {
if (!contents[0]) {
return Promise.resolve();
} else {

if (keyPrefix) {
testPrefix = true;
prefixRegexp = new RegExp('^' + keyPrefix);
}
const objects = contents.map(function(content) {
return {Key: content.Key};
}).filter(content => !testPrefix || prefixRegexp.test(content.Key));
const objects = contents
.map(function (content) {
return { Key: content.Key };
})
.filter(content => !testPrefix || prefixRegexp.test(content.Key));

if (objects.length === 0) {
return Promise.resolve()
return Promise.resolve();
}

const params = {
Expand Down
2 changes: 1 addition & 1 deletion lib/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function configurePolicyForBucket(aws, bucketName, customPolicy) {
function configureCorsForBucket(aws, bucketName) {
const params = {
Bucket: bucketName,
CORSConfiguration: require('./resources/CORSPolicy')
CORSConfiguration: require('./resources/cors-policy.json')
};

return aws.request('S3', 'putBucketCors', params);
Expand Down
File renamed without changes.
15 changes: 7 additions & 8 deletions index.js → lib/plugin.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
'use strict';

const path = require('path');
const fs = require('fs');

const confirm = require('@serverless/utils/inquirer/confirm');
const fs = require('fs');
const path = require('path');

const bucketUtils = require('./lib/bucketUtils');
const configure = require('./lib/configure');
const regionUrls = require('./lib/resources/awsRegionUrls');
const uploadDirectory = require('./lib/upload');
const validateClient = require('./lib/validate');
const bucketUtils = require('./bucket-utils');
const configure = require('./configure');
const regionUrls = require('./resources/aws-region-urls.json');
const uploadDirectory = require('./upload');
const validateClient = require('./validate');

class Client {
constructor(serverless, cliOptions, { log }) {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/deploy.test.js → lib/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const inquirer = require('@serverless/utils/inquirer');
const chai = require('chai');
const sinon = require('sinon');

const runServerless = require('../run-serverless');
const runServerless = require('../test/run-serverless');

chai.use(require('chai-as-promised'));
chai.use(require('sinon-chai'));
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 3 additions & 6 deletions lib/upload.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
'use strict';

const fs = require('fs');
const path = require('path');

const mime = require('mime');

const getFileList = require('./utilities/getFileList');
const regionUrls = require('./resources/awsRegionUrls');

const minimatch = require('minimatch');
const path = require('path');

const getFileList = require('./get-file-list');

/**
* Uploads client files to an S3 bucket
Expand Down
3 changes: 1 addition & 2 deletions lib/validate.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
'use strict';

const fs = require('fs');
const path = require('path');

const is = require('is_js');
const path = require('path');

/**
* Validates the configuration parameters that will be used for deployment
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"node": ">=14.15.5"
},
"description": "Deploy your serverless static website to AWS S3.",
"main": "index.js",
"main": "lib/plugin.js",
"scripts": {
"prepare": "husky install",
"test": "mocha \"test/unit/**/*.test.js\"",
"test": "mocha \"lib/**/*.test.js\"",
"coverage": "nyc npm run test",
"integration-test": "mocha-isolated --pass-through-aws-creds \"test/integration/**/*.test.js\""
},
Expand Down

0 comments on commit 4667b99

Please sign in to comment.