the-road-to-graphql / fullstack-apollo-express-postgresql-boilerplate

💥 A sophisticated GraphQL with Apollo, Express and PostgreSQL boilerplate project.
https://roadtoreact.com
MIT License
1.21k stars 263 forks source link

npm run scripts on Windows #44

Open pmosconi opened 5 years ago

pmosconi commented 5 years ago

npm run scripting syntax is slightly different on Windows due to the underlying shell being used. Usually the default is cmd.exe (the old DOS), even though it is possible to override the default.

The key changes required for the testing scripts (p. 315 of the book) are: "test-server": "set TEST_DATABASE=mytestdatabase&& npm start", "test": "mocha --require @babel/register src/**/*.spec.js" In test-server, there is no space between the variable's value and && on purpose otherwise trailing spaces would be added to the value (https://stackoverflow.com/questions/25112510/how-to-set-environment-variables-from-within-package-json-node-js#comment58812038_27090755). Note that TEST_DATABASE=mytestdatabase && npm start will not work in Linux because && starts another shell where the variable is not defined.

In test, single quote are omitted otherwise * are not expanded, or at leasr I think.

Unfortunately there is no way to define cross environment scripts without using external packages.

rwieruch commented 5 years ago

Thanks for reporting this @pmosconi Need to check how to fix this! Any help on it is very much appreciated if anyone else runs into this 👍

pmosconi commented 5 years ago

For simple scripts the best solution is using cross-env: "test-server": "cross-env TEST_DATABASE=mytestdatabase npm start" I'm not sure about quote expansion though.

tmstani23 commented 5 years ago

Pmosconi's solution worked for me on Windows. I think the book should be updated to note this for Windows users as I spent about 2 hours trying to figure out what was going on before coming here. I am guessing there are many readers who have been stuck at this part of the book.

rwieruch commented 5 years ago

Thank you for confirming @tmstani23 Sorry that you had to go through this trouble ... It's always difficult for me to align all operating systems on a topic. I will fix it!

In the end, did you use

"test-server": "set TEST_DATABASE=mytestdatabase&& npm start", 
"test": "mocha --require @babel/register src/**/*.spec.js"

or

"test-server": "cross-env TEST_DATABASE=mytestdatabase npm start"

or both and both worked for you?

Thank you again!

tmstani23 commented 5 years ago

I used:

"test-server": "set TEST_DATABASE=mytestdatabase&& npm start", "test": "mocha --require @babel/register src/*/.spec.js"

I haven't tried cross-env. I'm wondering if that's a library or a part of node? Thanks for the response. I've really been enjoying the book so far and learning so much!

Regards, Timothy Stanislav

On Tue, Jan 15, 2019 at 7:02 PM Robin Wieruch notifications@github.com wrote:

Thank you for confirming @tmstani23 https://github.com/tmstani23 Sorry that you had to go through this trouble ... It's always difficult for me to align all operating systems on a topic. I will fix it!

In the end, did you use

"test-server": "set TEST_DATABASE=mytestdatabase&& npm start", "test": "mocha --require @babel/register src/*/.spec.js"

or

"test-server": "cross-env TEST_DATABASE=mytestdatabase npm start"

or both and both worked for you?

Thank you again!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/the-road-to-graphql/fullstack-apollo-express-postgresql-boilerplate/issues/44#issuecomment-454611212, or mute the thread https://github.com/notifications/unsubscribe-auth/AG3iALTdqL_Lr8PKfmIcucOP4zTRF1HXks5vDno_gaJpZM4Zl2ph .

-- Timothy Stanislav Cell:507-261-9867 Email:tmstani23@gmail.com

pmosconi commented 5 years ago

cross-env is an npm module you have to add to your dev dependencies.

paolo

Da: Tim Stanislav notifications@github.com Inviato: mercoledì 16 gennaio 2019 14:38 A: the-road-to-graphql/fullstack-apollo-express-postgresql-boilerplate fullstack-apollo-express-postgresql-boilerplate@noreply.github.com Cc: Paolo Mosconi pmosconi@gmail.com; Mention mention@noreply.github.com Oggetto: Re: [the-road-to-graphql/fullstack-apollo-express-postgresql-boilerplate] npm run scripts on Windows (#44)

I used:

"test-server": "set TEST_DATABASE=mytestdatabase&& npm start", "test": "mocha --require @babel/register src/*/.spec.js"

I haven't tried cross-env. I'm wondering if that's a library or a part of node? Thanks for the response. I've really been enjoying the book so far and learning so much!

Regards, Timothy Stanislav

On Tue, Jan 15, 2019 at 7:02 PM Robin Wieruch <notifications@github.com mailto:notifications@github.com > wrote:

Thank you for confirming @tmstani23 https://github.com/tmstani23 Sorry that you had to go through this trouble ... It's always difficult for me to align all operating systems on a topic. I will fix it!

In the end, did you use

"test-server": "set TEST_DATABASE=mytestdatabase&& npm start", "test": "mocha --require @babel/register src/*/.spec.js"

or

"test-server": "cross-env TEST_DATABASE=mytestdatabase npm start"

or both and both worked for you?

Thank you again!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/the-road-to-graphql/fullstack-apollo-express-postgresql-boilerplate/issues/44#issuecomment-454611212, or mute the thread https://github.com/notifications/unsubscribe-auth/AG3iALTdqL_Lr8PKfmIcucOP4zTRF1HXks5vDno_gaJpZM4Zl2ph .

-- Timothy Stanislav Cell:507-261-9867 Email:tmstani23@gmail.com

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/the-road-to-graphql/fullstack-apollo-express-postgresql-boilerplate/issues/44#issuecomment-454781360 , or mute the thread https://github.com/notifications/unsubscribe-auth/AG8cIoaSYry6QtcdpVJDRcsfgEqCVkc9ks5vDysbgaJpZM4Zl2ph . https://github.com/notifications/beacon/AG8cIqB2CMV89-G98ZA-VSgWCN4hfqnTks5vDysbgaJpZM4Zl2ph.gif