/
clean.ts
78 lines (62 loc) · 1.44 KB
/
clean.ts
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import {Command, flags} from '@oclif/command'
import cli from 'cli-ux'
import * as fs from 'fs'
import {join} from 'path'
import {projectPath} from '../util'
import {execSync, spawnSync} from 'child_process'
export default class Clean extends Command {
static description = 'Delete a tree created by `build`'
static args = [{name: 'file'}]
static flags = {
format: flags.string({
default: 'gedcom',
}),
}
binDir
format
prefix
async run() {
const {args, flags} = this.parse(Clean)
this.binDir = join(this.config.root, '/bin')
this.format = flags.format
cli.action.start('Cleaning')
if (args.file) {
this.clean(args.file)
} else {
const files = await this.files()
files.forEach(f => {
let underline = ''
for (let i = 0; i < f.length; i++) {
underline += '-'
}
this.clean(f)
})
}
cli.action.stop()
}
clean(file) {
execSync(`bash ${this.binDir}/clean "genealogit/${file}/"`)
}
async files() {
let files = []
let regex
switch(this.format) {
case 'gedcom':
regex = /\.ged$/
break
case 'json':
regex = /\.json$/
break
case 'yaml':
regex = /\.yaml$/
break
}
fs.readdirSync(projectPath()).forEach(child => {
const matches = child.match(regex)
if (matches) {
files = [...files, child]
}
})
return files
}
}