quasar

Форк
0
/
build.lang.js 
67 строк · 1.8 Кб
1
const path = require('node:path')
2
const glob = require('fast-glob')
3
const fse = require('fs-extra')
4

5
const { logError, writeFileIfChanged, convertToCjs } = require('./build.utils')
6

7
const
8
  root = path.resolve(__dirname, '..'),
9
  resolve = file => path.resolve(root, file)
10

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 }).
15
 */
16
`
17

18
function parse (prop, txt) {
19
  const
20
    propIndex = txt.indexOf(prop),
21
    startIndex = txt.indexOf('\'', propIndex) + 1
22

23
  let stopIndex = txt.indexOf('\'', startIndex)
24

25
  while (txt.charAt(stopIndex - 1) === '\\') {
26
    stopIndex = txt.indexOf('\'', stopIndex + 1)
27
  }
28

29
  return txt.substring(startIndex, stopIndex).replace('\\', '')
30
}
31

32
module.exports.generate = function () {
33
  const languages = []
34
  const promises = []
35
  try {
36
    glob.sync('lang/*.mjs', { cwd: root, absolute: true })
37
      .forEach(file => {
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 })
42

43
        const cjsFile = file.replace('.mjs', '.js')
44
        const banner = cjsBanner(path.basename(file))
45
        promises.push(
46
          writeFileIfChanged(cjsFile, convertToCjs(content, banner))
47
        )
48
      })
49

50
    const
51
      langFile = resolve('lang/index.json'),
52
      quasarLangIndex = JSON.stringify(languages)
53

54
    promises.push(
55
      writeFileIfChanged(langFile, quasarLangIndex)
56
    )
57

58
    return Promise.all(promises).then(() => languages)
59
  }
60
  catch (err) {
61
    logError('build.lang.js: something went wrong...')
62
    console.log()
63
    console.error(err)
64
    console.log()
65
    process.exit(1)
66
  }
67
}
68

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.