1
const path = require('node:path')
2
const glob = require('fast-glob')
3
const fse = require('fs-extra')
5
const { logError, writeFileIfChanged, convertToCjs } = require('./build.utils')
8
root = path.resolve(__dirname, '..'),
9
resolve = file => path.resolve(root, file)
11
const cjsBanner = setName => `/**
12
* DO NOT EDIT THIS FILE. It is automatically generated
13
* from its .mjs counterpart (same filename but with .mjs extension).
14
* Edit that file instead (${ setName }).
18
function parse (prop, txt) {
20
propIndex = txt.indexOf(prop),
21
startIndex = txt.indexOf('\'', propIndex) + 1
23
let stopIndex = txt.indexOf('\'', startIndex)
25
while (txt.charAt(stopIndex - 1) === '\\') {
26
stopIndex = txt.indexOf('\'', stopIndex + 1)
29
return txt.substring(startIndex, stopIndex).replace('\\', '')
32
module.exports.generate = function () {
36
glob.sync('lang/*.mjs', { cwd: root, absolute: true })
38
const content = fse.readFileSync(file, 'utf-8')
39
const isoName = parse('isoName', content)
40
const nativeName = parse('nativeName', content)
41
languages.push({ isoName, nativeName })
43
const cjsFile = file.replace('.mjs', '.js')
44
const banner = cjsBanner(path.basename(file))
46
writeFileIfChanged(cjsFile, convertToCjs(content, banner))
51
langFile = resolve('lang/index.json'),
52
quasarLangIndex = JSON.stringify(languages)
55
writeFileIfChanged(langFile, quasarLangIndex)
58
return Promise.all(promises).then(() => languages)
61
logError('build.lang.js: something went wrong...')