tscoverage/ts/npmts.check.ts

126 lines
4.2 KiB
TypeScript
Raw Permalink Normal View History

2016-09-06 15:21:25 +00:00
import * as plugins from './npmts.plugins'
import * as paths from './npmts.paths'
import { npmtsOra } from './npmts.promisechain'
2016-07-28 01:10:51 +00:00
2016-09-06 15:21:25 +00:00
import {ProjectinfoNpm} from 'projectinfo'
2016-09-02 12:10:09 +00:00
2016-09-06 15:21:25 +00:00
export let projectInfo: ProjectinfoNpm
2016-09-02 12:10:09 +00:00
2016-07-28 01:10:51 +00:00
let checkProjectTypings = (configArg) => {
2016-09-22 21:23:16 +00:00
let done = plugins.q.defer()
npmtsOra.text('Check Module: Check Project Typings...')
2016-09-06 15:21:25 +00:00
projectInfo = new ProjectinfoNpm(paths.cwd)
if (typeof projectInfo.packageJson.typings === 'undefined') {
plugins.beautylog.error(`please add typings field to package.json`)
process.exit(1)
};
2016-09-06 15:21:25 +00:00
done.resolve(configArg)
return done.promise
}
2016-07-28 01:10:51 +00:00
const depcheckOptions = {
ignoreBinPackage: false, // ignore the packages with bin entry
parsers: { // the target parsers
2016-09-06 15:21:25 +00:00
'*.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
2016-09-06 15:21:25 +00:00
]
}
2016-07-28 01:10:51 +00:00
let checkDependencies = (configArg) => {
2016-09-22 21:23:16 +00:00
let done = plugins.q.defer()
npmtsOra.text('Check Module: Check Dependencies...')
2016-09-18 11:08:31 +00:00
let depcheckOptionsMerged = plugins.lodash.merge(depcheckOptions, {
2016-07-28 01:10:51 +00:00
ignoreDirs: [ // folder with these names will be ignored
'test',
'dist',
'bower_components'
],
ignoreMatches: [ // ignore dependencies that matches these globs
2016-09-06 15:21:25 +00:00
'@types/*',
'babel-preset-*'
]
})
plugins.depcheck(paths.cwd, depcheckOptionsMerged, (unused) => {
for (let item of unused.dependencies) {
2016-09-22 21:23:16 +00:00
plugins.beautylog.warn(`Watch out: unused dependency "${item}"`)
}
for (let item in unused.missing) {
plugins.beautylog.error(`unused devDependency "${item}"`)
}
if (unused.missing.length > 0) {
2016-09-06 15:21:25 +00:00
plugins.beautylog.info('exiting due to missing dependencies in package.json')
process.exit(1)
2016-07-28 01:10:51 +00:00
}
2016-09-22 21:23:16 +00:00
for (let item in unused.invalidFiles) {
2016-09-06 15:21:25 +00:00
plugins.beautylog.warn(`Watch out: could not parse file ${item.red}`)
};
2016-09-22 21:23:16 +00:00
for (let item in unused.invalidDirs) {
2016-09-06 15:21:25 +00:00
plugins.beautylog.warn(`Watch out: could not parse directory ${item.red}`)
2016-09-22 21:23:16 +00:00
}
2016-09-06 15:21:25 +00:00
done.resolve(configArg)
})
return done.promise
}
let checkDevDependencies = (configArg) => {
2016-09-22 21:23:16 +00:00
let done = plugins.q.defer()
npmtsOra.text('Check Module: Check devDependencies...')
2016-09-18 11:08:31 +00:00
let depcheckOptionsMerged = plugins.lodash.merge(depcheckOptions, {
ignoreDirs: [ // folder with these names will be ignored
'ts',
'dist',
'bower_components'
],
ignoreMatches: [ // ignore dependencies that matches these globs
2016-09-06 15:21:25 +00:00
'@types/*',
'babel-preset-*'
]
})
plugins.depcheck(paths.cwd, depcheckOptionsMerged, (unused) => {
for (let item of unused.devDependencies) {
2016-09-06 15:21:25 +00:00
plugins.beautylog.log(`unused devDependency ${item.red}`)
2016-09-22 21:23:16 +00:00
}
for (let item in unused.missing) {
2016-09-06 15:21:25 +00:00
plugins.beautylog.error(`unused devDependency ${item.red}`)
2016-09-22 21:23: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')
process.exit(1)
}
2016-09-22 21:23:16 +00:00
for (let item in unused.invalidFiles) {
2016-09-06 15:21:25 +00:00
plugins.beautylog.warn(`Watch out: could not parse file ${item.red}`)
}
2016-09-22 21:23:16 +00:00
for (let item in unused.invalidDirs) {
2016-09-06 15:21:25 +00:00
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
let checkNodeVersion = (configArg) => {
2016-09-22 21:23:16 +00:00
let done = plugins.q.defer()
npmtsOra.text('checking node version')
2016-09-06 15:21:25 +00:00
done.resolve(configArg)
return done.promise
2016-07-28 01:10:51 +00:00
}
export let run = (configArg) => {
2016-09-22 21:23:16 +00:00
let done = plugins.q.defer()
npmtsOra.text('Check Module: ...')
2016-09-06 15:21:25 +00:00
checkProjectTypings(configArg)
.then(checkDependencies)
.then(checkDevDependencies)
.then(checkNodeVersion)
.then(done.resolve)
2016-09-22 21:23:16 +00:00
.catch((err) => { console.log(err) })
2016-09-06 15:21:25 +00:00
return done.promise
2016-07-28 01:10:51 +00:00
}