now checling for typings field in package.json
This commit is contained in:
parent
b69bd24cec
commit
97c47ed696
79
dist/npmts.check.js
vendored
79
dist/npmts.check.js
vendored
@ -4,13 +4,32 @@ var paths = require("./npmts.paths");
|
|||||||
var npmts_promisechain_1 = require("./npmts.promisechain");
|
var npmts_promisechain_1 = require("./npmts.promisechain");
|
||||||
var checkProjectTypings = function (configArg) {
|
var checkProjectTypings = function (configArg) {
|
||||||
var done = plugins.Q.defer();
|
var done = plugins.Q.defer();
|
||||||
|
var cwdProjectInfo = new plugins.projectinfo.ProjectinfoNpm(paths.cwd);
|
||||||
|
if (typeof cwdProjectInfo.packageJson.typings == "undefined") {
|
||||||
|
plugins.beautylog.error("please add typings field to package.json");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
;
|
||||||
done.resolve(configArg);
|
done.resolve(configArg);
|
||||||
return done.promise;
|
return done.promise;
|
||||||
};
|
};
|
||||||
|
var depcheckOptions = {
|
||||||
|
ignoreBinPackage: false,
|
||||||
|
parsers: {
|
||||||
|
'*.ts': plugins.depcheck.parser.typescript,
|
||||||
|
},
|
||||||
|
detectors: [
|
||||||
|
plugins.depcheck.detector.requireCallExpression,
|
||||||
|
plugins.depcheck.detector.importDeclaration
|
||||||
|
],
|
||||||
|
specials: [
|
||||||
|
plugins.depcheck.special.eslint,
|
||||||
|
plugins.depcheck.special.webpack
|
||||||
|
],
|
||||||
|
};
|
||||||
var checkDependencies = function (configArg) {
|
var checkDependencies = function (configArg) {
|
||||||
var done = plugins.Q.defer();
|
var done = plugins.Q.defer();
|
||||||
var options = {
|
var depcheckOptionsMerged = plugins.lodashObject.merge(depcheckOptions, {
|
||||||
ignoreBinPackage: false,
|
|
||||||
ignoreDirs: [
|
ignoreDirs: [
|
||||||
'test',
|
'test',
|
||||||
'dist',
|
'dist',
|
||||||
@ -19,20 +38,9 @@ var checkDependencies = function (configArg) {
|
|||||||
ignoreMatches: [
|
ignoreMatches: [
|
||||||
"@types/*",
|
"@types/*",
|
||||||
"babel-preset-*"
|
"babel-preset-*"
|
||||||
],
|
]
|
||||||
parsers: {
|
});
|
||||||
'*.ts': plugins.depcheck.parser.typescript,
|
plugins.depcheck(paths.cwd, depcheckOptionsMerged, function (unused) {
|
||||||
},
|
|
||||||
detectors: [
|
|
||||||
plugins.depcheck.detector.requireCallExpression,
|
|
||||||
plugins.depcheck.detector.importDeclaration
|
|
||||||
],
|
|
||||||
specials: [
|
|
||||||
plugins.depcheck.special.eslint,
|
|
||||||
plugins.depcheck.special.webpack
|
|
||||||
],
|
|
||||||
};
|
|
||||||
plugins.depcheck(paths.cwd, options, function (unused) {
|
|
||||||
for (var _i = 0, _a = unused.dependencies; _i < _a.length; _i++) {
|
for (var _i = 0, _a = unused.dependencies; _i < _a.length; _i++) {
|
||||||
var item = _a[_i];
|
var item = _a[_i];
|
||||||
plugins.beautylog.warn("Watch out: unused dependency " + item.red);
|
plugins.beautylog.warn("Watch out: unused dependency " + item.red);
|
||||||
@ -71,6 +79,44 @@ var checkDependencies = function (configArg) {
|
|||||||
});
|
});
|
||||||
return done.promise;
|
return done.promise;
|
||||||
};
|
};
|
||||||
|
var checkDevDependencies = function (configArg) {
|
||||||
|
var done = plugins.Q.defer();
|
||||||
|
var depcheckOptionsMerged = plugins.lodashObject.merge(depcheckOptions, {
|
||||||
|
ignoreDirs: [
|
||||||
|
'ts',
|
||||||
|
'dist',
|
||||||
|
'bower_components'
|
||||||
|
],
|
||||||
|
ignoreMatches: [
|
||||||
|
"@types/*",
|
||||||
|
"babel-preset-*"
|
||||||
|
]
|
||||||
|
});
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
;
|
||||||
|
for (var _b = 0, _c = unused.using; _b < _c.length; _b++) {
|
||||||
|
var item = _c[_b];
|
||||||
|
console.log(item);
|
||||||
|
}
|
||||||
|
;
|
||||||
|
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;
|
||||||
|
};
|
||||||
var checkNodeVersion = function (configArg) {
|
var checkNodeVersion = function (configArg) {
|
||||||
var done = plugins.Q.defer();
|
var done = plugins.Q.defer();
|
||||||
done.resolve(configArg);
|
done.resolve(configArg);
|
||||||
@ -81,6 +127,7 @@ exports.run = function (configArg) {
|
|||||||
npmts_promisechain_1.npmtsOra.text("running project checks..."),
|
npmts_promisechain_1.npmtsOra.text("running project checks..."),
|
||||||
checkProjectTypings(configArg)
|
checkProjectTypings(configArg)
|
||||||
.then(checkDependencies)
|
.then(checkDependencies)
|
||||||
|
.then(checkDevDependencies)
|
||||||
.then(checkNodeVersion)
|
.then(checkNodeVersion)
|
||||||
.then(done.resolve);
|
.then(done.resolve);
|
||||||
return done.promise;
|
return done.promise;
|
||||||
|
@ -1,18 +1,36 @@
|
|||||||
import * as plugins from "./npmts.plugins";
|
import * as plugins from "./npmts.plugins";
|
||||||
import * as paths from "./npmts.paths";
|
import * as paths from "./npmts.paths";
|
||||||
import {npmtsOra} from "./npmts.promisechain";
|
import { npmtsOra } from "./npmts.promisechain";
|
||||||
|
|
||||||
let checkProjectTypings = (configArg) => {
|
let checkProjectTypings = (configArg) => {
|
||||||
let done = plugins.Q.defer();
|
let done = plugins.Q.defer();
|
||||||
|
let cwdProjectInfo = new plugins.projectinfo.ProjectinfoNpm(paths.cwd);
|
||||||
|
if(typeof cwdProjectInfo.packageJson.typings == "undefined"){
|
||||||
|
plugins.beautylog.error(`please add typings field to package.json`);
|
||||||
|
process.exit(1);
|
||||||
|
};
|
||||||
done.resolve(configArg);
|
done.resolve(configArg);
|
||||||
return done.promise;
|
return done.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const depcheckOptions = {
|
||||||
|
ignoreBinPackage: false, // ignore the packages with bin entry
|
||||||
|
parsers: { // the target parsers
|
||||||
|
'*.ts': plugins.depcheck.parser.typescript,
|
||||||
|
},
|
||||||
|
detectors: [ // the target detectors
|
||||||
|
plugins.depcheck.detector.requireCallExpression,
|
||||||
|
plugins.depcheck.detector.importDeclaration
|
||||||
|
],
|
||||||
|
specials: [ // the target special parsers
|
||||||
|
plugins.depcheck.special.eslint,
|
||||||
|
plugins.depcheck.special.webpack
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
let checkDependencies = (configArg) => {
|
let checkDependencies = (configArg) => {
|
||||||
let done = plugins.Q.defer();
|
let done = plugins.Q.defer();
|
||||||
const options = {
|
let depcheckOptionsMerged = plugins.lodashObject.merge(depcheckOptions, {
|
||||||
ignoreBinPackage: false, // ignore the packages with bin entry
|
|
||||||
ignoreDirs: [ // folder with these names will be ignored
|
ignoreDirs: [ // folder with these names will be ignored
|
||||||
'test',
|
'test',
|
||||||
'dist',
|
'dist',
|
||||||
@ -21,41 +39,60 @@ let checkDependencies = (configArg) => {
|
|||||||
ignoreMatches: [ // ignore dependencies that matches these globs
|
ignoreMatches: [ // ignore dependencies that matches these globs
|
||||||
"@types/*",
|
"@types/*",
|
||||||
"babel-preset-*"
|
"babel-preset-*"
|
||||||
],
|
]
|
||||||
parsers: { // the target parsers
|
})
|
||||||
'*.ts': plugins.depcheck.parser.typescript,
|
plugins.depcheck(paths.cwd, depcheckOptionsMerged, (unused) => {
|
||||||
},
|
for (let item of unused.dependencies) {
|
||||||
detectors: [ // the target detectors
|
|
||||||
plugins.depcheck.detector.requireCallExpression,
|
|
||||||
plugins.depcheck.detector.importDeclaration
|
|
||||||
],
|
|
||||||
specials: [ // the target special parsers
|
|
||||||
plugins.depcheck.special.eslint,
|
|
||||||
plugins.depcheck.special.webpack
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
plugins.depcheck(paths.cwd, options, (unused) => {
|
|
||||||
for (let item of unused.dependencies){
|
|
||||||
plugins.beautylog.warn(`Watch out: unused dependency ${item.red}`);
|
plugins.beautylog.warn(`Watch out: unused dependency ${item.red}`);
|
||||||
};
|
};
|
||||||
for (let item of unused.devDependencies){
|
for (let item of unused.devDependencies) {
|
||||||
plugins.beautylog.log(`unused devDependency ${item.red}`);
|
plugins.beautylog.log(`unused devDependency ${item.red}`);
|
||||||
};
|
};
|
||||||
for (let item of unused.missing){
|
for (let item of unused.missing) {
|
||||||
plugins.beautylog.error(`unused devDependency ${item.red}`);
|
plugins.beautylog.error(`unused devDependency ${item.red}`);
|
||||||
};
|
};
|
||||||
if(unused.missing.length > 0){
|
if (unused.missing.length > 0) {
|
||||||
plugins.beautylog.info("exiting due to missing dependencies in package.json");
|
plugins.beautylog.info("exiting due to missing dependencies in package.json");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
for (let item of unused.using){
|
for (let item of unused.using) {
|
||||||
console.log(item);
|
console.log(item);
|
||||||
};
|
};
|
||||||
for(let item of unused.invalidFiles){
|
for (let item of unused.invalidFiles) {
|
||||||
plugins.beautylog.warn(`Watch out: could not parse file ${item.red}`);
|
plugins.beautylog.warn(`Watch out: could not parse file ${item.red}`);
|
||||||
};
|
};
|
||||||
for(let item of unused.invalidDirs){
|
for (let item of unused.invalidDirs) {
|
||||||
|
plugins.beautylog.warn(`Watch out: could not parse directory ${item.red}`);
|
||||||
|
};
|
||||||
|
done.resolve(configArg);
|
||||||
|
});
|
||||||
|
return done.promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
let checkDevDependencies = (configArg) => {
|
||||||
|
let done = plugins.Q.defer();
|
||||||
|
let depcheckOptionsMerged = plugins.lodashObject.merge(depcheckOptions, {
|
||||||
|
ignoreDirs: [ // folder with these names will be ignored
|
||||||
|
'ts',
|
||||||
|
'dist',
|
||||||
|
'bower_components'
|
||||||
|
],
|
||||||
|
ignoreMatches: [ // ignore dependencies that matches these globs
|
||||||
|
"@types/*",
|
||||||
|
"babel-preset-*"
|
||||||
|
]
|
||||||
|
})
|
||||||
|
plugins.depcheck(paths.cwd, depcheckOptionsMerged, (unused) => {
|
||||||
|
for (let item of unused.devDependencies) {
|
||||||
|
plugins.beautylog.log(`unused devDependency ${item.red}`);
|
||||||
|
};
|
||||||
|
for (let item of unused.using) {
|
||||||
|
console.log(item);
|
||||||
|
};
|
||||||
|
for (let item of unused.invalidFiles) {
|
||||||
|
plugins.beautylog.warn(`Watch out: could not parse file ${item.red}`);
|
||||||
|
};
|
||||||
|
for (let item of unused.invalidDirs) {
|
||||||
plugins.beautylog.warn(`Watch out: could not parse directory ${item.red}`);
|
plugins.beautylog.warn(`Watch out: could not parse directory ${item.red}`);
|
||||||
};
|
};
|
||||||
done.resolve(configArg);
|
done.resolve(configArg);
|
||||||
@ -73,9 +110,10 @@ let checkNodeVersion = (configArg) => {
|
|||||||
export let run = (configArg) => {
|
export let run = (configArg) => {
|
||||||
let done = plugins.Q.defer();
|
let done = plugins.Q.defer();
|
||||||
npmtsOra.text("running project checks..."),
|
npmtsOra.text("running project checks..."),
|
||||||
checkProjectTypings(configArg)
|
checkProjectTypings(configArg)
|
||||||
.then(checkDependencies)
|
.then(checkDependencies)
|
||||||
.then(checkNodeVersion)
|
.then(checkDevDependencies)
|
||||||
.then(done.resolve);
|
.then(checkNodeVersion)
|
||||||
|
.then(done.resolve);
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user