Skip to content

Commit cab3849

Browse files
committed
Convert to imports.
1 parent 61e908b commit cab3849

7 files changed

Lines changed: 586 additions & 135 deletions

File tree

.eslintrc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
{
22
"parser": "@typescript-eslint/parser",
33
"root": true,
4-
"plugins": [
5-
"@typescript-eslint"
6-
],
74
"extends": [
8-
"cimpress-atsquad",
9-
"plugin:@typescript-eslint/recommended"
5+
"@authress/eslint-config"
106
],
117
"rules": {
128
"arrow-parens": ["error", "as-needed"],

jsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"target": "esnext",
4+
"module": "commonjs",
5+
"allowSyntheticDefaultImports": false
6+
},
7+
"exclude": [
8+
]
9+
}

make.js

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,48 @@
1-
/* eslint-disable @typescript-eslint/no-var-requires */
1+
/* eslint-disable node/no-unpublished-import */
22
/* eslint-disable no-console */
33

4-
const aws = require('aws-sdk');
5-
const { Route53Client, GetHostedZoneCommand } = require("@aws-sdk/client-route-53");
6-
const { STSClient, GetCallerIdentityCommand } = require("@aws-sdk/client-sts");
7-
const commander = require('commander');
8-
const AwsArchitect = require('aws-architect');
9-
const path = require('path');
10-
const yaml = require('js-yaml');
11-
const fs = require('fs-extra');
4+
import aws from 'aws-sdk';
5+
import { Route53Client, ListHostedZonesByNameCommand } from '@aws-sdk/client-route-53';
6+
import { STSClient, GetCallerIdentityCommand } from '@aws-sdk/client-sts';
7+
import commander from 'commander';
8+
import AwsArchitect from 'aws-architect';
9+
import path from 'path';
10+
import fs from 'fs-extra';
11+
12+
import stackTemplateProvider from './template/cloudFormationWebsiteTemplate.js';
1213

1314
aws.config.update({ region: 'us-east-1' });
1415

15-
const packageMetadataFile = path.join(__dirname, 'package.json');
16-
const packageMetadata = require(packageMetadataFile);
16+
const underscoreDirname = path.dirname(import.meta.url).replace('file:', '');
17+
const packageMetadataFile = path.join(underscoreDirname, 'package.json');
18+
const packageMetadata = await fs.readJson(packageMetadataFile);
1719

1820
function getVersion() {
1921
let release_version = '0.0';
2022
const pull_request = '';
2123
const branch = process.env.GITHUB_REF;
2224
const build_number = process.env.GITHUB_RUN_NUMBER;
2325

24-
//Builds of pull requests
26+
// Builds of pull requests
2527
if (pull_request && !pull_request.match(/false/i)) {
2628
release_version = `0.${pull_request}`;
2729
} else if (!branch || !branch.match(/^(refs\/heads\/)?release[/-]/i)) {
28-
//Builds of branches that aren't master or release
30+
// Builds of branches that aren't master or release
2931
release_version = '0.0';
3032
} else {
31-
//Builds of release branches (or locally or on server)
33+
// Builds of release branches (or locally or on server)
3234
release_version = branch.match(/^(?:refs\/heads\/)?release[/-](\d+(?:\.\d+){0,3})$/i)[1];
3335
}
3436
return `${release_version}.${(build_number || '0')}.0.0.0.0`.split('.').slice(0, 3).join('.');
3537
}
3638
const version = getVersion();
3739
commander.version(version);
3840

39-
4041
const parameters = { hostedName: 'dev0ps.fyi' };
4142

4243
const contentOptions = {
4344
bucket: parameters.hostedName,
44-
contentDirectory: path.join(__dirname, 'build')
45+
contentDirectory: path.join(underscoreDirname, 'build')
4546
};
4647

