...
|
...
|
@@ -2,7 +2,7 @@ const shelljs = require('shelljs'); |
|
|
const yargs = require('yargs');
|
|
|
const path = require('path');
|
|
|
const cssnano = require('cssnano');
|
|
|
const request = require('request');
|
|
|
const rp = require('request-promise');
|
|
|
const fs = require('fs');
|
|
|
const pkg = require('../package.json');
|
|
|
|
...
|
...
|
@@ -33,19 +33,30 @@ new Promise((resolve, reject) => { // 加载manifest.json文件 |
|
|
cpPaths.push(`dist/statics/yohobuywap-node/${pkg.version}/manifest.json`);
|
|
|
resolve();
|
|
|
} else {
|
|
|
request({
|
|
|
url: `https://cdn.yoho.cn/yohobuywap-node/${pkg.version}/manifest.json`,
|
|
|
gzip: true,
|
|
|
json: true
|
|
|
}, (error, response, data) => {
|
|
|
if (error || !data || data.error) {
|
|
|
return reject(`download manifest.json faild:${error || !data || data.error}`);
|
|
|
return Promise.all([
|
|
|
rp({
|
|
|
url: `https://cdn.yoho.cn/yohobuywap-node/${pkg.version}/manifest.json`,
|
|
|
gzip: true,
|
|
|
json: true
|
|
|
}),
|
|
|
rp({
|
|
|
url: 'https://m.yohobuy.com/sw.js',
|
|
|
gzip: true
|
|
|
}),
|
|
|
]).then(results => {
|
|
|
const [manifest, sw] = results;
|
|
|
|
|
|
if (!manifest || !sw) {
|
|
|
throw 'manifest.json or sw.js download faild';
|
|
|
}
|
|
|
fs.writeFileSync(path.join(distDir, 'manifest.json'), JSON.stringify(data), {
|
|
|
fs.writeFileSync(path.join(distDir, 'manifest.json'), JSON.stringify(manifest), {
|
|
|
flag: 'w'
|
|
|
});
|
|
|
fs.writeFileSync(path.join(__dirname, '../public/static/sw.js'), sw, {
|
|
|
flag: 'w'
|
|
|
});
|
|
|
resolve();
|
|
|
});
|
|
|
}).catch(reject);
|
|
|
}
|
|
|
}).then(() => { // 拷贝node代码
|
|
|
cpPaths.forEach(p => {
|
...
|
...
|
|