diff --git a/js/grunt/Gruntfile.js b/js/grunt/Gruntfile.js index f350378a9..bc3ea1302 100644 --- a/js/grunt/Gruntfile.js +++ b/js/grunt/Gruntfile.js @@ -157,7 +157,10 @@ module.exports = function( grunt ) { } ) ); const reportTscResults = results => { - if ( ( results.stderr && results.stderr.length > 0 ) || results.code !== 0 ) { + if ( results.ignored ) { + grunt.log.ok( 'TypeScript compilation ignored due to no support in repo.' ); + } + else if ( ( results.stderr && results.stderr.length > 0 ) || results.code !== 0 ) { grunt.fail.fatal( `tsc failed with code: ${results.code} stdout: ${results.stdout} @@ -170,10 +173,10 @@ ${results.stderr}` ); }; grunt.registerTask( 'output-js', 'Outputs JS just for the specified repo', - wrapTask( async () => reportTscResults( await tsc( '../chipper', [ '--project', `../${repo}` ] ) ) ) + wrapTask( async () => reportTscResults( await tsc( '../chipper', [ '--project', `../${repo}` ], repo ) ) ) ); grunt.registerTask( 'output-js-project', 'Outputs JS for the specified repo and its dependencies', - wrapTask( async () => reportTscResults( await tsc( '../chipper', [ '--build', `../${repo}` ] ) ) ) + wrapTask( async () => reportTscResults( await tsc( '../chipper', [ '--build', `../${repo}` ], repo ) ) ) ); grunt.registerTask( 'output-js-all', 'Outputs JS for all repos', wrapTask( async () => reportTscResults( await tsc( '../chipper', [ '--build', '../chipper/tsconfig/all' ] ) ) ) diff --git a/js/grunt/tsc.js b/js/grunt/tsc.js index 4832cc7b5..312589627 100644 --- a/js/grunt/tsc.js +++ b/js/grunt/tsc.js @@ -8,17 +8,23 @@ // modules const execute = require( '../../../perennial-alias/js/dual/execute' ); +const fs = require( 'fs' ); /** * @param {string} path - path to tsconfig file or directory containing tsconfig file * @param {Array.} commandLineArgs + * @param {string} [repo] - if supplied, use to check on if repo supports typescript * @returns {Promise<{execResult: {stdout:string,stderr:string,code:number}, time: number}>} - the results from exec, and the elapsed time */ -const tsc = async function( path, commandLineArgs ) { +const tsc = async function( path, commandLineArgs, repo ) { const args = [ '../chipper/node_modules/typescript/bin/tsc', ...commandLineArgs ]; - return execute( 'node', args, path, { - errors: 'resolve' - } ); + if ( !repo || ( repo && fs.existsSync( `${repo}/tsconfig.json` ) ) ) { + + return execute( 'node', args, path, { + errors: 'resolve' + } ); + } + return Promise.resolve( { ignored: true } ); }; // so that hook-pre-commit.js knows if it loaded a compatible version