Skip to content

Commit

Permalink
feat: tsconfig, gitignore, npm script enhancements (#782)
Browse files Browse the repository at this point in the history
* chore: enable strict mode

* feat: tsconfig enhancements for codegen'd SDK

* chore: update test fixtures

* feat: gitignore dist directory

* feat: add tsc lint script
  • Loading branch information
kanadgupta authored Oct 25, 2023
1 parent 521683a commit cd9e22c
Show file tree
Hide file tree
Showing 28 changed files with 112 additions and 19 deletions.
23 changes: 22 additions & 1 deletion packages/api/src/codegen/languages/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ export default class TSGenerator extends CodeGenerator {
const srcDirectory = this.project.createDirectory('src');
const sdkSource = this.createSDKSource(srcDirectory);

this.createGitIgnore();
this.createPackageJSON();
this.createTSConfig();
this.createREADME();
Expand Down Expand Up @@ -522,6 +523,22 @@ sdk.server('https://eu.api.example.com/v14');`),
return sourceFile;
}

/**
* Creates a `.gitignore` file to prevent the `dist/` directory from being tracked.
*
*/
createGitIgnore() {
const file = `# This file prevents the \`dist/\` directory from being tracked via git.
# This is recommended since the \`prepare\` npm script automatically
# regenerates the contents of the \`dist/\` directory as needed.
dist/
`;

const sourceFile = this.project.createSourceFile('.gitignore', file);

return sourceFile;
}

/**
* Create the `tsconfig.json` file that will allow this SDK to be compiled for use.
*
Expand All @@ -531,8 +548,11 @@ sdk.server('https://eu.api.example.com/v14');`),

const config: TsConfigJson = {
compilerOptions: {
module: 'NodeNext',
esModuleInterop: true,
module: 'ESNext',
moduleResolution: 'Bundler',
resolveJsonModule: true,
strict: true,
},
include: ['./src/**/*'],
};
Expand Down Expand Up @@ -607,6 +627,7 @@ sdk.server('https://eu.api.example.com/v14');`),
license: this.spdxLicense ?? '',
files: ['dist', 'openapi.json'],
scripts: {
lint: 'tsc --noEmit',
prepare: 'tsup',
},
dependencies,
Expand Down
4 changes: 4 additions & 0 deletions packages/test-utils/sdks/alby/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file prevents the `dist/` directory from being tracked via git.
# This is recommended since the `prepare` npm script automatically
# regenerates the contents of the `dist/` directory as needed.
dist/
1 change: 1 addition & 0 deletions packages/test-utils/sdks/alby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"openapi.json"
],
"scripts": {
"lint": "tsc --noEmit",
"prepare": "tsup"
},
"dependencies": {
Expand Down
7 changes: 5 additions & 2 deletions packages/test-utils/sdks/alby/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"compilerOptions": {
"module": "NodeNext",
"resolveJsonModule": true
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"strict": true
},
"include": [
"./src/**/*"
Expand Down
4 changes: 4 additions & 0 deletions packages/test-utils/sdks/metrotransit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file prevents the `dist/` directory from being tracked via git.
# This is recommended since the `prepare` npm script automatically
# regenerates the contents of the `dist/` directory as needed.
dist/
1 change: 1 addition & 0 deletions packages/test-utils/sdks/metrotransit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"openapi.json"
],
"scripts": {
"lint": "tsc --noEmit",
"prepare": "tsup"
},
"dependencies": {
Expand Down
7 changes: 5 additions & 2 deletions packages/test-utils/sdks/metrotransit/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"compilerOptions": {
"module": "NodeNext",
"resolveJsonModule": true
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"strict": true
},
"include": [
"./src/**/*"
Expand Down
4 changes: 4 additions & 0 deletions packages/test-utils/sdks/operationid-quirks/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file prevents the `dist/` directory from being tracked via git.
# This is recommended since the `prepare` npm script automatically
# regenerates the contents of the `dist/` directory as needed.
dist/
1 change: 1 addition & 0 deletions packages/test-utils/sdks/operationid-quirks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"openapi.json"
],
"scripts": {
"lint": "tsc --noEmit",
"prepare": "tsup"
},
"dependencies": {
Expand Down
7 changes: 5 additions & 2 deletions packages/test-utils/sdks/operationid-quirks/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"compilerOptions": {
"module": "NodeNext",
"resolveJsonModule": true
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"strict": true
},
"include": [
"./src/**/*"
Expand Down
4 changes: 4 additions & 0 deletions packages/test-utils/sdks/optional-payload/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file prevents the `dist/` directory from being tracked via git.
# This is recommended since the `prepare` npm script automatically
# regenerates the contents of the `dist/` directory as needed.
dist/
1 change: 1 addition & 0 deletions packages/test-utils/sdks/optional-payload/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"openapi.json"
],
"scripts": {
"lint": "tsc --noEmit",
"prepare": "tsup"
},
"dependencies": {
Expand Down
7 changes: 5 additions & 2 deletions packages/test-utils/sdks/optional-payload/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"compilerOptions": {
"module": "NodeNext",
"resolveJsonModule": true
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"strict": true
},
"include": [
"./src/**/*"
Expand Down
4 changes: 4 additions & 0 deletions packages/test-utils/sdks/petstore/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file prevents the `dist/` directory from being tracked via git.
# This is recommended since the `prepare` npm script automatically
# regenerates the contents of the `dist/` directory as needed.
dist/
1 change: 1 addition & 0 deletions packages/test-utils/sdks/petstore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"openapi.json"
],
"scripts": {
"lint": "tsc --noEmit",
"prepare": "tsup"
},
"dependencies": {
Expand Down
7 changes: 5 additions & 2 deletions packages/test-utils/sdks/petstore/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"compilerOptions": {
"module": "NodeNext",
"resolveJsonModule": true
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"strict": true
},
"include": [
"./src/**/*"
Expand Down
4 changes: 4 additions & 0 deletions packages/test-utils/sdks/readme/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file prevents the `dist/` directory from being tracked via git.
# This is recommended since the `prepare` npm script automatically
# regenerates the contents of the `dist/` directory as needed.
dist/
1 change: 1 addition & 0 deletions packages/test-utils/sdks/readme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"openapi.json"
],
"scripts": {
"lint": "tsc --noEmit",
"prepare": "tsup"
},
"dependencies": {
Expand Down
7 changes: 5 additions & 2 deletions packages/test-utils/sdks/readme/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"compilerOptions": {
"module": "NodeNext",
"resolveJsonModule": true
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"strict": true
},
"include": [
"./src/**/*"
Expand Down
4 changes: 4 additions & 0 deletions packages/test-utils/sdks/response-title-quirks/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file prevents the `dist/` directory from being tracked via git.
# This is recommended since the `prepare` npm script automatically
# regenerates the contents of the `dist/` directory as needed.
dist/
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"openapi.json"
],
"scripts": {
"lint": "tsc --noEmit",
"prepare": "tsup"
},
"dependencies": {
Expand Down
7 changes: 5 additions & 2 deletions packages/test-utils/sdks/response-title-quirks/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"compilerOptions": {
"module": "NodeNext",
"resolveJsonModule": true
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"strict": true
},
"include": [
"./src/**/*"
Expand Down
4 changes: 4 additions & 0 deletions packages/test-utils/sdks/simple/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file prevents the `dist/` directory from being tracked via git.
# This is recommended since the `prepare` npm script automatically
# regenerates the contents of the `dist/` directory as needed.
dist/
1 change: 1 addition & 0 deletions packages/test-utils/sdks/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"openapi.json"
],
"scripts": {
"lint": "tsc --noEmit",
"prepare": "tsup"
},
"dependencies": {
Expand Down
7 changes: 5 additions & 2 deletions packages/test-utils/sdks/simple/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"compilerOptions": {
"module": "NodeNext",
"resolveJsonModule": true
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"strict": true
},
"include": [
"./src/**/*"
Expand Down
4 changes: 4 additions & 0 deletions packages/test-utils/sdks/star-trek/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file prevents the `dist/` directory from being tracked via git.
# This is recommended since the `prepare` npm script automatically
# regenerates the contents of the `dist/` directory as needed.
dist/
1 change: 1 addition & 0 deletions packages/test-utils/sdks/star-trek/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"openapi.json"
],
"scripts": {
"lint": "tsc --noEmit",
"prepare": "tsup"
},
"dependencies": {
Expand Down
7 changes: 5 additions & 2 deletions packages/test-utils/sdks/star-trek/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"compilerOptions": {
"module": "NodeNext",
"resolveJsonModule": true
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"strict": true
},
"include": [
"./src/**/*"
Expand Down

0 comments on commit cd9e22c

Please sign in to comment.