1.5.0 • Published 5 years ago
platform-specific-env v1.5.0
Platform Specific Env
Use case
Sometimes you find yourself in need of platform specific environment variables. But still you want to specify the variable in the repository, like .npmrc
.
Example
Tools, like Cypress, may need different binaries depending on current platform. This tool will translate environment variables:
export CYPRESS_INSTALL_BINARY___linux='https://this.is/the/linux/binary.zip'
export CYPRESS_INSTALL_BINARY___win32='https://this.is/the/win32/binary.zip'
Like this:
Supported platforms: (aix|darwin|freebsd|linux|openbsd|sunos|win32)
Current platform: linux
Setting CYPRESS_INSTALL_BINARY to value of CYPRESS_INSTALL_BINARY___linux
Setting new platform specific variables:
CYPRESS_INSTALL_BINARY = https://this.is/the/linux/binary.zip
Usge
It can be used as a library, or just put it in scripts
and have it translate platform specific variables before installing packages.
export WHATEVER_VARIABLE___linux='https://this.is/the/linux/binary.zip'
Library
import { setPlatformSpecificEnvironment } from "platform-specific-env/lib";
setPlatformSpecificEnvironment(process);
console.log(
"Platform specific variable: " + process.env.WHATEVER_VARIABLE
);
Scripts
...
"scripts": {
"myscript": "npx platform-specific-env node consolelog.js"
},
...
console.log("WHATEVER_VARIABLE is: " + process.env.WHATEVER_VARIABLE);
WHATEVER_VARIABLE is: https://this.is/the/linux/binary.zip
See the example
folders in the Git repository.