Skip to content

Commit

Permalink
add support for output-js to apply to a repo without a tsconfig.json …
Browse files Browse the repository at this point in the history
…file, #1073
  • Loading branch information
zepumph committed Sep 11, 2021
1 parent 095967a commit caf9eb7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
9 changes: 6 additions & 3 deletions js/grunt/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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' ] ) ) )
Expand Down
14 changes: 10 additions & 4 deletions js/grunt/tsc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<string>} 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
Expand Down

0 comments on commit caf9eb7

Please sign in to comment.