-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathall.ts
76 lines (57 loc) · 1.73 KB
/
all.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
import execa from "execa"
import { flags } from "@oclif/command"
import BaseInfrastructureCommand from "../../BaseInfrastructureCommand"
import InfrastructureFactory from "../../lib/infrastructures/InfrastructureFactory"
/**
* Represents the "scaffold cdktf:{command}" command
* used to forward commands to the CDKTF binary.
*/
class CdktfAll extends BaseInfrastructureCommand {
static aliases = [
"deploy",
"destroy",
"diff",
"get",
"init",
"login",
"synth",
].map(alias => `cdktf:${alias}`)
static args = []
static description = "forward commands to the CDKTF binary"
static flags = {
help: flags.help({
char: "h",
}),
}
async run() {
await this.ensureAllRequirements()
const infrastructurePath = await this.infrastructurePath()
if (!infrastructurePath) {
this.error("No infrastructures found.")
}
const infrastructurePackage = await this.infrastructurePackage(infrastructurePath)
if (!infrastructurePackage) {
this.error("Invalid scaffold.json file.")
}
const infrastructure = InfrastructureFactory.infrastructure(infrastructurePackage.type)
if (!infrastructure) {
this.error("Unknown infrastructure.")
}
const cdktfPath = this.cdktfPath(infrastructurePath)
// Remove ["node", "{path}"]
const passedArgs = process.argv.slice(2)
passedArgs[0] = passedArgs[0].replace(/^cdktf:/, "")
const cdktfCommand = execa(cdktfPath, passedArgs, {
cwd: infrastructurePath,
})
cdktfCommand.stderr.pipe(process.stderr)
cdktfCommand.stdout.pipe(process.stdout)
process.stdin.pipe(cdktfCommand.stdin)
try {
await cdktfCommand
} catch (error) {
this.exit(1)
}
}
}
export default CdktfAll