Skip to content

Commit

Permalink
Update documentation, see phetsims/chipper#1156
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Dec 6, 2021
1 parent 2e9557e commit bafc227
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
12 changes: 4 additions & 8 deletions doc/typescript-quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,10 @@ The compiler is also configured for incremental compilation. This means subsequ
4. Compile via `grunt output-js-project` and run it in the browser. Did it print `7`?
5. Try creating a type error like `const x:string=7` and see what happens.

### Toward more efficient iteration
1. Install TypeScript with the same version as listed in chipper/package.json. You can do this globally via `npm install -g typescript@4.4.2`.
`tsc` is a program that comes bundled with the npm module `typescript`. Alternatively, you can set an
alias like `alias tsc = node /path/chipper/node_modules/typescript/bin/tsc`, which would make sure you are always using
the same version of typescript as in chipper.
2. Start a watch process by `cd chipper/tsconfig/all` and `tsc -b --watch`. This will will watch for any file changes
and auto-recompile.
3. I have not yet experimented with having the IDE do the builds, but maybe that will be more efficient.
### Transpile TypeScript
* Change directory to the build tools: `cd chipper/`
* Run the TypeScript transpiler: `node js/scripts/transpile.js --watch` which starts a process that will auto-transpile when files change.
* If you prefer to experiment with using WebStorm/IDEA File Watchers, please see https://github.com/phetsims/phet-info/blob/master/doc/typescript-webstorm-file-watcher.md

### Process Changes
1. TypeScript sims need to be compiled using `grunt output-js-project` before generating their PhET-iO API using `grunt generate-phet-io-api`.
Expand Down
17 changes: 17 additions & 0 deletions doc/typescript-webstorm-file-watcher.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Configuring WebStorm/IDEA File Watchers for TypeScript Transpilation

The best supported way to transpile code is by using chipper's `node js/scripts/transpile.js --watch`. However,
for developers that want IDE integration way want to experiment with WebStorm/IDEA File Watchers. This process is
not well-vetted and should be used at your own risk.

I experimented with a configuration like so:

![image](https://user-images.githubusercontent.com/679486/143963489-ab2c1ae7-86b2-4bbf-bc29-d54cbf144353.png)

And I observed that it quickly transpiles a single file when saved. It seems to be working nicely and could be a good solution for those who don't want to run a watch process. You can also see an indicator in the bottom bar of WebStorm that shows when compilation starts and ends. It's pretty speedy.

My main concern about using File Watcher is my uncertainty about what's best for "Scope"--when I tried "all files" changes to Sim.js seemed to trigger on sim mains as well (even when unchanged). Could setting scope to "all changed files" sometimes do more or less than it should?

Also, keep in mind you need to watch both *.js and *.ts files. I'm not sure if those can be combined into one watcher or if they have to be 2 separate watchers.

Also, should "auto save edited files to trigger the watcher" be checked? Probably.

0 comments on commit bafc227

Please sign in to comment.