|
1
|
async function generateCurrencies() { |
|
2
|
const { currencies } = await import( |
|
3
|
"@medusajs/medusa/dist/utils/currencies.js" |
|
4
|
) |
|
5
|
const fs = await import("fs") |
|
6
|
const path = await import("path") |
|
7
|
|
|
8
|
const record = Object.entries(currencies).reduce((acc, [key, values]) => { |
|
9
|
const code = values.code |
|
10
|
const symbol_native = values.symbol_native |
|
11
|
const name = values.name |
|
12
|
const decimal_digits = values.decimal_digits |
|
13
|
|
|
14
|
acc[key] = { |
|
15
|
code, |
|
16
|
name, |
|
17
|
symbol_native, |
|
18
|
decimal_digits, |
|
19
|
} |
|
20
|
|
|
21
|
return acc |
|
22
|
}, {}) |
|
23
|
|
|
24
|
const json = JSON.stringify(record, null, 2) |
|
25
|
|
|
26
|
const dest = path.join(__dirname, "../src/lib/currencies.ts") |
|
27
|
const destDir = path.dirname(dest) |
|
28
|
|
|
29
|
const fileContent = `/** This file is auto-generated. Do not modify it manually. */\ntype CurrencyInfo = { code: string; name: string; symbol_native: string; decimal_digits: number }\n\nexport const currencies: Record<string, CurrencyInfo> = ${json}` |
|
30
|
|
|
31
|
if (!fs.existsSync(destDir)) { |
|
32
|
fs.mkdirSync(destDir, { recursive: true }) |
|
33
|
} |
|
34
|
|
|
35
|
fs.writeFileSync(dest, fileContent) |
|
36
|
} |
|
37
|
|
|
38
|
;(async () => { |
|
39
|
console.log("Generating currency info") |
|
40
|
try { |
|
41
|
await generateCurrencies() |
|
42
|
console.log("Currency info generated") |
|
43
|
} catch (e) { |
|
44
|
console.error(e) |
|
45
|
} |
|
46
|
})() |