123456789101112131415161718192021222324252627282930313233343536373839404142 |
- const fs = require('fs');
- const request = require('request');
- const newPath = process.argv[2];
- if (!newPath) {
- process.exit(0);
- }
- const fontPath = 'http://at.alicdn.com/t/' + newPath;
- const suffixs = ['.eot', '.woff', '.ttf', '.svg', '.css'];
- const promise = (ele) => {
- return new Promise((resolve, reject) => {
- const downloadPath = `${fontPath}${ele}`;
- const options = {
- method: 'GET',
- url: downloadPath,
- headers: {
- 'cache-control': 'no-cache'
- }
- };
- request(options, (error, response, body) => {
- if (error) {
- reject(`iconfont${ele} fail`);
- throw new Error(error);
- }
- if (ele === '.css') {
- // body = body.replace(/16px/, '50px');
- fs.writeFileSync(`./src/assets/iconfont/iconfont.less`, body);
- } else {
- fs.writeFileSync(`./src/assets/iconfont/iconfont${ele}`, body);
- }
- resolve(`iconfont${ele} downloaded`);
- });
- });
- };
- const promises = suffixs.map((ele) => {
- return promise(ele);
- });
- Promise.all(promises).then((res) => {
- console.log(res);
- process.exit(0);
- });
|