2016-07-28 01:10:51 +00:00
|
|
|
"use strict";
|
2016-09-22 21:23:16 +00:00
|
|
|
const plugins = require("./npmts.plugins");
|
|
|
|
const paths = require("./npmts.paths");
|
|
|
|
const npmts_promisechain_1 = require("./npmts.promisechain");
|
|
|
|
const projectinfo_1 = require("projectinfo");
|
|
|
|
let checkProjectTypings = (configArg) => {
|
|
|
|
let done = plugins.q.defer();
|
|
|
|
npmts_promisechain_1.npmtsOra.text('Check Module: Check Project Typings...');
|
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-09-22 21:23:16 +00:00
|
|
|
plugins.beautylog.error(`please add typings field to package.json`);
|
2016-07-28 01:45:14 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
;
|
2016-07-28 01:10:51 +00:00
|
|
|
done.resolve(configArg);
|
|
|
|
return done.promise;
|
|
|
|
};
|
2016-09-22 21:23:16 +00:00
|
|
|
const depcheckOptions = {
|
2016-07-28 01:45:14 +00:00
|
|
|
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-09-22 21:23:16 +00:00
|
|
|
let checkDependencies = (configArg) => {
|
|
|
|
let done = plugins.q.defer();
|
|
|
|
npmts_promisechain_1.npmtsOra.text('Check Module: Check Dependencies...');
|
|
|
|
let 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
|
|
|
]
|
|
|
|
});
|
2016-09-22 21:23:16 +00:00
|
|
|
plugins.depcheck(paths.cwd, depcheckOptionsMerged, (unused) => {
|
|
|
|
for (let item of unused.dependencies) {
|
|
|
|
plugins.beautylog.warn(`Watch out: unused dependency "${item}"`);
|
2016-07-28 01:10:51 +00:00
|
|
|
}
|
2016-09-22 21:23:16 +00:00
|
|
|
for (let item in unused.missing) {
|
|
|
|
plugins.beautylog.error(`unused devDependency "${item}"`);
|
2016-07-28 01:10:51 +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-07-28 01:10:51 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2016-09-22 21:23:16 +00:00
|
|
|
for (let item in unused.invalidFiles) {
|
|
|
|
plugins.beautylog.warn(`Watch out: could not parse file ${item.red}`);
|
2016-07-28 01:10:51 +00:00
|
|
|
}
|
|
|
|
;
|
2016-09-22 21:23:16 +00:00
|
|
|
for (let item in unused.invalidDirs) {
|
|
|
|
plugins.beautylog.warn(`Watch out: could not parse directory ${item.red}`);
|
2016-07-28 01:10:51 +00:00
|
|
|
}
|
|
|
|
done.resolve(configArg);
|
|
|
|
});
|
|
|
|
return done.promise;
|
|
|
|
};
|
2016-09-22 21:23:16 +00:00
|
|
|
let checkDevDependencies = (configArg) => {
|
|
|
|
let done = plugins.q.defer();
|
|
|
|
npmts_promisechain_1.npmtsOra.text('Check Module: Check devDependencies...');
|
|
|
|
let 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
|
|
|
]
|
|
|
|
});
|
2016-09-22 21:23:16 +00:00
|
|
|
plugins.depcheck(paths.cwd, depcheckOptionsMerged, (unused) => {
|
|
|
|
for (let item of unused.devDependencies) {
|
|
|
|
plugins.beautylog.log(`unused devDependency ${item.red}`);
|
2016-07-28 01:45:14 +00:00
|
|
|
}
|
2016-09-22 21:23:16 +00:00
|
|
|
for (let item in unused.missing) {
|
|
|
|
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-09-22 21:23:16 +00:00
|
|
|
for (let item in unused.invalidFiles) {
|
|
|
|
plugins.beautylog.warn(`Watch out: could not parse file ${item.red}`);
|
2016-07-28 01:45:14 +00:00
|
|
|
}
|
2016-09-22 21:23:16 +00:00
|
|
|
for (let item in unused.invalidDirs) {
|
|
|
|
plugins.beautylog.warn(`Watch out: could not parse directory ${item.red}`);
|
2016-07-28 01:45:14 +00:00
|
|
|
}
|
|
|
|
done.resolve(configArg);
|
|
|
|
});
|
|
|
|
return done.promise;
|
|
|
|
};
|
2016-09-22 21:23:16 +00:00
|
|
|
let checkNodeVersion = (configArg) => {
|
|
|
|
let done = plugins.q.defer();
|
|
|
|
npmts_promisechain_1.npmtsOra.text('checking node version');
|
2016-07-28 01:10:51 +00:00
|
|
|
done.resolve(configArg);
|
|
|
|
return done.promise;
|
|
|
|
};
|
2016-09-22 21:23:16 +00:00
|
|
|
exports.run = (configArg) => {
|
|
|
|
let done = plugins.q.defer();
|
|
|
|
npmts_promisechain_1.npmtsOra.text('Check Module: ...');
|
2016-09-06 15:21:25 +00:00
|
|
|
checkProjectTypings(configArg)
|
|
|
|
.then(checkDependencies)
|
|
|
|
.then(checkDevDependencies)
|
|
|
|
.then(checkNodeVersion)
|
2016-09-22 21:23:16 +00:00
|
|
|
.then(done.resolve)
|
|
|
|
.catch((err) => { console.log(err); });
|
2016-07-28 01:10:51 +00:00
|
|
|
return done.promise;
|
|
|
|
};
|