-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add quicktype, typescript source code and eslint
- Loading branch information
1 parent
9899a52
commit 92fe40d
Showing
10 changed files
with
220 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
{ | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:prettier/recommended" | ||
], | ||
"rules": { | ||
"curly": [ | ||
"error", | ||
"all" | ||
], | ||
"eqeqeq": [ | ||
"error", | ||
"smart" | ||
], | ||
"import/no-extraneous-dependencies": [ | ||
"error", | ||
{ | ||
"devDependencies": true, | ||
"optionalDependencies": false, | ||
"peerDependencies": false | ||
} | ||
], | ||
"no-shadow": [ | ||
"error", | ||
{ | ||
"hoist": "all" | ||
} | ||
], | ||
"prefer-const": "error", | ||
"import/order": [ | ||
"error", | ||
{ | ||
"groups": [ | ||
[ | ||
"external", | ||
"builtin" | ||
], | ||
"internal", | ||
[ | ||
"parent", | ||
"sibling", | ||
"index" | ||
] | ||
] | ||
} | ||
], | ||
"sort-imports": [ | ||
"error", | ||
{ | ||
"ignoreCase": true, | ||
"ignoreDeclarationSort": true, | ||
"ignoreMemberSort": false, | ||
"memberSyntaxSortOrder": [ | ||
"none", | ||
"all", | ||
"multiple", | ||
"single" | ||
] | ||
} | ||
], | ||
"padding-line-between-statements": [ | ||
"error", | ||
{ | ||
"blankLine": "always", | ||
"prev": "*", | ||
"next": "return" | ||
} | ||
] | ||
}, | ||
"root": true, | ||
"plugins": [ | ||
"import" | ||
], | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
}, | ||
"overrides": [ | ||
{ | ||
"files": [ | ||
"src/**/*.ts" | ||
], | ||
"extends": [ | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:@typescript-eslint/recommended-requiring-type-checking", | ||
"prettier/@typescript-eslint" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"project": "tsconfig.json" | ||
}, | ||
"rules": { | ||
"@typescript-eslint/prefer-optional-chain": "error", | ||
"no-shadow": "off", | ||
"@typescript-eslint/no-shadow": "error", | ||
"@typescript-eslint/prefer-nullish-coalescing": "error", | ||
"@typescript-eslint/strict-boolean-expressions": "error", | ||
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "error", | ||
"@typescript-eslint/no-unnecessary-condition": "error", | ||
"@typescript-eslint/no-unnecessary-type-arguments": "error", | ||
"@typescript-eslint/prefer-string-starts-ends-with": "error", | ||
"@typescript-eslint/switch-exhaustiveness-check": "error" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Tests | ||
on: | ||
push | ||
|
||
jobs: | ||
tests: | ||
name: Run serverless/typescript tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install Node.js and npm | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 14.x | ||
registry-url: https://registry.npmjs.org | ||
|
||
- name: Install dependencies | ||
run: npm i | ||
|
||
- name: Run lint tests | ||
run: npm run test:lint | ||
|
||
- name: Run type tests | ||
run: npm run test:type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
dist | ||
node_modules | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.github | ||
.gitignore | ||
dist | ||
node_modules | ||
package-lock.json | ||
plugin.js | ||
src | ||
serverless.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ provider: | |
name: aws | ||
|
||
plugins: | ||
- ./plugin | ||
- ./dist/plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { InputData, JSONSchemaInput, quicktype } from "quicktype-core"; | ||
import { writeFileSync } from "fs"; | ||
|
||
interface Serverless { | ||
configSchemaHandler: { | ||
schema: Record<string, string>; | ||
}; | ||
} | ||
|
||
class ConfigSchemaHandlerTypescriptDefinitionsPlugin { | ||
private schema: Record<string, string>; | ||
|
||
constructor(serverless: Serverless) { | ||
this.schema = serverless.configSchemaHandler.schema; | ||
} | ||
|
||
commands = { | ||
schema: { | ||
usage: "Get JSON schema definition and generate TS definitions", | ||
lifecycleEvents: ["generate"], | ||
}, | ||
}; | ||
|
||
hooks = { | ||
"schema:generate": this.generateSchema.bind(this), | ||
}; | ||
|
||
async generateSchema() { | ||
const schemaInput = new JSONSchemaInput(undefined); | ||
await schemaInput.addSource({ | ||
name: "AWS", | ||
schema: JSON.stringify(this.schema), | ||
}); | ||
const inputData = new InputData(); | ||
inputData.addInput(schemaInput); | ||
|
||
const { lines: serverlessTs } = await quicktype({ | ||
inputData, | ||
lang: "typescript", | ||
rendererOptions: { | ||
"just-types": "true", | ||
}, | ||
}); | ||
|
||
writeFileSync("index.d.ts", serverlessTs.join("\n")); | ||
} | ||
} | ||
|
||
module.exports = ConfigSchemaHandlerTypescriptDefinitionsPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"declaration": false, | ||
"esModuleInterop": true, | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"noFallthroughCasesInSwitch": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"outDir": "dist", | ||
"preserveConstEnums": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"target": "es6" | ||
}, | ||
"include": ["src"], | ||
} |