Skip to content
This repository has been archived by the owner on Jul 7, 2023. It is now read-only.

Migrate CootWorker to TS #375

Merged
merged 8 commits into from
Jun 20, 2023
Merged

Migrate CootWorker to TS #375

merged 8 commits into from
Jun 20, 2023

Conversation

FilomenoSanchez
Copy link
Collaborator

@FilomenoSanchez FilomenoSanchez commented Jun 20, 2023

This update migrates the coot worker to TS. A few considerations.

  • Changes to CootWorker.ts will trigger a reload (during development) but the changes will not be actually included. If a change is done to the worker TS file then the file has to be transpiled by running npm run transpile-ts-worker . Another quick alternative (only for development) is to modify the JS file, but then it's important to add those changes back to the TS file.
  • Any production build script has to be aware of this. I think I have taken care of this but @stuartjamesmcnicholas please check that I didn't break electron builds in package.json. I have tested npm run-script make-linux on my machine and it produced a working electron app.

sed command needs to be invoked after transpiling the worker code otherwise the result is not a valid JS worker file. Problem is described here and here.

Comment on lines 115 to 129
"transpile-ts-worker": "npx tsc --module es2015 --lib webworker --skipLibCheck public/baby-gru/CootWorker.ts && sed -i '/export {}/d' public/baby-gru/CootWorker.js",
"prestart": "npm run transpile-ts-worker",
"start": "react-scripts start",
"start-tsc": "npx nodemon --trace-warnings",
"build": "react-scripts build",
"build-cloud-dev": "webpack --mode development --devtool inline-source-map",
"build-cloud": "webpack --mode production",
"build": "npm run transpile-ts-worker && react-scripts build",
"build-npm-registry": "npm run transpile-ts-worker && webpack --mode development --devtool inline-source-map --env destination='npmRegistry'",
"build-cloud-dev": "npm run transpile-ts-worker && webpack --mode development --devtool inline-source-map --env destination='ccp4Cloud'",
"build-cloud": "npm run transpile-ts-worker && webpack --mode production --env destination='ccp4Cloud'",
"test": "react-scripts test",
"eject": "react-scripts eject",
"dev": "concurrently -k \"BROWSER=none npm start\" \"npm:electron\"",
"electron": "wait-on tcp:3000 && electron-forge start",
"package": "react-scripts build && electron-forge package",
"make-mac": "react-scripts build && electron-forge make --platform darwin",
"make-linux": "react-scripts build && electron-forge make --platform linux",
"make-win32": "react-scripts build && electron-forge make --platform win32"
"package": "npm run build && electron-forge package",
"make-mac": "npm run build && electron-forge make --platform darwin",
"make-linux": "npm run build && electron-forge make --platform linux",
"make-win32": "npm run build && electron-forge make --platform win32"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here @stuartjamesmcnicholas I create a script transpile-ts-worker that transpiles the worker TS file. The script is called in npm run build, which in turn is invoked in make-mac, make-win32...etc.

Copy link
Owner

@stuartjamesmcnicholas stuartjamesmcnicholas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem when I run 'npm start', presumably a difference between linux and mac sed:
Stuarts-MacBook-Pro:baby-gru stuart$ npm start

moorhen@0.1.0 prestart
npm run transpile-ts-worker

moorhen@0.1.0 transpile-ts-worker
npx tsc --module es2015 --lib webworker --skipLibCheck public/baby-gru/CootWorker.ts && sed -i '/export {}/d' public/baby-gru/CootWorker.js

sed: 1: "public/baby-gru/CootWor ...": extra characters at the end of p command

@stuartjamesmcnicholas
Copy link
Owner

Need to add '.bu' sub-option to -i, I think

sed -i.bu '/export {}/d' public/baby-gru/CootWorker.js

@FilomenoSanchez
Copy link
Collaborator Author

Thanks indeed the sed shipped with linux is different than mac OS. I've now added -i.bu option as suggested.

@stuartjamesmcnicholas stuartjamesmcnicholas merged commit b1f97ea into stuartjamesmcnicholas:master Jun 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants