@fiftth/fiftth-cli 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish-npm.yml +62 -0
- package/README.md +123 -111
- package/dist/api/client.d.ts +1 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +4 -0
- package/dist/api/client.js.map +1 -1
- package/dist/commands/checkout.d.ts +1 -1
- package/dist/commands/checkout.d.ts.map +1 -1
- package/dist/commands/checkout.js +63 -31
- package/dist/commands/checkout.js.map +1 -1
- package/dist/commands/tasks.d.ts.map +1 -1
- package/dist/commands/tasks.js +4 -1
- package/dist/commands/tasks.js.map +1 -1
- package/dist/config/configService.d.ts.map +1 -1
- package/dist/config/configService.js +17 -4
- package/dist/config/configService.js.map +1 -1
- package/dist/index.js +25 -25
- package/dist/index.js.map +1 -1
- package/dist/services/taskService.d.ts +1 -0
- package/dist/services/taskService.d.ts.map +1 -1
- package/dist/services/taskService.js +7 -0
- package/dist/services/taskService.js.map +1 -1
- package/package.json +56 -56
- package/src/api/client.ts +31 -26
- package/src/commands/checkout.ts +101 -68
- package/src/commands/login.ts +145 -145
- package/src/commands/repo.ts +113 -113
- package/src/commands/tasks.ts +86 -83
- package/src/commands/use.ts +149 -149
- package/src/config/configService.ts +56 -40
- package/src/context/runtimeContext.ts +42 -42
- package/src/git/gitService.ts +29 -29
- package/src/index.ts +133 -133
- package/src/services/taskContext.ts +32 -32
- package/src/services/taskService.ts +53 -45
- package/src/utils/api.ts +41 -41
- package/src/utils/config.ts +48 -48
- package/src/utils/ui.ts +46 -46
- package/tsconfig.json +18 -18
- package/vitest.config.ts +8 -8
package/src/commands/tasks.ts
CHANGED
|
@@ -1,83 +1,86 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
2
|
-
import inquirer from 'inquirer'
|
|
3
|
-
import { loadConfig } from '../utils/config.js'
|
|
4
|
-
import { fetchActiveTasks, type Task } from '../services/taskService.js'
|
|
5
|
-
import { setRuntimeSelectedTask } from '../context/runtimeContext.js'
|
|
6
|
-
import { cmd, fail, info, kv, muted, ok, section } from '../utils/ui.js'
|
|
7
|
-
|
|
8
|
-
function printTaskRepositories(task: Task): void {
|
|
9
|
-
console.log(`\n${section(`Linked repositories for: ${task.title}`)}\n`)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
console.log('')
|
|
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
|
-
}
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
import inquirer from 'inquirer'
|
|
3
|
+
import { loadConfig } from '../utils/config.js'
|
|
4
|
+
import { fetchActiveTasks, type Task } from '../services/taskService.js'
|
|
5
|
+
import { setRuntimeSelectedTask } from '../context/runtimeContext.js'
|
|
6
|
+
import { cmd, fail, info, kv, muted, ok, section } from '../utils/ui.js'
|
|
7
|
+
|
|
8
|
+
function printTaskRepositories(task: Task): void {
|
|
9
|
+
console.log(`\n${section(`Linked repositories for: ${task.title}`)}\n`)
|
|
10
|
+
console.log(kv('Task ID', task.id))
|
|
11
|
+
console.log('')
|
|
12
|
+
|
|
13
|
+
for (const repository of task.repositories) {
|
|
14
|
+
console.log(kv('Repository', repository.fullName))
|
|
15
|
+
console.log(` ${muted('branch')} ${chalk.bold(repository.branch)}`)
|
|
16
|
+
console.log('')
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function tasksCommand(): Promise<void> {
|
|
21
|
+
const config = loadConfig()
|
|
22
|
+
|
|
23
|
+
if (!config.token) {
|
|
24
|
+
console.error(
|
|
25
|
+
`\n${fail('Not authenticated.')} ${muted(`Run ${cmd('fiftth login')} first.`)}\n`,
|
|
26
|
+
)
|
|
27
|
+
process.exit(1)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!config.workspaceId) {
|
|
31
|
+
console.error(
|
|
32
|
+
`\n${fail('Workspace not selected.')} ${muted(`Run ${cmd('fiftth use')} first.`)}\n`,
|
|
33
|
+
)
|
|
34
|
+
process.exit(1)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let tasks: Task[]
|
|
38
|
+
try {
|
|
39
|
+
tasks = await fetchActiveTasks(config.workspaceId)
|
|
40
|
+
} catch {
|
|
41
|
+
console.error(`\n${fail('Failed to fetch tasks from API.')}\n`)
|
|
42
|
+
process.exit(1)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (tasks.length === 0) {
|
|
46
|
+
console.log(`\n${info('No active tasks found.')}\n`)
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
console.log(`\n${section(`Active tasks in ${config.workspace ?? 'workspace'}`)}\n`)
|
|
51
|
+
|
|
52
|
+
const { selectedTaskId } = await inquirer.prompt<{ selectedTaskId: string }>([
|
|
53
|
+
{
|
|
54
|
+
type: 'list',
|
|
55
|
+
name: 'selectedTaskId',
|
|
56
|
+
message: 'Choose a task',
|
|
57
|
+
choices: tasks.map((task) => ({
|
|
58
|
+
name: `${task.title} (${task.id})`,
|
|
59
|
+
value: task.id,
|
|
60
|
+
})),
|
|
61
|
+
},
|
|
62
|
+
])
|
|
63
|
+
|
|
64
|
+
const selectedTask = tasks.find((task) => task.id === selectedTaskId)
|
|
65
|
+
|
|
66
|
+
if (!selectedTask) {
|
|
67
|
+
console.error(`\n${fail('No active tasks found.')}\n`)
|
|
68
|
+
process.exit(1)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
setRuntimeSelectedTask({
|
|
72
|
+
taskId: selectedTask.id,
|
|
73
|
+
title: selectedTask.title,
|
|
74
|
+
repositories: selectedTask.repositories,
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
console.log(`\n${ok(`Task selected: ${chalk.bold(selectedTask.title)}`)}`)
|
|
78
|
+
console.log(kv('Task ID', selectedTask.id))
|
|
79
|
+
|
|
80
|
+
if (selectedTask.repositories.length === 0) {
|
|
81
|
+
console.log(`${info('This task has no linked repositories.')}\n`)
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
printTaskRepositories(selectedTask)
|
|
86
|
+
}
|
package/src/commands/use.ts
CHANGED
|
@@ -1,149 +1,149 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
2
|
-
import { select } from '@inquirer/prompts'
|
|
3
|
-
import ora from 'ora'
|
|
4
|
-
import { loadConfig, saveConfig } from '../utils/config.js'
|
|
5
|
-
import { createApiClient, type Workspace } from '../utils/api.js'
|
|
6
|
-
import { cmd, fail, info, kv, muted, ok, section } from '../utils/ui.js'
|
|
7
|
-
|
|
8
|
-
interface UseOptions {
|
|
9
|
-
list?: boolean
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export async function useCommand(
|
|
13
|
-
workspace: string | undefined,
|
|
14
|
-
options: UseOptions,
|
|
15
|
-
): Promise<void> {
|
|
16
|
-
const config = loadConfig()
|
|
17
|
-
|
|
18
|
-
if (!config.token) {
|
|
19
|
-
console.error(
|
|
20
|
-
`\n${fail('Not authenticated.')} ${muted(`Run ${cmd('fiftth login')} first.`)}\n`,
|
|
21
|
-
)
|
|
22
|
-
process.exit(1)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const client = createApiClient()
|
|
26
|
-
|
|
27
|
-
if (options.list) {
|
|
28
|
-
await listWorkspaces(client)
|
|
29
|
-
return
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (workspace) {
|
|
33
|
-
await switchWorkspace(workspace, config, client)
|
|
34
|
-
} else {
|
|
35
|
-
await interactiveSelectWorkspace(config, client)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async function listWorkspaces(
|
|
40
|
-
client: ReturnType<typeof createApiClient>,
|
|
41
|
-
): Promise<void> {
|
|
42
|
-
const spinner = ora('Fetching workspaces…').start()
|
|
43
|
-
|
|
44
|
-
let workspaces: Workspace[]
|
|
45
|
-
try {
|
|
46
|
-
workspaces = await client.getWorkspaces()
|
|
47
|
-
} catch (err) {
|
|
48
|
-
spinner.fail(fail('Failed to fetch workspaces.'))
|
|
49
|
-
console.error(`\n${muted(err instanceof Error ? err.message : String(err))}\n`)
|
|
50
|
-
process.exit(1)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
spinner.stop()
|
|
54
|
-
|
|
55
|
-
if (workspaces.length === 0) {
|
|
56
|
-
console.log(`\n${info('No workspaces found.')}\n`)
|
|
57
|
-
return
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const config = loadConfig()
|
|
61
|
-
|
|
62
|
-
console.log(`\n${section('Available workspaces')}\n`)
|
|
63
|
-
for (const ws of workspaces) {
|
|
64
|
-
const active = ws.slug === config.workspace
|
|
65
|
-
const marker = active ? chalk.green('✓') : chalk.dim('·')
|
|
66
|
-
const name = active ? chalk.bold(ws.name) : ws.name
|
|
67
|
-
console.log(` ${marker} ${name} ${muted(ws.slug)}`)
|
|
68
|
-
}
|
|
69
|
-
console.log()
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async function switchWorkspace(
|
|
73
|
-
slug: string,
|
|
74
|
-
config: ReturnType<typeof loadConfig>,
|
|
75
|
-
client: ReturnType<typeof createApiClient>,
|
|
76
|
-
): Promise<void> {
|
|
77
|
-
const spinner = ora('Fetching workspaces...').start()
|
|
78
|
-
|
|
79
|
-
let workspaces: Workspace[]
|
|
80
|
-
try {
|
|
81
|
-
workspaces = await client.getWorkspaces()
|
|
82
|
-
} catch (err) {
|
|
83
|
-
spinner.fail(fail('Failed to fetch workspaces.'))
|
|
84
|
-
console.error(`\n${muted(err instanceof Error ? err.message : String(err))}\n`)
|
|
85
|
-
process.exit(1)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
spinner.stop()
|
|
89
|
-
|
|
90
|
-
const match = workspaces.find(
|
|
91
|
-
(ws) => ws.slug === slug || ws.name === slug,
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
if (!match) {
|
|
95
|
-
console.error(`\n${fail(`Workspace ${chalk.bold(slug)} not found.`)}\n`)
|
|
96
|
-
console.log(`${muted(`Run ${cmd('fiftth use --list')} to see available workspaces.`)}\n`)
|
|
97
|
-
process.exit(1)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
saveConfig({
|
|
101
|
-
...config,
|
|
102
|
-
workspace: match.slug,
|
|
103
|
-
workspaceId: match.id,
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
console.log(`\n${ok(`Now using workspace ${chalk.bold(match.name)} ${muted(`(${match.slug})`)}`)}`)
|
|
107
|
-
console.log(`${kv('Workspace ID', match.id)}\n`)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
async function interactiveSelectWorkspace(
|
|
111
|
-
config: ReturnType<typeof loadConfig>,
|
|
112
|
-
client: ReturnType<typeof createApiClient>,
|
|
113
|
-
): Promise<void> {
|
|
114
|
-
const spinner = ora('Fetching workspaces...').start()
|
|
115
|
-
|
|
116
|
-
let workspaces: Workspace[]
|
|
117
|
-
try {
|
|
118
|
-
workspaces = await client.getWorkspaces()
|
|
119
|
-
} catch (err) {
|
|
120
|
-
spinner.fail(fail('Failed to fetch workspaces.'))
|
|
121
|
-
console.error(`\n${muted(err instanceof Error ? err.message : String(err))}\n`)
|
|
122
|
-
process.exit(1)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
spinner.stop()
|
|
126
|
-
|
|
127
|
-
if (workspaces.length === 0) {
|
|
128
|
-
console.log(`\n${info('No workspaces found.')}\n`)
|
|
129
|
-
return
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const chosen = await select<string>({
|
|
133
|
-
message: 'Select a workspace',
|
|
134
|
-
choices: workspaces.map((ws) => ({
|
|
135
|
-
value: ws.slug,
|
|
136
|
-
name: `${ws.name} ${chalk.dim(ws.slug)}`,
|
|
137
|
-
})),
|
|
138
|
-
default: config.workspace,
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
const match = workspaces.find((ws) => ws.slug === chosen)!
|
|
142
|
-
saveConfig({
|
|
143
|
-
...config,
|
|
144
|
-
workspace: chosen,
|
|
145
|
-
workspaceId: match.id,
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
console.log(`\n${ok(`Now using workspace ${chalk.bold(match.name)} ${muted(`(${match.slug})`)}`)}\n`)
|
|
149
|
-
}
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
import { select } from '@inquirer/prompts'
|
|
3
|
+
import ora from 'ora'
|
|
4
|
+
import { loadConfig, saveConfig } from '../utils/config.js'
|
|
5
|
+
import { createApiClient, type Workspace } from '../utils/api.js'
|
|
6
|
+
import { cmd, fail, info, kv, muted, ok, section } from '../utils/ui.js'
|
|
7
|
+
|
|
8
|
+
interface UseOptions {
|
|
9
|
+
list?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function useCommand(
|
|
13
|
+
workspace: string | undefined,
|
|
14
|
+
options: UseOptions,
|
|
15
|
+
): Promise<void> {
|
|
16
|
+
const config = loadConfig()
|
|
17
|
+
|
|
18
|
+
if (!config.token) {
|
|
19
|
+
console.error(
|
|
20
|
+
`\n${fail('Not authenticated.')} ${muted(`Run ${cmd('fiftth login')} first.`)}\n`,
|
|
21
|
+
)
|
|
22
|
+
process.exit(1)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const client = createApiClient()
|
|
26
|
+
|
|
27
|
+
if (options.list) {
|
|
28
|
+
await listWorkspaces(client)
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (workspace) {
|
|
33
|
+
await switchWorkspace(workspace, config, client)
|
|
34
|
+
} else {
|
|
35
|
+
await interactiveSelectWorkspace(config, client)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function listWorkspaces(
|
|
40
|
+
client: ReturnType<typeof createApiClient>,
|
|
41
|
+
): Promise<void> {
|
|
42
|
+
const spinner = ora('Fetching workspaces…').start()
|
|
43
|
+
|
|
44
|
+
let workspaces: Workspace[]
|
|
45
|
+
try {
|
|
46
|
+
workspaces = await client.getWorkspaces()
|
|
47
|
+
} catch (err) {
|
|
48
|
+
spinner.fail(fail('Failed to fetch workspaces.'))
|
|
49
|
+
console.error(`\n${muted(err instanceof Error ? err.message : String(err))}\n`)
|
|
50
|
+
process.exit(1)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
spinner.stop()
|
|
54
|
+
|
|
55
|
+
if (workspaces.length === 0) {
|
|
56
|
+
console.log(`\n${info('No workspaces found.')}\n`)
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const config = loadConfig()
|
|
61
|
+
|
|
62
|
+
console.log(`\n${section('Available workspaces')}\n`)
|
|
63
|
+
for (const ws of workspaces) {
|
|
64
|
+
const active = ws.slug === config.workspace
|
|
65
|
+
const marker = active ? chalk.green('✓') : chalk.dim('·')
|
|
66
|
+
const name = active ? chalk.bold(ws.name) : ws.name
|
|
67
|
+
console.log(` ${marker} ${name} ${muted(ws.slug)}`)
|
|
68
|
+
}
|
|
69
|
+
console.log()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function switchWorkspace(
|
|
73
|
+
slug: string,
|
|
74
|
+
config: ReturnType<typeof loadConfig>,
|
|
75
|
+
client: ReturnType<typeof createApiClient>,
|
|
76
|
+
): Promise<void> {
|
|
77
|
+
const spinner = ora('Fetching workspaces...').start()
|
|
78
|
+
|
|
79
|
+
let workspaces: Workspace[]
|
|
80
|
+
try {
|
|
81
|
+
workspaces = await client.getWorkspaces()
|
|
82
|
+
} catch (err) {
|
|
83
|
+
spinner.fail(fail('Failed to fetch workspaces.'))
|
|
84
|
+
console.error(`\n${muted(err instanceof Error ? err.message : String(err))}\n`)
|
|
85
|
+
process.exit(1)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
spinner.stop()
|
|
89
|
+
|
|
90
|
+
const match = workspaces.find(
|
|
91
|
+
(ws) => ws.slug === slug || ws.name === slug,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
if (!match) {
|
|
95
|
+
console.error(`\n${fail(`Workspace ${chalk.bold(slug)} not found.`)}\n`)
|
|
96
|
+
console.log(`${muted(`Run ${cmd('fiftth use --list')} to see available workspaces.`)}\n`)
|
|
97
|
+
process.exit(1)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
saveConfig({
|
|
101
|
+
...config,
|
|
102
|
+
workspace: match.slug,
|
|
103
|
+
workspaceId: match.id,
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
console.log(`\n${ok(`Now using workspace ${chalk.bold(match.name)} ${muted(`(${match.slug})`)}`)}`)
|
|
107
|
+
console.log(`${kv('Workspace ID', match.id)}\n`)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function interactiveSelectWorkspace(
|
|
111
|
+
config: ReturnType<typeof loadConfig>,
|
|
112
|
+
client: ReturnType<typeof createApiClient>,
|
|
113
|
+
): Promise<void> {
|
|
114
|
+
const spinner = ora('Fetching workspaces...').start()
|
|
115
|
+
|
|
116
|
+
let workspaces: Workspace[]
|
|
117
|
+
try {
|
|
118
|
+
workspaces = await client.getWorkspaces()
|
|
119
|
+
} catch (err) {
|
|
120
|
+
spinner.fail(fail('Failed to fetch workspaces.'))
|
|
121
|
+
console.error(`\n${muted(err instanceof Error ? err.message : String(err))}\n`)
|
|
122
|
+
process.exit(1)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
spinner.stop()
|
|
126
|
+
|
|
127
|
+
if (workspaces.length === 0) {
|
|
128
|
+
console.log(`\n${info('No workspaces found.')}\n`)
|
|
129
|
+
return
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const chosen = await select<string>({
|
|
133
|
+
message: 'Select a workspace',
|
|
134
|
+
choices: workspaces.map((ws) => ({
|
|
135
|
+
value: ws.slug,
|
|
136
|
+
name: `${ws.name} ${chalk.dim(ws.slug)}`,
|
|
137
|
+
})),
|
|
138
|
+
default: config.workspace,
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
const match = workspaces.find((ws) => ws.slug === chosen)!
|
|
142
|
+
saveConfig({
|
|
143
|
+
...config,
|
|
144
|
+
workspace: chosen,
|
|
145
|
+
workspaceId: match.id,
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
console.log(`\n${ok(`Now using workspace ${chalk.bold(match.name)} ${muted(`(${match.slug})`)}`)}\n`)
|
|
149
|
+
}
|
|
@@ -1,40 +1,56 @@
|
|
|
1
|
-
import Conf from 'conf'
|
|
2
|
-
|
|
3
|
-
interface LocalCliConfig {
|
|
4
|
-
repositories: Record<string, string>
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
const config = new Conf<LocalCliConfig>({
|
|
8
|
-
projectName: 'fiftth-cli',
|
|
9
|
-
defaults: {
|
|
10
|
-
repositories: {},
|
|
11
|
-
},
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
export function getRepositories(): Record<string, string> {
|
|
15
|
-
return config.get('repositories')
|
|
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
|
-
|
|
1
|
+
import Conf from 'conf'
|
|
2
|
+
|
|
3
|
+
interface LocalCliConfig {
|
|
4
|
+
repositories: Record<string, string>
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const config = new Conf<LocalCliConfig>({
|
|
8
|
+
projectName: 'fiftth-cli',
|
|
9
|
+
defaults: {
|
|
10
|
+
repositories: {},
|
|
11
|
+
},
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
export function getRepositories(): Record<string, string> {
|
|
15
|
+
return config.get('repositories')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function findRepositoryKey(repoName: string): string | undefined {
|
|
19
|
+
const repositories = getRepositories()
|
|
20
|
+
const exactMatch = Object.prototype.hasOwnProperty.call(repositories, repoName)
|
|
21
|
+
|
|
22
|
+
if (exactMatch) {
|
|
23
|
+
return repoName
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const normalizedRepoName = repoName.toLowerCase()
|
|
27
|
+
return Object.keys(repositories).find((name) => name.toLowerCase() === normalizedRepoName)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function getRepoPath(repoName: string): string | undefined {
|
|
31
|
+
const repositoryKey = findRepositoryKey(repoName)
|
|
32
|
+
if (!repositoryKey) {
|
|
33
|
+
return undefined
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return getRepositories()[repositoryKey]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function addRepository(repoName: string, repoPath: string): { overwritten: boolean } {
|
|
40
|
+
const repositories = getRepositories()
|
|
41
|
+
const overwritten = Boolean(repositories[repoName])
|
|
42
|
+
|
|
43
|
+
config.set(`repositories.${repoName}`, repoPath)
|
|
44
|
+
|
|
45
|
+
return { overwritten }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function removeRepository(repoName: string): boolean {
|
|
49
|
+
const repositoryKey = findRepositoryKey(repoName)
|
|
50
|
+
if (!repositoryKey) {
|
|
51
|
+
return false
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
config.delete(`repositories.${repositoryKey}`)
|
|
55
|
+
return true
|
|
56
|
+
}
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import Conf from 'conf'
|
|
2
|
-
|
|
3
|
-
interface SelectedTaskRepository {
|
|
4
|
-
fullName: string
|
|
5
|
-
branch: string
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface SelectedTaskContext {
|
|
9
|
-
taskId: string
|
|
10
|
-
title: string
|
|
11
|
-
repositories: SelectedTaskRepository[]
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface RuntimeContextStore {
|
|
15
|
-
selectedTask?: SelectedTaskContext
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const contextStore = new Conf<RuntimeContextStore>({
|
|
19
|
-
projectName: 'fiftth-cli',
|
|
20
|
-
defaults: {},
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
let selectedTaskInMemory: SelectedTaskContext | null = null
|
|
24
|
-
|
|
25
|
-
export function setRuntimeSelectedTask(task: SelectedTaskContext): void {
|
|
26
|
-
selectedTaskInMemory = task
|
|
27
|
-
contextStore.set('selectedTask', task)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function getRuntimeSelectedTask(): SelectedTaskContext | null {
|
|
31
|
-
if (selectedTaskInMemory) {
|
|
32
|
-
return selectedTaskInMemory
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return contextStore.get('selectedTask') ?? null
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function clearRuntimeSelectedTask(): void {
|
|
39
|
-
selectedTaskInMemory = null
|
|
40
|
-
contextStore.delete('selectedTask')
|
|
41
|
-
}
|
|
42
|
-
|
|
1
|
+
import Conf from 'conf'
|
|
2
|
+
|
|
3
|
+
interface SelectedTaskRepository {
|
|
4
|
+
fullName: string
|
|
5
|
+
branch: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface SelectedTaskContext {
|
|
9
|
+
taskId: string
|
|
10
|
+
title: string
|
|
11
|
+
repositories: SelectedTaskRepository[]
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface RuntimeContextStore {
|
|
15
|
+
selectedTask?: SelectedTaskContext
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const contextStore = new Conf<RuntimeContextStore>({
|
|
19
|
+
projectName: 'fiftth-cli',
|
|
20
|
+
defaults: {},
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
let selectedTaskInMemory: SelectedTaskContext | null = null
|
|
24
|
+
|
|
25
|
+
export function setRuntimeSelectedTask(task: SelectedTaskContext): void {
|
|
26
|
+
selectedTaskInMemory = task
|
|
27
|
+
contextStore.set('selectedTask', task)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function getRuntimeSelectedTask(): SelectedTaskContext | null {
|
|
31
|
+
if (selectedTaskInMemory) {
|
|
32
|
+
return selectedTaskInMemory
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return contextStore.get('selectedTask') ?? null
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function clearRuntimeSelectedTask(): void {
|
|
39
|
+
selectedTaskInMemory = null
|
|
40
|
+
contextStore.delete('selectedTask')
|
|
41
|
+
}
|
|
42
|
+
|