Skip to content

Commit

Permalink
Module Init
Browse files Browse the repository at this point in the history
  • Loading branch information
Arylo committed Nov 28, 2018
0 parents commit ea9fefb
Show file tree
Hide file tree
Showing 19 changed files with 7,363 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[*.{md,json,yml,yaml}]
trim_trailing_whitespace = false
indent_style = space
indent_size = 2
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
bower_components/

dist/
19 changes: 19 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
extends: "standard"
plugins:
- "standard"
- "promise"
- "node"
rules:
indent:
- "warn"
- 4
semi:
- "warn"
- "always"
semi-style:
- "warn"
- "last"
semi-spacing:
- "error"
- before: false
after: true
61 changes: 61 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# Node Export Files
/dist
6 changes: 6 additions & 0 deletions .huskyrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"hooks": {
"pre-commit": "lint-staged",
"pre-merge": "lint-staged"
}
}
22 changes: 22 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"linters": {
"./**/*.ts": [
"prettier --write --tab-width 4",
"npm run lint:typescript -- --fix",
"git add"
],
"./**/*.js": [
"prettier --write --tab-width 4",
"npm run lint:javascript -- --fix",
"git add"
],
"./**/*.{json,yaml,yml}": ["prettier --write --tab-width 2", "git add"],
"./.lintstagedrc": [
"prettier --write --tab-width 2 --parser json",
"git add"
]
},
"globOptions": {
"dot": true
}
}
31 changes: 31 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
language: node_js

node_js:
- "node"
- "lts/*"
- "8"
- "6"

before_script:
- "npm install nyc --global"

script:
- "npm run build"
- "nyc npm test"

after_success:
- "npm install coveralls@~3.0.0 --global"
- "nyc report --reporter=text-lcov | coveralls"

before_deploy:
- "npm run clean"
- "npm run build -- -P ./tsconfig.prod.json"

deploy:
skip_cleanup: true
provider: npm
email: "arylo.open+npm@gmail.com"
api_key: "${NPM_TOKEN}"
on:
branch: master
node_js: "node"
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"eslint.alwaysShowStatus": true,
"eslint.autoFixOnSave": true,
"eslint.enable": true,
"tslint.alwaysShowStatus": true,
"tslint.autoFixOnSave": true,
"tslint.enable": true
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Arylo Yeung

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.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# nodenv

Operating on the NODE_ENV environmental variable

[![node][NPM_URL]][NPM_HREF]
[![Travis][TRAVIS_URL]][TRAVIS_HREF]
[![Coveralls][COVERALLS_URL]][COVERALLS_HREF]
[![Known Vulnerabilities][SNYK_URL]][SNYK_HREF]
[![David][DAVID_URL]][DAVID_HREF]
[![Author][AUTHOR_URL]][AUTHOR_HREF]
[![license][LICENSE_URL]][LICENSE_HREF]

[NPM_URL]: https://img.shields.io/node/v/nodenv.svg?style=flat-square&maxAge=600
[NPM_HREF]: https://www.npmjs.com/package/nodenv
[TRAVIS_URL]: https://img.shields.io/travis/Arylo/nodenv/master.svg?style=flat-square&logo=travis&maxAge=600
[TRAVIS_HREF]: https://travis-ci.org/Arylo/nodenv
[COVERALLS_URL]: https://img.shields.io/coveralls/github/Arylo/nodenv/master.svg?style=flat-square&maxAge=600
[COVERALLS_HREF]: https://coveralls.io/github/Arylo/nodenv
[SNYK_URL]: https://snyk.io/test/github/Arylo/nodenv/badge.svg?style=flat-square&maxAge=600
[SNYK_HREF]: https://snyk.io/test/github/Arylo/nodenv
[DAVID_URL]: https://img.shields.io/david/Arylo/nodenv.svg?style=flat-square&maxAge=600
[DAVID_HREF]: https://github.com/Arylo/nodenv
[AUTHOR_URL]: https://img.shields.io/badge/Author-AryloYeung-blue.svg?style=flat-square&maxAge=7200
[AUTHOR_HREF]: https://github.com/arylo
[LICENSE_URL]: https://img.shields.io/github/license/Arylo/npm-project-init.svg?style=flat-square&maxAge=7200
[LICENSE_HREF]: https://opensource.org/licenses/MIT
5 changes: 5 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"experimentalDecorators": true
}
}
114 changes: 114 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/**
* process.env.NODE_ENV 不存在时,初始化为`env`
* @param env {string} [env="development"]
*/
export const init = (env = "development") => {
if (!process.env.NODE_ENV) {
set(env);
}
};

/**
* 获取process.env.NODE_ENV
*/
export const get = () => {
return process.env.NODE_ENV;
};

/**
* 设置process.env.NODE_ENV 为`env`
* @param env {string} [env="development"]
*/
export const set = (env = "development") => {
process.env.NODE_ENV = env.trim().toUpperCase();
};

/**
* 是否本地环境
* @returns boolean
*/
export const isLocal = () => {
let env = process.env.NODE_ENV;
if (typeof env !== "string") {
return false;
}
env = env.trim().toUpperCase();
return ["local"].map((item) => item.trim().toUpperCase()).indexOf(env) !== -1;
};

/**
* 是否测试环境
* @returns boolean
*/
export const isTest = () => {
let env = process.env.NODE_ENV;
if (typeof env !== "string") {
return false;
}
env = env.trim().toUpperCase();
return ["test"].map((item) => item.trim().toUpperCase()).indexOf(env) !== -1;
};

/**
* 是否开发环境
* @returns boolean
*/
export const isDev = () => {
let env = process.env.NODE_ENV;
if (typeof env !== "string") {
return false;
}
env = env.trim().toUpperCase();
return (
["dev", "develop", "development"]
.map((item) => item.trim().toUpperCase())
.indexOf(env) !== -1
);
};

/**
* 是否生产环境
* @returns boolean
*/
export const isProd = () => {
let env = process.env.NODE_ENV;
if (typeof env !== "string") {
return false;
}
env = env.trim().toUpperCase();
return (
["prod", "production"]
.map((item) => item.trim().toUpperCase())
.indexOf(env) !== -1
);
};

/**
* 是否Gray 环境
* @returns boolean
*/
export const isExp = () => {
let env = process.env.NODE_ENV;
if (typeof env !== "string") {
return false;
}
env = env.trim().toUpperCase();
return (
["exp", "experience"]
.map((item) => item.trim().toUpperCase())
.indexOf(env) !== -1
);
};

/**
* 是否Gray 环境
* @returns boolean
*/
export const isGray = () => {
let env = process.env.NODE_ENV;
if (typeof env !== "string") {
return false;
}
env = env.trim().toUpperCase();
return ["gray"].map((item) => item.trim().toUpperCase()).indexOf(env) !== -1;
};
Loading

0 comments on commit ea9fefb

Please sign in to comment.