From 726d7ff8521e6069992a8de3285471639b737f1b Mon Sep 17 00:00:00 2001 From: Nazarii Romankiv Date: Thu, 23 Jan 2025 19:41:58 +0200 Subject: [PATCH 1/4] feat: implemented check:types script to ensure TS types correctness --- .../workflows/check-types.yml-template | 23 ++++++++++++++ .../workflows/check-types.yml-template | 23 ++++++++++++++ .../workflows/check-types.yml-template | 23 ++++++++++++++ mate-scripts/package.json | 1 + .../src/commands/CheckTypes.command.ts | 31 +++++++++++++++++++ mate-scripts/src/commands/index.ts | 1 + mate-scripts/src/index.ts | 6 ++++ 7 files changed, 108 insertions(+) create mode 100644 mate-scripts/configs/reactTypescript/.github/workflows/check-types.yml-template create mode 100644 mate-scripts/configs/typescript/.github/workflows/check-types.yml-template create mode 100644 mate-scripts/configs/vueTypescript/workflows/check-types.yml-template create mode 100644 mate-scripts/src/commands/CheckTypes.command.ts diff --git a/mate-scripts/configs/reactTypescript/.github/workflows/check-types.yml-template b/mate-scripts/configs/reactTypescript/.github/workflows/check-types.yml-template new file mode 100644 index 00000000..ebb671c6 --- /dev/null +++ b/mate-scripts/configs/reactTypescript/.github/workflows/check-types.yml-template @@ -0,0 +1,23 @@ +name: Check Types + +on: + pull_request: + branches: [ master ] + +jobs: + run_linter: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [20.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm run check:types diff --git a/mate-scripts/configs/typescript/.github/workflows/check-types.yml-template b/mate-scripts/configs/typescript/.github/workflows/check-types.yml-template new file mode 100644 index 00000000..ebb671c6 --- /dev/null +++ b/mate-scripts/configs/typescript/.github/workflows/check-types.yml-template @@ -0,0 +1,23 @@ +name: Check Types + +on: + pull_request: + branches: [ master ] + +jobs: + run_linter: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [20.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm run check:types diff --git a/mate-scripts/configs/vueTypescript/workflows/check-types.yml-template b/mate-scripts/configs/vueTypescript/workflows/check-types.yml-template new file mode 100644 index 00000000..ebb671c6 --- /dev/null +++ b/mate-scripts/configs/vueTypescript/workflows/check-types.yml-template @@ -0,0 +1,23 @@ +name: Check Types + +on: + pull_request: + branches: [ master ] + +jobs: + run_linter: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [20.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm run check:types diff --git a/mate-scripts/package.json b/mate-scripts/package.json index 38e4d676..3d94de8c 100644 --- a/mate-scripts/package.json +++ b/mate-scripts/package.json @@ -8,6 +8,7 @@ "lint": "eslint ./src", "test": "echo \"Error: no test specified\" && exit 1", "build": "rm -rf ./bin && rollup -c && node ./shebangify.js && chmod +x ./bin/mateScripts.js", + "build:windows": "rollup -c && node ./shebangify.js", "prepublishOnly": "npm run build", "postpublish": "rm -rf ./bin", "patch": "npm version patch && npm publish", diff --git a/mate-scripts/src/commands/CheckTypes.command.ts b/mate-scripts/src/commands/CheckTypes.command.ts new file mode 100644 index 00000000..e434a316 --- /dev/null +++ b/mate-scripts/src/commands/CheckTypes.command.ts @@ -0,0 +1,31 @@ +import { Command } from './Command'; +import {execBashCodeSilent} from "../tools"; + +export type CheckTypesOptions = Record; + +export class CheckTypesCommand extends Command { + protected common(): void { + // do nothing + } + + protected reactTypescript = (options: CheckTypesOptions) => { + this.checkTypes(); + }; + + + protected vueTypescript = (options: CheckTypesOptions) => { + this.checkTypes(); + }; + + + protected typescript = (options: CheckTypesOptions) => { + this.checkTypes(); + }; + + private checkTypes() { + execBashCodeSilent( + `${this.binDir}tsc --no-emit`, + ); + } + +} diff --git a/mate-scripts/src/commands/index.ts b/mate-scripts/src/commands/index.ts index 9b867915..1fa72605 100644 --- a/mate-scripts/src/commands/index.ts +++ b/mate-scripts/src/commands/index.ts @@ -7,3 +7,4 @@ export * from './Build.command'; export * from './Deploy.command'; export * from './Update.command'; export * from './Migrate.command'; +export * from './CheckTypes.command'; diff --git a/mate-scripts/src/index.ts b/mate-scripts/src/index.ts index 7e92048a..d61a44ac 100644 --- a/mate-scripts/src/index.ts +++ b/mate-scripts/src/index.ts @@ -10,6 +10,7 @@ import { TestCommand, UpdateCommand, MigrateCommand, + CheckTypesCommand, } from './commands'; import { deployController, @@ -50,6 +51,11 @@ program .description('lint html, css and js files') .action(commandFactory.make(LintCommand, lintController)); +program + .command('check:types') + .description('validates TS types') + .action(commandFactory.make(CheckTypesCommand)); + program .command('test') .option('-n, --not-open', 'should open test report in browser', false) From 5a00ea02e0ce81b116c9c30ad93c8e152134147c Mon Sep 17 00:00:00 2001 From: Nazarii Romankiv Date: Thu, 23 Jan 2025 19:46:47 +0200 Subject: [PATCH 2/4] style: refactor code according to the linter --- mate-scripts/src/commands/CheckTypes.command.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/mate-scripts/src/commands/CheckTypes.command.ts b/mate-scripts/src/commands/CheckTypes.command.ts index e434a316..2bf20ccb 100644 --- a/mate-scripts/src/commands/CheckTypes.command.ts +++ b/mate-scripts/src/commands/CheckTypes.command.ts @@ -1,5 +1,5 @@ import { Command } from './Command'; -import {execBashCodeSilent} from "../tools"; +import { execBashCodeSilent } from '../tools'; export type CheckTypesOptions = Record; @@ -8,17 +8,15 @@ export class CheckTypesCommand extends Command { // do nothing } - protected reactTypescript = (options: CheckTypesOptions) => { + protected reactTypescript = () => { this.checkTypes(); }; - - protected vueTypescript = (options: CheckTypesOptions) => { + protected vueTypescript = () => { this.checkTypes(); }; - - protected typescript = (options: CheckTypesOptions) => { + protected typescript = () => { this.checkTypes(); }; @@ -27,5 +25,4 @@ export class CheckTypesCommand extends Command { `${this.binDir}tsc --no-emit`, ); } - } From 60a7bafe8db0a9e0807ac951aac404384cf6a703 Mon Sep 17 00:00:00 2001 From: Nazarii Romankiv Date: Thu, 23 Jan 2025 19:54:53 +0200 Subject: [PATCH 3/4] fix: tsc flag for noEmit --- mate-scripts/src/commands/CheckTypes.command.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mate-scripts/src/commands/CheckTypes.command.ts b/mate-scripts/src/commands/CheckTypes.command.ts index 2bf20ccb..44dfb315 100644 --- a/mate-scripts/src/commands/CheckTypes.command.ts +++ b/mate-scripts/src/commands/CheckTypes.command.ts @@ -22,7 +22,7 @@ export class CheckTypesCommand extends Command { private checkTypes() { execBashCodeSilent( - `${this.binDir}tsc --no-emit`, + `${this.binDir}tsc --noEmit`, ); } } From 812a4aa43af065847a687c292752ad493662e663 Mon Sep 17 00:00:00 2001 From: Nazarii Romankiv Date: Thu, 23 Jan 2025 19:58:59 +0200 Subject: [PATCH 4/4] refactor: renamed github action job --- .../reactTypescript/.github/workflows/check-types.yml-template | 2 +- .../typescript/.github/workflows/check-types.yml-template | 2 +- .../configs/vueTypescript/workflows/check-types.yml-template | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mate-scripts/configs/reactTypescript/.github/workflows/check-types.yml-template b/mate-scripts/configs/reactTypescript/.github/workflows/check-types.yml-template index ebb671c6..7f0882d6 100644 --- a/mate-scripts/configs/reactTypescript/.github/workflows/check-types.yml-template +++ b/mate-scripts/configs/reactTypescript/.github/workflows/check-types.yml-template @@ -5,7 +5,7 @@ on: branches: [ master ] jobs: - run_linter: + check_types: runs-on: ubuntu-latest diff --git a/mate-scripts/configs/typescript/.github/workflows/check-types.yml-template b/mate-scripts/configs/typescript/.github/workflows/check-types.yml-template index ebb671c6..7f0882d6 100644 --- a/mate-scripts/configs/typescript/.github/workflows/check-types.yml-template +++ b/mate-scripts/configs/typescript/.github/workflows/check-types.yml-template @@ -5,7 +5,7 @@ on: branches: [ master ] jobs: - run_linter: + check_types: runs-on: ubuntu-latest diff --git a/mate-scripts/configs/vueTypescript/workflows/check-types.yml-template b/mate-scripts/configs/vueTypescript/workflows/check-types.yml-template index ebb671c6..7f0882d6 100644 --- a/mate-scripts/configs/vueTypescript/workflows/check-types.yml-template +++ b/mate-scripts/configs/vueTypescript/workflows/check-types.yml-template @@ -5,7 +5,7 @@ on: branches: [ master ] jobs: - run_linter: + check_types: runs-on: ubuntu-latest