2016-07-28 01:10:51 +00:00
|
|
|
"use strict";
|
2016-09-14 11:16:36 +00:00
|
|
|
var plugins = require("./npmts.plugins");
|
|
|
|
var paths = require("./npmts.paths");
|
|
|
|
var npmts_promisechain_1 = require("./npmts.promisechain");
|
|
|
|
var projectinfo_1 = require("projectinfo");
|
2016-07-28 01:10:51 +00:00
|
|
|
var checkProjectTypings = function (configArg) {
|
|
|
|
var done = plugins.Q.defer();
|
2016-09-02 15:42:41 +00:00
|
|
|
exports.projectInfo = new projectinfo_1.ProjectinfoNpm(paths.cwd);
|
2016-09-06 15:21:25 +00:00
|
|
|
if (typeof exports.projectInfo.packageJson.typings === 'undefined') {
|
2016-07-28 01:45:14 +00:00
|
|
|
plugins.beautylog.error("please add typings field to package.json");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
;
|
2016-07-28 01:10:51 +00:00
|
|
|
done.resolve(configArg);
|
|
|
|
return done.promise;
|
|
|
|
};
|
2016-07-28 01:45:14 +00:00
|
|
|
var depcheckOptions = {
|
|
|
|
ignoreBinPackage: false,
|
|
|
|
parsers: {
|
2016-09-06 15:21:25 +00:00
|
|
|
'*.ts': plugins.depcheck.parser.typescript
|
2016-07-28 01:45:14 +00:00
|
|
|
},
|
|
|
|
detectors: [
|
|
|
|
plugins.depcheck.detector.requireCallExpression,
|
|
|
|
plugins.depcheck.detector.importDeclaration
|
|
|
|
],
|
|
|
|
specials: [
|
|
|
|
plugins.depcheck.special.eslint,
|
|
|
|
plugins.depcheck.special.webpack
|
2016-09-06 15:21:25 +00:00
|
|
|
]
|
2016-07-28 01:45:14 +00:00
|
|
|
};
|
2016-07-28 01:10:51 +00:00
|
|
|
var checkDependencies = function (configArg) {
|
|
|
|
var done = plugins.Q.defer();
|
2016-09-18 11:08:31 +00:00
|
|
|
var depcheckOptionsMerged = plugins.lodash.merge(depcheckOptions, {
|
2016-07-28 01:10:51 +00:00
|
|
|
ignoreDirs: [
|
|
|
|
'test',
|
|
|
|
'dist',
|
|
|
|
'bower_components'
|
|
|
|
],
|
|
|
|
ignoreMatches: [
|
2016-09-06 15:21:25 +00:00
|
|
|
'@types/*',
|
|
|
|
'babel-preset-*'
|
2016-07-28 01:45:14 +00:00
|
|
|
]
|
|
|
|
});
|
|
|
|
plugins.depcheck(paths.cwd, depcheckOptionsMerged, function (unused) {
|
2016-07-28 01:10:51 +00:00
|
|
|
for (var _i = 0, _a = unused.dependencies; _i < _a.length; _i++) {
|
|
|
|
var item = _a[_i];
|
|
|
|
plugins.beautylog.warn("Watch out: unused dependency " + item.red);
|
|
|
|
}
|
|
|
|
;
|
2016-07-28 01:56:02 +00:00
|
|
|
for (var _b = 0, _c = unused.missing; _b < _c.length; _b++) {
|
2016-07-28 01:10:51 +00:00
|
|
|
var item = _c[_b];
|
|
|
|
plugins.beautylog.error("unused devDependency " + item.red);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
if (unused.missing.length > 0) {
|
2016-09-06 15:21:25 +00:00
|
|
|
plugins.beautylog.info('exiting due to missing dependencies in package.json');
|
2016-07-28 01:10:51 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2016-08-02 13:49:16 +00:00
|
|
|
for (var _d = 0, _e = unused.invalidFiles; _d < _e.length; _d++) {
|
2016-07-28 01:56:02 +00:00
|
|
|
var item = _e[_d];
|
2016-07-28 01:10:51 +00:00
|
|
|
plugins.beautylog.warn("Watch out: could not parse file " + item.red);
|
|
|
|
}
|
|
|
|
;
|
2016-08-02 13:49:16 +00:00
|
|
|
for (var _f = 0, _g = unused.invalidDirs; _f < _g.length; _f++) {
|
|
|
|
var item = _g[_f];
|
2016-07-28 01:10:51 +00:00
|
|
|
plugins.beautylog.warn("Watch out: could not parse directory " + item.red);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
done.resolve(configArg);
|
|
|
|
});
|
|
|
|
return done.promise;
|
|
|
|
};
|
2016-07-28 01:45:14 +00:00
|
|
|
var checkDevDependencies = function (configArg) {
|
|
|
|
var done = plugins.Q.defer();
|
2016-09-18 11:08:31 +00:00
|
|
|
var depcheckOptionsMerged = plugins.lodash.merge(depcheckOptions, {
|
2016-07-28 01:45:14 +00:00
|
|
|
ignoreDirs: [
|
|
|
|
'ts',
|
|
|
|
'dist',
|
|
|
|
'bower_components'
|
|
|
|
],
|
|
|
|
ignoreMatches: [
|
2016-09-06 15:21:25 +00:00
|
|
|
'@types/*',
|
|
|
|
'babel-preset-*'
|
2016-07-28 01:45:14 +00:00
|
|
|
]
|
|
|
|
});
|
|
|
|
plugins.depcheck(paths.cwd, depcheckOptionsMerged, function (unused) {
|
|
|
|
for (var _i = 0, _a = unused.devDependencies; _i < _a.length; _i++) {
|
|
|
|
var item = _a[_i];
|
|
|
|
plugins.beautylog.log("unused devDependency " + item.red);
|
|
|
|
}
|
|
|
|
;
|
2016-08-02 13:49:16 +00:00
|
|
|
for (var _b = 0, _c = unused.missing; _b < _c.length; _b++) {
|
2016-07-28 01:45:14 +00:00
|
|
|
var item = _c[_b];
|
2016-08-02 13:49:16 +00:00
|
|
|
plugins.beautylog.error("unused devDependency " + item.red);
|
2016-07-28 01:45:14 +00:00
|
|
|
}
|
|
|
|
;
|
2016-08-02 13:49:16 +00:00
|
|
|
if (unused.missing.length > 0) {
|
2016-09-06 15:21:25 +00:00
|
|
|
plugins.beautylog.info('exiting due to missing dependencies in package.json');
|
2016-08-02 13:49:16 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2016-07-28 01:45:14 +00:00
|
|
|
for (var _d = 0, _e = unused.invalidFiles; _d < _e.length; _d++) {
|
|
|
|
var item = _e[_d];
|
|
|
|
plugins.beautylog.warn("Watch out: could not parse file " + item.red);
|
|
|
|
}
|
|
|
|
for (var _f = 0, _g = unused.invalidDirs; _f < _g.length; _f++) {
|
|
|
|
var item = _g[_f];
|
|
|
|
plugins.beautylog.warn("Watch out: could not parse directory " + item.red);
|
|
|
|
}
|
|
|
|
done.resolve(configArg);
|
|
|
|
});
|
|
|
|
return done.promise;
|
|
|
|
};
|
2016-07-28 01:10:51 +00:00
|
|
|
var checkNodeVersion = function (configArg) {
|
|
|
|
var done = plugins.Q.defer();
|
|
|
|
done.resolve(configArg);
|
|
|
|
return done.promise;
|
|
|
|
};
|
|
|
|
exports.run = function (configArg) {
|
|
|
|
var done = plugins.Q.defer();
|
2016-09-06 15:21:25 +00:00
|
|
|
npmts_promisechain_1.npmtsOra.text('running project checks...');
|
|
|
|
checkProjectTypings(configArg)
|
|
|
|
.then(checkDependencies)
|
|
|
|
.then(checkDevDependencies)
|
|
|
|
.then(checkNodeVersion)
|
|
|
|
.then(done.resolve);
|
2016-07-28 01:10:51 +00:00
|
|
|
return done.promise;
|
|
|
|
};
|