files.js 653 B

123456789101112131415161718192021222324252627282930
  1. const fs = require('fs');
  2. const path = require('path');
  3. module.exports = {
  4. getCurrentDirectoryBase: () => {
  5. return path.basename(process.cwd());
  6. },
  7. directoryExists: (filePath) => {
  8. return fs.existsSync(filePath);
  9. },
  10. writeIpAddress: (value) => {
  11. const data = {
  12. ipAddress: value
  13. }
  14. try {
  15. fs.writeFileSync('./data/MiWatch.json', JSON.stringify(data))
  16. } catch (err) {
  17. console.log(err)
  18. }
  19. },
  20. loadPackageList: () => {
  21. try {
  22. const packageList = JSON.parse(fs.readFileSync('./data/packageList.json', 'utf8'));
  23. return packageList
  24. } catch (err) {
  25. console.log(err)
  26. }
  27. },
  28. };