Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert modulify-generated files to TypeScript #1218

Open
zepumph opened this issue Apr 7, 2022 · 17 comments
Open

Convert modulify-generated files to TypeScript #1218

zepumph opened this issue Apr 7, 2022 · 17 comments
Assignees

Comments

@zepumph
Copy link
Member

zepumph commented Apr 7, 2022

From TypeScript meeting today, @samreid volunteered to take the lead. Thanks!

@zepumph zepumph changed the title Convert modulify-generated files to typescript Convert modulify-generated files to TypeScript Apr 7, 2022
@samreid
Copy link
Member

samreid commented Apr 7, 2022

This issue will take longer since we will want to track the js=>ts changes as renames, not as delete/creates.

@zepumph
Copy link
Member Author

zepumph commented Apr 7, 2022

I personally do not think we need to keep git history for these generated files. Git history for the asset itself (the image/mp3/etc) would be more important. I'm happy to be outvoted though.

@samreid
Copy link
Member

samreid commented Apr 10, 2022

I accept the vote above that we should not devote time to maintaining the history as renames for JS=>TS. However, I realized we still need to expend about as much effort to delete the former JS files. So I think they can be renamed like so:

execute( 'git', [ 'mv', path.basename( jsFilePath ), path.basename( tsFilePath ) ], path.dirname( jsFilePath ) );

@samreid
Copy link
Member

samreid commented Apr 10, 2022

I posted to slack:

As decided in this week’s dev meeting, I’m going to start converting images, sounds mipmaps, etc to TS as part of the modulify step. Please be aware and report any problems in #1218

samreid added a commit that referenced this issue Apr 10, 2022
@samreid
Copy link
Member

samreid commented Apr 10, 2022

In the course of working on this issue, I tested the image files and discovered that in a TypeScript sim, it correctly infers the HTMLImageElement type from both *.js and *.ts image files. Also, no changes or type annotations are required in the image files. Therefore the value of this step is questionable--might it slow down the type checker? Still, it seems we agreed on this for consistency and we will get more benefit out of the more complex modulified types.

samreid added a commit that referenced this issue Apr 10, 2022
samreid added a commit to phetsims/acid-base-solutions that referenced this issue Apr 10, 2022
samreid added a commit to phetsims/color-vision that referenced this issue Apr 10, 2022
samreid added a commit to phetsims/build-a-molecule that referenced this issue Apr 10, 2022
samreid added a commit to phetsims/arithmetic that referenced this issue Apr 10, 2022
samreid added a commit to phetsims/capacitor-lab-basics that referenced this issue Apr 10, 2022
samreid added a commit to phetsims/beers-law-lab that referenced this issue Apr 10, 2022
samreid added a commit to phetsims/expression-exchange that referenced this issue Apr 10, 2022
samreid added a commit to phetsims/equality-explorer that referenced this issue Apr 10, 2022
samreid added a commit to phetsims/gas-properties that referenced this issue Apr 10, 2022
samreid added a commit to phetsims/circuit-construction-kit-dc that referenced this issue Apr 10, 2022
samreid added a commit to phetsims/estimation that referenced this issue Apr 10, 2022
samreid added a commit to phetsims/density-buoyancy-common that referenced this issue Apr 10, 2022
samreid added a commit to phetsims/circuit-construction-kit-common that referenced this issue Apr 10, 2022
samreid added a commit to phetsims/masses-and-springs-basics that referenced this issue Apr 10, 2022
samreid added a commit to phetsims/energy-forms-and-changes that referenced this issue Apr 10, 2022
samreid added a commit to phetsims/function-builder that referenced this issue Apr 10, 2022
samreid added a commit to phetsims/counting-common that referenced this issue Apr 10, 2022
samreid added a commit to phetsims/forces-and-motion-basics that referenced this issue Apr 10, 2022
samreid added a commit to phetsims/pendulum-lab that referenced this issue Aug 20, 2024
samreid added a commit to phetsims/gene-expression-essentials that referenced this issue Aug 20, 2024
samreid added a commit to phetsims/area-model-common that referenced this issue Aug 20, 2024
samreid added a commit to phetsims/gravity-and-orbits that referenced this issue Aug 20, 2024
samreid added a commit to phetsims/density that referenced this issue Aug 20, 2024
samreid added a commit to phetsims/trig-tour that referenced this issue Aug 20, 2024
samreid added a commit to phetsims/fractions-common that referenced this issue Aug 20, 2024
samreid added a commit to phetsims/function-builder that referenced this issue Aug 20, 2024
samreid added a commit to phetsims/projectile-motion that referenced this issue Aug 20, 2024
samreid added a commit to phetsims/charges-and-fields that referenced this issue Aug 20, 2024
samreid added a commit to phetsims/faradays-law that referenced this issue Aug 20, 2024
samreid added a commit to phetsims/states-of-matter that referenced this issue Aug 20, 2024
samreid added a commit to phetsims/make-a-ten that referenced this issue Aug 20, 2024
samreid added a commit to phetsims/balancing-chemical-equations that referenced this issue Aug 20, 2024
samreid added a commit to phetsims/expression-exchange that referenced this issue Aug 20, 2024
samreid added a commit that referenced this issue Aug 20, 2024
samreid added a commit to phetsims/circuit-construction-kit-common that referenced this issue Aug 20, 2024
samreid added a commit to phetsims/greenhouse-effect that referenced this issue Aug 20, 2024
samreid added a commit to phetsims/scenery-phet that referenced this issue Aug 20, 2024
@samreid
Copy link
Member

