1 | #!/usr/bin/env node
|
2 |
|
3 | const fs = require('fs')
|
4 | const path = require('path')
|
5 |
|
6 | const checks = []
|
7 | function check(name, callback) {
|
8 | checks.push([checks.length + 1, name, callback])
|
9 | }
|
10 |
|
11 | function run() {
|
12 | process.stdout.write(`1..${checks.length}\n`)
|
13 | checks.forEach(([count, name, callback]) => {
|
14 | Promise.resolve()
|
15 | .then(callback)
|
16 | .then(() => {
|
17 | process.stdout.write(`ok ${count} - ${name}\n`)
|
18 | })
|
19 | .catch(error => {
|
20 | process.stdout.write(`not ok ${count} - ${name}\n ${error}\n`)
|
21 | })
|
22 | })
|
23 | }
|
24 |
|
25 | const packageRoot = process.argv[2]
|
26 |
|
27 | check('package.json exists', () => {
|
28 | const packageJsonPath = path.join(packageRoot, 'package.json')
|
29 |
|
30 | if (!fs.existsSync(packageJsonPath)) {
|
31 | throw new Error('package.json does not exist')
|
32 | }
|
33 | })
|
34 |
|
35 | check('package.json license is set', () => {
|
36 | const packageJsonPath = path.join(packageRoot, 'package.json')
|
37 | const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
|
38 |
|
39 | if (!pkg.license) {
|
40 | throw new Error('license not set')
|
41 | }
|
42 | })
|
43 |
|
44 | run()
|