Skip to content

Commit

Permalink
feat: run tsc --noEmit on typescript projects
Browse files Browse the repository at this point in the history
  • Loading branch information
kabaros committed Oct 18, 2024
1 parent 494c20f commit b94f3f8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
17 changes: 16 additions & 1 deletion src/commands/types/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { exit } = require('@dhis2/cli-helpers-engine')
const { eslint } = require('../../tools/eslint.js')
const { prettier } = require('../../tools/prettier.js')
const { stylelint } = require('../../tools/stylelint.js')
const { typescriptCheck } = require('../../tools/typescript-check.js')
const { configured } = require('../../utils/config.js')
const { selectFiles } = require('../../utils/files.js')
const {
Expand Down Expand Up @@ -52,8 +53,22 @@ exports.handler = (argv, callback) => {
return
}

const isTypescriptProject = configured('typescript')

if (isTypescriptProject) {
log.info('typescript > tsc --noEmit')
typescriptCheck({ callback: finalStatus })

if (finalStatus() === 0) {
log.print('Typescript check completed successfully.')
log.print('')
}
}

if (configured('eslint')) {
log.info('javascript > eslint')
log.info(
`${isTypescriptProject ? 'typescript' : 'javascript'} > eslint`
)
eslint({
apply,
files: jsFiles,
Expand Down
9 changes: 2 additions & 7 deletions src/tools/typescript-check.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
const path = require('path')
const { bin } = require('@dhis2/cli-helpers-engine').exec
const { fileExists } = require('../utils/files.js')
const { PROJECT_ROOT } = require('../utils/paths.js')

exports.typescriptCheck = () => {
exports.typescriptCheck = ({ callback }) => {
const cmd = 'tsc'
const tsconfigFile = path.join(PROJECT_ROOT, 'tsconfig.json')

if (fileExists(tsconfigFile)) {
bin(cmd, { args: ['--noEmit'], PROJECT_ROOT })
}
bin(cmd, { args: ['--noEmit'], PROJECT_ROOT }, callback)
}
1 change: 1 addition & 0 deletions src/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const packageConfigs = {
* project.
*/
const projectConfigs = {
typescript: path.join(PROJECT_ROOT, 'tsconfig.json'),
editorconfig: path.join(PROJECT_ROOT, '.editorconfig'),
eslint: path.join(PROJECT_ROOT, '.eslintrc.js'),
prettier: path.join(PROJECT_ROOT, '.prettierrc.js'),
Expand Down

0 comments on commit b94f3f8

Please sign in to comment.