From a397dc0824778b00a08e26d5390fa0fe5fcaabdd Mon Sep 17 00:00:00 2001 From: Sam Reid Date: Tue, 15 Oct 2024 08:31:46 -0600 Subject: [PATCH] Convert to TypeScript, see https://github.com/phetsims/chipper/issues/1465 --- js/grunt/copySupplementalPhetioFiles.ts | 6 ++++-- js/grunt/tasks/generate-phet-io-api.ts | 2 +- .../{formatPhetioAPI.js => formatPhetioAPI.ts} | 14 ++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) rename js/phet-io/{formatPhetioAPI.js => formatPhetioAPI.ts} (74%) diff --git a/js/grunt/copySupplementalPhetioFiles.ts b/js/grunt/copySupplementalPhetioFiles.ts index a64693367..a783e0d77 100644 --- a/js/grunt/copySupplementalPhetioFiles.ts +++ b/js/grunt/copySupplementalPhetioFiles.ts @@ -13,6 +13,8 @@ import * as _ from 'lodash'; import IntentionalAny from '../../../phet-core/js/types/IntentionalAny.js'; import webpackBuild from './webpackBuild.ts'; import buildStandalone from './buildStandalone.ts'; +import formatPhetioAPI from '../phet-io/formatPhetioAPI'; +import reportTscResults from './reportTscResults'; const assert = require( 'assert' ); const archiver = require( 'archiver' ); @@ -21,11 +23,11 @@ const copyDirectory = require( '../grunt/copyDirectory' ); const execute = require( '../../../perennial-alias/js/common/execute' ); const grunt = require( 'grunt' ); const generatePhetioMacroAPI = require( '../phet-io/generatePhetioMacroAPI' ); -const formatPhetioAPI = require( '../phet-io/formatPhetioAPI' ); + const minify = require( '../grunt/minify' ); const marked = require( 'marked' ); const tsc = require( './tsc' ); -import reportTscResults from './reportTscResults'; + const getPhetLibs = require( './getPhetLibs' ); const path = require( 'path' ); const webpack = require( 'webpack' ); diff --git a/js/grunt/tasks/generate-phet-io-api.ts b/js/grunt/tasks/generate-phet-io-api.ts index 5350f4f60..d77a6294f 100644 --- a/js/grunt/tasks/generate-phet-io-api.ts +++ b/js/grunt/tasks/generate-phet-io-api.ts @@ -2,6 +2,7 @@ import getOption from '../../../../perennial-alias/js/grunt/tasks/util/getOption'; import getRepo from '../../../../perennial-alias/js/grunt/tasks/util/getRepo'; +import formatPhetioAPI from '../../phet-io/formatPhetioAPI'; /** * Output the PhET-iO API as JSON to phet-io-sim-specific/api. @@ -16,7 +17,6 @@ import getRepo from '../../../../perennial-alias/js/grunt/tasks/util/getRepo'; */ const repo = getRepo(); -const formatPhetioAPI = require( '../../phet-io/formatPhetioAPI' ); const getSimList = require( '../../common/getSimList' ); const generatePhetioMacroAPI = require( '../../phet-io/generatePhetioMacroAPI' ); const fs = require( 'fs' ); diff --git a/js/phet-io/formatPhetioAPI.js b/js/phet-io/formatPhetioAPI.ts similarity index 74% rename from js/phet-io/formatPhetioAPI.js rename to js/phet-io/formatPhetioAPI.ts index 2fb298370..b723a2488 100644 --- a/js/phet-io/formatPhetioAPI.js +++ b/js/phet-io/formatPhetioAPI.ts @@ -10,15 +10,16 @@ * @author Sam Reid (PhET Interactive Simulations) */ - const assert = require( 'assert' ); const fixEOL = require( '../grunt/fixEOL' ); +import IntentionalAny from '../../../phet-core/js/types/IntentionalAny.ts'; + /** * Creates a new object, recursively, by sorting the keys at each level. - * @param {Object} unordered - jsonifiable object to be sorted by key name. Sorting is recursive. + * @param unordered - jsonifiable object to be sorted by key name. Sorting is recursive. */ -const copyWithSortedKeys = unordered => { +const copyWithSortedKeys = ( unordered: IntentionalAny ): Record => { if ( Array.isArray( unordered ) ) { return unordered.map( copyWithSortedKeys ); } @@ -26,7 +27,7 @@ const copyWithSortedKeys = unordered => { return unordered; } - const ordered = {}; + const ordered: Record = {}; Object.keys( unordered ).sort().forEach( key => { const value = unordered[ key ]; ordered[ key ] = copyWithSortedKeys( value ); @@ -34,10 +35,7 @@ const copyWithSortedKeys = unordered => { return ordered; }; -/** - * @param {Object} api - */ -module.exports = api => { +export default ( api: IntentionalAny ): string => { assert( api, 'api expected' ); const objectString = JSON.stringify( copyWithSortedKeys( api ), null, 2 ); return fixEOL( objectString );