files.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const fs = require('fs');
  2. const path = require('path');
  3. const tiny = require("@peterpanhihi/tiny");
  4. const { resolve } = require('path');
  5. module.exports = {
  6. getCurrentDirectoryBase: () => {
  7. return path.basename(process.cwd());
  8. },
  9. directoryExists: (filePath) => {
  10. return fs.existsSync(filePath);
  11. },
  12. writeIpAddress: (value) => {
  13. const data = {
  14. ipAddress: value
  15. }
  16. try {
  17. fs.writeFileSync('./data/options.json', JSON.stringify(data))
  18. } catch (err) {
  19. console.log(err)
  20. }
  21. },
  22. loadPackageList: () => {
  23. try {
  24. const packageList = JSON.parse(fs.readFileSync('./data/xiaomiPackageRemovalList.json', 'utf8'));
  25. return packageList
  26. } catch (err) {
  27. console.log(err)
  28. }
  29. },
  30. renameLocalApk: async (apkList) => {
  31. return new Promise(function (resolve, reject) {
  32. for (let e of apkList) {
  33. a = tiny(e)
  34. fs.rename(e, a, function (err) {
  35. if (err) console.log('ERROR: ' + err);
  36. });
  37. }
  38. resolve(x / y);
  39. }).catch(err => NaN)
  40. }
  41. }