akabekobeko / npm-cross-conf-env Goto Github PK
View Code? Open in Web Editor NEWTo cross-platform the "config" and root variable reference of package.json in npm-scripts.
License: MIT License
To cross-platform the "config" and root variable reference of package.json in npm-scripts.
License: MIT License
Those are not working under windows 10
"var": "cross-conf-env echo npm_package_version:npm_package_version"
"var": "cross-conf-env echo $npm_package_version:$npm_package_version"
npm run var
0.0.1:npm_package_version
This will work:
"var": "cross-conf-env echo %npm_package_version%:%npm_package_version%"
Adopt JavaScript Standard Style as coding rule. Also add a check by ESLint.
&
is converted into a &
in and is contained site of npm.
cross-conf-env
has worked great for me when the command is self-contained, but if I try to redirect the output to a file that uses a conf it doesn't seem to work on Mac and Windows.
Other than creating a separate custom node script that manages all of that, is there something I am missing or some special syntax to do what I'm looking for?
"scripts": {
"//": "The following only works on mac using $",
"build:worksOnMac": "mustache data.json src/index.mustache.js | uglifyjs > public/$npm_package_version/index.min.js",
"//": "The following only work on windows using %",
"build:worksOnWindows": "mustache data.json src/index.mustache.js | uglifyjs > public/%npm_package_version%/index.min.js",
"//": "The following should work on both, but since the config is in the redirect it doesn't not get updated",
"build:doesNotWork": "cross-conf-env mustache data.json src/index.mustache.js | uglifyjs > public/$npm_package_version/index.min.js",
"//": "Any other ideas of what to try or CLI helpers to use?",
"//": "NOTE: I know I could write a custom node program, but I'm trying to see if there is another way",
"build:anythingWorkInBoth": "echo I surely hope so...",
},
{
"files": [
"bin",
"lib",
"index.js"
]
}
refs: #22
This file is deleted because it is unnecessary.
To put the arguments that have been specified in the npm run
to npm_config
.
The active Node.js LTS is v12, so update the lower bound.
When the X to contain the Y may be Y in the X is replaced.
npm-scripts:
{
"config": {
"app": "MyApp",
"app_mode": "Test",
"appMode": "Test2"
},
"scripts": {
"start": "cross-conf-env echo npm_package_config_app npm_package_config_app_mode npm_package_config_appMode"
}
}
Expected:
$ npm start
MyApp Test Test2
Actual:
$ npm start
MyApp MyApp_mode MyAppMode
This npm is appropriate to install in npm-scripts only a so devDependencies.
README and more.
Correctly is config.
{
"name": "sample",
"version": "1.0.0",
"config": {
"app": "MyApp"
},
"scripts": {
"var": "cross-config-env echo npm_package_config_app npm_package_version",
"var:bash": "cross-config-env echo $npm_package_config_app $npm_package_version",
"var:win": "cross-config-env echo %npm_package_config_app% %npm_package_version%"
},
"dependencies": {
"cross-conf-env": "^1.0.0"
}
}
Move the setting to the esdoc
property of package.json
.
ES 2015 support improved in Node v 6 and later. Since this npm uses only the function of ES2015, transpile by Babel is unnecessary.
However, as import
is not supported, it is necessary to change to require
.
The active Node.js LTS is v14, so update the lower bound.
package.json:
{
"version": "1.0.0",
"config": {
"app": "myapp"
},
"scripts": {
"var": "cross-conf-env echo npm_package_config_app-npm_package_version"
},
"devDependencies": {
"cross-conf-env": "^1.0.4"
}
}
expected:
$ npm run ver
myapp-1.0.0
npm ERR! Failed to parse json
npm ERR! Unexpected token '\n' at 17:45
npm ERR! "task:a": "npm-run-all task:a1 task:a2".
npm ERR!
I believe the only thing that prevents us from using env variables in npm scripts is that normal OSs use $[A-za-z0-9_-]+
and Windows uses %[A-za-z0-9_-]+%
.
If your library wasn't limited to config variables only but would look for these patterns and adjust them according to the detected OS then it would solve the problem of cross-os replacment of environment variables in npm scripts, which is dreamt feature for many people, including me.
Is it doable? Is there any problem I can't see with such solution?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.