-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage.js
executable file
·46 lines (40 loc) · 965 Bytes
/
package.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
const { success, error } = require('log-symbols')
const pkgFields = [
'main',
'bin',
'browser',
'man',
'types',
'typings',
'module',
'files'
]
const pkg = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'package.json')))
const errors = []
function check (prop) {
if (!fs.existsSync(path.join(process.cwd(), prop))) {
errors.push(prop)
}
}
pkgFields.forEach(field => {
const theProp = pkg[field]
if (theProp) {
if (typeof theProp === 'object') {
Object.values(theProp).forEach(prop => check(prop))
} else {
check(theProp)
}
}
})
if (errors.length > 0) {
errors.forEach(file => {
console.log(chalk.red(`${error} ${file} file not found at ${process.cwd()}/${file}`))
})
process.exit(1)
} else {
console.log(`${success} Woohoo! The package is healthy and all fields' files were found`)
}