samreid commented Aug 20, 2024

I git mv renamed the modulified mipmap files from js to ts. Using this script, and manual for function-builder:

import { existsSync } from 'https://deno.land/std/fs/mod.ts';
import { extname, join } from 'https://deno.land/std/path/mod.ts';

const activeReposFile = './perennial/data/active-repos';

try {
  const data = await Deno.readTextFile( activeReposFile );
  const repos = data.split( '\n' ).filter( ( repo: string ) => repo.trim() !== '' );

  for ( const repo of repos ) {
    const mipmapsDir = `${repo}/mipmaps`;

    if ( existsSync( mipmapsDir ) ) {
      console.log( `Processing ${repo}` );

      const renameJsToTs = async ( dir: string ) => {
        for await ( const entry of Deno.readDir( dir ) ) {
          if ( entry.isFile && extname( entry.name ) === '.js' ) {
            const jsFilePath = join( 'mipmaps', entry.name );
            const tsFilePath = jsFilePath.replace( /\.js$/, '.ts' );

            // Execute the git mv command with the cwd option set to the repo directory
            const process = Deno.run( {
              cmd: [ 'git', 'mv', jsFilePath, tsFilePath ],
              cwd: repo, // Set the cwd to the repository directory
              stdout: 'piped',
              stderr: 'piped'
            } );

            const { code } = await process.status();
            if ( code === 0 ) {
              console.log( `Renamed ${jsFilePath} to ${tsFilePath}` );
            }
            else {
              const rawError = await process.stderrOutput();
              console.error( `Failed to rename ${jsFilePath}:`, new TextDecoder().decode( rawError ) );
            }

            process.close();
          }
        }
      };

      await renameJsToTs( mipmapsDir );

      // if ( repo === 'function-builder' && existsSync( `${mipmapsDir}/functions` ) ) {
      //   await renameJsToTs( `${mipmapsDir}/functions` );
      // }
    }
  }

  console.log( 'Renaming completed. Please review the changes.' );
}
catch( error ) {
  console.error( 'Error processing the repositories:', error );
}

I changed the output of grunt modulify so that mipmaps output to *.ts in this commit. I tested by running grunt modulify in buoyancy and saw that there were no changes. I tested running a built sim and unbuilt sim. All seems well.

Current status:

Output ts

  • Images
  • Mipmaps
  • Strings
  • SVG

Still in js

  • Shaders
  • Sounds

I am uncertain whether the value will exceed the effort for converting shaders and sounds, let's assign to @jonathanolson and @jbphet about those steps and see if they would like to work on it.

@samreid samreid assigned jonathanolson and jbphet and unassigned samreid Aug 20, 2024
@zepumph
Copy link
Member Author

zepumph commented Aug 20, 2024

Side note: All repos will get a grunt modulify tonight for the daily grunt work. That may be a good thing to look at tomorrow morning to see if any changes come in unexpectedly.

samreid added a commit to phetsims/babel that referenced this issue Aug 20, 2024
@samreid
Copy link
Member

samreid commented Aug 20, 2024

I also ran for-each.sh active-repos grunt modulify

@jonathanolson
Copy link
Contributor

@AgustinVallejo is my-solar-system's PathsPainter (.shader and .vert, under shaders/) being used? It looks vestigial.

I've also removed the files needing transpilation in alpenglow, and I don't think we have '.glsl' suffix files, so I'm hoping we can just remove support for shader transpilation. (The alpenglow approach won't rely on the transpiler for this at all).

Also, my personal opinion is that it would be nice to move the sound files to .ts.

@jbphet
Copy link
Contributor

jbphet commented Aug 23, 2024

Note to self: If I work on this, it might be a good time to also try and tackle phetsims/tambo#153.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants