Skip to content

update eslint config #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
"node": true
},
"extends": [
"eslint:recommended"
"standard"
],
"root": true,
"rules": {
"prefer-arrow-callback": [
"error"
],
"arrow-spacing": [
"error",
{
Expand Down Expand Up @@ -46,6 +49,9 @@
{
}
],
"no-tabs": [
"off"
],
"quotes": [
"error",
"single",
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';

const config = require('./lib/config')(process.argv);
Object.keys(config).forEach(key => {
process.env['npm_config_' + key] = config[key];
Expand Down
1 change: 0 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env node

'use strict';
const npmrc = require('./npmrc');
const env = require('./env');
const path = require('path');
Expand Down
6 changes: 3 additions & 3 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
function getConf(argv) {

function getConf (argv) {
const npmrc = {
registry: 'http://registry.npm.taobao.org',
disturl: 'http://npm.taobao.org/dist',
Expand All @@ -12,7 +12,7 @@ function getConf(argv) {
profiler_binary_host_mirror: '{mirrors}node-inspector/',
python_mirror: '{mirrors}python',
sass_binary_site: '{mirrors}node-sass',
sqlite3_binary_site: '{mirrors}sqlite3',
sqlite3_binary_site: '{mirrors}sqlite3'
};

argv.forEach(arg => {
Expand Down
13 changes: 6 additions & 7 deletions lib/env.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use strict';

const path = require('path');
const os = require('os');
const exec = (require('util').promisify || require('util.promisify'))(require('child_process').execFile);
const fs = require('fs-extra');

const MIRRORS = {
iojs:[
iojs: [
'IOJS_ORG_MIRROR',
'NODIST_IOJS_MIRROR',
'NVM_IOJS_ORG_MIRROR',
'NVMW_IOJS_ORG_MIRROR'
],
node:[
node: [
'NODEJS_ORG_MIRROR',
'NODIST_NODE_MIRROR',
'NVM_NODEJS_ORG_MIRROR',
Expand All @@ -22,7 +22,7 @@ const MIRRORS = {
]
};

function getMirrors(tmp) {
function getMirrors (tmp) {
return Array.prototype.concat.apply(
[],
Object.keys(MIRRORS).map(project => {
Expand All @@ -35,7 +35,7 @@ function getMirrors(tmp) {
);
}

function envForWin() {
function envForWin () {
const cmdTmpSetx = (key, url) => ['SETX', key, url];
const cmdTmpReg = (key, url) => ['REG', 'ADD', 'HKCU\\Environment', '/v', key, '/d', url, '/f'];

Expand All @@ -45,8 +45,7 @@ function envForWin() {
).then(getMirrors).then(cmds => Promise.all(cmds.map(cmdArgs => exec(cmdArgs[0], cmdArgs.slice(1)))));
}

function envInProfile() {

function envInProfile () {
// 环境变量信息转换为shell脚本
let sh = getMirrors((key, url) => `export ${key}=${url}`);

Expand Down
2 changes: 1 addition & 1 deletion lib/install.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';

const npmrc = require('./npmrc');
const env = require('./env');

Expand Down
6 changes: 3 additions & 3 deletions lib/npmrc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

const fs = require('fs-extra');
const config = require('./config');

function setConf(argv, configFile) {
function setConf (argv, configFile) {
const npmrc = config(argv);

// 读取npmrc文件
Expand Down Expand Up @@ -30,7 +30,7 @@ function setConf(argv, configFile) {
// 将文件中没有的配置项,追加到其末尾
Object.keys(npmrc).forEach(key => {
if (npmrc[key]) {
config.push( key + '=' + npmrc[key]);
config.push(key + '=' + npmrc[key]);
}
});

Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"description": "Mirrors in China about node.js",
"devDependencies": {
"eslint": "^4.13.1",
"eslint-config-standard": "^11.0.0-beta.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-node": "^5.2.1",
"eslint-plugin-promise": "^3.6.0",
"eslint-plugin-standard": "^3.0.1",
"mocha": "^4.0.1"
},
"homepage": "https://github.com/gucong3000/mirror-config-china#readme",
Expand All @@ -31,7 +36,7 @@
"scripts": {
"preinstall": "node -e \"require('util').promisify.call\" || npm i util.promisify",
"install": "node lib/install",
"pretest": "eslint lib/**/*.js *.js",
"pretest": "eslint lib test *.js",
"test": "mocha"
},
"version": "2.2.0"
Expand Down
File renamed without changes.
22 changes: 11 additions & 11 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';

const assert = require('assert');
const util = require('util');
if (!util.promisify) {
util.promisify = require('util.promisify');
}
const exec = util.promisify(require('child_process').execFile);

describe('environment variables', function() {
describe('environment variables', () => {
before(() => {
if (process.platform == 'win32') {
if (process.platform === 'win32') {
return exec('REG', ['QUERY', 'HKCU\\Environment']).then(regs => {
regs.stdout.replace(/^\s*(\w+)\s+REG_\w+\s*(.+)$/gm, (s, key, value) => {
process.env[key] = value;
Expand All @@ -17,31 +17,31 @@ describe('environment variables', function() {
}
});

it('NODEJS_ORG_MIRROR', function() {
it('NODEJS_ORG_MIRROR', () => {
assert.equal(process.env.NODEJS_ORG_MIRROR, 'https://npm.taobao.org/mirrors/node');
});

it('NVM_NODEJS_ORG_MIRROR', function() {
it('NVM_NODEJS_ORG_MIRROR', () => {
assert.equal(process.env.NVM_NODEJS_ORG_MIRROR, 'https://npm.taobao.org/mirrors/node');
});

it('IOJS_ORG_MIRROR', function() {
it('IOJS_ORG_MIRROR', () => {
assert.equal(process.env.IOJS_ORG_MIRROR, 'https://npm.taobao.org/mirrors/iojs');
});

it('NVM_IOJS_ORG_MIRROR', function() {
it('NVM_IOJS_ORG_MIRROR', () => {
assert.equal(process.env.NVM_IOJS_ORG_MIRROR, 'https://npm.taobao.org/mirrors/iojs');
});
});

describe('npm config', function() {
it('electron', function() {
describe('npm config', () => {
it('electron', () => {
assert.equal(process.env.npm_config_electron_mirror, 'https://npm.taobao.org/mirrors/electron/');
});
it('git4win_mirror', function() {
it('git4win_mirror', () => {
assert.equal(process.env.npm_config_git4win_mirror, 'https://npm.taobao.org/mirrors/git-for-windows');
});
it('python_mirror', function() {
it('python_mirror', () => {
assert.equal(process.env.npm_config_python_mirror, 'https://npm.taobao.org/mirrors/python');
});
});