createConfig.js 766 B

123456789101112131415161718192021222324252627
  1. import fs from 'fs'
  2. import path from 'path'
  3. const homeDir =
  4. process.env[process.platform === 'win32' ? 'USERPROFILE' : 'HOME']
  5. const configDir = path.join(homeDir, '.config', 'gpt-cli')
  6. const pluginsDir = path.join(configDir, 'plugins')
  7. const configFile = path.join(configDir, '.gptrc')
  8. // if not config directory, create it
  9. if (!fs.existsSync(configDir)) {
  10. fs.mkdirSync(configDir, { recursive: true })
  11. }
  12. // if not plugin directory, create it
  13. if (!fs.existsSync(pluginsDir)) {
  14. fs.mkdirSync(pluginsDir, { recursive: true })
  15. }
  16. // if exits, do nothing, process exits with code 0
  17. if (fs.existsSync(configFile)) {
  18. process.exit(0)
  19. }
  20. fs.writeFileSync(configFile, '', { mode: 0o600 })
  21. console.log(`${configDir} directory and ${configFile} file were created.`)