-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpull.ts
103 lines (86 loc) · 2.62 KB
/
pull.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import {flags} from '@oclif/command'
import Base from '../helper/base'
import cli from 'cli-ux'
import * as Path from 'path'
import * as FileSystem from 'fs'
/**
* @class {Pull}
*/
export default class Pull extends Base {
/**
* @type {string}
*/
static description = 'update the devitools resources'
/**
* @type {string[]}
*/
static examples = [
'$ devi pull',
]
/**
* @type {Array}
*/
static args = [
]
/**
* @type {Record<string, any>}
*/
static flags = {
help: flags.help({char: 'h'}),
}
/**
*/
async run() {
await this.welcome()
const filename = Path.join(process.cwd(), '.devitools.json')
const exists = await this.exists(filename)
if (!exists) {
this.warn('The project is not valid')
this.bye()
return
}
const content = FileSystem.readFileSync(filename)
const settings = JSON.parse(String(content))
const choices = []
if (settings.front.type) {
this.disabled('Devitools "frontend" detected')
choices.push({name: 'frontend'})
}
if (settings.back.type) {
this.disabled('Devitools "backend" detected')
choices.push({name: 'backend'})
}
if (choices.length === 2) {
choices.push({name: 'both'})
}
const {update} = await this.choose('update', 'Which one do you wanna update?', choices)
cli.action.start('# cleaning up', 'waiting', {stdout: true})
await this.execute('git submodule foreach --recursive git reset --hard')
cli.action.stop('all clear')
if (update === 'frontend') {
const root = settings.front.root.split('/')
root.shift()
const frontend = root.join('/') + '/@devitools'
cli.action.start('# updating frontend', 'waiting', {stdout: true})
await this.execute(`git submodule update --remote --recursive "${frontend}"`)
// eslint-disable-next-line no-warning-comments
// TODO: review the strategy
// frontend\@devitools$ git checkout nightly
// frontend\@devitools$ git merge --ff --ff-only refs/remotes/origin/nightly
// frontend\@devitools$ git checkout nightly
}
if (update === 'backend') {
const root = settings.back.root.split('/')
root.shift()
const backend = root.join('/') + '/@devitools'
cli.action.start('# updating backend', 'waiting', {stdout: true})
await this.execute(`git submodule update --remote --recursive "${backend}"`)
}
if (update === 'both') {
cli.action.start('# updating', 'waiting', {stdout: true})
await this.execute('git submodule update --remote --recursive')
}
cli.action.stop('all updated')
this.bye()
}
}