-
Notifications
You must be signed in to change notification settings - Fork 393
/
Copy pathconfig-manual.ts
115 lines (100 loc) · 3.22 KB
/
config-manual.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
104
105
106
107
108
109
110
111
112
113
114
115
import inquirer from 'inquirer'
import { exit, log } from '../command-helpers.js'
import type BaseCommand from '../../commands/base-command.js'
import type { RepoData } from '../get-repo-data.js'
import { createDeployKey, type DeployKey, getBuildSettings, saveNetlifyToml, setupSite } from './utils.js'
/**
* Prompts for granting the netlify ssh public key access to your repo
*/
const addDeployKey = async (deployKey: DeployKey) => {
log('\nGive this Netlify SSH public key access to your repository:\n')
// FIXME(serhalp): Handle nullish `deployKey.public_key` by throwing user-facing error or fixing upstream type.
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
log(`\n${deployKey.public_key}\n\n`)
const { sshKeyAdded } = (await inquirer.prompt([
{
type: 'confirm',
name: 'sshKeyAdded',
message: 'Continue?',
default: true,
},
])) as { sshKeyAdded: boolean }
if (!sshKeyAdded) {
return exit()
}
}
const getRepoPath = async ({ repoData }: { repoData: RepoData }): Promise<string> => {
const { repoPath } = await inquirer.prompt<{ repoPath: string }>([
{
type: 'input',
name: 'repoPath',
message: 'The SSH URL of the remote git repo:',
default: repoData.url,
validate: (url: string) => (SSH_URL_REGEXP.test(url) ? true : 'The URL provided does not use the SSH protocol'),
},
])
return repoPath
}
const addDeployHook = async (deployHook: string | undefined): Promise<boolean> => {
log('\nConfigure the following webhook for your repository:\n')
// FIXME(serhalp): Handle nullish `deployHook` by throwing user-facing error or fixing upstream type.
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
log(`\n${deployHook}\n\n`)
const { deployHookAdded } = await inquirer.prompt<{ deployHookAdded: boolean }>([
{
type: 'confirm',
name: 'deployHookAdded',
message: 'Continue?',
default: true,
},
])
return deployHookAdded
}
export default async function configManual({
command,
repoData,
siteId,
}: {
command: BaseCommand
repoData: RepoData
siteId: string
}) {
const { netlify } = command
const {
api,
cachedConfig: { configPath },
config,
repositoryRoot,
} = netlify
const { baseDir, buildCmd, buildDir, functionsDir, pluginsToInstall } = await getBuildSettings({
config,
command,
})
await saveNetlifyToml({ repositoryRoot, config, configPath, baseDir, buildCmd, buildDir, functionsDir })
const deployKey = await createDeployKey({ api })
await addDeployKey(deployKey)
const repoPath = await getRepoPath({ repoData })
const repo = {
provider: 'manual',
repo_path: repoPath,
repo_branch: repoData.branch,
allowed_branches: [repoData.branch],
deploy_key_id: deployKey.id,
base: baseDir,
dir: buildDir,
functions_dir: functionsDir,
...(buildCmd && { cmd: buildCmd }),
}
const updatedSite = await setupSite({
api,
siteId,
repo,
configPlugins: config.plugins ?? [],
pluginsToInstall,
})
const deployHookAdded = await addDeployHook(updatedSite.deploy_hook)
if (!deployHookAdded) {
exit()
}
}
const SSH_URL_REGEXP = /(ssh:\/\/|[a-zA-Z]*@|[a-zA-Z.].*:(?!\/\/))/