fg-devkit 1.6.8 → 1.6.9
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 +1 -1
- package/scaffold/vue/package.json +1 -1
- package/scripts/poeditor-upload.mjs +32 -15
package/package.json
CHANGED
|
@@ -8,21 +8,37 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import fs from 'node:fs'
|
|
11
|
+
import path from 'node:path'
|
|
11
12
|
|
|
12
13
|
import { getFlagValue, getPoeditorToken, loadPoeditorConfig, parseFlags, resolvePathFromCwd } from './poeditor-common.mjs'
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
function getUploadType(filePath) {
|
|
16
|
+
const extension = path.extname(filePath).toLowerCase().replace('.', '')
|
|
17
|
+
if (!extension) {
|
|
18
|
+
throw new Error(`Cannot determine file type from "${filePath}"`)
|
|
19
|
+
}
|
|
20
|
+
if (extension === 'json') {
|
|
21
|
+
return 'key_value_json'
|
|
22
|
+
}
|
|
23
|
+
return extension
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function uploadFile({ token, projectId, language, filePath }) {
|
|
27
|
+
const fileBuffer = fs.readFileSync(filePath)
|
|
28
|
+
const fileName = path.basename(filePath)
|
|
29
|
+
const uploadType = getUploadType(filePath)
|
|
30
|
+
const form = new FormData()
|
|
31
|
+
form.append('api_token', token)
|
|
32
|
+
form.append('id', String(projectId))
|
|
33
|
+
form.append('updating', 'terms_translations')
|
|
34
|
+
form.append('language', language)
|
|
35
|
+
form.append('overwrite', '1')
|
|
36
|
+
form.append('type', uploadType)
|
|
37
|
+
form.append('file', new Blob([fileBuffer]), fileName)
|
|
21
38
|
|
|
22
39
|
const res = await fetch('https://api.poeditor.com/v2/projects/upload', {
|
|
23
40
|
method: 'POST',
|
|
24
|
-
|
|
25
|
-
body: params,
|
|
41
|
+
body: form,
|
|
26
42
|
})
|
|
27
43
|
if (!res.ok) {
|
|
28
44
|
throw new Error(`PoEditor upload failed (${res.status})`)
|
|
@@ -31,6 +47,10 @@ async function uploadFile({ token, projectId, language, updating }) {
|
|
|
31
47
|
if (data?.response?.status !== 'success') {
|
|
32
48
|
throw new Error(`Upload failed: ${JSON.stringify(data)}`)
|
|
33
49
|
}
|
|
50
|
+
const translations = data?.result?.translations
|
|
51
|
+
console.log(
|
|
52
|
+
`[poeditor-upload] Upload complete for "${language}" (parsed: ${translations?.parsed ?? 0}, updated: ${translations?.updated ?? 0}, added: ${translations?.added ?? 0})`,
|
|
53
|
+
)
|
|
34
54
|
}
|
|
35
55
|
|
|
36
56
|
async function main() {
|
|
@@ -49,8 +69,7 @@ async function main() {
|
|
|
49
69
|
if (hasExplicitLanguage || hasExplicitFile) {
|
|
50
70
|
const language = getFlagValue(flags, 'language', cfg.defaultLanguage)
|
|
51
71
|
const filePath = resolvePathFromCwd(getFlagValue(flags, 'file', cfg.uploadFile))
|
|
52
|
-
|
|
53
|
-
await uploadFile({ token, projectId, language, updating })
|
|
72
|
+
await uploadFile({ token, projectId, language, filePath })
|
|
54
73
|
console.log(`[poeditor-upload] Upload completed for ${language}: ${filePath}`)
|
|
55
74
|
return
|
|
56
75
|
}
|
|
@@ -59,8 +78,7 @@ async function main() {
|
|
|
59
78
|
if (uploads.length > 0) {
|
|
60
79
|
for (const [language, file] of uploads) {
|
|
61
80
|
const filePath = resolvePathFromCwd(file)
|
|
62
|
-
|
|
63
|
-
await uploadFile({ token, projectId, language, updating })
|
|
81
|
+
await uploadFile({ token, projectId, language, filePath })
|
|
64
82
|
console.log(`[poeditor-upload] Upload completed for ${language}: ${filePath}`)
|
|
65
83
|
}
|
|
66
84
|
return
|
|
@@ -68,8 +86,7 @@ async function main() {
|
|
|
68
86
|
|
|
69
87
|
const language = cfg.defaultLanguage
|
|
70
88
|
const filePath = resolvePathFromCwd(cfg.uploadFile)
|
|
71
|
-
|
|
72
|
-
await uploadFile({ token, projectId, language, updating })
|
|
89
|
+
await uploadFile({ token, projectId, language, filePath })
|
|
73
90
|
console.log(`[poeditor-upload] Upload completed for ${language}: ${filePath}`)
|
|
74
91
|
}
|
|
75
92
|
|