config.js 963 B

1234567891011121314151617181920212223242526272829303132333435
  1. import fs from 'fs'
  2. import Path from 'path'
  3. import { fileURLToPath } from 'url'
  4. const __dirname = fileURLToPath(new URL('.', import.meta.url))
  5. const ONESKY_SETTING_PATH = Path.join(__dirname, '../../data/onesky.json')
  6. let userOptions
  7. try {
  8. userOptions = JSON.parse(fs.readFileSync(ONESKY_SETTING_PATH))
  9. } catch (err) {
  10. if (err.code !== 'ENOENT') throw err
  11. if (!process.env.ONE_SKY_PUBLIC_KEY) {
  12. console.error(
  13. 'Cannot detect onesky credentials.\n\tDevelopers: see the docs at',
  14. 'https://github.com/overleaf/developer-manual/blob/master/code/translations.md#testing-translations-scripts',
  15. '\n\tOps: environment variable ONE_SKY_PUBLIC_KEY is not set'
  16. )
  17. process.exit(1)
  18. }
  19. }
  20. function withAuth(options) {
  21. return Object.assign(
  22. options,
  23. {
  24. apiKey: process.env.ONE_SKY_PUBLIC_KEY,
  25. secret: process.env.ONE_SKY_PRIVATE_KEY,
  26. projectId: '25049',
  27. },
  28. userOptions
  29. )
  30. }
  31. export default {
  32. withAuth,
  33. }