Skip to content

Commit

Permalink
feat: ✨ few type changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeeltilva committed Mar 28, 2023
1 parent f0bc2d5 commit 2ab6a44
Show file tree
Hide file tree
Showing 4 changed files with 903 additions and 45 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"mocha": "^10.1.0",
"prettier": "^2.2.1",
"semantic-release": "^19.0.2",
"serverless-schema": "^1.26.0",
"ts-node": "^10.9.1",
"typescript": "^4.9.0-dev.20220916"
},
Expand Down
89 changes: 49 additions & 40 deletions src/compiler.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
const toIdentifier = name => {
const id = name.replace(/[^0-9A-Za-z]/g, "");
return id.charAt(0).toUpperCase() + id.slice(1);
};
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* eslint-disable @typescript-eslint/restrict-plus-operands */
// const toIdentifier = (name: string) => {
// const id = name.replace(/[^0-9A-Za-z]/g, "");
// return id.charAt(0).toUpperCase() + id.slice(1);
// };

const toTags = (tags = {}) => {
return Object.entries(tags).map(([Key, Value]) => ({ Key, Value }));
};

const toEnvironment = tags =>
Object.entries(tags).map(([Name, Value]) => ({ Name, Value }));
// const toEnvironment = tags =>
// Object.entries(tags).map(([Name, Value]) => ({ Name, Value }));

const compileCluster = (config, images, service) => ({
const compileCluster = (
config: Record<string, any>,
images: Record<string, any>,
service: Record<string, any>
) => ({
Resources: {
[service.name + "AppRunnerService"]: {
Type: "AWS::AppRunner::Service",
Expand Down Expand Up @@ -172,38 +178,38 @@ const compileIamRoles = config => ({
// },
// });

const compileScheduledTask = (identifier, task) => ({
Type: "AWS::Events::Rule",
DependsOn: task.dependsOn,
Properties: {
ScheduleExpression: task.schedule,
Targets: [
{
Id: identifier,
Arn: {
"Fn::GetAtt": ["FargateTasksCluster", "Arn"],
},
RoleArn: {
"Fn::GetAtt": ["FargateIamExecutionRole", "Arn"],
},
EcsParameters: {
TaskDefinitionArn: {
"Fn::Sub": "${" + identifier + "Task}",
},
TaskCount: 1,
LaunchType: "FARGATE",
NetworkConfiguration: {
AwsVpcConfiguration: {
AssignPublicIp: task.vpc.assignPublicIp ? "ENABLED" : "DISABLED",
SecurityGroups: task.vpc.securityGroupIds,
Subnets: task.vpc.subnetIds,
},
},
},
},
],
},
});
// const compileScheduledTask = (identifier, task) => ({
// Type: "AWS::Events::Rule",
// DependsOn: task.dependsOn,
// Properties: {
// ScheduleExpression: task.schedule,
// Targets: [
// {
// Id: identifier,
// Arn: {
// "Fn::GetAtt": ["FargateTasksCluster", "Arn"],
// },
// RoleArn: {
// "Fn::GetAtt": ["FargateIamExecutionRole", "Arn"],
// },
// EcsParameters: {
// TaskDefinitionArn: {
// "Fn::Sub": "${" + identifier + "Task}",
// },
// TaskCount: 1,
// LaunchType: "FARGATE",
// NetworkConfiguration: {
// AwsVpcConfiguration: {
// AssignPublicIp: task.vpc.assignPublicIp ? "ENABLED" : "DISABLED",
// SecurityGroups: task.vpc.securityGroupIds,
// Subnets: task.vpc.subnetIds,
// },
// },
// },
// },
// ],
// },
// });

// const compileService = (identifier, task) => ({
// Type: 'AWS::ECS::Service',
Expand Down Expand Up @@ -274,7 +280,10 @@ const compileScheduledTask = (identifier, task) => ({
// };
// };

export const compile = (images, config) => {
export const compile = (
images: Record<string, any>,
config: Record<string, any>
) => {
const iamRoles = compileIamRoles(config);
const services = config.services.reduce(({ Resources, Outputs }, service) => {
const compiled = compileCluster(config, images, service);
Expand Down
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ import { get } from "./util";
import { parser } from "./parser";
import { compile } from "./compiler";
import { schema } from "./schema";
import { ServerlessFrameworkConfiguration } from "serverless-schema";

interface ServerlessPluginOptions {
globalOptions?: boolean;
}
class ServerlessPlugin {
serverless: Serverless;
serverless: ServerlessFrameworkConfiguration;
options: ServerlessPluginOptions;
config: any;
hooks: { "package:compileFunctions": any };
constructor(serverless: Serverless, options: ServerlessPluginOptions) {
constructor(
serverless: ServerlessFrameworkConfiguration,
options: ServerlessPluginOptions
) {
this.serverless = serverless;
this.options = options;

Expand Down
Loading

0 comments on commit 2ab6a44

Please sign in to comment.