-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.ts
101 lines (87 loc) · 4.08 KB
/
install.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
import path from 'path'
import { flags } from '@oclif/command'
import { BaseCommand } from '../lib/base-command'
import { resolveRepoList, resolveStage } from '../lib/repo'
import { assertIsFrameworkRoot, Stage } from '../lib/assertions'
import { cloneAndLinkRepos, installLocalRepository } from '../lib/install'
import { ENV_LOCAL_PATH, ENV_REPO, ENV_REPO_BRANCH, ENV_STAGE, VALUE_ALL_REPOS } from '../lib/constants'
export default class Install extends BaseCommand {
static description = `Installs one or multiple repos in the framework meta-repo.
NOTE: This command must be executed from the root of the framework meta-repo.
This command will install one or multiple repos, listed in the repositories.json file,
within the .repos directory of the documentation framework.
Repositories will be either cloned from Github or symlink-ed from the local filesystem (--local-path flag).
The repositories.json file will be fetched from the local instance of the documentation framework.
Repositories are either specified via the --repo flag, or the ${ENV_REPO}: if no value is specified,
kuzdoc will ask it via a prompt.
Kuzdoc will not overwrite existing repositories. If a folder with the same name of a selected
repository is already present, the selected repository will be skipped and the folder will be left untouched.`
static flags = {
help: flags.help({ char: 'h' }),
repo: flags.string({
description: `The list of repositories to install, or the value ${VALUE_ALL_REPOS} to install all repos.
If not specified, kuzdoc will ask a prompt.
Environment variable: $${ENV_REPO}`,
default: process.env[ENV_REPO]
}),
repoBranch: flags.string({
description: `The branch to checkout from the repo to install.
This option is valid if only 1 repo is specified.
Environment variable: $${ENV_REPO_BRANCH}`,
default: process.env[ENV_REPO_BRANCH]
}),
stage: flags.string({
description: `The branch type to checkout.
If this option is not specified, kuzdoc will try to infer it based on the current branch of the framework meta-repo.
Environment variable: $${ENV_STAGE}`,
options: ['stable', 'dev'],
default: process.env[ENV_STAGE]
}),
localPath: flags.string({
description: `Installs the repo from a local path instead of cloning it from Github. Handy for testing locally developed features.
This option is valid if only 1 repo is specified. Overrides --repoBranch.
Environment variable: $${ENV_LOCAL_PATH}`,
default: process.env[ENV_LOCAL_PATH]
})
}
async run() {
try {
assertIsFrameworkRoot(process.cwd())
} catch (error) {
this.log('⛔️ Aborting.')
this.log(`It doesn't seem that you are executing this command from the root of the framework repo ${process.cwd()}: ${error.message}`)
return
}
const { flags: _flags } = this.parse(Install)
const stage: Stage = _flags.stage as Stage || await resolveStage(process.cwd())
const repoList = await resolveRepoList(_flags.repo, false, !_flags.localPath)
if (repoList.length === 0) {
this.log(`\n 🤷♂️ No repo resolved from ${_flags.repo}.\n`)
return
}
if (_flags.repo) {
this.log(`\n 👉 Resolved repos ${repoList.map(r => r.name).join(', ')}\n`)
}
if (repoList.length === 1) {
if (_flags.localPath) {
const absoluteLocalPath = path.join(process.cwd(), _flags.localPath)
return installLocalRepository(absoluteLocalPath, repoList[0]).run()
}
if (_flags.repoBranch) {
repoList[0].customBranch = _flags.repoBranch
}
} else {
if (_flags.repoBranch) {
throw new Error('ABORT: cannot use --repoBranch flag with multiple repos')
}
if (_flags.localPath) {
throw new Error('ABORT: cannot use --localPath flag with multiple repos')
}
}
const task = await cloneAndLinkRepos(repoList, stage)
await task.run()
this.log('\n ✅ All done!')
this.log(' You can export or prepend your further operations with the following environment variable:\n')
this.log(` ${ENV_REPO}=${repoList.map(r => r.name).join(',')}\n`)
}
}