4748
/**
@@ -51,24 +52,22 @@ commander
5152
.command('build')
5253
.description('Setup require build files for npm package.')
5354
.action(async () => {
54-
let package_metadata = require('./package.json');
55-
package_metadata.version = version;
56-
await fs.writeJson('./package.json', package_metadata, { spaces: 2 });
55+
packageMetadata.version = version;
56+
await fs.writeJson('./package.json', packageMetadata, { spaces: 2 });
5757

58-
console.log('Building package %s (%s)', package_metadata.name, version);
58+
console.log('Building package %s (%s)', packageMetadata.name, version);
5959
console.log('');
6060
});
6161

6262
commander
6363
.command('deploy')
6464
.description('Deploying website to AWS.')
6565
.action(async () => {
66-
// eslint-disable-next-line @typescript-eslint/no-var-requires
67-
const stackTemplateProvider = require('./template/cloudFormationWebsiteTemplate');
68-
const requestInterceptorLambdaFunction = await fs.readFile(path.join(__dirname, 'template/requestInterceptorLambdaFunction.js'));
66+
const requestInterceptorLambdaFunction = await fs.readFile(path.join(underscoreDirname, 'template/requestInterceptorLambdaFunction.js'));
6967
const stackTemplate = stackTemplateProvider.getStack(requestInterceptorLambdaFunction.toString());
7068

71-
const callerIdentityResponse = await client.send(new GetCallerIdentityCommand({}));
69+
const stsClient = new STSClient({});
70+
const callerIdentityResponse = await stsClient.send(new GetCallerIdentityCommand({}));
7271
const apiOptions = {
7372
deploymentBucket: `rhosys-deployments-artifacts-${callerIdentityResponse.Account}-${aws.config.region}`
7473
};
@@ -86,16 +85,15 @@ commander
8685
automaticallyProtectStack: true
8786
};
8887

89-
const config = {};
90-
const client = new Route53Client(config);
88+
const route53Client = new Route53Client({});
9189
const command = new ListHostedZonesByNameCommand({ DNSName: parameters.hostedName });
92-
const response = await client.send(command);
90+
const response = await route53Client.send(command);
9391
const hostedZoneId = response.HostedZones[0].Id;
9492
parameters.hostedZoneId = hostedZoneId;
9593
await awsArchitect.deployTemplate(stackTemplate, stackConfiguration, parameters);
9694
}
9795

98-
console.log(`Deployed to ${deploymentLocation}`);
96+
console.log('Deployment Success!');
9997
} catch (failure) {
10098
console.log(`Failed to upload website ${failure} - ${JSON.stringify(failure, null, 2)}`);
10199
process.exit(1);

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
{
22
"name": "PodcastLinkProxy",
33
"version": "0.0.0",
4+
"type": "module",
45
"private": "true",
56
"scripts": {
67
"deploy": "node make.js deploy",
78
"delete": "node make.js delete",
8-
"lint": "eslint --ext=.jsx,.js,.tsx,.ts src"
9+
"lint": "eslint --ext=.jsx,.js,.tsx,.ts ."
910
},
1011
"dependencies": {
12+
"aws-sdk": "^2.1254.0",
1113
"error-object-polyfill": "^1.0.11",
1214
"lodash": "4.17.5",
1315
"luxon": "^3.2.0"
1416
},
1517
"devDependencies": {
16-
"@authress/eslint-config": "1.0.4",
18+
"@authress/eslint-config": "^1.0.5",
1719
"@aws-sdk/client-route-53": "^3.896.0",
1820
"@aws-sdk/client-sts": "^3.896.0",
21+
"@typescript-eslint/eslint-plugin": "^8.44.1",
22+
"@typescript-eslint/parser": "^8.44.1",
1923
"aws-architect": "^6.7.101",
20-
"aws-sdk": "^2.1254.0",
2124
"axios": "^0.21.4",
2225
"commander": "2.15.1",
2326
"cross-env": "^7.0.2",
@@ -26,7 +29,7 @@
2629
"eslint-friendly-formatter": "^3.0.0",
2730
"eslint-loader": "^1.7.1",
2831
"fs-extra": "^11.1.0",
29-
"mocha": "^5.0.5",
32+
"mocha": "^11.7.2",
3033
"sinon": "3.2.1",
3134
"sinon-chai": "2.13.0",
3235
"typescript": "^4.9.4",

template/cloudFormationWebsiteTemplate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,4 +406,4 @@ const stackProvider = {
406406
}
407407
};
408408

409-
module.exports = stackProvider;
409+
export default stackProvider;

template/requestInterceptorLambdaFunction.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// eslint-disable-next-line node/no-missing-import
12
import cf from 'cloudfront';
23

34
const kvsId = '';
@@ -19,7 +20,7 @@ try {
1920
}));
2021
}
2122

22-
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
23+
// eslint-disable-next-line no-unused-vars
2324
async function handler(event) {
2425
// IMPORTANT: if this path requested doesn't exist in the bucket then the site error default will be loaded instead:
2526
// https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/functions-event-structure.html#functions-event-structure-request
@@ -41,7 +42,7 @@ async function handler(event) {
4142
location: { value: `${redirectUrl}` }
4243
}
4344
};
44-
} catch (err) {
45+
} catch (error) {
4546
// eslint-disable-next-line no-console
4647
console.log(JSON.stringify({
4748
message: {

0 commit comments

Comments
 (0)