jest.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const fs = require('fs');
  2. const request = require('request');
  3. const newPath = process.argv[2];
  4. if (!newPath) {
  5. process.exit(0);
  6. }
  7. const fontPath = 'http://at.alicdn.com/t/' + newPath;
  8. const suffixs = ['.eot', '.woff', '.ttf', '.svg', '.css'];
  9. const promise = (ele) => {
  10. return new Promise((resolve, reject) => {
  11. const downloadPath = `${fontPath}${ele}`;
  12. const options = {
  13. method: 'GET',
  14. url: downloadPath,
  15. headers: {
  16. 'cache-control': 'no-cache'
  17. }
  18. };
  19. request(options, (error, response, body) => {
  20. if (error) {
  21. reject(`iconfont${ele} fail`);
  22. throw new Error(error);
  23. }
  24. if (ele === '.css') {
  25. // body = body.replace(/16px/, '50px');
  26. fs.writeFileSync(`./src/assets/iconfont/iconfont.less`, body);
  27. } else {
  28. fs.writeFileSync(`./src/assets/iconfont/iconfont${ele}`, body);
  29. }
  30. resolve(`iconfont${ele} downloaded`);
  31. });
  32. });
  33. };
  34. const promises = suffixs.map((ele) => {
  35. return promise(ele);
  36. });
  37. Promise.all(promises).then((res) => {
  38. console.log(res);
  39. process.exit(0);
  40. });