charlesguse / run-script-os

run-script-os will let you use OS specific operations in npm scripts without specifying which OS you are on. It's not magic though... you still have to write OS specific scripts.
MIT License
197 stars 30 forks source link

Support :default platform #3

Closed mgkeeley closed 5 years ago

mgkeeley commented 6 years ago

Could you add a feature where you can specify :default, meaning "all other platforms". e.g.

"foo": "run-script-os",
"foo:win32": "echo windows",
"foo:darwin": "echo mac",
"foo:default": "echo everything else",
charlesguse commented 6 years ago

Hi @mgkeeley ! Can you elaborate a bit on your use-case? For example, when creating this, I did it with the use case of needing to be able to run foo on Windows or Linux interchangeably so that I could develop on Windows and both test and run CI/CD on Linux.

Do you (or anyone else reading this) have a use-case where you expect to run the npm scripts on the the different platforms supported here?

The current way of doing this would be to add:

"foo:aix:freebsd:linux:openbsd:sunos": "echo everything else"

I agree that adding :default would simplify that but I would like to understand more before adding more features.

mgkeeley commented 6 years ago

As you say, it is to simplify the syntax, and also so that it might automatically support new platforms if they are added in the future. e.g. `"foo:default": "echo Does not run on this platform.". Sometimes it would also be for "linux-like" systems; the script might run on everything but windows for example. Also it means I don't have to look up the documentation every time to find out that long list!

charlesguse commented 6 years ago

Do you (or anyone else reading this) actually run it against all of those different OSes? I agree that needing to look up the documentation every time to find out the list is less than ideal. When I use it, I only add Windows and Linux because I know those are my two OSes I am going to be using my projects in.

I generally expected people to only use the Windows, and Mac/Linux as the two options in the package.json. From that perspective, adding :default wouldn't be that useful, and also could cause some confusion if used in a system where one of the commands don't line up for one of the other OSes.

(thinking outloud here) I don't know enough about aix, freebsd, openbsd, or sunos to know they don't follow the same Linux-like commands where a :default will just work with them. If they do, why does NPM differentiate them but not others? I should go ask Stack Overflow :D

Part of the reason I want to understand this so thoroughly is because if I am going to add mappings like :default, :linuxlike (probably can find a better name :)), I would also add mappings so you could say :macos instead of :darwin.

mgkeeley commented 6 years ago

I certainly don't run it against all. Windows, MacOS, CentOS, Ubuntu. Maybe :linuxlike (or :posix? :unix? :nix?) is a more descriptive alternative, and better than using :default when targeting linux-like systems. There is also :android coming up now! However, I think :default is also useful for the "i don't support this platform" error case. I also like the :macos alias.

*BSD has very similar commands to linux, but kernel is not binary compatible from memory, I guess that is why they are separated out.

See also this project: https://github.com/Lewiscowles1986/node-platform that has a similar idea.

charlesguse commented 6 years ago

Thanks for the info @mgkeeley. If you have an approach and would like this sooner rather than later, I would be happy to take a pull request.

I will work towards something over time but I can't guarantee a deadline. I am very honored people are using this and very grateful to you for taking the time creating, and responding to this issue but don't currently have a regular development cycle against this.

I will post in here when this feature gets added.

mathiscode commented 5 years ago

I have submitted this feature in PR #19