Coder Social home page Coder Social logo

akabekobeko / npm-cross-conf-env Goto Github PK

View Code? Open in Web Editor NEW
25.0 25.0 1.0 50 KB

To cross-platform the "config" and root variable reference of package.json in npm-scripts.

License: MIT License

JavaScript 1.05% TypeScript 98.95%
cross-platform environment-variables node npm npm-scripts package-json

npm-cross-conf-env's People

Contributors

akabekobeko avatar proudust avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

proudust

npm-cross-conf-env's Issues

Using ':' between two variables not working on Windows 10

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%"

Version 1.1.0 should have been a major version bump

  • Removing babel transpilation is a breaking change for anyone using node v4. In fact, this has broken our entire build system since we still use node v4.
  • Recommend unpublishing and re-releasing as v2.0.0.

Using a Config in a Redirect on Mac & Windows

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...",
},

Can't correctly identify the prefix

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

"config" is "conf" in package.json sample of README

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"
  }
}

Drop transpile by Babel

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.

Do not limit cleverness of this lib to conf-env variables only

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.