-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserverless-docker.ts
70 lines (49 loc) · 1.91 KB
/
serverless-docker.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
import { join } from "path"
import { flags } from "@oclif/command"
import { pathExists, readdirSync } from "fs-extra"
import sanitizeFilename from "sanitize-filename"
import slugify from "slugify"
import ux from "cli-ux"
import AWSServerlessDocker from "../../lib/infrastructures/aws/AWSServerlessDocker"
import BaseInfrastructureCommand from "../../BaseInfrastructureCommand"
import InfrastructureInstallManager from "../../lib/infrastructures/InfrastructureInstallManager"
import projectNamePrompt from "../../lib/prompts/projectNamePrompt"
/**
* Represents the "scaffold aws:serverless-docker" command
* used to download and install the AWS serverless docker infrastructure.
*/
export default class AwsServerlessDocker extends BaseInfrastructureCommand {
static args = [{
name: "project_name",
required: false,
}]
static description = "download serverless docker infrastructure code"
static flags = {
help: flags.help({ char: "h" }),
}
async run() {
await this.ensureAllRequirements()
const { args } = this.parse(AwsServerlessDocker)
let projectName: string = args.project_name
if (!projectName) {
projectName = await projectNamePrompt()
this.log("")
}
const projectDirName = slugify(sanitizeFilename(projectName))
if (!projectDirName) {
this.error("Invalid project name")
}
const projectPath = join(process.cwd(), projectDirName)
const projectPathExists = await pathExists(projectPath)
if (projectPathExists) {
if (readdirSync(projectPath).filter(f => !f.startsWith(".")).length > 0) {
this.error("Cannot download infrastructure code in a non-empty directory")
}
}
ux.action.start("Downloading")
const awsServerlessDocker = new AWSServerlessDocker()
await awsServerlessDocker.install(projectPath)
ux.action.stop()
InfrastructureInstallManager.displaySuccessfulInstallMessage(projectPath)
}
}