crowdin-credentials.ts 827 B

1234567891011121314151617181920212223242526272829
  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(
  19. configPath,
  20. file.replace(credentialPlaceholder, CREDENTIAL)
  21. )
  22. consola.success(chalk.green('Crowdin credential update successfully'))
  23. } catch (e: any) {
  24. errorAndExit(e)
  25. }
  26. })()