Skip to content

Commit 06363d7

Browse files
committed
feat: 去掉 stylelint 以提升安装速度
1 parent 8f83d47 commit 06363d7

File tree

9 files changed

+26
-351
lines changed

9 files changed

+26
-351
lines changed

lib/commands/lint.js

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@ exports.usage = '代码质量检测';
99
exports.setOptions = function (optimist) {
1010
optimist.alias('d', 'dir');
1111
optimist.describe('d', '检测特定目录/文件');
12-
optimist.alias('t', 'type');
13-
optimist.describe('t', '检测特定目录/文件');
1412
};
1513

1614
exports.run = function (options) {
1715
var project = this.project,
18-
dir = options.d || options.dir,
19-
lintType = options.t || options.type;
16+
dir = options.d || options.dir;
2017

2118
var isGoingToContinue = true;
2219

@@ -38,9 +35,9 @@ exports.run = function (options) {
3835
process.exit(1);
3936
}
4037

41-
var installCmd = 'npm i eslint@2.13.1 stylelint@6.9.0 --registry https://registry.npm.taobao.org';
38+
var installCmd = 'npm i eslint@2.13.1 --registry https://registry.npm.taobao.org';
4239
try {
43-
log('intalling eslint & stylelint ...');
40+
log('intalling eslint...');
4441
log(child_process.execSync(installCmd, { cwd: sysPath.resolve(__dirname, '../../'), encoding: 'utf8' }));
4542
} catch (e) {
4643
error(e);
@@ -49,23 +46,11 @@ exports.run = function (options) {
4946
});
5047
}
5148

52-
// lint type
53-
var lintFileTypes = ['js', 'css'];
54-
if (lintType) {
55-
if (lintFileTypes.indexOf(lintType) > -1) {
56-
lintFileTypes = [lintType];
57-
} else {
58-
error('lintType只能为"js"或"css"');
59-
process.exit(1);
60-
}
61-
}
62-
var lintFuncs = lintFileTypes.map(function (lintFileTypeItem) {
63-
return lintFileTypeItem === 'js' ? function (callback) {
64-
return project.lint(dir, callback);
65-
} : function (callback) {
66-
return project.lintCss(dir, callback);
67-
};
68-
});
49+
var lintFuncs = [
50+
// 暂时只 lint js
51+
function (callback) {
52+
project.lint(dir, callback);
53+
}];
6954

