dingtalk-h5package-opensdk
Advanced tools
Comparing version 2.0.4 to 2.0.5
@@ -92,7 +92,6 @@ #!/usr/bin/env node | ||
const config = yield readResourceConfig(opts); | ||
const file = yield pack({ | ||
yield pack({ | ||
filename: `${config.miniAppId}.tar.gz`, | ||
config, | ||
}); | ||
console.log('打包完成: %s', file); | ||
}); | ||
@@ -99,0 +98,0 @@ }); |
@@ -15,3 +15,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PackagePacker = exports.pathToUrl = exports.urlToPath = void 0; | ||
exports.PackagePacker = exports.pathToUrl = exports.urlToPath = exports.MAX_PATH_LENGTH = void 0; | ||
const archiver_1 = __importDefault(require("archiver")); | ||
@@ -22,2 +22,4 @@ const fs_extra_1 = __importDefault(require("fs-extra")); | ||
const glob_1 = __importDefault(require("glob")); | ||
// 文件路径最大长度是100,扣除"web_assets/"目录,实际最大长度是89; | ||
exports.MAX_PATH_LENGTH = 88; | ||
function urlToPath(url) { | ||
@@ -64,4 +66,11 @@ let uri; | ||
this.prom = new Promise((r, c) => { | ||
this.arch.on('error', c); | ||
this.output.on('close', r); | ||
this.arch.on('error', err => { | ||
console.error('打包失败', err); | ||
c(err); | ||
}); | ||
this.output.on('close', () => { | ||
// eslint-disable-next-line no-console | ||
console.log('打包完成', this.file); | ||
r(); | ||
}); | ||
}); | ||
@@ -78,3 +87,3 @@ this.arch.pipe(this.output); | ||
else if (stat.isFile()) { | ||
this.arch.file(p, { name: urlToPath(url), }); | ||
this._file(url, p); | ||
} | ||
@@ -86,12 +95,19 @@ else { | ||
} | ||
_file(url, filename) { | ||
const fullFilePath = urlToPath(url); | ||
if (fullFilePath.length > exports.MAX_PATH_LENGTH) { | ||
console.warn(`以下文件被忽略,原因:文件路径过长(>${exports.MAX_PATH_LENGTH}): ${path_1.default.relative(process.cwd(), filename)}`); | ||
return; | ||
} | ||
this.arch.file(filename, { name: fullFilePath, }); | ||
this.includeUrlSet.add(url); | ||
} | ||
appendDirectory(url, directory) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const prefixURL = new URL(url); | ||
const prefixPathname = prefixURL.pathname; | ||
const files = glob_1.default.sync('**/*', { cwd: directory, nodir: true, }); | ||
for (const file of files) { | ||
const fullPathname = path_1.default.join(prefixPathname, file); | ||
const fullUrl = new URL(fullPathname, prefixURL.origin).toString(); | ||
this.arch.file(path_1.default.join(directory, file), { name: urlToPath(fullUrl), }); | ||
this.includeUrlSet.add(fullUrl); | ||
const filename = path_1.default.join(directory, file); | ||
const fullUrl = new URL(path_1.default.join(prefixURL.pathname, file), prefixURL.origin).toString(); | ||
this._file(fullUrl, filename); | ||
} | ||
@@ -98,0 +114,0 @@ }); |
{ | ||
"name": "dingtalk-h5package-opensdk", | ||
"version": "2.0.4", | ||
"version": "2.0.5", | ||
"description": "H5离线包OpenSDK", | ||
@@ -5,0 +5,0 @@ "author": "vularr <vularr@hotmail.com>", |
21703
404