uva-cli 1.1.0 → 1.2.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/bin.mjs +6 -2
- package/commands/init.mjs +10 -5
- package/lib/config.mjs +31 -4
- package/lib/locales/en.mjs +1 -0
- package/lib/locales/pt-br.mjs +1 -0
- package/package.json +1 -1
package/bin.mjs
CHANGED
|
@@ -9,11 +9,15 @@ import { runStart } from './commands/start.mjs'
|
|
|
9
9
|
|
|
10
10
|
const program = new Command()
|
|
11
11
|
|
|
12
|
-
program.name('uva').description('UVA CLI — Git workflow automation').version('1.
|
|
12
|
+
program.name('uva').description('UVA CLI — Git workflow automation').version('1.1.0')
|
|
13
13
|
|
|
14
14
|
program.command('start').description('Show all available options interactively').action(runStart)
|
|
15
15
|
|
|
16
|
-
program
|
|
16
|
+
program
|
|
17
|
+
.command('init')
|
|
18
|
+
.description('Set up UVA CLI for this project')
|
|
19
|
+
.option('--global', 'save as global config (~/.config/uva/config.json)')
|
|
20
|
+
.action(runInit)
|
|
17
21
|
|
|
18
22
|
program
|
|
19
23
|
.command('commit')
|
package/commands/init.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { text, select, confirm, isCancel } from '@clack/prompts'
|
|
1
|
+
import { text, select, confirm, isCancel, log } from '@clack/prompts'
|
|
2
2
|
import { bannerIntro, bannerOutro, bannerCancelled } from '../lib/banner.mjs'
|
|
3
|
-
import { loadConfig, saveConfig } from '../lib/config.mjs'
|
|
3
|
+
import { loadConfig, loadGlobalConfig, saveConfig, saveGlobalConfig } from '../lib/config.mjs'
|
|
4
4
|
import { COMMIT_FORMATS, BRANCH_FORMATS } from '../lib/types.mjs'
|
|
5
5
|
import { getLocale } from '../lib/i18n.mjs'
|
|
6
6
|
|
|
7
|
-
export async function runInit() {
|
|
7
|
+
export async function runInit(opts = {}) {
|
|
8
|
+
const isGlobal = Boolean(opts.global)
|
|
8
9
|
bannerIntro('init')
|
|
9
10
|
|
|
10
11
|
// Language is always the first question — no config exists yet
|
|
@@ -22,7 +23,11 @@ export async function runInit() {
|
|
|
22
23
|
|
|
23
24
|
const t = getLocale({ project: { lang } })
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
if (isGlobal) {
|
|
27
|
+
log.info(t.init.globalMode)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const existing = isGlobal ? loadGlobalConfig() : loadConfig()
|
|
26
31
|
if (existing) {
|
|
27
32
|
const overwrite = await confirm({ message: t.init.overwriteConfirm })
|
|
28
33
|
if (isCancel(overwrite) || !overwrite) {
|
|
@@ -167,6 +172,6 @@ export async function runInit() {
|
|
|
167
172
|
},
|
|
168
173
|
}
|
|
169
174
|
|
|
170
|
-
const configPath = saveConfig(config)
|
|
175
|
+
const configPath = isGlobal ? saveGlobalConfig(config) : saveConfig(config)
|
|
171
176
|
bannerOutro(t.init.saved(configPath))
|
|
172
177
|
}
|
package/lib/config.mjs
CHANGED
|
@@ -1,15 +1,34 @@
|
|
|
1
|
-
import { existsSync, readFileSync, writeFileSync } from 'fs'
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs'
|
|
2
2
|
import { join } from 'path'
|
|
3
|
+
import { homedir } from 'os'
|
|
3
4
|
import { log } from '@clack/prompts'
|
|
4
5
|
import { getGitRoot } from './git.mjs'
|
|
5
6
|
|
|
6
7
|
function getConfigPath() {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
try {
|
|
9
|
+
const root = getGitRoot()
|
|
10
|
+
return join(root, 'uva.config.json')
|
|
11
|
+
} catch {
|
|
12
|
+
return null
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function getGlobalConfigPath() {
|
|
17
|
+
return join(homedir(), '.config', 'uva', 'config.json')
|
|
9
18
|
}
|
|
10
19
|
|
|
11
20
|
export function loadConfig() {
|
|
12
21
|
const path = getConfigPath()
|
|
22
|
+
if (!path || !existsSync(path)) return null
|
|
23
|
+
try {
|
|
24
|
+
return JSON.parse(readFileSync(path, { encoding: 'utf-8' }))
|
|
25
|
+
} catch {
|
|
26
|
+
return null
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function loadGlobalConfig() {
|
|
31
|
+
const path = getGlobalConfigPath()
|
|
13
32
|
if (!existsSync(path)) return null
|
|
14
33
|
try {
|
|
15
34
|
return JSON.parse(readFileSync(path, { encoding: 'utf-8' }))
|
|
@@ -24,8 +43,16 @@ export function saveConfig(config) {
|
|
|
24
43
|
return path
|
|
25
44
|
}
|
|
26
45
|
|
|
46
|
+
export function saveGlobalConfig(config) {
|
|
47
|
+
const dir = join(homedir(), '.config', 'uva')
|
|
48
|
+
const path = join(dir, 'config.json')
|
|
49
|
+
mkdirSync(dir, { recursive: true })
|
|
50
|
+
writeFileSync(path, JSON.stringify(config, null, 2) + '\n', { encoding: 'utf-8' })
|
|
51
|
+
return path
|
|
52
|
+
}
|
|
53
|
+
|
|
27
54
|
export function requireConfig() {
|
|
28
|
-
const config = loadConfig()
|
|
55
|
+
const config = loadConfig() ?? loadGlobalConfig()
|
|
29
56
|
if (!config) {
|
|
30
57
|
log.error('No configuration found. Run `uva init` to set up your project.')
|
|
31
58
|
process.exit(1)
|
package/lib/locales/en.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export default {
|
|
2
2
|
init: {
|
|
3
3
|
langSelect: 'Language / Idioma',
|
|
4
|
+
globalMode: 'Global configuration — applies to all projects without a local config',
|
|
4
5
|
overwriteConfirm: 'A configuration already exists. Do you want to overwrite it?',
|
|
5
6
|
projectName: 'Project name',
|
|
6
7
|
projectNamePlaceholder: 'My Awesome Project',
|
package/lib/locales/pt-br.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export default {
|
|
2
2
|
init: {
|
|
3
3
|
langSelect: 'Language / Idioma',
|
|
4
|
+
globalMode: 'Configuração global — aplicada a todos os projetos sem config local',
|
|
4
5
|
overwriteConfirm: 'Já existe uma configuração. Deseja sobrescrever?',
|
|
5
6
|
projectName: 'Nome do projeto',
|
|
6
7
|
projectNamePlaceholder: 'Meu Projeto Incrível',
|