Good vs. Evil

  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

duckfan77

Popular Member
Mar 18, 2013
80
683
118
66 They really are. I've got about a month left before I'm back to Uni, so I'm getting as much reading in as I can
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
65 why did I choose to use react+typescript for a project I do for someone? The amount of steps it takes to "compile" it every time I want to test is just.... annoying >_<

The first part is typescripts tooling. This is purely to go from Typescript to javascript that works in as many browsers as possible.
We start with the linter. This makes sure your code follows some standards. So far, so good.
We then compile to JS. This is needed as browsers are stupid and only can run Javascript. Again, so far so good.
I think this JS then gets compiled again to an older standard of JS. I'm not sure about that though.

For normal projects, this is it. The generated JS is placed somewhere where your webserver can read it and you are a simple refresh away to see your code in action.
However, I'm using cordova. Which, is not just a simple webserver. So..... more steps are needed.

It now combines your new awesome content that has been written to run on all its platforms with any code that you have written for specific platforms. That way, if method x works on all but 1 platform you can do method y specifically on just that platform.
After that, it either needs to boot up its own webserver hosting the combined code, "compile" it to an app for android or IOS, an .exe for windows or a binary for linux depending on what you platform you want to test it on.
After this, it needs to run this program. In my case, as I am using it foremost to create a web application it opens a new tab in my default browser pointing to the index page.


Note how it opens a tab in your default browser. As far as I know, this can not be turned off. So, if like me you use another browser to actually develop the new tabs won't open there. Additionally, YOU CAN'T EVEN REFRESH PROPERLY! Because unlike servers like apache or nginx the server that cordova uses has no way to set custom routes.

Meaning that an url like /users/123 will always make it try to load a file in the users folder called 123. Making it impossible to use the url as a way to store at which page you are.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
66 it luckily is just contained in 1 command.
Code:
npm run start:browser
It is however, rather slow
 

duckfan77

Popular Member
Mar 18, 2013
80
683
118
67 My schedule isn't consistent week to week, I get what hours I get assigned. It's not really a full time job.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
68 This happened some time ago, but I changed the start:browser script.
Now, cordova compiles it to run in the browser and I automatically move the result to my own apache server.

There is a bit of a hack needed though, as the cp command behaves differently if the folder I need to move it to already exist or not. My fix is to just add a rm command before that though that does mean that if the copy ever fails th rm command will fail the next time I run the script. This means I either need to manually make a folder for rm to delete or temporary take it out before the start:browser script will run again :(

Oh well, at least it works and I won't have to deal with stupid tabs opening every single time again. Now, the only thing left to do is make some kind of watcher so every time I save something it will at least try and compile my code.
 

duckfan77

Popular Member
Mar 18, 2013
80
683
118
69 Every save? Or is this different than standard file saving. I frequently end up saving things that aren't functional, just because I'd prefer not to lose content in the event of a crash