This commit is contained in:
chrosey
2017-09-13 07:52:34 +02:00
parent a1f16c37f4
commit 2340b0226b
24621 changed files with 2912161 additions and 149 deletions
+4
View File
@@ -0,0 +1,4 @@
# CHANGELOG
The changelog is automatically updated using [semantic-release](https://github.com/semantic-release/semantic-release).
You can see it on the [releases page](../../releases).
+20
View File
@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2016 Kent C. Dodds
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+154
View File
@@ -0,0 +1,154 @@
# cross-env
Run scripts that set and use environment variables across platforms
[![Travis Build Status][build-badge]][build]
[![AppVeyor Build Status][win-build-badge]][win-build]
[![Code Coverage][coverage-badge]][coverage]
[![Dependencies][dependencyci-badge]][dependencyci]
[![version][version-badge]][package]
[![downloads][downloads-badge]][npm-stat]
[![MIT License][license-badge]][LICENSE]
[![All Contributors](https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome][prs-badge]][prs]
[![Donate][donate-badge]][donate]
[![Code of Conduct][coc-badge]][coc]
[![Roadmap][roadmap-badge]][roadmap]
[![Examples][examples-badge]][examples]
[![Watch on GitHub][github-watch-badge]][github-watch]
[![Star on GitHub][github-star-badge]][github-star]
[![Tweet][twitter-badge]][twitter]
## The problem
Most Windows command prompts will choke when you set environment variables with
`NODE_ENV=production` like that. (The exception is [Bash on Windows][win-bash],
which uses native Bash.) Similarly, there's a difference in how windows and
POSIX commands utilize environment variables. With POSIX, you use: `$ENV_VAR`
and on windows you use `%ENV_VAR%`.
## This solution
`cross-env` makes it so you can have a single command without worrying about
setting or using the environment variable properly for the platform. Just set it
like you would if it's running on a POSIX system, and `cross-env` will take care
of setting it properly.
## Prerequisites
- [NodeJS][node] version 4.0 or greater.
## Installation
This module is distributed via [npm][npm] which is bundled with [node][node] and
should be installed as one of your project's `devDependencies`:
```
npm install --save-dev cross-env
```
## Usage
I use this in my npm scripts:
```json
{
"scripts": {
"build": "cross-env NODE_ENV=production webpack --config build/webpack.config.js"
}
}
```
Ultimately, the command that is executed (using `cross-spawn`) is:
```
webpack --config build/webpack.config.js
```
The `NODE_ENV` environment variable will be set by `cross-env`
You can also split a command into several ones, or separate the environment
variables declaration from the actual command execution. You can do it this way:
```json
{
"scripts": {
"parentScript": "cross-env GREET=\"Joe\" npm run childScript",
"childScript": "echo Hello $GREET"
}
}
```
Where `childScript` holds the actual command to execute and `parentScript` sets
the environment variables to use. Then instead of run the childScript you run
the parent. This is quite useful for launching the same command with different
env variables or when the environment variables are too long to have everything
in one line.
## Inspiration
I originally created this to solve a problem I was having with my npm scripts in
[angular-formly][angular-formly]. This made it made contributing to the project
much easier for windows users.
## Other Solutions
- [`env-cmd`](https://github.com/toddbluhm/env-cmd) - Reads environment variables from a file instead
## Contributors
Thanks goes to these people ([emoji key][emojis]):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub>Kent C. Dodds</sub>](https://kentcdodds.com)<br />[💻](https://github.com/kentcdodds/cross-env/commits?author=kentcdodds) [📖](https://github.com/kentcdodds/cross-env/commits?author=kentcdodds) 🚇 [⚠️](https://github.com/kentcdodds/cross-env/commits?author=kentcdodds) | [<img src="https://avatars1.githubusercontent.com/u/499038?v=3" width="100px;"/><br /><sub>Ya Zhuang </sub>](https://zhuangya.me)<br />🔌 [📖](https://github.com/kentcdodds/cross-env/commits?author=zhuangya) | [<img src="https://avatars3.githubusercontent.com/u/3440094?v=3" width="100px;"/><br /><sub>James Harris</sub>](https://wopian.me)<br />[📖](https://github.com/kentcdodds/cross-env/commits?author=wopian) | [<img src="https://avatars1.githubusercontent.com/u/8941730?v=3" width="100px;"/><br /><sub>compumike08</sub>](https://github.com/compumike08)<br />[🐛](https://github.com/kentcdodds/cross-env/issues?q=author%3Acompumike08) [📖](https://github.com/kentcdodds/cross-env/commits?author=compumike08) [⚠️](https://github.com/kentcdodds/cross-env/commits?author=compumike08) | [<img src="https://avatars1.githubusercontent.com/u/2270425?v=3" width="100px;"/><br /><sub>Daniel Rodríguez Rivero</sub>](https://github.com/danielo515)<br />[🐛](https://github.com/kentcdodds/cross-env/issues?q=author%3Adanielo515) [💻](https://github.com/kentcdodds/cross-env/commits?author=danielo515) [📖](https://github.com/kentcdodds/cross-env/commits?author=danielo515) | [<img src="https://avatars2.githubusercontent.com/u/1508477?v=3" width="100px;"/><br /><sub>Jonas Keinholz</sub>](https://github.com/inyono)<br />[🐛](https://github.com/kentcdodds/cross-env/issues?q=author%3Ainyono) [💻](https://github.com/kentcdodds/cross-env/commits?author=inyono) [⚠️](https://github.com/kentcdodds/cross-env/commits?author=inyono) | [<img src="https://avatars3.githubusercontent.com/u/1656170?v=3" width="100px;"/><br /><sub>Hugo Wood</sub>](https://github.com/hgwood/blog)<br />[🐛](https://github.com/kentcdodds/cross-env/issues?q=author%3Ahgwood) [💻](https://github.com/kentcdodds/cross-env/commits?author=hgwood) [⚠️](https://github.com/kentcdodds/cross-env/commits?author=hgwood) |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors][all-contributors] specification. Contributions of any kind welcome!
> Note: this was added late into the project. If you've contributed to this
> project in any way, please make a pull request to add yourself to the list
> by following the instructions in the `CONTRIBUTING.md`
## LICENSE
MIT
[npm]: https://www.npmjs.com/
[node]: https://nodejs.org
[build-badge]: https://img.shields.io/travis/kentcdodds/cross-env.svg?style=flat-square
[build]: https://travis-ci.org/kentcdodds/cross-env
[win-build-badge]: https://img.shields.io/appveyor/ci/kentcdodds/cross-env.svg?style=flat-square
[win-build]: https://ci.appveyor.com/project/kentcdodds/cross-env
[coverage-badge]: https://img.shields.io/codecov/c/github/kentcdodds/cross-env.svg?style=flat-square
[coverage]: https://codecov.io/github/kentcdodds/cross-env
[dependencyci-badge]: https://dependencyci.com/github/kentcdodds/cross-env/badge?style=flat-square
[dependencyci]: https://dependencyci.com/github/kentcdodds/cross-env
[version-badge]: https://img.shields.io/npm/v/cross-env.svg?style=flat-square
[package]: https://www.npmjs.com/package/cross-env
[downloads-badge]: https://img.shields.io/npm/dm/cross-env.svg?style=flat-square
[npm-stat]: http://npm-stat.com/charts.html?package=cross-env&from=2016-04-01
[license-badge]: https://img.shields.io/npm/l/cross-env.svg?style=flat-square
[license]: https://github.com/kentcdodds/cross-env/blob/master/other/LICENSE
[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
[prs]: http://makeapullrequest.com
[donate-badge]: https://img.shields.io/badge/$-support-green.svg?style=flat-square
[donate]: http://kcd.im/donate
[coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square
[coc]: https://github.com/kentcdodds/cross-env/blob/master/other/CODE_OF_CONDUCT.md
[roadmap-badge]: https://img.shields.io/badge/%F0%9F%93%94-roadmap-CD9523.svg?style=flat-square
[roadmap]: https://github.com/kentcdodds/cross-env/blob/master/other/ROADMAP.md
[examples-badge]: https://img.shields.io/badge/%F0%9F%92%A1-examples-8C8E93.svg?style=flat-square
[examples]: https://github.com/kentcdodds/cross-env/blob/master/other/EXAMPLES.md
[github-watch-badge]: https://img.shields.io/github/watchers/kentcdodds/cross-env.svg?style=social
[github-watch]: https://github.com/kentcdodds/cross-env/watchers
[github-star-badge]: https://img.shields.io/github/stars/kentcdodds/cross-env.svg?style=social
[github-star]: https://github.com/kentcdodds/cross-env/stargazers
[twitter]: https://twitter.com/intent/tweet?text=Check%20out%20cross-env!%20https://github.com/kentcdodds/cross-env%20%F0%9F%91%8D
[twitter-badge]: https://img.shields.io/twitter/url/https/github.com/kentcdodds/cross-env.svg?style=social
[emojis]: https://github.com/kentcdodds/all-contributors#emoji-key
[all-contributors]: https://github.com/kentcdodds/all-contributors
[win-bash]: https://msdn.microsoft.com/en-us/commandline/wsl/about
[angular-formly]: https://github.com/formly-js/angular-formly
+10
View File
@@ -0,0 +1,10 @@
#!/usr/bin/env node
'use strict';
var _ = require('../');
var _2 = _interopRequireDefault(_);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
(0, _2.default)(process.argv.slice(2));
+32
View File
@@ -0,0 +1,32 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _isWindows = require('is-windows');
var _isWindows2 = _interopRequireDefault(_isWindows);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = commandConvert;
var envUseUnixRegex = /\$(\w+)/; // $my_var
var envUseWinRegex = /%(.*?)%/; // %my_var%
/**
* Converts an environment variable usage to be appropriate for the current OS
* @param {String} command Command to convert
* @returns {String} Converted command
*/
function commandConvert(command) {
var isWin = (0, _isWindows2.default)();
var envExtract = isWin ? envUseUnixRegex : envUseWinRegex;
var match = envExtract.exec(command);
if (match) {
command = isWin ? `%${match[1]}%` : `$${match[1]}`;
}
return command;
}
+75
View File
@@ -0,0 +1,75 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _crossSpawn = require('cross-spawn');
var _command = require('./command');
var _command2 = _interopRequireDefault(_command);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = crossEnv;
var envSetterRegex = /(\w+)=('(.+)'|"(.+)"|(.+))/;
function crossEnv(args) {
var _getCommandArgsAndEnv = getCommandArgsAndEnvVars(args),
_getCommandArgsAndEnv2 = _slicedToArray(_getCommandArgsAndEnv, 3),
command = _getCommandArgsAndEnv2[0],
commandArgs = _getCommandArgsAndEnv2[1],
env = _getCommandArgsAndEnv2[2];
if (command) {
var proc = (0, _crossSpawn.spawn)(command, commandArgs, { stdio: 'inherit', env });
process.on('SIGTERM', function () {
return proc.kill('SIGTERM');
});
process.on('SIGINT', function () {
return proc.kill('SIGINT');
});
process.on('SIGBREAK', function () {
return proc.kill('SIGBREAK');
});
process.on('SIGHUP', function () {
return proc.kill('SIGHUP');
});
proc.on('exit', process.exit);
return proc;
}
return null;
}
function getCommandArgsAndEnvVars(args) {
var envVars = getEnvVars();
var commandArgs = args.map(_command2.default);
var command = getCommand(commandArgs, envVars);
return [command, commandArgs, envVars];
}
function getCommand(commandArgs, envVars) {
while (commandArgs.length) {
var shifted = commandArgs.shift();
var match = envSetterRegex.exec(shifted);
if (match) {
envVars[match[1]] = match[3] || match[4] || match[5];
} else {
return shifted;
}
}
return null;
}
function getEnvVars() {
var envVars = Object.assign({}, process.env);
if (process.env.APPDATA) {
envVars.APPDATA = process.env.APPDATA;
}
return envVars;
}
+158
View File
@@ -0,0 +1,158 @@
{
"_args": [
[
{
"raw": "cross-env@^3.2.3",
"scope": null,
"escapedName": "cross-env",
"name": "cross-env",
"rawSpec": "^3.2.3",
"spec": ">=3.2.3 <4.0.0",
"type": "range"
},
"c:\\xampp\\htdocs\\laravel"
]
],
"_from": "cross-env@>=3.2.3 <4.0.0",
"_id": "cross-env@3.2.4",
"_inCache": true,
"_location": "/cross-env",
"_nodeVersion": "6.10.0",
"_npmOperationalInternal": {
"host": "packages-18-east.internal.npmjs.com",
"tmp": "tmp/cross-env-3.2.4.tgz_1489508640872_0.23967337561771274"
},
"_npmUser": {
"name": "kentcdodds",
"email": "kent@doddsfamily.us"
},
"_npmVersion": "3.10.10",
"_phantomChildren": {},
"_requested": {
"raw": "cross-env@^3.2.3",
"scope": null,
"escapedName": "cross-env",
"name": "cross-env",
"rawSpec": "^3.2.3",
"spec": ">=3.2.3 <4.0.0",
"type": "range"
},
"_requiredBy": [
"#DEV:/",
"/laravel-mix"
],
"_resolved": "https://registry.npmjs.org/cross-env/-/cross-env-3.2.4.tgz",
"_shasum": "9e0585f277864ed421ce756f81a980ff0d698aba",
"_shrinkwrap": null,
"_spec": "cross-env@^3.2.3",
"_where": "c:\\xampp\\htdocs\\laravel",
"author": {
"name": "Kent C. Dodds",
"email": "kent@doddsfamily.us",
"url": "http://kentcdodds.com/"
},
"bin": {
"cross-env": "dist/bin/cross-env.js"
},
"bugs": {
"url": "https://github.com/kentcdodds/cross-env/issues"
},
"config": {
"commitizen": {
"path": "node_modules/cz-conventional-changelog"
}
},
"dependencies": {
"cross-spawn": "^5.1.0",
"is-windows": "^1.0.0"
},
"description": "Run scripts that set and use environment variables across platforms",
"devDependencies": {
"all-contributors-cli": "^4.0.1",
"babel-cli": "^6.23.0",
"babel-core": "^6.23.1",
"babel-jest": "^19.0.0",
"babel-preset-env": "^1.2.0",
"babel-preset-stage-2": "^6.22.0",
"babel-register": "^6.23.0",
"codecov": "^1.0.1",
"commitizen": "^2.9.6",
"cz-conventional-changelog": "^2.0.0",
"eslint": "^3.17.0",
"eslint-config-kentcdodds": "^12.0.0",
"husky": "^0.13.2",
"jest-cli": "^19.0.2",
"lint-staged": "^3.3.1",
"nps": "^5.0.3",
"nps-utils": "^1.1.2",
"opt-cli": "^1.5.1",
"prettier-eslint-cli": "^3.1.2",
"semantic-release": "^6.3.6",
"validate-commit-msg": "^2.11.1"
},
"directories": {},
"dist": {
"shasum": "9e0585f277864ed421ce756f81a980ff0d698aba",
"tarball": "https://registry.npmjs.org/cross-env/-/cross-env-3.2.4.tgz"
},
"engines": {
"node": ">=4.0"
},
"eslintConfig": {
"extends": [
"kentcdodds",
"kentcdodds/jest"
],
"rules": {
"max-len": [
"error",
80
]
}
},
"files": [
"dist"
],
"gitHead": "c1a9ed0764fe1e88f2ba370b43c4ade21d536f60",
"homepage": "https://github.com/kentcdodds/cross-env#readme",
"jest": {
"testEnvironment": "node",
"coverageThreshold": {
"global": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
}
},
"keywords": [],
"license": "MIT",
"lint-staged": {
"*.js": [
"prettier-eslint --write",
"git add"
]
},
"main": "dist/index.js",
"maintainers": [
{
"name": "kentcdodds",
"email": "kent@doddsfamily.us"
}
],
"name": "cross-env",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/kentcdodds/cross-env.git"
},
"scripts": {
"commitmsg": "opt --in commit-msg --exec \"validate-commit-msg\"",
"precommit": "lint-staged && opt --in pre-commit --exec \"npm start validate\"",
"start": "nps",
"test": "nps test"
},
"version": "3.2.4"
}