fg-devkit 1.6.6 → 1.6.8
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/package.json
CHANGED
|
@@ -10,6 +10,34 @@ function readJsonIfExists(filePath) {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
function readEnvValueFromFile(filePath, key) {
|
|
14
|
+
if (!fs.existsSync(filePath)) return ''
|
|
15
|
+
try {
|
|
16
|
+
const raw = fs.readFileSync(filePath, 'utf8')
|
|
17
|
+
const lines = raw.split(/\r?\n/)
|
|
18
|
+
for (const line of lines) {
|
|
19
|
+
const trimmed = line.trim()
|
|
20
|
+
if (!trimmed || trimmed.startsWith('#')) continue
|
|
21
|
+
const noExport = trimmed.startsWith('export ') ? trimmed.slice(7).trim() : trimmed
|
|
22
|
+
const eqIdx = noExport.indexOf('=')
|
|
23
|
+
if (eqIdx <= 0) continue
|
|
24
|
+
const k = noExport.slice(0, eqIdx).trim()
|
|
25
|
+
if (k !== key) continue
|
|
26
|
+
let value = noExport.slice(eqIdx + 1).trim()
|
|
27
|
+
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
28
|
+
value = value.slice(1, -1)
|
|
29
|
+
} else {
|
|
30
|
+
const hashIdx = value.indexOf(' #')
|
|
31
|
+
if (hashIdx >= 0) value = value.slice(0, hashIdx).trim()
|
|
32
|
+
}
|
|
33
|
+
return value
|
|
34
|
+
}
|
|
35
|
+
} catch {
|
|
36
|
+
return ''
|
|
37
|
+
}
|
|
38
|
+
return ''
|
|
39
|
+
}
|
|
40
|
+
|
|
13
41
|
function resolveFromCwd(p) {
|
|
14
42
|
return path.isAbsolute(p) ? p : path.resolve(process.cwd(), p)
|
|
15
43
|
}
|
|
@@ -112,6 +140,12 @@ export function getPoeditorToken(flags) {
|
|
|
112
140
|
const fromFlag = getFlagValue(flags, 'api-token')
|
|
113
141
|
if (fromFlag) return fromFlag
|
|
114
142
|
if (process.env.POEDITOR_API_KEY) return process.env.POEDITOR_API_KEY
|
|
143
|
+
const plainEnvLocal = readEnvValueFromFile(resolveFromCwd('./env.local'), 'POEDITOR_API_KEY')
|
|
144
|
+
if (plainEnvLocal) return plainEnvLocal
|
|
145
|
+
const envLocal = readEnvValueFromFile(resolveFromCwd('./.env.local'), 'POEDITOR_API_KEY')
|
|
146
|
+
if (envLocal) return envLocal
|
|
147
|
+
const envFile = readEnvValueFromFile(resolveFromCwd('./.env'), 'POEDITOR_API_KEY')
|
|
148
|
+
if (envFile) return envFile
|
|
115
149
|
const publicConfigPath = resolveFromCwd('./public/config.json')
|
|
116
150
|
const publicConfig = readJsonIfExists(publicConfigPath)
|
|
117
151
|
if (typeof publicConfig?.POEDITOR_API_KEY === 'string') {
|
|
@@ -36,9 +36,16 @@ async function exportLanguage({ token, projectId, language, format }) {
|
|
|
36
36
|
throw new Error(`PoEditor export failed (${res.status})`)
|
|
37
37
|
}
|
|
38
38
|
const data = await res.json()
|
|
39
|
+
if (data?.response?.status !== 'success') {
|
|
40
|
+
const message = data?.response?.message ?? 'Unknown PoEditor error'
|
|
41
|
+
const code = data?.response?.code
|
|
42
|
+
const details = data?.response?.details
|
|
43
|
+
const suffix = [code !== undefined ? `code=${code}` : '', details ? `details=${details}` : ''].filter(Boolean).join(', ')
|
|
44
|
+
throw new Error(`PoEditor export failed for language ${language}: ${message}${suffix ? ` (${suffix})` : ''}`)
|
|
45
|
+
}
|
|
39
46
|
const url = data?.result?.url
|
|
40
47
|
if (!url) {
|
|
41
|
-
throw new Error(`PoEditor export missing URL for language ${language}`)
|
|
48
|
+
throw new Error(`PoEditor export missing URL for language ${language}: ${JSON.stringify(data)}`)
|
|
42
49
|
}
|
|
43
50
|
return url
|
|
44
51
|
}
|