grunt-cacheinfo
Advanced tools
Comparing version 0.4.7 to 0.4.8
{ | ||
"name": "grunt-cacheinfo", | ||
"description": "cacheinfo.", | ||
"version": "0.4.7", | ||
"version": "0.4.8", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "bachi", |
@@ -23,2 +23,4 @@ # grunt-cacheinfo | ||
- 0.4.8 | ||
- 支持 `market.m.taobao.com` 域名构建 | ||
- 0.4.5 | ||
@@ -25,0 +27,0 @@ - 请求 `offline-config/index.json` 失败,立刻终止构建 |
@@ -41,3 +41,3 @@ /* | ||
offlineSyncDir: 'offline-trip-sync', | ||
offlineSyncHost: 'g.alicdn.com', | ||
offlineSyncHost: 'g.alicdn.com' | ||
}); | ||
@@ -171,2 +171,20 @@ | ||
} else { | ||
let isAir = (abc.defPublishType === 'weex' || abc.defPublishType === 'webapp') && !abc.awpProxy; | ||
let wapUrlDomain = options.wapUrlDomain || (isAir ? 'http://market.m.taobao.com/' : 'http://h5.m.taobao.com/'); | ||
let baseUrl = abc.baseUrl.replace(/^\//, ''); | ||
// 迁移至 weex/webapp 兼容老版本 | ||
if (isAir && !/^\/?app\//.test(baseUrl)) { | ||
// trip/abc => trip/h5-abc | ||
if (/^h5-/.test(abc.name) && !/^trip\/h5-/.test(baseUrl)) { | ||
baseUrl = baseUrl.replace(/^trip\//, 'trip/h5-'); | ||
} | ||
// trip/h5-abc/home => trip/h5-abc/pages/home | ||
if (baseUrl.indexOf('trip/' + abc.name + '/pages/') !== 0) { | ||
baseUrl = baseUrl.replace('trip/' + abc.name, 'trip/' + abc.name + '/pages'); | ||
} | ||
// trip/h5-abc/pages/home => app/trip/h5-abc/pages/home | ||
baseUrl = 'app/' + baseUrl; | ||
} | ||
// 优先取 abc.json 中配置 | ||
@@ -178,3 +196,4 @@ return { | ||
main: abc.basePath, | ||
wapUrl: 'http://h5.m.taobao.com/' + abc.baseUrl.replace(/^\//, '') | ||
wapUrl: wapUrlDomain + baseUrl, | ||
isAir: isAir | ||
}; | ||
@@ -218,4 +237,6 @@ } | ||
var cache_files = {}; | ||
var weex_cache_files = {}; | ||
var abc = require(path.resolve(process.cwd(), options.abc)); | ||
var packageName = pkg.name.replace(/^h5-/, ''); | ||
var packageName = pkg.isAir ? pkg.name : pkg.name.replace(/^h5-/, ''); | ||
all_files.forEach(function (file, k) { | ||
@@ -239,2 +260,3 @@ // ----------这段逻辑是浩志写的,不明用意,我抄过来的 | ||
} | ||
key = key.replace('/pages/pages/', '/pages/'); | ||
if (key) { | ||
@@ -305,6 +327,35 @@ cache_files[key] = file; | ||
if (pkg.isAir) { | ||
if (abc.defPublishType === 'weex') { | ||
Object.keys(cache_files).forEach(function(p) { | ||
const f = cache_files[p]; | ||
// 处理 html | ||
if (/\.html$/.test(f)) { | ||
if (/\/index\.html$/.test(f)) { | ||
cache_files[p.replace(/\/index\.html/, abc.composite ? '.html' : '')] = f; | ||
delete cache_files[p]; | ||
} | ||
} | ||
// 处理 index.weex.js | ||
if (/\.js$/.test(f)) { | ||
if (/pages\/[^/]+\/index\.(weex|native)(-min)?\.js$/.test(f)) { | ||
weex_cache_files[p.replace(/\/index\.(weex|native)(-min)?\.js$/, abc.composite ? '.html' : '')] = f; | ||
} else { | ||
weex_cache_files[p] = cache_files[p]; | ||
} | ||
delete cache_files[p]; | ||
} | ||
}); | ||
if (Object.keys(weex_cache_files).length) { | ||
abcJSON.weexCache = weex_cache_files; | ||
} | ||
} | ||
abcJSON.cacheInfoVersion = '1.0.0'; | ||
} | ||
// 备份目录 | ||
fsExtra.copySync(options.src, path.join(options.distDir, options.offlineSyncDir)); | ||
abcJSON.cache.onlinePrefix = `https:\/\/${options.offlineSyncHost}\/` + abc.group + '\/' + abc.name + '\/' + abc.version + '\/' + options.offlineSyncDir + '\/'; | ||
weex_cache_files.onlinePrefix = cache_files.onlinePrefix = `https:\/\/${options.offlineSyncHost}\/` + abc.group + '\/' + abc.name + '\/' + abc.version + '\/' + options.offlineSyncDir + '\/'; | ||
@@ -372,2 +423,2 @@ clamUtil.fs.writeJSONFile(genABCJSONPath, abcJSON, function (err) { | ||
}; | ||
}; |
19484
458
66