crowdin-credentials.ts 847 B

1234567891011121314151617181920212223242526
  1. import path from 'path'
  2. import fs from 'fs/promises'
  3. import chalk from 'chalk'
  4. import consola from 'consola'
  5. import { docRoot, errorAndExit } from '@element-plus/build-utils'
  6. const credentialPlaceholder = 'API_TOKEN_PLACEHOLDER'
  7. const CREDENTIAL = process.env.CROWDIN_TOKEN
  8. if (!CREDENTIAL) {
  9. errorAndExit(new Error('Environment variable CROWDIN_TOKEN cannot be empty'))
  10. }
  11. ;(async () => {
  12. consola.debug(chalk.cyan('Fetching Crowdin credential'))
  13. const configPath = path.resolve(docRoot, 'crowdin.yml')
  14. try {
  15. const file = await fs.readFile(configPath, {
  16. encoding: 'utf-8',
  17. })
  18. await fs.writeFile(configPath, file.replace(credentialPlaceholder, CREDENTIAL))
  19. consola.success(chalk.green('Crowdin credential update successfully'))
  20. } catch (e: any) {
  21. errorAndExit(e)
  22. }
  23. })()