/
diff.ts
36 lines (29 loc) · 1.12 KB
/
diff.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
import color from '@heroku-cli/color'
import {Command} from '@heroku-cli/command'
import {diffLines} from 'diff'
import Addon from '../../../../addon'
export default class Diff extends Command {
static description = 'compares remote manifest to local manifest and finds differences'
async run() {
this.parse(Diff)
const addon = new Addon(this.config)
// reading current manifest
const body = await addon.remote().get()
const fetchedManifest = JSON.stringify(body, null, 2)
const localManifest = JSON.stringify(addon.local().get(), null, 2)
const diff = diffLines(fetchedManifest, localManifest, {newlineIsToken: true, ignoreCase: true})
diff.forEach((substr: any) => {
let outputColor: 'white' | 'green' | 'red' = 'white'
if (substr.added) {
outputColor = 'green' // this is supposed to be a bold green (chalk.green.bold)
} else if (substr.removed) {
outputColor = 'red'
}
let message: string = color[outputColor](substr.value)
if (outputColor === 'green') {
message = color.italic.bold(message)
}
this.log(message)
})
}
}