7055
if (isGoingToContinue) {
7156
async.series(lintFuncs, function (err, results) {

lib/config/stylelint.json

Lines changed: 0 additions & 98 deletions
This file was deleted.

lib/models/Project.js

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ var Project = function () {
3434
this.middlewares = [];
3535
this.packCallbacks = [];
3636
this.eslintConfig = require('../config/eslint.json');
37-
this.stylelintConfig = require('../config/stylelint.json');
3837
this.configFile = globby.sync(['ykit.*.js', 'ykit.js'], {
3938
cwd: this.cwd
4039
})[0] || '';
@@ -62,11 +61,6 @@ var Project = function () {
6261
value: function setEslintConfig(projectEslintConfig) {
6362
extend(true, this.eslintConfig, projectEslintConfig);
6463
}
65-
}, {
66-
key: 'setStylelintConfig',
67-
value: function setStylelintConfig(projectStylelintConfig) {
68-
extend(true, this.stylelintConfig, projectStylelintConfig);
69-
}
7064
}, {
7165
key: 'readConfig',
7266
value: function readConfig(options) {
@@ -84,13 +78,11 @@ var Project = function () {
8478
setSync: this.config.setSync.bind(this.config),
8579
setCommands: this.setCommands.bind(this),
8680
setEslintConfig: this.setEslintConfig.bind(this),
87-
setStylelintConfig: this.setStylelintConfig.bind(this),
8881
config: this.config.getConfig(),
8982
commands: this.commands,
9083
middlewares: this.middlewares,
9184
packCallbacks: this.packCallbacks,
9285
eslintConfig: this.eslintConfig,
93-
stylelintConfig: this.stylelintConfig,
9486
applyMiddleware: this.config.applyMiddleware.bind(this.config),
9587
env: this._getCurrentEnv() // 默认为本地环境,
9688
},
@@ -120,7 +112,6 @@ var Project = function () {
120112
}
121113

122114
extend(true, userConfig.eslintConfig, Manager.loadEslintConfig(modulePath));
123-
extend(true, userConfig.stylelintConfig, Manager.loadStylelintConfig(modulePath));
124115
_this.ignores.push(Manager.loadIgnoreFile(modulePath));
125116

126117
if (fs.existsSync(modulePath)) {
@@ -137,7 +128,6 @@ var Project = function () {
137128
var _module2 = require(item.path);
138129

139130
extend(true, userConfig.eslintConfig, Manager.loadEslintConfig(item.path));
140-
extend(true, userConfig.stylelintConfig, Manager.loadStylelintConfig(item.path));
141131
_this.ignores.push(Manager.loadIgnoreFile(item.path));
142132

143133
if (_module2 && _module2.config) {
@@ -162,7 +152,6 @@ var Project = function () {
162152

163153
var configMethod = this._requireUncached(sysPath.join(this.cwd, this.configFile));
164154
extend(true, userConfig.eslintConfig, Manager.loadEslintConfig(this.cwd));
165-
extend(true, userConfig.stylelintConfig, Manager.loadStylelintConfig(this.cwd));
166155
this.ignores.push(Manager.loadIgnoreFile(this.cwd));
167156

168157
if (configMethod) {
@@ -296,33 +285,6 @@ var Project = function () {
296285

297286
callback(null, !report.errorCount);
298287
}
299-
}, {
300-
key: 'lintCss',
301-
value: function lintCss(dir, callback) {
302-
var stylelint = require('stylelint');
303-
304-
warn('Linting CSS Files ...');
305-
306-
var config = {
307-
config: this.stylelintConfig,
308-
files: this._getLintFiles(dir, 'css'),
309-
syntax: 'scss',
310-
formatter: 'verbose'
311-
};
312-
313-
if (config.files.length) {
314-
stylelint.lint(config).then(function (data) {
315-
if (data.errored) {
316-
error(data.output);
317-
}
318-
callback(null, !data.errored);
319-
}).catch(function () {
320-
callback(true);
321-
});
322-
} else {
323-
callback(null, true);
324-
}
325-
}
326288
}, {
327289
key: 'pack',
328290
value: function pack(opt, callback) {
@@ -419,8 +381,6 @@ var Project = function () {
419381
if (opt.lint) {
420382
async.series([function (callback) {
421383
return _this4.lint(callback);
422-
}, function (callback) {
423-
return _this4.lintCss(callback);
424384
}], function (err, results) {
425385
if (!err) {
426386
if (results[0] && results[1]) {
@@ -501,14 +461,13 @@ var Project = function () {
501461
}, {
502462
key: '_isCacheDirExists',
503463
value: function _isCacheDirExists(cwd) {
504-
var isCacheExists = void 0,
505-
isYkitCacheExists = void 0;
464+
var isCacheExists = void 0;
506465

507466
try {
508467
fs.statSync(sysPath.join(cwd, '.ykit_cache'));
509468
return sysPath.join(cwd, '.ykit_cache');
510469
} catch (e) {
511-
isYkitCacheExists = false;
470+
// do nothing
512471
}
513472

514473
try {

lib/modules/manager.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,16 @@ var Project = require('../models/Project.js'),
4343
}
4444
},
4545
loadConfigFile = function loadConfigFile(filePath) {
46+
// eslint-disable-line
4647
var config = void 0;
4748

4849
switch (sysPath.extname(filePath)) {
4950
case '.js':
5051
config = loadJSConfigFile(filePath);
51-
if (file.configName) {
52-
config = config.configs[file.configName];
53-
}
52+
// FIXME
53+
// if (file && file.configName) {
54+
// config = config.configs[file.configName];
55+
// }
5456
break;
5557

5658
case '.json':
@@ -120,7 +122,7 @@ var writeRC = exports.writeRC = function (rc) {
120122
fs.writeFileSync(YKIT_RC, JSON.stringify(rc, {}, 4), 'UTF-8');
121123
};
122124

123-
var reloadRC = exports.reloadRC = function () {
125+
exports.reloadRC = function () {
124126
var root = childProcess.execSync('npm root -g', {
125127
encoding: 'utf-8'
126128
}).split('\n')[0],
@@ -152,8 +154,6 @@ var reloadRC = exports.reloadRC = function () {
152154
return rc;
153155
};
154156

155-
// lint config
156-
157157
exports.loadEslintConfig = function (path) {
158158
try {
159159
var eslintConfigFile = require('eslint/lib/config/config-file.js');
@@ -165,13 +165,6 @@ exports.loadEslintConfig = function (path) {
165165
}
166166
};
167167

168-
exports.loadStylelintConfig = function (path) {
169-
var stylelintConfPath = globby.sync(['.stylelintrc.js', '.stylelintrc.yaml', '.stylelintrc.yml', '.stylelintrc.json', '.stylelintrc', 'package.json'], {
170-
cwd: path
171-
})[0];
172-
return stylelintConfPath ? loadConfigFile(sysPath.join(path, stylelintConfPath)) : {};
173-
};
174-
175168
exports.loadIgnoreFile = function (path) {
176169
var ignoreFile = sysPath.join(path, '.lintignore');
177170
return fs.existsSync(ignoreFile) ? fs.readFileSync(ignoreFile, 'UTF-8') : '';

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"serve-index": "^1.8.0",
4343
"serve-static": "^1.11.1",
4444
"style-loader": "^0.13.1",
45-
"stylelint": "^6.9.0",
4645
"through2": "^2.0.1",
4746
"webpack": "^1.13.1",
4847
"webpack-dev-middleware": "^1.6.1",

src/commands/lint.js

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@ exports.usage = '代码质量检测';
99
exports.setOptions = (optimist) => {
1010
optimist.alias('d', 'dir');
1111
optimist.describe('d', '检测特定目录/文件');
12-
optimist.alias('t', 'type');
13-
optimist.describe('t', '检测特定目录/文件');
1412
};
1513

1614
exports.run = function (options) {
1715
let project = this.project,
18-
dir = options.d || options.dir,
19-
lintType = options.t || options.type;
16+
dir = options.d || options.dir;
2017

2118
let isGoingToContinue = true;
2219

@@ -38,9 +35,9 @@ exports.run = function (options) {
3835
process.exit(1);
3936
}
4037

41-
const installCmd = 'npm i eslint@2.13.1 stylelint@6.9.0 --registry https://registry.npm.taobao.org';
38+
const installCmd = 'npm i eslint@2.13.1 --registry https://registry.npm.taobao.org';
4239
try {
43-
log('intalling eslint & stylelint ...');
40+
log('intalling eslint...');
4441
log(child_process.execSync(installCmd, {cwd: sysPath.resolve(__dirname, '../../'), encoding: 'utf8'}));
4542
} catch (e) {
4643
error(e);
@@ -49,21 +46,12 @@ exports.run = function (options) {
4946
});
5047
}
5148

52-
// lint type
53-
let lintFileTypes = ['js', 'css'];
54-
if(lintType) {
55-
if(lintFileTypes.indexOf(lintType) > -1) {
56-
lintFileTypes = [lintType];
57-
} else {
58-
error('lintType只能为"js"或"css"');
59-
process.exit(1);
49+
const lintFuncs = [
50+
// 暂时只 lint js
51+
function(callback) {
52+
project.lint(dir, callback);
6053
}
61-
}
62-
const lintFuncs = lintFileTypes.map((lintFileTypeItem) => {
63-
return lintFileTypeItem === 'js'
64-
? (callback) => project.lint(dir, callback)
65-
: (callback) => project.lintCss(dir, callback);
66-
});
54+
];
6755

6856
if(isGoingToContinue) {
6957
async.series(lintFuncs, (err, results) => {

0 commit comments

Comments
 (0)