本文整理汇总了TypeScript中jszip.generate函数的典型用法代码示例。如果您正苦于以下问题:TypeScript generate函数的具体用法?TypeScript generate怎么用?TypeScript generate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了generate函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: zipAssests
static zipAssests(assetFolder: string, targetPath: string) {
Guard.argumentNotNullOrEmpty(assetFolder, "assetFolder");
Guard.argumentNotNullOrEmpty(targetPath, "targetPath");
let zip = new jszip();
fs.readdirSync(assetFolder).forEach(file => {
let filePath = path.join(assetFolder, file);
if (fs.lstatSync(filePath).isFile()) {
let ext = path.extname(filePath);
if (ext !== '.xml' && ext !== '.pdb') {
let content = fs.readFileSync(filePath);
zip.file(file, content);
}
}
});
let buffer = zip.generate({ type: "nodebuffer", compression: "DEFLATE" });
if (fs.existsSync(targetPath)) {
fs.unlinkSync(targetPath);
}
fs.writeFileSync(targetPath, buffer);
}
开发者ID:928PJY,项目名称:docfx,代码行数:25,代码来源:common.ts
示例2: pack
pack(module_name: string, callback: Function) {
var baseFolder = global.clientAppRoot + "\\modules\\" + module_name + "\\";
var manifest_file = fs.readJsonSync(baseFolder + consts.MANIFEST_NAME, { throws: false });
//merge the manifest into the modules.json file
if (manifest_file === null)
callback("invalid json, try using ascii file");
var zip = new JSZip();
var filesArr: Array<any> = [];
for (var i = 0; i < manifest_file.files.length; i++) {
if (fs.existsSync(baseFolder + manifest_file.files[i])) {
var fileContent = fs.readFileSync(baseFolder + manifest_file.files[i]);
zip.file(manifest_file.files[i], fileContent);
}
}
if (manifest_file.routes !== undefined) {
var routeBase: string = serverRoot + "/routes/";
for (var i = 0; i < manifest_file.routes.length; i++) {
if (fs.existsSync(routeBase + manifest_file.routes[i].path)) {
var fileContent = fs.readFileSync(routeBase + manifest_file.routes[i].path);
zip.folder("routes").file(manifest_file.routes[i].path, fileContent);
}
var tsfile = routeBase + manifest_file.routes[i].path.replace('.js', '.ts');
if (fs.existsSync(tsfile)) {
var fileContent = fs.readFileSync(tsfile);
zip.folder("routes").file(manifest_file.routes[i].path.replace('.js', '.ts'), fileContent);
}
}
}
if (manifest_file.scripts !== undefined) {
for (var i = 0; i < manifest_file.scripts.length; i++) {
if (fs.existsSync(baseFolder + "/scripts/" + manifest_file.scripts[i])) {
var fileContent = fs.readFileSync(baseFolder + "/scripts/" + manifest_file.scripts[i]);
zip.folder("scripts").file(manifest_file.scripts[i], fileContent);
}
}
}
if (fs.existsSync(baseFolder + "about.html")) {
var fileContent = fs.readFileSync(baseFolder + "about.html");
zip.file("about.html", fileContent);
}
var manifestContent = fs.readFileSync(baseFolder + consts.MANIFEST_NAME);
zip.file(consts.MANIFEST_NAME, manifestContent);
var content = zip.generate({ type: "nodebuffer" });
var packageFileName = appRoot + "/nodulus_modules/" + module_name + ".zip";
var packageBackupFileName = appRoot + "/nodulus_modules/" + module_name + "/" + module_name + "." + this.timestamp() + ".zip";
if (fs.existsSync(packageFileName)) {
fs.ensureDirSync(appRoot + "/nodulus_modules/" + module_name);
fs.renameSync(packageFileName, packageBackupFileName);
}
//var oldPackage = fs.readFileSync(global.appRoot + "/nodulus_modules/" + module_name + ".zip");
// see FileSaver.js
fs.writeFile(packageFileName, content, function (err: any) {
if (err) throw err;
callback(null, manifest_file);
});
}
开发者ID:gitter-badger,项目名称:nodulus,代码行数:86,代码来源:modules.ts
示例3: createPackage
createPackage(module_name: string, callback: Function) {
var baseFolder = global.clientAppRoot + "\\modules\\modules\\template\\";
var manifest_file = fs.readJsonSync(baseFolder + consts.MANIFEST_NAME, { throws: false });
var manifestString = JSON.stringify(manifest_file);
manifestString = this.replaceAll("$$module_name$$", module_name, manifestString);
manifest_file = JSON.parse(manifestString);
////for (var i = 0; i < manifest_file.files.length; i++) {
//// manifest_file.files[i] = manifest_file.files[i].replace("$$module_name$$" , module_name);
////}
////for (var i = 0; i < manifest_file.scripts.length; i++) {
//// manifest_file.scripts[i] = manifest_file.scripts[i].replace("$$module_name$$" , module_name);
////}
////for (var i = 0; i < manifest_file.routes.length; i++) {
//// manifest_file.routes[i].route = manifest_file.routes[i].route.replace("$$module_name$$" , module_name);
//// manifest_file.routes[i].path = manifest_file.routes[i].path.replace("$$module_name$$" , module_name);
////}
////for (var i = 0; i < manifest_file.navigation.length; i++) {
//// manifest_file.navigation[i].route = manifest_file.routes[i].route.replace("$$module_name$$" , module_name);
//// manifest_file.navigation[i].path = manifest_file.routes[i].path.replace("$$module_name$$" , module_name);
////}
var zip = new JSZip();
var filesArr: Array<any> = [];
var fileContent = fs.readFileSync(baseFolder + "\\template.js", "utf-8");
fileContent = this.replaceAll("$$module_name$$", module_name, fileContent);
zip.file(module_name + ".js", fileContent);
var fileContent = fs.readFileSync(baseFolder + "\\template.html", "utf-8");
fileContent = this.replaceAll("$$module_name$$", module_name, fileContent);
zip.file(module_name + ".html", fileContent);
zip.file(consts.MANIFEST_NAME, JSON.stringify(manifest_file));
var fileContent = fs.readFileSync(baseFolder + "\\about.html", "utf-8");
fileContent = this.replaceAll("$$module_name$$", module_name, fileContent);
zip.file("about.html", fileContent);
var fileContent = fs.readFileSync(baseFolder + "\\routes\\template.js");
zip.folder("routes").file(module_name + ".js", fileContent);
//get manifest template:
var content = zip.generate({ type: "nodebuffer" });
var packageFileName = appRoot + "/nodulus_modules/" + module_name + ".zip";
var packageBackupFileName = appRoot + "/nodulus_modules/" + module_name + "/" + module_name + "." + this.timestamp() + ".zip";
if (!fs.existsSync(appRoot + "/nodulus_modules/")) {
fs.ensureDirSync(appRoot + "/nodulus_modules/");
}
if (fs.existsSync(packageFileName)) {
fs.ensureDirSync(appRoot + "/nodulus_modules/" + module_name);
fs.renameSync(packageFileName, packageBackupFileName);
}
//var oldPackage = fs.readFileSync(global.appRoot + "/nodulus_modules/" + module_name + ".zip");
// see FileSaver.js
fs.writeFile(packageFileName, content, function (err: any) {
if (err) throw err;
callback(null, manifest_file);
});
}
开发者ID:gitter-badger,项目名称:nodulus,代码行数:84,代码来源:modules.ts
注:本文中的jszip.generate函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论