UNPKG

1.13 kBJavaScriptView Raw
1'use strict'
2
3const path = require('path')
4const fs = require('fs')
5const subarg = require('subarg')
6const args = subarg(process.argv.slice(2))
7
8setTimeout(() => {
9 if (args.error === 'throw') {
10 throw new Error('Failing with exception.')
11 }
12
13 if (args.error === 'log') {
14 console.error('Failing with error log.')
15 console.error('Second error line.')
16 process.exit(0)
17 }
18
19 if (args.error === 'exit') {
20 process.exit(1)
21 }
22
23 if (args.clean) {
24 console.log('Cleaning.')
25 const distPath = path.resolve(__dirname, 'dist')
26 for (const file of fs.readdirSync(distPath)) {
27 const filePath = path.resolve(distPath, file)
28 fs.unlinkSync(filePath)
29 }
30
31 process.exit(0)
32 }
33
34 if (args.generate) {
35 console.log('Generating:', args.generate)
36 const fileName = path.basename(args.generate)
37 const filePath = path.resolve(__dirname, 'dist', fileName)
38 fs.writeFileSync(filePath)
39 process.exit()
40 }
41
42 if (args.background) {
43 console.log('Chillin\' in the background...')
44 console.error('Loging an error.')
45 setInterval(() => {}, 1000)
46 }
47}, parseInt(args.delay || 0, 10))