Merge branch 'feature/fixsw' into 'release/10.10'
fix sw See merge request !1549
Showing
3 changed files
with
29 additions
and
17 deletions
@@ -2,7 +2,7 @@ const shelljs = require('shelljs'); | @@ -2,7 +2,7 @@ const shelljs = require('shelljs'); | ||
2 | const yargs = require('yargs'); | 2 | const yargs = require('yargs'); |
3 | const path = require('path'); | 3 | const path = require('path'); |
4 | const cssnano = require('cssnano'); | 4 | const cssnano = require('cssnano'); |
5 | -const request = require('request'); | 5 | +const rp = require('request-promise'); |
6 | const fs = require('fs'); | 6 | const fs = require('fs'); |
7 | const pkg = require('../package.json'); | 7 | const pkg = require('../package.json'); |
8 | 8 | ||
@@ -33,19 +33,30 @@ new Promise((resolve, reject) => { // 加载manifest.json文件 | @@ -33,19 +33,30 @@ new Promise((resolve, reject) => { // 加载manifest.json文件 | ||
33 | cpPaths.push(`dist/statics/yohobuywap-node/${pkg.version}/manifest.json`); | 33 | cpPaths.push(`dist/statics/yohobuywap-node/${pkg.version}/manifest.json`); |
34 | resolve(); | 34 | resolve(); |
35 | } else { | 35 | } else { |
36 | - request({ | ||
37 | - url: `https://cdn.yoho.cn/yohobuywap-node/${pkg.version}/manifest.json`, | ||
38 | - gzip: true, | ||
39 | - json: true | ||
40 | - }, (error, response, data) => { | ||
41 | - if (error || !data || data.error) { | ||
42 | - return reject(`download manifest.json faild:${error || !data || data.error}`); | 36 | + return Promise.all([ |
37 | + rp({ | ||
38 | + url: `https://cdn.yoho.cn/yohobuywap-node/${pkg.version}/manifest.json`, | ||
39 | + gzip: true, | ||
40 | + json: true | ||
41 | + }), | ||
42 | + rp({ | ||
43 | + url: 'https://m.yohobuy.com/sw.js', | ||
44 | + gzip: true | ||
45 | + }), | ||
46 | + ]).then(results => { | ||
47 | + const [manifest, sw] = results; | ||
48 | + | ||
49 | + if (!manifest || !sw) { | ||
50 | + throw 'manifest.json or sw.js download faild'; | ||
43 | } | 51 | } |
44 | - fs.writeFileSync(path.join(distDir, 'manifest.json'), JSON.stringify(data), { | 52 | + fs.writeFileSync(path.join(distDir, 'manifest.json'), JSON.stringify(manifest), { |
53 | + flag: 'w' | ||
54 | + }); | ||
55 | + fs.writeFileSync(path.join(__dirname, '../public/static/sw.js'), sw, { | ||
45 | flag: 'w' | 56 | flag: 'w' |
46 | }); | 57 | }); |
47 | resolve(); | 58 | resolve(); |
48 | - }); | 59 | + }).catch(reject); |
49 | } | 60 | } |
50 | }).then(() => { // 拷贝node代码 | 61 | }).then(() => { // 拷贝node代码 |
51 | cpPaths.forEach(p => { | 62 | cpPaths.forEach(p => { |
@@ -4778,9 +4778,9 @@ inflight@^1.0.4: | @@ -4778,9 +4778,9 @@ inflight@^1.0.4: | ||
4778 | once "^1.3.0" | 4778 | once "^1.3.0" |
4779 | wrappy "1" | 4779 | wrappy "1" |
4780 | 4780 | ||
4781 | -influx-batch-sender@^0.1.6: | ||
4782 | - version "0.1.6" | ||
4783 | - resolved "http://npm.yohops.com/influx-batch-sender/-/influx-batch-sender-0.1.6.tgz#fe4fb11ac80ece3ca791e40c8de098ce0181d499" | 4781 | +influx-batch-sender@^0.1.7: |
4782 | + version "0.1.7" | ||
4783 | + resolved "http://npm.yohops.com/influx-batch-sender/-/influx-batch-sender-0.1.7.tgz#9f925bfc500e886cae27001b3cc20f2584fa464a" | ||
4784 | dependencies: | 4784 | dependencies: |
4785 | debug "^3.0.1" | 4785 | debug "^3.0.1" |
4786 | lodash "^4.17.4" | 4786 | lodash "^4.17.4" |
@@ -11102,13 +11102,13 @@ yoho-md5@^2.0.0: | @@ -11102,13 +11102,13 @@ yoho-md5@^2.0.0: | ||
11102 | version "2.1.0" | 11102 | version "2.1.0" |
11103 | resolved "http://npm.yohops.com/yoho-md5/-/yoho-md5-2.1.0.tgz#f0c00d343f775e77952ebce0826863ac52e0ad50" | 11103 | resolved "http://npm.yohops.com/yoho-md5/-/yoho-md5-2.1.0.tgz#f0c00d343f775e77952ebce0826863ac52e0ad50" |
11104 | 11104 | ||
11105 | -yoho-node-lib@=0.6.32: | ||
11106 | - version "0.6.32" | ||
11107 | - resolved "http://npm.yohops.com/yoho-node-lib/-/yoho-node-lib-0.6.32.tgz#285b9c89445ed3e6aed9e2cdd4efb7637652a375" | 11105 | +yoho-node-lib@=0.6.33: |
11106 | + version "0.6.33" | ||
11107 | + resolved "http://npm.yohops.com/yoho-node-lib/-/yoho-node-lib-0.6.33.tgz#fca4dadedb80438d30d06fbb386d09912a4f9ca6" | ||
11108 | dependencies: | 11108 | dependencies: |
11109 | dnscache "^1.0.1" | 11109 | dnscache "^1.0.1" |
11110 | handlebars "^4.0.5" | 11110 | handlebars "^4.0.5" |
11111 | - influx-batch-sender "^0.1.6" | 11111 | + influx-batch-sender "^0.1.7" |
11112 | lodash "^4.13.1" | 11112 | lodash "^4.13.1" |
11113 | lru-cache "^4.1.1" | 11113 | lru-cache "^4.1.1" |
11114 | md5 "^2.1.0" | 11114 | md5 "^2.1.0" |
-
Please register or login to post a comment