Skip to content
This repository has been archived by the owner on Jul 23, 2023. It is now read-only.

Commit

Permalink
chore: fixed prettier warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Jun 11, 2020
1 parent b87c8f8 commit 6e8c34b
Show file tree
Hide file tree
Showing 25 changed files with 195 additions and 208 deletions.
26 changes: 13 additions & 13 deletions bin/terranext.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@ Examples
gatewayKey: {
type: "string",
default: "Terranext",
alias: "g"
alias: "g",
},
// eslint-disable-next-line unicorn/prevent-abbreviations
nextAppDir: {
type: "string",
alias: "d",
default: "./"
default: "./",
},
provider: {
type: "string"
type: "string",
},
env: {
type: "string"
}
}
type: "string",
},
},
}
);

explorer
.search()
.then(async result => {
.then(async (result) => {
const { gatewayKey, nextAppDir, provider, env } = cli.flags;
let parsedEnvs;
if (env) {
Expand All @@ -61,11 +61,11 @@ explorer
gatewayKey,
nextAppDir,
provider,
env: parsedEnvs
env: parsedEnvs,
};
await generateResources(options, true);
})
.catch(error => {
.catch((error) => {
// eslint-disable-next-line no-console
console.error(error);
process.exit(1);
Expand All @@ -74,11 +74,11 @@ explorer

function parseEnv(unparsedEnv) {
if (Array.isArray(unparsedEnv)) {
return unparsedEnv.map(env => {
return unparsedEnv.map((env) => {
const splitEnv = env.split(",");
return {
key: splitEnv[0],
value: splitEnv[1]
value: splitEnv[1],
};
});
}
Expand All @@ -88,7 +88,7 @@ function parseEnv(unparsedEnv) {
return [
{
key: splitEnv[0],
value: splitEnv[1]
}
value: splitEnv[1],
},
];
}
14 changes: 7 additions & 7 deletions src/compatLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const requestResponseMapper = (event, callback) => {
body: Buffer.from(""),
isBase64Encoded: base64Support,
statusCode: 200,
multiValueHeaders: {}
multiValueHeaders: {},
};

const request = new Stream.Readable();
Expand Down Expand Up @@ -54,7 +54,7 @@ const requestResponseMapper = (event, callback) => {
request.headers[key.toLowerCase()] = headers[key].toString();
}

request.getHeader = name => {
request.getHeader = (name) => {
return request.headers[name.toLowerCase()];
};
request.getHeaders = () => {
Expand All @@ -71,29 +71,29 @@ const requestResponseMapper = (event, callback) => {
},
set(statusCode) {
response.statusCode = statusCode;
}
},
});
res.headers = {};
res.writeHead = (status, headers) => {
response.statusCode = status;
if (headers) res.headers = Object.assign(res.headers, headers);
};
res.write = chunk => {
res.write = (chunk) => {
response.body = Buffer.concat([response.body, Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)]);
};
res.setHeader = (name, value) => {
res.headers[name] = value;
};
res.removeHeader = name => {
res.removeHeader = (name) => {
delete res.headers[name];
};
res.getHeader = name => {
res.getHeader = (name) => {
return res.headers[name.toLowerCase()];
};
res.getHeaders = () => {
return res.headers;
};
res.end = text => {
res.end = (text) => {
if (text) res.write(text);
response.body = Buffer.from(response.body).toString(base64Support ? "base64" : undefined);
response.multiValueHeaders = res.headers;
Expand Down
6 changes: 3 additions & 3 deletions src/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Configuration {
buildPath: buildPath || ".next",
provider,
nextAppDir: nextAppDir ? path.resolve(process.cwd(), nextAppDir) : "./",
routes
routes,
};
}

Expand All @@ -50,7 +50,7 @@ class Configuration {

if (routes) {
if (Array.isArray(routes)) {
const isInvalid = routes.some(r => Configuration.checkRoutes(r) === false);
const isInvalid = routes.some((r) => Configuration.checkRoutes(r) === false);
if (isInvalid === true) errors.push(new IncorrectRoutesError());
} else {
if (!Configuration.checkRoutes(routes)) errors.push(new IncorrectRoutesError());
Expand Down Expand Up @@ -79,7 +79,7 @@ class Configuration {

if (typeof routes.prefix !== "string") return false;

valid = routes.mappings.every(mapping => {
valid = routes.mappings.every((mapping) => {
return !!mapping.route && !!mapping.page;
});

Expand Down
6 changes: 3 additions & 3 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const path = require("path");

const PROVIDERS = {
AWS: "AWS"
AWS: "AWS",
};

const FILE_NAMES = {
LAMBDAS: "lambdas.terraform.tf.json",
GATEWAY: "gateway.terraform.tf.json"
GATEWAY: "gateway.terraform.tf.json",
};

const NEXT_CONFIG = "next.config.js";
Expand All @@ -16,5 +16,5 @@ module.exports = {
PROVIDERS,
FILE_NAMES,
NEXT_CONFIG,
COMPAT_LAYER_PATH
COMPAT_LAYER_PATH,
};
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function terranext(configuration, write = false) {
*/
const finalConfiguration = {
...fileConfiguration,
...configuration
...configuration,
};
const config = new AwsConfig(finalConfiguration);
const nextConfig = config.getNextConfig();
Expand All @@ -47,7 +47,7 @@ async function terranext(configuration, write = false) {
const gateway = await aws.generateGatewayResources();
return {
gateway,
lambdas
lambdas,
};
}
} catch (error) {
Expand Down
44 changes: 22 additions & 22 deletions src/providers/aws/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ class AwsResources extends BaseProvider {
}

parseParameters(parameters) {
return Object.keys(parameters).map(parameterKey => {
return Object.keys(parameters).map((parameterKey) => {
return {
name: parameterKey,
mandatory: parameters[parameterKey]
mandatory: parameters[parameterKey],
};
});
}

getParametersFromPath(pathname) {
return pathname
.split("/")
.map(pathPart => {
.map((pathPart) => {
if (pathPart.includes(":")) {
return {
name: pathPart.replace(":", ""),
mandatory: true
mandatory: true,
};
}
return undefined;
Expand Down Expand Up @@ -66,7 +66,7 @@ class AwsResources extends BaseProvider {
id: generateUniqueName(parts.slice(0, index + 1)),
params: urlParameters,
queryStringParams: queryStringParameters,
lambdaName
lambdaName,
});

const gatewayResource = gateway.generate();
Expand All @@ -81,7 +81,7 @@ class AwsResources extends BaseProvider {
* @param {Route} routeObject
*/
generateResourcesFromRoute(routeObject) {
routeObject.mappings.forEach(currentRoute => {
routeObject.mappings.forEach((currentRoute) => {
const { params, page, route } = currentRoute;
const prefix = routeObject.prefix ? routeObject.prefix : "";
const pathname = prefix + route;
Expand All @@ -96,23 +96,23 @@ class AwsResources extends BaseProvider {
parts,
pathname,
lambdaName,
params
params,
});
});
});
}

generateResources(routesObject) {
if (Array.isArray(routesObject)) {
routesObject.forEach(routeObject => this.generateResourcesFromRoute(routeObject));
routesObject.forEach((routeObject) => this.generateResourcesFromRoute(routeObject));
} else {
this.generateResourcesFromRoute(routesObject);
}
}

deleteDir(pathToDelete) {
if (fs.existsSync(pathToDelete)) {
fs.readdirSync(pathToDelete).forEach(file => {
fs.readdirSync(pathToDelete).forEach((file) => {
const curPath = path.join(pathToDelete, file);
if (fs.lstatSync(curPath).isDirectory()) {
// recurse
Expand Down Expand Up @@ -144,20 +144,20 @@ class AwsResources extends BaseProvider {
resource: {
aws_api_gateway_resource: this.apiGatewayResource,
aws_api_gateway_method: this.apiGatewayMethod,
aws_api_gateway_integration: this.apiGatewayIntegration
aws_api_gateway_integration: this.apiGatewayIntegration,
},
variable: {
integrationList: {
default: Object.keys(this.apiGatewayIntegration).map(key => `aws_api_gateway_integration.${key}`)
}
}
default: Object.keys(this.apiGatewayIntegration).map((key) => `aws_api_gateway_integration.${key}`),
},
},
};

if (write) {
// eslint-disable-next-line no-console
console.log(`Generating file ${FILE_NAMES.GATEWAY}`);
fs.writeFileSync(path.join(process.cwd(), FILE_NAMES.GATEWAY), JSON.stringify(this.terraformConfiguration, null, 4), {
encoding: "utf-8"
encoding: "utf-8",
});
} else {
return this.terraformConfiguration;
Expand All @@ -178,8 +178,8 @@ class AwsResources extends BaseProvider {
fs.mkdirSync(buildPath + "/lambdas");

return getLambdaFiles(serverlessBuildPath)
.then(files => {
files.forEach(file => {
.then((files) => {
files.forEach((file) => {
const pathToFile = path.resolve(serverlessBuildPath, file);
if (!fs.lstatSync(pathToFile).isDirectory()) {
/**
Expand All @@ -201,7 +201,7 @@ class AwsResources extends BaseProvider {

const lambda = new Lambda(this.config, {
id: lambdaName,
directoryName: lambdaName
directoryName: lambdaName,
});
// 3.
lambda.emitLambdaFile(lambdaName, buildPath);
Expand All @@ -225,24 +225,24 @@ class AwsResources extends BaseProvider {
let lambdaResources = {
resource: {
aws_lambda_function: this.lambdasResources,
aws_lambda_permission: this.lambdasPermissions
aws_lambda_permission: this.lambdasPermissions,
},
data: {
archive_file: this.lambdaZip
}
archive_file: this.lambdaZip,
},
};

if (write === true) {
// eslint-disable-next-line no-console
console.log(`Generating file ${FILE_NAMES.LAMBDAS}`);
fs.writeFileSync(path.join(process.cwd(), FILE_NAMES.LAMBDAS), JSON.stringify(lambdaResources, null, 4), {
encoding: "utf-8"
encoding: "utf-8",
});
} else {
return lambdaResources;
}
})
.catch(error => {
.catch((error) => {
throw new FolderNotFoundError(serverlessBuildPath, error);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/providers/aws/resources/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Gateway {
return {
resource,
method,
integration
integration,
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/providers/aws/resources/gatewayIntegration.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GatewayIntegration {
generateGatewayIntegration(gatewayResourceId) {
return {
uniqueId: `${this.config.getGatewayKey()}-${this.options.id}`,
resource: this.generateResource(gatewayResourceId)
resource: this.generateResource(gatewayResourceId),
};
}

Expand All @@ -46,7 +46,7 @@ class GatewayIntegration {
this.config.getLambdaPrefix() +
"-" +
this.options.lambdaName +
".arn}/invocations"
".arn}/invocations",
};

if (this.options.params && this.options.params.length > 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/providers/aws/resources/gatewayMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class GatewayMethod {
generateGatewayMethod(gatewayResourceId) {
return {
uniqueId: `${this.config.getGatewayKey()}-${this.options.id}`,
resource: this.generateResource(gatewayResourceId)
resource: this.generateResource(gatewayResourceId),
};
}

Expand All @@ -34,7 +34,7 @@ class GatewayMethod {
rest_api_id: this.config.getGatewayResourceId(),
resource_id: "${aws_api_gateway_resource." + resourceId + ".id}",
http_method: "GET",
authorization: "NONE"
authorization: "NONE",
};
if (this.options.params && this.options.params.length > 0) {
resource.request_parameters = this.options.params.reduce((result, parameter) => {
Expand Down
Loading

0 comments on commit 6e8c34b

Please sign in to comment.