@ffflorian/jszip-cli
Advanced tools
| import { TerminalOptions } from './interfaces'; | ||
| export declare class BuildService { | ||
| compressedFilesCount: number; | ||
| outputFile: string | null; | ||
| private entries; | ||
| private readonly fileService; | ||
| private readonly ignoreEntries; | ||
| private readonly jszip; | ||
| private readonly logger; | ||
| private readonly options; | ||
| private readonly progressBar; | ||
| constructor(options: Required<TerminalOptions>); | ||
| add(rawEntries: string[]): BuildService; | ||
| save(): Promise<BuildService>; | ||
| /** | ||
| * Note: glob patterns should always use / as a path separator, even on Windows systems, | ||
| * as \ is used to escape glob characters. | ||
| * https://github.com/isaacs/node-glob | ||
| */ | ||
| private normalizePaths; | ||
| private addFile; | ||
| private addLink; | ||
| private checkEntry; | ||
| private checkOutput; | ||
| private getBuffer; | ||
| private walkDir; | ||
| } |
| "use strict"; | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
| }); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.BuildService = void 0; | ||
| const fs = require("fs-extra"); | ||
| const JSZip = require("jszip"); | ||
| const logdown = require("logdown"); | ||
| const path = require("path"); | ||
| const progress = require("progress"); | ||
| const FileService_1 = require("./FileService"); | ||
| const glob_1 = require("glob"); | ||
| class BuildService { | ||
| constructor(options) { | ||
| this.fileService = new FileService_1.FileService(options); | ||
| this.jszip = new JSZip(); | ||
| this.options = options; | ||
| this.logger = logdown('jszip-cli/BuildService', { | ||
| logger: console, | ||
| markdown: false, | ||
| }); | ||
| this.logger.state = { isEnabled: options.verbose }; | ||
| this.entries = []; | ||
| this.ignoreEntries = this.options.ignoreEntries.map(entry => entry instanceof RegExp ? entry : new RegExp(entry.replace(/\*/g, '.*'))); | ||
| this.outputFile = this.options.outputEntry ? path.resolve(this.options.outputEntry) : null; | ||
| this.progressBar = new progress('Compressing [:bar] :percent :elapseds', { | ||
| complete: '=', | ||
| incomplete: ' ', | ||
| total: 100, | ||
| width: 20, | ||
| }); | ||
| this.compressedFilesCount = 0; | ||
| } | ||
| add(rawEntries) { | ||
| this.logger.info(`Adding ${rawEntries.length} entr${rawEntries.length === 1 ? 'y' : 'ies'} to ZIP file.`); | ||
| const normalizedEntries = this.normalizePaths(rawEntries); | ||
| this.entries = (0, glob_1.globSync)(normalizedEntries).map(rawEntry => { | ||
| const resolvedPath = path.resolve(rawEntry); | ||
| const baseName = path.basename(rawEntry); | ||
| return { | ||
| resolvedPath, | ||
| zipPath: baseName, | ||
| }; | ||
| }); | ||
| return this; | ||
| } | ||
| save() { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| yield this.checkOutput(); | ||
| yield Promise.all(this.entries.map(entry => this.checkEntry(entry))); | ||
| const data = yield this.getBuffer(); | ||
| if (this.outputFile) { | ||
| if (!this.outputFile.match(/\.\w+$/)) { | ||
| this.outputFile = path.join(this.outputFile, 'data.zip'); | ||
| } | ||
| this.logger.info(`Saving finished zip file to "${this.outputFile}" ...`); | ||
| yield this.fileService.writeFile(data, this.outputFile); | ||
| } | ||
| else { | ||
| process.stdout.write(data); | ||
| } | ||
| return this; | ||
| }); | ||
| } | ||
| /** | ||
| * Note: glob patterns should always use / as a path separator, even on Windows systems, | ||
| * as \ is used to escape glob characters. | ||
| * https://github.com/isaacs/node-glob | ||
| */ | ||
| normalizePaths(rawEntries) { | ||
| return rawEntries.map(entry => entry.replace(/\\/g, '/')); | ||
| } | ||
| addFile(entry, isLink = false) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| const { resolvedPath, zipPath } = entry; | ||
| let fileStat; | ||
| let fileData; | ||
| try { | ||
| fileData = isLink ? yield fs.readlink(resolvedPath) : yield fs.readFile(resolvedPath); | ||
| fileStat = yield fs.lstat(resolvedPath); | ||
| } | ||
| catch (error) { | ||
| if (!this.options.quiet) { | ||
| console.info(`Can't read file "${entry.resolvedPath}". Ignoring.`); | ||
| } | ||
| this.logger.info(error); | ||
| return; | ||
| } | ||
| this.logger.info(`Adding file "${resolvedPath}" to ZIP file ...`); | ||
| this.jszip.file(zipPath, fileData, { | ||
| createFolders: true, | ||
| date: fileStat.mtime, | ||
| // See https://github.com/Stuk/jszip/issues/550 | ||
| // dosPermissions: fileStat.mode, | ||
| unixPermissions: fileStat.mode, | ||
| }); | ||
| this.compressedFilesCount++; | ||
| }); | ||
| } | ||
| addLink(entry) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| const { resolvedPath, zipPath } = entry; | ||
| if (this.options.dereferenceLinks) { | ||
| let realPath; | ||
| try { | ||
| realPath = yield fs.realpath(resolvedPath); | ||
| } | ||
| catch (error) { | ||
| if (!this.options.quiet) { | ||
| console.info(`Can't read link "${entry.resolvedPath}". Ignoring.`); | ||
| } | ||
| this.logger.info(error); | ||
| return; | ||
| } | ||
| this.logger.info(`Found real path "${realPath} for symbolic link".`); | ||
| yield this.checkEntry({ | ||
| resolvedPath: realPath, | ||
| zipPath, | ||
| }); | ||
| } | ||
| else { | ||
| yield this.addFile(entry, true); | ||
| } | ||
| }); | ||
| } | ||
| checkEntry(entry) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| let fileStat; | ||
| try { | ||
| fileStat = yield fs.lstat(entry.resolvedPath); | ||
| } | ||
| catch (error) { | ||
| if (!this.options.quiet) { | ||
| console.info(`Can't read file "${entry.resolvedPath}". Ignoring.`); | ||
| } | ||
| this.logger.info(error); | ||
| return; | ||
| } | ||
| const ignoreEntries = this.ignoreEntries.filter(ignoreEntry => Boolean(entry.resolvedPath.match(ignoreEntry))); | ||
| if (ignoreEntries.length) { | ||
| this.logger.info(`Found ${entry.resolvedPath}. Not adding since it's on the ignore list:`, ignoreEntries.map(entry => String(entry))); | ||
| return; | ||
| } | ||
| if (fileStat.isDirectory()) { | ||
| this.logger.info(`Found directory "${entry.resolvedPath}".`); | ||
| yield this.walkDir(entry); | ||
| } | ||
| else if (fileStat.isFile()) { | ||
| this.logger.info(`Found file "${entry.resolvedPath}".`); | ||
| yield this.addFile(entry); | ||
| } | ||
| else if (fileStat.isSymbolicLink()) { | ||
| this.logger.info(`Found symbolic link "${entry.resolvedPath}".`); | ||
| yield this.addLink(entry); | ||
| } | ||
| else { | ||
| this.logger.info('Unknown file type.', { fileStat }); | ||
| if (!this.options.quiet) { | ||
| console.info(`Can't read file "${entry.resolvedPath}". Ignoring.`); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| checkOutput() { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| if (this.outputFile) { | ||
| if (this.outputFile.match(/\.\w+$/)) { | ||
| const dirExists = yield this.fileService.dirExists(path.dirname(this.outputFile)); | ||
| if (!dirExists) { | ||
| throw new Error(`Directory "${path.dirname(this.outputFile)}" doesn't exist or is not writable.`); | ||
| } | ||
| const fileIsWritable = yield this.fileService.fileIsWritable(this.outputFile); | ||
| if (!fileIsWritable) { | ||
| throw new Error(`File "${this.outputFile}" already exists.`); | ||
| } | ||
| } | ||
| else { | ||
| const dirExists = yield this.fileService.dirExists(this.outputFile); | ||
| if (!dirExists) { | ||
| throw new Error(`Directory "${this.outputFile}" doesn't exist or is not writable.`); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| getBuffer() { | ||
| const compressionType = this.options.compressionLevel === 0 ? 'STORE' : 'DEFLATE'; | ||
| let lastPercent = 0; | ||
| return this.jszip.generateAsync({ | ||
| compression: compressionType, | ||
| compressionOptions: { | ||
| level: this.options.compressionLevel, | ||
| }, | ||
| type: 'nodebuffer', | ||
| }, ({ percent }) => { | ||
| const diff = Math.floor(percent) - Math.floor(lastPercent); | ||
| if (diff && !this.options.quiet) { | ||
| this.progressBar.tick(diff); | ||
| lastPercent = Math.floor(percent); | ||
| } | ||
| }); | ||
| } | ||
| walkDir(entry) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| this.logger.info(`Walking directory ${entry.resolvedPath} ...`); | ||
| const dirEntries = yield fs.readdir(entry.resolvedPath); | ||
| for (const dirEntry of dirEntries) { | ||
| const newZipPath = entry.zipPath === '.' ? dirEntry : `${entry.zipPath}/${dirEntry}`; | ||
| const newResolvedPath = path.join(entry.resolvedPath, dirEntry); | ||
| yield this.checkEntry({ | ||
| resolvedPath: newResolvedPath, | ||
| zipPath: newZipPath, | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| exports.BuildService = BuildService; | ||
| //# sourceMappingURL=BuildService.js.map |
| {"version":3,"file":"BuildService.js","sourceRoot":"","sources":["../src/BuildService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAA+B;AAC/B,+BAA+B;AAC/B,mCAAmC;AACnC,6BAA6B;AAC7B,qCAAqC;AACrC,+CAA0C;AAE1C,+BAA8B;AAE9B,MAAa,YAAY;IAWvB,YAAY,OAAkC;QAC5C,IAAI,CAAC,WAAW,GAAG,IAAI,yBAAW,CAAC,OAAO,CAAC,CAAC;QAC5C,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,wBAAwB,EAAE;YAC9C,MAAM,EAAE,OAAO;YACf,QAAQ,EAAE,KAAK;SAChB,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,EAAC,SAAS,EAAE,OAAO,CAAC,OAAO,EAAC,CAAC;QACjD,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAC1D,KAAK,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CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,IAAI,QAAQ,EAAE,CAAC;gBACrF,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;gBAChE,MAAM,IAAI,CAAC,UAAU,CAAC;oBACpB,YAAY,EAAE,eAAe;oBAC7B,OAAO,EAAE,UAAU;iBACpB,CAAC,CAAC;aACJ;QACH,CAAC;KAAA;CACF;AAjOD,oCAiOC"} |
| #!/usr/bin/env node | ||
| export {}; |
+121
| #!/usr/bin/env node | ||
| "use strict"; | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
| }); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const commander_1 = require("commander"); | ||
| const fs = require("fs-extra"); | ||
| const path = require("path"); | ||
| const JSZipCLI_1 = require("./JSZipCLI"); | ||
| const defaultPackageJsonPath = path.join(__dirname, 'package.json'); | ||
| const packageJsonPath = fs.existsSync(defaultPackageJsonPath) | ||
| ? defaultPackageJsonPath | ||
| : path.join(__dirname, '../package.json'); | ||
| const { description, name, version } = fs.readJSONSync(packageJsonPath); | ||
| commander_1.program | ||
| .name(name.replace(/^@[^/]+\//, '')) | ||
| .description(description) | ||
| .option('--noconfig', "don't look for a configuration file") | ||
| .option('-c, --config <path>', 'use a configuration file (default: .jsziprc.json)') | ||
| .option('-d, --dereference', 'dereference (follow) links', false) | ||
| .option('-f, --force', 'force overwriting files and directories when extracting', false) | ||
| .option('-i, --ignore <entry>', 'ignore a file or directory') | ||
| .option('-l, --level <number>', 'set the compression level', '5') | ||
| .option('-o, --output <dir>', 'set the output file or directory (default: stdout)') | ||
| .option('-q, --quiet', "don't log anything", false) | ||
| .option('-V, --verbose', 'enable verbose logging', false) | ||
| .version(version, '-v, --version') | ||
| .on('command:*', args => { | ||
| console.error(`\n error: invalid command \`${args[0]}'\n`); | ||
| process.exit(1); | ||
| }); | ||
| commander_1.program | ||
| .command('add') | ||
| .alias('a') | ||
| .description('add files and directories to a new ZIP archive') | ||
| .option('--noconfig', "don't look for a configuration file") | ||
| .option('-c, --config <path>', 'use a configuration file') | ||
| .option('-d, --dereference', 'dereference (follow) symlinks', false) | ||
| .option('-f, --force', 'force overwriting files and directories when extracting', false) | ||
| .option('-i, --ignore <entry>', 'ignore a file or directory') | ||
| .option('-l, --level <number>', 'set the compression level', '5') | ||
| .option('-o, --output <dir>', 'set the output file or directory (default: stdout)') | ||
| .option('-q, --quiet', "don't log anything excluding errors", false) | ||
| .option('-V, --verbose', 'enable verbose logging', false) | ||
| .arguments('[entries...]') | ||
| .action((entries) => __awaiter(void 0, void 0, void 0, function* () { | ||
| const options = commander_1.program.opts(); | ||
| try { | ||
| const jszip = new JSZipCLI_1.JSZipCLI(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (options.level && { compressionLevel: Number(options.level) })), ((options.config && { configFile: options.config }) || (options.noconfig && { configFile: false }))), (options.dereference && { dereferenceLinks: options.dereference })), (options.force && { force: options.force })), (options.ignore && { ignoreEntries: [options.ignore] })), (options.output && { outputEntry: options.output })), (options.quiet && { quiet: options.quiet })), (options.verbose && { verbose: options.verbose }))); | ||
| jszip.add(entries); | ||
| const { outputFile, compressedFilesCount } = yield jszip.save(); | ||
| if (options.output && !options.quiet) { | ||
| console.info(`Done compressing ${compressedFilesCount} files to "${outputFile}".`); | ||
| } | ||
| } | ||
| catch (error) { | ||
| console.error('Error:', error.message); | ||
| process.exit(1); | ||
| } | ||
| })); | ||
| commander_1.program | ||
| .command('extract') | ||
| .alias('e') | ||
| .description('extract files and directories from ZIP archive(s)') | ||
| .option('--noconfig', "don't look for a configuration file", false) | ||
| .option('-c, --config <path>', 'use a configuration file (default: .jsziprc.json)') | ||
| .option('-o, --output <dir>', 'set the output file or directory (default: stdout)') | ||
| .option('-i, --ignore <entry>', 'ignore a file or directory') | ||
| .option('-f, --force', 'force overwriting files and directories', false) | ||
| .option('-V, --verbose', 'enable verbose logging', false) | ||
| .option('-q, --quiet', "don't log anything excluding errors", false) | ||
| .arguments('<archives...>') | ||
| .action((archives) => __awaiter(void 0, void 0, void 0, function* () { | ||
| const options = commander_1.program.opts(); | ||
| try { | ||
| const { outputDir, extractedFilesCount } = yield new JSZipCLI_1.JSZipCLI(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, ((options.config && { configFile: options.config }) || (options.noconfig && { configFile: false }))), (options.force && { force: options.force })), (options.ignore && { ignoreEntries: [options.ignore] })), (options.output && { outputEntry: options.output })), (options.quiet && { quiet: options.quiet })), (options.verbose && { verbose: options.verbose }))).extract(archives); | ||
| if (options.output && !options.quiet) { | ||
| console.info(`Done extracting ${extractedFilesCount} files to "${outputDir}".`); | ||
| } | ||
| } | ||
| catch (error) { | ||
| console.error('Error:', error.message); | ||
| process.exit(1); | ||
| } | ||
| })); | ||
| commander_1.program | ||
| .command('fileMode', { hidden: true, isDefault: true }) | ||
| .option('--noconfig', "don't look for a configuration file", false) | ||
| .option('-c, --config <path>', 'use a configuration file (default: .jsziprc.json)') | ||
| .option('-o, --output <dir>', 'set the output file or directory (default: stdout)') | ||
| .option('-i, --ignore <entry>', 'ignore a file or directory') | ||
| .option('-f, --force', 'force overwriting files and directories', false) | ||
| .option('-V, --verbose', 'enable verbose logging', false) | ||
| .option('-q, --quiet', "don't log anything excluding errors", false) | ||
| .action(() => __awaiter(void 0, void 0, void 0, function* () { | ||
| const options = commander_1.program.opts(); | ||
| try { | ||
| if (options.noconfig) { | ||
| commander_1.program.outputHelp(); | ||
| } | ||
| yield new JSZipCLI_1.JSZipCLI(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (options.config && { configFile: options.config })), (options.force && { force: options.force })), (options.ignore && { ignoreEntries: [options.ignore] })), (options.output && { outputEntry: options.output })), (options.quiet && { quiet: options.quiet })), (options.verbose && { verbose: options.verbose }))).fileMode(); | ||
| } | ||
| catch (error) { | ||
| if (error.message.includes('ENOENT')) { | ||
| console.error('Error:', `Configuration file "${options.config}" not found and no mode specified.`); | ||
| } | ||
| else { | ||
| console.error('Error:', error.message); | ||
| } | ||
| process.exit(1); | ||
| } | ||
| })); | ||
| commander_1.program.parse(process.argv); | ||
| //# sourceMappingURL=cli.js.map |
| {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,yCAA+C;AAC/C,+BAA+B;AAC/B,6BAA6B;AAE7B,yCAAoC;AAEpC,MAAM,sBAAsB,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;AACpE,MAAM,eAAe,GAAG,EAAE,CAAC,UAAU,CAAC,sBAAsB,CAAC;IAC3D,CAAC,CAAC,sBAAsB;IACxB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;AAE5C,MAAM,EAAC,WAAW,EAAE,IAAI,EAAE,OAAO,EAAC,GAChC,EAAE,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;AAcnC,mBAAS;KACN,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;KACnC,WAAW,CAAC,WAAW,CAAC;KACxB,MAAM,CAAC,YAAY,EAAE,qCAAqC,CAAC;KAC3D,MAAM,CAAC,qBAAqB,EAAE,mDAAmD,CAAC;KAClF,MAAM,CAAC,mBAAmB,EAAE,4BAA4B,EAAE,KAAK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;QAED,MAAM,IAAI,mBAAQ,yFACb,CAAC,OAAO,CAAC,MAAM,IAAI,EAAC,UAAU,EAAE,OAAO,CAAC,MAAM,EAAC,CAAC,GAChD,CAAC,OAAO,CAAC,KAAK,IAAI,EAAC,KAAK,EAAE,OAAO,CAAC,KAAK,EAAC,CAAC,GACzC,CAAC,OAAO,CAAC,MAAM,IAAI,EAAC,aAAa,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,EAAC,CAAC,GACrD,CAAC,OAAO,CAAC,MAAM,IAAI,EAAC,WAAW,EAAE,OAAO,CAAC,MAAM,EAAC,CAAC,GACjD,CAAC,OAAO,CAAC,KAAK,IAAI,EAAC,KAAK,EAAE,OAAO,CAAC,KAAK,EAAC,CAAC,GACzC,CAAC,OAAO,CAAC,OAAO,IAAI,EAAC,OAAO,EAAE,OAAO,CAAC,OAAO,EAAC,CAAC,EAClD,CAAC,QAAQ,EAAE,CAAC;KACf;IAAC,OAAO,KAAK,EAAE;QACd,IAAK,KAAe,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;YAC/C,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,uBAAuB,OAAO,CAAC,MAAM,oCAAoC,CAAC,CAAC;SACpG;aAAM;YACL,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAG,KAAe,CAAC,OAAO,CAAC,CAAC;SACnD;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC,CAAA,CAAC,CAAC;AAEL,mBAAS,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"} |
| import { TerminalOptions } from './interfaces'; | ||
| export declare class ExtractService { | ||
| extractedFilesCount: number; | ||
| outputDir: string | null; | ||
| private readonly logger; | ||
| private readonly options; | ||
| private readonly progressBar; | ||
| constructor(options: Required<TerminalOptions>); | ||
| extract(rawEntries: string[]): Promise<ExtractService>; | ||
| private printStream; | ||
| } |
| "use strict"; | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
| }); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.ExtractService = void 0; | ||
| const fs = require("fs-extra"); | ||
| const JSZip = require("jszip"); | ||
| const logdown = require("logdown"); | ||
| const os = require("os"); | ||
| const path = require("path"); | ||
| const progress = require("progress"); | ||
| class ExtractService { | ||
| constructor(options) { | ||
| this.options = options; | ||
| this.logger = logdown('jszip-cli/ExtractService', { | ||
| logger: console, | ||
| markdown: false, | ||
| }); | ||
| this.logger.state.isEnabled = this.options.verbose; | ||
| this.outputDir = this.options.outputEntry ? path.resolve(this.options.outputEntry) : null; | ||
| this.progressBar = new progress('Extracting [:bar] :percent :elapseds', { | ||
| complete: '=', | ||
| incomplete: ' ', | ||
| total: 100, | ||
| width: 20, | ||
| }); | ||
| this.extractedFilesCount = 0; | ||
| } | ||
| extract(rawEntries) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| const isWin32 = os.platform() === 'win32'; | ||
| for (const entry of rawEntries) { | ||
| const jszip = new JSZip(); | ||
| if (this.outputDir) { | ||
| yield fs.ensureDir(this.outputDir); | ||
| } | ||
| const resolvedPath = path.resolve(entry); | ||
| const data = yield fs.readFile(resolvedPath); | ||
| const entries = []; | ||
| yield jszip.loadAsync(data, { createFolders: true }); | ||
| if (!this.outputDir) { | ||
| yield this.printStream(jszip.generateNodeStream()); | ||
| return this; | ||
| } | ||
| jszip.forEach((filePath, entry) => { | ||
| if (filePath.includes('..')) { | ||
| this.logger.info(`Skipping bad path "${filePath}"`); | ||
| } | ||
| else { | ||
| entries.push([filePath, entry]); | ||
| } | ||
| }); | ||
| let lastPercent = 0; | ||
| yield Promise.all(entries.map(([filePath, entry], index) => __awaiter(this, void 0, void 0, function* () { | ||
| const resolvedFilePath = path.join(this.outputDir, filePath); | ||
| if (entry.dir) { | ||
| yield fs.ensureDir(resolvedFilePath); | ||
| } | ||
| else { | ||
| const data = yield entry.async('nodebuffer'); | ||
| yield fs.writeFile(resolvedFilePath, data, { | ||
| encoding: 'utf-8', | ||
| }); | ||
| this.extractedFilesCount++; | ||
| const diff = Math.floor(index / entries.length) - Math.floor(lastPercent); | ||
| if (diff && !this.options.quiet) { | ||
| this.progressBar.tick(diff); | ||
| lastPercent = Math.floor(index / entries.length); | ||
| } | ||
| } | ||
| if (isWin32) { | ||
| if (entry.dosPermissions) { | ||
| yield fs.chmod(resolvedFilePath, entry.dosPermissions); | ||
| } | ||
| } | ||
| else if (entry.unixPermissions) { | ||
| yield fs.chmod(resolvedFilePath, entry.unixPermissions); | ||
| } | ||
| }))); | ||
| } | ||
| return this; | ||
| }); | ||
| } | ||
| printStream(fileStream) { | ||
| return new Promise((resolve, reject) => { | ||
| const stream = fileStream.pipe(process.stdout); | ||
| stream.on('finish', resolve); | ||
| stream.on('error', reject); | ||
| }); | ||
| } | ||
| } | ||
| exports.ExtractService = ExtractService; | ||
| //# sourceMappingURL=ExtractService.js.map |
| {"version":3,"file":"ExtractService.js","sourceRoot":"","sources":["../src/ExtractService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAA+B;AAC/B,+BAA+B;AAC/B,mCAAmC;AACnC,yBAAyB;AACzB,6BAA6B;AAC7B,qCAAqC;AAGrC,MAAa,cAAc;IAOzB,YAAY,OAAkC;QAC5C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,0BAA0B,EAAE;YAChD,MAAM,EAAE,OAAO;YACf,QAAQ,EAAE,KA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AAG,OAAO,CAAC,MAAM,CAAC,CAAC;yBAClD;qBACF;oBAED,IAAI,OAAO,EAAE;wBACX,IAAI,KAAK,CAAC,cAAc,EAAE;4BACxB,MAAM,EAAE,CAAC,KAAK,CAAC,gBAAgB,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;yBACxD;qBACF;yBAAM,IAAI,KAAK,CAAC,eAAe,EAAE;wBAChC,MAAM,EAAE,CAAC,KAAK,CAAC,gBAAgB,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;qBACzD;gBACH,CAAC,CAAA,CAAC,CACH,CAAC;aACH;YACD,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;IAEO,WAAW,CAAC,UAAiC;QACnD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAC/C,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC7B,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA7FD,wCA6FC"} |
| /// <reference types="node" /> | ||
| import type { TerminalOptions } from './interfaces'; | ||
| export declare class FileService { | ||
| private readonly logger; | ||
| private readonly options; | ||
| constructor(options: Required<TerminalOptions>); | ||
| dirExists(dirPath: string): Promise<boolean>; | ||
| fileIsReadable(filePath: string): Promise<boolean>; | ||
| fileIsWritable(filePath: string): Promise<boolean>; | ||
| writeFile(data: Buffer, filePath: string): Promise<FileService>; | ||
| } |
| "use strict"; | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
| }); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.FileService = void 0; | ||
| const fs = require("fs-extra"); | ||
| const logdown = require("logdown"); | ||
| const path = require("path"); | ||
| class FileService { | ||
| constructor(options) { | ||
| this.options = options; | ||
| this.logger = logdown('jszip-cli/FileService', { | ||
| logger: console, | ||
| markdown: false, | ||
| }); | ||
| this.logger.state.isEnabled = this.options.verbose; | ||
| } | ||
| dirExists(dirPath) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| try { | ||
| yield fs.access(dirPath, fs.constants.F_OK); | ||
| try { | ||
| yield fs.access(dirPath, fs.constants.W_OK); | ||
| return true; | ||
| } | ||
| catch (error) { | ||
| this.logger.info(`Directory "${dirPath}" exists but is not writable.`); | ||
| return false; | ||
| } | ||
| } | ||
| catch (error) { | ||
| this.logger.info(`Directory "${dirPath}" doesn't exist.`, this.options.force ? 'Creating.' : 'Not creating.'); | ||
| if (this.options.force) { | ||
| yield fs.ensureDir(dirPath); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| }); | ||
| } | ||
| fileIsReadable(filePath) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| const dirExists = yield this.dirExists(path.dirname(filePath)); | ||
| if (dirExists) { | ||
| try { | ||
| yield fs.access(filePath, fs.constants.F_OK | fs.constants.R_OK); | ||
| return true; | ||
| } | ||
| catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| return false; | ||
| }); | ||
| } | ||
| fileIsWritable(filePath) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| const dirName = path.dirname(filePath); | ||
| const dirExists = yield this.dirExists(dirName); | ||
| if (dirExists) { | ||
| try { | ||
| yield fs.access(filePath, fs.constants.F_OK | fs.constants.R_OK); | ||
| this.logger.info(`File "${filePath}" already exists.`, this.options.force ? 'Forcing overwrite.' : 'Not overwriting.'); | ||
| return this.options.force; | ||
| } | ||
| catch (error) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| }); | ||
| } | ||
| writeFile(data, filePath) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| const fileIsWritable = yield this.fileIsWritable(filePath); | ||
| if (fileIsWritable) { | ||
| yield fs.writeFile(filePath, data); | ||
| return this; | ||
| } | ||
| throw new Error(`File "${this.options.outputEntry}" already exists.`); | ||
| }); | ||
| } | ||
| } | ||
| exports.FileService = FileService; | ||
| //# sourceMappingURL=FileService.js.map |
| {"version":3,"file":"FileService.js","sourceRoot":"","sources":["../src/FileService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAA+B;AAC/B,mCAAmC;AACnC,6BAA6B;AAG7B,MAAa,WAAW;IAGtB,YAAY,OAAkC;QAC5C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,uBAAuB,EAAE;YAC7C,MAAM,EAAE,OAAO;YACf,QAAQ,EAAE,KAAK;SAChB,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;IACrD,CAAC;IAEY,SAAS,CAAC,OAAe;;YACpC,IAAI;gBACF,MAAM,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;gBAC5C,IAAI;oBACF,MAAM,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;oBAC5C,OAAO,IAAI,CAAC;iBACb;gBAAC,OAAO,KAAK,EAAE;oBACd,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,OAAO,+BAA+B,CAAC,CAAC;oBACvE,OAAO,KAAK,CAAC;iBACd;aACF;YA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C,CAAC,oBAAoB,CAAC,CAAC,CAAC,kBAAkB,CAC/D,CAAC;oBACF,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;iBAC3B;gBAAC,OAAO,KAAK,EAAE;oBACd,OAAO,IAAI,CAAC;iBACb;aACF;YACD,OAAO,KAAK,CAAC;QACf,CAAC;KAAA;IAEY,SAAS,CAAC,IAAY,EAAE,QAAgB;;YACnD,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;YAC3D,IAAI,cAAc,EAAE;gBAClB,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;gBACnC,OAAO,IAAI,CAAC;aACb;YACD,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,CAAC,OAAO,CAAC,WAAW,mBAAmB,CAAC,CAAC;QACxE,CAAC;KAAA;CACF;AAvED,kCAuEC"} |
| export * from './JSZipCLI'; | ||
| export * from './interfaces'; |
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| __exportStar(require("./JSZipCLI"), exports); | ||
| __exportStar(require("./interfaces"), exports); | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,+CAA6B"} |
| export interface TerminalOptions { | ||
| /** The compression level to use (0 = save only, 9 = best compression) (default: 5). */ | ||
| compressionLevel?: number; | ||
| /** Use a configuration file (default: .jsziprc.json). */ | ||
| configFile?: string | boolean; | ||
| /** Whether to dereference (follow) symlinks (default: false). */ | ||
| dereferenceLinks?: boolean; | ||
| /** Force overwriting files and directories when extracting (default: false). */ | ||
| force?: boolean; | ||
| /** Ignore entries (e.g. `*.js.map`). */ | ||
| ignoreEntries?: Array<string | RegExp>; | ||
| /** Set the output directory (default: stdout). */ | ||
| outputEntry?: string | null; | ||
| /** Don't log anything excluding errors (default: false). */ | ||
| quiet?: boolean; | ||
| /** Enable verbose logging (default: false). */ | ||
| verbose?: boolean; | ||
| } | ||
| export interface ConfigFileOptions extends TerminalOptions { | ||
| /** Which files or directories to add. */ | ||
| entries: string[]; | ||
| /** Add or extract files. */ | ||
| mode: 'add' | 'extract'; | ||
| } | ||
| export interface Entry { | ||
| resolvedPath: string; | ||
| zipPath: string; | ||
| } |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| //# sourceMappingURL=interfaces.js.map |
| {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":""} |
| import { BuildService } from './BuildService'; | ||
| import { ExtractService } from './ExtractService'; | ||
| import type { TerminalOptions } from './interfaces'; | ||
| export declare class JSZipCLI { | ||
| private readonly buildService; | ||
| private readonly configExplorer; | ||
| private readonly configFile?; | ||
| private readonly extractService; | ||
| private readonly logger; | ||
| private options; | ||
| private readonly terminalOptions?; | ||
| constructor(options?: TerminalOptions); | ||
| /** | ||
| * Add files and directories to the ZIP file. | ||
| * @param rawEntries The entries (files, directories) to add. | ||
| * If not specified, entries from configuration file are used. | ||
| */ | ||
| add(rawEntries?: string[]): BuildService; | ||
| /** | ||
| * Add files and directories to the ZIP file. | ||
| * @param rawEntries The entries (files, directories) to extract. | ||
| * If not specified, entries from configuration file are used. | ||
| */ | ||
| extract(rawEntries?: string[]): Promise<ExtractService>; | ||
| /** | ||
| * Run in file mode - reads entries and settings from configuration file. | ||
| * Options from the constructor still take precedence. | ||
| */ | ||
| fileMode(): Promise<JSZipCLI>; | ||
| save(): Promise<BuildService>; | ||
| private checkConfigFile; | ||
| } |
+137
| "use strict"; | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
| }); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.JSZipCLI = void 0; | ||
| const cosmiconfig_1 = require("cosmiconfig"); | ||
| const logdown = require("logdown"); | ||
| const BuildService_1 = require("./BuildService"); | ||
| const ExtractService_1 = require("./ExtractService"); | ||
| const defaultOptions = { | ||
| compressionLevel: 5, | ||
| configFile: true, | ||
| dereferenceLinks: false, | ||
| force: false, | ||
| ignoreEntries: [], | ||
| outputEntry: null, | ||
| quiet: false, | ||
| verbose: false, | ||
| }; | ||
| class JSZipCLI { | ||
| constructor(options) { | ||
| this.terminalOptions = options; | ||
| this.logger = logdown('jszip-cli/index', { | ||
| logger: console, | ||
| markdown: false, | ||
| }); | ||
| this.configExplorer = (0, cosmiconfig_1.cosmiconfigSync)('jszip'); | ||
| this.options = Object.assign(Object.assign({}, defaultOptions), this.terminalOptions); | ||
| this.logger.state.isEnabled = this.options.verbose; | ||
| this.logger.info('Merged options', this.options); | ||
| this.checkConfigFile(); | ||
| this.logger.info('Loaded options', this.options); | ||
| this.buildService = new BuildService_1.BuildService(this.options); | ||
| this.extractService = new ExtractService_1.ExtractService(this.options); | ||
| } | ||
| /** | ||
| * Add files and directories to the ZIP file. | ||
| * @param rawEntries The entries (files, directories) to add. | ||
| * If not specified, entries from configuration file are used. | ||
| */ | ||
| add(rawEntries) { | ||
| if (!rawEntries || !rawEntries.length) { | ||
| if (this.options.entries) { | ||
| rawEntries = this.options.entries; | ||
| } | ||
| else { | ||
| throw new Error('No entries to add.'); | ||
| } | ||
| } | ||
| return this.buildService.add(rawEntries); | ||
| } | ||
| /** | ||
| * Add files and directories to the ZIP file. | ||
| * @param rawEntries The entries (files, directories) to extract. | ||
| * If not specified, entries from configuration file are used. | ||
| */ | ||
| extract(rawEntries) { | ||
| if (!rawEntries || !rawEntries.length) { | ||
| if (this.options.entries) { | ||
| rawEntries = this.options.entries; | ||
| } | ||
| else { | ||
| throw new Error('No entries to extract.'); | ||
| } | ||
| } | ||
| return this.extractService.extract(rawEntries); | ||
| } | ||
| /** | ||
| * Run in file mode - reads entries and settings from configuration file. | ||
| * Options from the constructor still take precedence. | ||
| */ | ||
| fileMode() { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| if (!this.options.mode && !this.configFile) { | ||
| throw new Error('No configuration file and no mode specified.'); | ||
| } | ||
| if (this.options.mode === 'add') { | ||
| const { outputFile, compressedFilesCount } = yield this.add().save(); | ||
| if (this.options.outputEntry && !this.options.quiet) { | ||
| console.info(`Done compressing ${compressedFilesCount} files to "${outputFile}".`); | ||
| } | ||
| return this; | ||
| } | ||
| else if (this.options.mode === 'extract') { | ||
| const { outputDir, extractedFilesCount } = yield this.extract(); | ||
| if (this.options.outputEntry && !this.options.quiet) { | ||
| console.info(`Done extracting ${extractedFilesCount} files to "${outputDir}".`); | ||
| } | ||
| return this; | ||
| } | ||
| throw new Error('No or invalid mode in configuration file defined.'); | ||
| }); | ||
| } | ||
| save() { | ||
| return this.buildService.save(); | ||
| } | ||
| checkConfigFile() { | ||
| if (!this.options.configFile) { | ||
| this.logger.info('Not using any configuration file.'); | ||
| return; | ||
| } | ||
| let configResult = null; | ||
| if (typeof this.options.configFile === 'string') { | ||
| try { | ||
| configResult = this.configExplorer.load(this.options.configFile); | ||
| } | ||
| catch (error) { | ||
| throw new Error(`Can't read configuration file: ${error.message}`); | ||
| } | ||
| } | ||
| else if (this.options.configFile === true) { | ||
| try { | ||
| configResult = this.configExplorer.search(); | ||
| } | ||
| catch (error) { | ||
| this.logger.error(error); | ||
| } | ||
| } | ||
| if (!configResult || configResult.isEmpty) { | ||
| this.logger.info('Not using any configuration file.'); | ||
| return; | ||
| } | ||
| const configFileData = configResult.config; | ||
| this.logger.info(`Using configuration file ${configResult.filepath}`); | ||
| this.options = Object.assign(Object.assign(Object.assign({}, defaultOptions), configFileData), this.terminalOptions); | ||
| this.logger.state.isEnabled = this.options.verbose; | ||
| } | ||
| } | ||
| exports.JSZipCLI = JSZipCLI; | ||
| //# sourceMappingURL=JSZipCLI.js.map |
| {"version":3,"file":"JSZipCLI.js","sourceRoot":"","sources":["../src/JSZipCLI.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA4C;AAE5C,mCAAmC;AAEnC,iDAA4C;AAC5C,qDAAgD;AAGhD,MAAM,cAAc,GAA8B;IAChD,gBAAgB,EAAE,CAAC;IACnB,UAAU,EAAE,IAAI;IAChB,gBAAgB,EAAE,KAAK;IACvB,KAAK,EAAE,KAAK;IACZ,aAAa,EAAE,EAAE;IACjB,WAAW,EAAE,IAAI;IACjB,KAAK,EAAE,KAAK;IACZ,OAAO,EAAE,KAAK;CACf,CAAC;AAEF,MAAa,QAAQ;IASnB,YAAY,OAAyB;QACnC,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,iBAAiB,EAAE;YACvC,MAAM,EAAE,OAAO;YACf,QAAQ,EAAE,KAAK;SAChB,CAAC,CAAC;QACH,IAAI,CAAC,cAAc,GAAG,IAAA,6BAAe,EAAC,OAAO,CAAC,CAAC;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AAY,GAAsB,IAAI,CAAC;QAE3C,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,KAAK,QAAQ,EAAE;YAC/C,IAAI;gBACF,YAAY,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;aAClE;YAAC,OAAO,KAAK,EAAE;gBACd,MAAM,IAAI,KAAK,CAAC,kCAAmC,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;aAC/E;SACF;aAAM,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,KAAK,IAAI,EAAE;YAC3C,IAAI;gBACF,YAAY,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC;aAC7C;YAAC,OAAO,KAAK,EAAE;gBACd,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;aAC1B;SACF;QAED,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,OAAO,EAAE;YACzC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;YACtD,OAAO;SACR;QAED,MAAM,cAAc,GAAG,YAAY,CAAC,MAA2B,CAAC;QAEhE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,4BAA4B,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEtE,IAAI,CAAC,OAAO,iDAAO,cAAc,GAAK,cAAc,GAAK,IAAI,CAAC,eAAe,CAAC,CAAC;QAC/E,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;IACrD,CAAC;CACF;AA/HD,4BA+HC"} |
+7
-31
| { | ||
| "author": "Florian Imdahl <git@ffflorian.de>", | ||
| "bin": { | ||
| "jszip-cli": "cli.js" | ||
| "jszip-cli": "dist/cli.js" | ||
| }, | ||
@@ -10,6 +10,6 @@ "dependencies": { | ||
| "fs-extra": "11.1.1", | ||
| "glob": "10.2.2", | ||
| "jszip": "3.10.1", | ||
| "logdown": "3.3.1", | ||
| "progress": "2.0.3", | ||
| "glob": "10.2.1" | ||
| "progress": "2.0.3" | ||
| }, | ||
@@ -29,23 +29,3 @@ "description": "A zip CLI based on jszip.", | ||
| "files": [ | ||
| "BuildService.d.ts", | ||
| "BuildService.js", | ||
| "BuildService.js.map", | ||
| "ExtractService.d.ts", | ||
| "ExtractService.js", | ||
| "ExtractService.js.map", | ||
| "FileService.d.ts", | ||
| "FileService.js", | ||
| "FileService.js.map", | ||
| "JSZipCLI.d.ts", | ||
| "JSZipCLI.js", | ||
| "JSZipCLI.js.map", | ||
| "cli.d.ts", | ||
| "cli.js", | ||
| "cli.js.map", | ||
| "index.d.ts", | ||
| "index.js", | ||
| "index.js.map", | ||
| "interfaces.d.ts", | ||
| "interfaces.js", | ||
| "interfaces.js.map" | ||
| "dist" | ||
| ], | ||
@@ -59,7 +39,4 @@ "keywords": [ | ||
| "license": "GPL-3.0", | ||
| "main": "index.js", | ||
| "main": "dist/index.js", | ||
| "name": "@ffflorian/jszip-cli", | ||
| "publishConfig": { | ||
| "directory": "flattened" | ||
| }, | ||
| "repository": "https://github.com/ffflorian/node-packages/tree/main/packages/jszip-cli", | ||
@@ -70,8 +47,7 @@ "scripts": { | ||
| "dist": "yarn clean && yarn build", | ||
| "flatten": "node ../publish-flat/dist/cli.js -o flattened", | ||
| "postversion": "node ../publish-flat/dist/cli-copy.js -o flattened/package.json version", | ||
| "start": "cross-env NODE_DEBUG=\"jszip-cli/*\" ts-node src/cli.ts", | ||
| "test": "ts-node -P tsconfig.jasmine.json ../../node_modules/jasmine/bin/jasmine.js" | ||
| }, | ||
| "version": "3.4.0" | ||
| "version": "3.4.1", | ||
| "gitHead": "fee6dde4396255259028c1c723a95b9f6ec5b281" | ||
| } |
| import { TerminalOptions } from './interfaces'; | ||
| export declare class BuildService { | ||
| compressedFilesCount: number; | ||
| outputFile: string | null; | ||
| private entries; | ||
| private readonly fileService; | ||
| private readonly ignoreEntries; | ||
| private readonly jszip; | ||
| private readonly logger; | ||
| private readonly options; | ||
| private readonly progressBar; | ||
| constructor(options: Required<TerminalOptions>); | ||
| add(rawEntries: string[]): BuildService; | ||
| save(): Promise<BuildService>; | ||
| /** | ||
| * Note: glob patterns should always use / as a path separator, even on Windows systems, | ||
| * as \ is used to escape glob characters. | ||
| * https://github.com/isaacs/node-glob | ||
| */ | ||
| private normalizePaths; | ||
| private addFile; | ||
| private addLink; | ||
| private checkEntry; | ||
| private checkOutput; | ||
| private getBuffer; | ||
| private walkDir; | ||
| } |
-226
| "use strict"; | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
| }); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.BuildService = void 0; | ||
| const fs = require("fs-extra"); | ||
| const JSZip = require("jszip"); | ||
| const logdown = require("logdown"); | ||
| const path = require("path"); | ||
| const progress = require("progress"); | ||
| const FileService_1 = require("./FileService"); | ||
| const glob_1 = require("glob"); | ||
| class BuildService { | ||
| constructor(options) { | ||
| this.fileService = new FileService_1.FileService(options); | ||
| this.jszip = new JSZip(); | ||
| this.options = options; | ||
| this.logger = logdown('jszip-cli/BuildService', { | ||
| logger: console, | ||
| markdown: false, | ||
| }); | ||
| this.logger.state = { isEnabled: options.verbose }; | ||
| this.entries = []; | ||
| this.ignoreEntries = this.options.ignoreEntries.map(entry => entry instanceof RegExp ? entry : new RegExp(entry.replace(/\*/g, '.*'))); | ||
| this.outputFile = this.options.outputEntry ? path.resolve(this.options.outputEntry) : null; | ||
| this.progressBar = new progress('Compressing [:bar] :percent :elapseds', { | ||
| complete: '=', | ||
| incomplete: ' ', | ||
| total: 100, | ||
| width: 20, | ||
| }); | ||
| this.compressedFilesCount = 0; | ||
| } | ||
| add(rawEntries) { | ||
| this.logger.info(`Adding ${rawEntries.length} entr${rawEntries.length === 1 ? 'y' : 'ies'} to ZIP file.`); | ||
| const normalizedEntries = this.normalizePaths(rawEntries); | ||
| this.entries = (0, glob_1.globSync)(normalizedEntries).map(rawEntry => { | ||
| const resolvedPath = path.resolve(rawEntry); | ||
| const baseName = path.basename(rawEntry); | ||
| return { | ||
| resolvedPath, | ||
| zipPath: baseName, | ||
| }; | ||
| }); | ||
| return this; | ||
| } | ||
| save() { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| yield this.checkOutput(); | ||
| yield Promise.all(this.entries.map(entry => this.checkEntry(entry))); | ||
| const data = yield this.getBuffer(); | ||
| if (this.outputFile) { | ||
| if (!this.outputFile.match(/\.\w+$/)) { | ||
| this.outputFile = path.join(this.outputFile, 'data.zip'); | ||
| } | ||
| this.logger.info(`Saving finished zip file to "${this.outputFile}" ...`); | ||
| yield this.fileService.writeFile(data, this.outputFile); | ||
| } | ||
| else { | ||
| process.stdout.write(data); | ||
| } | ||
| return this; | ||
| }); | ||
| } | ||
| /** | ||
| * Note: glob patterns should always use / as a path separator, even on Windows systems, | ||
| * as \ is used to escape glob characters. | ||
| * https://github.com/isaacs/node-glob | ||
| */ | ||
| normalizePaths(rawEntries) { | ||
| return rawEntries.map(entry => entry.replace(/\\/g, '/')); | ||
| } | ||
| addFile(entry, isLink = false) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| const { resolvedPath, zipPath } = entry; | ||
| let fileStat; | ||
| let fileData; | ||
| try { | ||
| fileData = isLink ? yield fs.readlink(resolvedPath) : yield fs.readFile(resolvedPath); | ||
| fileStat = yield fs.lstat(resolvedPath); | ||
| } | ||
| catch (error) { | ||
| if (!this.options.quiet) { | ||
| console.info(`Can't read file "${entry.resolvedPath}". Ignoring.`); | ||
| } | ||
| this.logger.info(error); | ||
| return; | ||
| } | ||
| this.logger.info(`Adding file "${resolvedPath}" to ZIP file ...`); | ||
| this.jszip.file(zipPath, fileData, { | ||
| createFolders: true, | ||
| date: fileStat.mtime, | ||
| // See https://github.com/Stuk/jszip/issues/550 | ||
| // dosPermissions: fileStat.mode, | ||
| unixPermissions: fileStat.mode, | ||
| }); | ||
| this.compressedFilesCount++; | ||
| }); | ||
| } | ||
| addLink(entry) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| const { resolvedPath, zipPath } = entry; | ||
| if (this.options.dereferenceLinks) { | ||
| let realPath; | ||
| try { | ||
| realPath = yield fs.realpath(resolvedPath); | ||
| } | ||
| catch (error) { | ||
| if (!this.options.quiet) { | ||
| console.info(`Can't read link "${entry.resolvedPath}". Ignoring.`); | ||
| } | ||
| this.logger.info(error); | ||
| return; | ||
| } | ||
| this.logger.info(`Found real path "${realPath} for symbolic link".`); | ||
| yield this.checkEntry({ | ||
| resolvedPath: realPath, | ||
| zipPath, | ||
| }); | ||
| } | ||
| else { | ||
| yield this.addFile(entry, true); | ||
| } | ||
| }); | ||
| } | ||
| checkEntry(entry) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| let fileStat; | ||
| try { | ||
| fileStat = yield fs.lstat(entry.resolvedPath); | ||
| } | ||
| catch (error) { | ||
| if (!this.options.quiet) { | ||
| console.info(`Can't read file "${entry.resolvedPath}". Ignoring.`); | ||
| } | ||
| this.logger.info(error); | ||
| return; | ||
| } | ||
| const ignoreEntries = this.ignoreEntries.filter(ignoreEntry => Boolean(entry.resolvedPath.match(ignoreEntry))); | ||
| if (ignoreEntries.length) { | ||
| this.logger.info(`Found ${entry.resolvedPath}. Not adding since it's on the ignore list:`, ignoreEntries.map(entry => String(entry))); | ||
| return; | ||
| } | ||
| if (fileStat.isDirectory()) { | ||
| this.logger.info(`Found directory "${entry.resolvedPath}".`); | ||
| yield this.walkDir(entry); | ||
| } | ||
| else if (fileStat.isFile()) { | ||
| this.logger.info(`Found file "${entry.resolvedPath}".`); | ||
| yield this.addFile(entry); | ||
| } | ||
| else if (fileStat.isSymbolicLink()) { | ||
| this.logger.info(`Found symbolic link "${entry.resolvedPath}".`); | ||
| yield this.addLink(entry); | ||
| } | ||
| else { | ||
| this.logger.info('Unknown file type.', { fileStat }); | ||
| if (!this.options.quiet) { | ||
| console.info(`Can't read file "${entry.resolvedPath}". Ignoring.`); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| checkOutput() { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| if (this.outputFile) { | ||
| if (this.outputFile.match(/\.\w+$/)) { | ||
| const dirExists = yield this.fileService.dirExists(path.dirname(this.outputFile)); | ||
| if (!dirExists) { | ||
| throw new Error(`Directory "${path.dirname(this.outputFile)}" doesn't exist or is not writable.`); | ||
| } | ||
| const fileIsWritable = yield this.fileService.fileIsWritable(this.outputFile); | ||
| if (!fileIsWritable) { | ||
| throw new Error(`File "${this.outputFile}" already exists.`); | ||
| } | ||
| } | ||
| else { | ||
| const dirExists = yield this.fileService.dirExists(this.outputFile); | ||
| if (!dirExists) { | ||
| throw new Error(`Directory "${this.outputFile}" doesn't exist or is not writable.`); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| getBuffer() { | ||
| const compressionType = this.options.compressionLevel === 0 ? 'STORE' : 'DEFLATE'; | ||
| let lastPercent = 0; | ||
| return this.jszip.generateAsync({ | ||
| compression: compressionType, | ||
| compressionOptions: { | ||
| level: this.options.compressionLevel, | ||
| }, | ||
| type: 'nodebuffer', | ||
| }, ({ percent }) => { | ||
| const diff = Math.floor(percent) - Math.floor(lastPercent); | ||
| if (diff && !this.options.quiet) { | ||
| this.progressBar.tick(diff); | ||
| lastPercent = Math.floor(percent); | ||
| } | ||
| }); | ||
| } | ||
| walkDir(entry) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| this.logger.info(`Walking directory ${entry.resolvedPath} ...`); | ||
| const dirEntries = yield fs.readdir(entry.resolvedPath); | ||
| for (const dirEntry of dirEntries) { | ||
| const newZipPath = entry.zipPath === '.' ? dirEntry : `${entry.zipPath}/${dirEntry}`; | ||
| const newResolvedPath = path.join(entry.resolvedPath, dirEntry); | ||
| yield this.checkEntry({ | ||
| resolvedPath: newResolvedPath, | ||
| zipPath: newZipPath, | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| exports.BuildService = BuildService; | ||
| //# sourceMappingURL=BuildService.js.map |
| {"version":3,"file":"BuildService.js","sourceRoot":"","sources":["../src/BuildService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAA+B;AAC/B,+BAA+B;AAC/B,mCAAmC;AACnC,6BAA6B;AAC7B,qCAAqC;AACrC,+CAA0C;AAE1C,+BAA8B;AAE9B,MAAa,YAAY;IAWvB,YAAY,OAAkC;QAC5C,IAAI,CAAC,WAAW,GAAG,IAAI,yBAAW,CAAC,OAAO,CAAC,CAAC;QAC5C,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,wBAAwB,EAAE;YAC9C,MAAM,EAAE,OAAO;YACf,QAAQ,EAAE,KAAK;SAChB,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,EAAC,SAAS,EAAE,OAAO,CAAC,OAAO,EAAC,CAAC;QACjD,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAC1D,KAAK,YAAY,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CACzE,CAAC;QACF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YAAY,EAAE,QAAQ,CAAC,CAAC;gBAChE,MAAM,IAAI,CAAC,UAAU,CAAC;oBACpB,YAAY,EAAE,eAAe;oBAC7B,OAAO,EAAE,UAAU;iBACpB,CAAC,CAAC;aACJ;QACH,CAAC;KAAA;CACF;AAjOD,oCAiOC"} |
-2
| #!/usr/bin/env node | ||
| export {}; |
-121
| #!/usr/bin/env node | ||
| "use strict"; | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
| }); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const commander_1 = require("commander"); | ||
| const fs = require("fs-extra"); | ||
| const path = require("path"); | ||
| const JSZipCLI_1 = require("./JSZipCLI"); | ||
| const defaultPackageJsonPath = path.join(__dirname, 'package.json'); | ||
| const packageJsonPath = fs.existsSync(defaultPackageJsonPath) | ||
| ? defaultPackageJsonPath | ||
| : path.join(__dirname, '../package.json'); | ||
| const { description, name, version } = fs.readJSONSync(packageJsonPath); | ||
| commander_1.program | ||
| .name(name.replace(/^@[^/]+\//, '')) | ||
| .description(description) | ||
| .option('--noconfig', "don't look for a configuration file") | ||
| .option('-c, --config <path>', 'use a configuration file (default: .jsziprc.json)') | ||
| .option('-d, --dereference', 'dereference (follow) links', false) | ||
| .option('-f, --force', 'force overwriting files and directories when extracting', false) | ||
| .option('-i, --ignore <entry>', 'ignore a file or directory') | ||
| .option('-l, --level <number>', 'set the compression level', '5') | ||
| .option('-o, --output <dir>', 'set the output file or directory (default: stdout)') | ||
| .option('-q, --quiet', "don't log anything", false) | ||
| .option('-V, --verbose', 'enable verbose logging', false) | ||
| .version(version, '-v, --version') | ||
| .on('command:*', args => { | ||
| console.error(`\n error: invalid command \`${args[0]}'\n`); | ||
| process.exit(1); | ||
| }); | ||
| commander_1.program | ||
| .command('add') | ||
| .alias('a') | ||
| .description('add files and directories to a new ZIP archive') | ||
| .option('--noconfig', "don't look for a configuration file") | ||
| .option('-c, --config <path>', 'use a configuration file') | ||
| .option('-d, --dereference', 'dereference (follow) symlinks', false) | ||
| .option('-f, --force', 'force overwriting files and directories when extracting', false) | ||
| .option('-i, --ignore <entry>', 'ignore a file or directory') | ||
| .option('-l, --level <number>', 'set the compression level', '5') | ||
| .option('-o, --output <dir>', 'set the output file or directory (default: stdout)') | ||
| .option('-q, --quiet', "don't log anything excluding errors", false) | ||
| .option('-V, --verbose', 'enable verbose logging', false) | ||
| .arguments('[entries...]') | ||
| .action((entries) => __awaiter(void 0, void 0, void 0, function* () { | ||
| const options = commander_1.program.opts(); | ||
| try { | ||
| const jszip = new JSZipCLI_1.JSZipCLI(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (options.level && { compressionLevel: Number(options.level) })), ((options.config && { configFile: options.config }) || (options.noconfig && { configFile: false }))), (options.dereference && { dereferenceLinks: options.dereference })), (options.force && { force: options.force })), (options.ignore && { ignoreEntries: [options.ignore] })), (options.output && { outputEntry: options.output })), (options.quiet && { quiet: options.quiet })), (options.verbose && { verbose: options.verbose }))); | ||
| jszip.add(entries); | ||
| const { outputFile, compressedFilesCount } = yield jszip.save(); | ||
| if (options.output && !options.quiet) { | ||
| console.info(`Done compressing ${compressedFilesCount} files to "${outputFile}".`); | ||
| } | ||
| } | ||
| catch (error) { | ||
| console.error('Error:', error.message); | ||
| process.exit(1); | ||
| } | ||
| })); | ||
| commander_1.program | ||
| .command('extract') | ||
| .alias('e') | ||
| .description('extract files and directories from ZIP archive(s)') | ||
| .option('--noconfig', "don't look for a configuration file", false) | ||
| .option('-c, --config <path>', 'use a configuration file (default: .jsziprc.json)') | ||
| .option('-o, --output <dir>', 'set the output file or directory (default: stdout)') | ||
| .option('-i, --ignore <entry>', 'ignore a file or directory') | ||
| .option('-f, --force', 'force overwriting files and directories', false) | ||
| .option('-V, --verbose', 'enable verbose logging', false) | ||
| .option('-q, --quiet', "don't log anything excluding errors", false) | ||
| .arguments('<archives...>') | ||
| .action((archives) => __awaiter(void 0, void 0, void 0, function* () { | ||
| const options = commander_1.program.opts(); | ||
| try { | ||
| const { outputDir, extractedFilesCount } = yield new JSZipCLI_1.JSZipCLI(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, ((options.config && { configFile: options.config }) || (options.noconfig && { configFile: false }))), (options.force && { force: options.force })), (options.ignore && { ignoreEntries: [options.ignore] })), (options.output && { outputEntry: options.output })), (options.quiet && { quiet: options.quiet })), (options.verbose && { verbose: options.verbose }))).extract(archives); | ||
| if (options.output && !options.quiet) { | ||
| console.info(`Done extracting ${extractedFilesCount} files to "${outputDir}".`); | ||
| } | ||
| } | ||
| catch (error) { | ||
| console.error('Error:', error.message); | ||
| process.exit(1); | ||
| } | ||
| })); | ||
| commander_1.program | ||
| .command('fileMode', { hidden: true, isDefault: true }) | ||
| .option('--noconfig', "don't look for a configuration file", false) | ||
| .option('-c, --config <path>', 'use a configuration file (default: .jsziprc.json)') | ||
| .option('-o, --output <dir>', 'set the output file or directory (default: stdout)') | ||
| .option('-i, --ignore <entry>', 'ignore a file or directory') | ||
| .option('-f, --force', 'force overwriting files and directories', false) | ||
| .option('-V, --verbose', 'enable verbose logging', false) | ||
| .option('-q, --quiet', "don't log anything excluding errors", false) | ||
| .action(() => __awaiter(void 0, void 0, void 0, function* () { | ||
| const options = commander_1.program.opts(); | ||
| try { | ||
| if (options.noconfig) { | ||
| commander_1.program.outputHelp(); | ||
| } | ||
| yield new JSZipCLI_1.JSZipCLI(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (options.config && { configFile: options.config })), (options.force && { force: options.force })), (options.ignore && { ignoreEntries: [options.ignore] })), (options.output && { outputEntry: options.output })), (options.quiet && { quiet: options.quiet })), (options.verbose && { verbose: options.verbose }))).fileMode(); | ||
| } | ||
| catch (error) { | ||
| if (error.message.includes('ENOENT')) { | ||
| console.error('Error:', `Configuration file "${options.config}" not found and no mode specified.`); | ||
| } | ||
| else { | ||
| console.error('Error:', error.message); | ||
| } | ||
| process.exit(1); | ||
| } | ||
| })); | ||
| commander_1.program.parse(process.argv); | ||
| //# sourceMappingURL=cli.js.map |
| {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,yCAA+C;AAC/C,+BAA+B;AAC/B,6BAA6B;AAE7B,yCAAoC;AAEpC,MAAM,sBAAsB,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;AACpE,MAAM,eAAe,GAAG,EAAE,CAAC,UAAU,CAAC,sBAAsB,CAAC;IAC3D,CAAC,CAAC,sBAAsB;IACxB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;AAE5C,MAAM,EAAC,WAAW,EAAE,IAAI,EAAE,OAAO,EAAC,GAChC,EAAE,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;AAcnC,mBAAS;KACN,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;KACnC,WAAW,CAAC,WAAW,CAAC;KACxB,MAAM,CAAC,YAAY,EAAE,qCAAqC,CAAC;KAC3D,MAAM,CAAC,qBAAqB,EAAE,mDAAmD,CAAC;KAClF,MAAM,CAAC,mBAAmB,EAAE,4BAA4B,EAAE,KAAK,CAAC;KAChE,MAAM,CAAC,aAAa,EAAE,yDAAyD,EAAE,KAAK,CAAC;KACvF,MAAM,CAAC,sBAAsB,EAAE,4BAA4B,CAAC;KAC5D,MAAM,CAAC,sBAAsB,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K,IAAI,EAAC,KAAK,EAAE,OAAO,CAAC,KAAK,EAAC,CAAC,GACzC,CAAC,OAAO,CAAC,MAAM,IAAI,EAAC,aAAa,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,EAAC,CAAC,GACrD,CAAC,OAAO,CAAC,MAAM,IAAI,EAAC,WAAW,EAAE,OAAO,CAAC,MAAM,EAAC,CAAC,GACjD,CAAC,OAAO,CAAC,KAAK,IAAI,EAAC,KAAK,EAAE,OAAO,CAAC,KAAK,EAAC,CAAC,GACzC,CAAC,OAAO,CAAC,OAAO,IAAI,EAAC,OAAO,EAAE,OAAO,CAAC,OAAO,EAAC,CAAC,EAClD,CAAC,QAAQ,EAAE,CAAC;KACf;IAAC,OAAO,KAAK,EAAE;QACd,IAAK,KAAe,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;YAC/C,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,uBAAuB,OAAO,CAAC,MAAM,oCAAoC,CAAC,CAAC;SACpG;aAAM;YACL,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAG,KAAe,CAAC,OAAO,CAAC,CAAC;SACnD;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC,CAAA,CAAC,CAAC;AAEL,mBAAS,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"} |
| import { TerminalOptions } from './interfaces'; | ||
| export declare class ExtractService { | ||
| extractedFilesCount: number; | ||
| outputDir: string | null; | ||
| private readonly logger; | ||
| private readonly options; | ||
| private readonly progressBar; | ||
| constructor(options: Required<TerminalOptions>); | ||
| extract(rawEntries: string[]): Promise<ExtractService>; | ||
| private printStream; | ||
| } |
| "use strict"; | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
| }); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.ExtractService = void 0; | ||
| const fs = require("fs-extra"); | ||
| const JSZip = require("jszip"); | ||
| const logdown = require("logdown"); | ||
| const os = require("os"); | ||
| const path = require("path"); | ||
| const progress = require("progress"); | ||
| class ExtractService { | ||
| constructor(options) { | ||
| this.options = options; | ||
| this.logger = logdown('jszip-cli/ExtractService', { | ||
| logger: console, | ||
| markdown: false, | ||
| }); | ||
| this.logger.state.isEnabled = this.options.verbose; | ||
| this.outputDir = this.options.outputEntry ? path.resolve(this.options.outputEntry) : null; | ||
| this.progressBar = new progress('Extracting [:bar] :percent :elapseds', { | ||
| complete: '=', | ||
| incomplete: ' ', | ||
| total: 100, | ||
| width: 20, | ||
| }); | ||
| this.extractedFilesCount = 0; | ||
| } | ||
| extract(rawEntries) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| const isWin32 = os.platform() === 'win32'; | ||
| for (const entry of rawEntries) { | ||
| const jszip = new JSZip(); | ||
| if (this.outputDir) { | ||
| yield fs.ensureDir(this.outputDir); | ||
| } | ||
| const resolvedPath = path.resolve(entry); | ||
| const data = yield fs.readFile(resolvedPath); | ||
| const entries = []; | ||
| yield jszip.loadAsync(data, { createFolders: true }); | ||
| if (!this.outputDir) { | ||
| yield this.printStream(jszip.generateNodeStream()); | ||
| return this; | ||
| } | ||
| jszip.forEach((filePath, entry) => { | ||
| if (filePath.includes('..')) { | ||
| this.logger.info(`Skipping bad path "${filePath}"`); | ||
| } | ||
| else { | ||
| entries.push([filePath, entry]); | ||
| } | ||
| }); | ||
| let lastPercent = 0; | ||
| yield Promise.all(entries.map(([filePath, entry], index) => __awaiter(this, void 0, void 0, function* () { | ||
| const resolvedFilePath = path.join(this.outputDir, filePath); | ||
| if (entry.dir) { | ||
| yield fs.ensureDir(resolvedFilePath); | ||
| } | ||
| else { | ||
| const data = yield entry.async('nodebuffer'); | ||
| yield fs.writeFile(resolvedFilePath, data, { | ||
| encoding: 'utf-8', | ||
| }); | ||
| this.extractedFilesCount++; | ||
| const diff = Math.floor(index / entries.length) - Math.floor(lastPercent); | ||
| if (diff && !this.options.quiet) { | ||
| this.progressBar.tick(diff); | ||
| lastPercent = Math.floor(index / entries.length); | ||
| } | ||
| } | ||
| if (isWin32) { | ||
| if (entry.dosPermissions) { | ||
| yield fs.chmod(resolvedFilePath, entry.dosPermissions); | ||
| } | ||
| } | ||
| else if (entry.unixPermissions) { | ||
| yield fs.chmod(resolvedFilePath, entry.unixPermissions); | ||
| } | ||
| }))); | ||
| } | ||
| return this; | ||
| }); | ||
| } | ||
| printStream(fileStream) { | ||
| return new Promise((resolve, reject) => { | ||
| const stream = fileStream.pipe(process.stdout); | ||
| stream.on('finish', resolve); | ||
| stream.on('error', reject); | ||
| }); | ||
| } | ||
| } | ||
| exports.ExtractService = ExtractService; | ||
| //# sourceMappingURL=ExtractService.js.map |
| {"version":3,"file":"ExtractService.js","sourceRoot":"","sources":["../src/ExtractService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAA+B;AAC/B,+BAA+B;AAC/B,mCAAmC;AACnC,yBAAyB;AACzB,6BAA6B;AAC7B,qCAAqC;AAGrC,MAAa,cAAc;IAOzB,YAAY,OAAkC;QAC5C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,0BAA0B,EAAE;YAChD,MAAM,EAAE,OAAO;YACf,QAAQ,EAAE,KAAK;SAChB,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;QACnD,IAAI,CAAC,SAAS,GAA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,CAAC,gBAAgB,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;yBACxD;qBACF;yBAAM,IAAI,KAAK,CAAC,eAAe,EAAE;wBAChC,MAAM,EAAE,CAAC,KAAK,CAAC,gBAAgB,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;qBACzD;gBACH,CAAC,CAAA,CAAC,CACH,CAAC;aACH;YACD,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;IAEO,WAAW,CAAC,UAAiC;QACnD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAC/C,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC7B,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA7FD,wCA6FC"} |
| /// <reference types="node" /> | ||
| import type { TerminalOptions } from './interfaces'; | ||
| export declare class FileService { | ||
| private readonly logger; | ||
| private readonly options; | ||
| constructor(options: Required<TerminalOptions>); | ||
| dirExists(dirPath: string): Promise<boolean>; | ||
| fileIsReadable(filePath: string): Promise<boolean>; | ||
| fileIsWritable(filePath: string): Promise<boolean>; | ||
| writeFile(data: Buffer, filePath: string): Promise<FileService>; | ||
| } |
| "use strict"; | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
| }); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.FileService = void 0; | ||
| const fs = require("fs-extra"); | ||
| const logdown = require("logdown"); | ||
| const path = require("path"); | ||
| class FileService { | ||
| constructor(options) { | ||
| this.options = options; | ||
| this.logger = logdown('jszip-cli/FileService', { | ||
| logger: console, | ||
| markdown: false, | ||
| }); | ||
| this.logger.state.isEnabled = this.options.verbose; | ||
| } | ||
| dirExists(dirPath) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| try { | ||
| yield fs.access(dirPath, fs.constants.F_OK); | ||
| try { | ||
| yield fs.access(dirPath, fs.constants.W_OK); | ||
| return true; | ||
| } | ||
| catch (error) { | ||
| this.logger.info(`Directory "${dirPath}" exists but is not writable.`); | ||
| return false; | ||
| } | ||
| } | ||
| catch (error) { | ||
| this.logger.info(`Directory "${dirPath}" doesn't exist.`, this.options.force ? 'Creating.' : 'Not creating.'); | ||
| if (this.options.force) { | ||
| yield fs.ensureDir(dirPath); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| }); | ||
| } | ||
| fileIsReadable(filePath) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| const dirExists = yield this.dirExists(path.dirname(filePath)); | ||
| if (dirExists) { | ||
| try { | ||
| yield fs.access(filePath, fs.constants.F_OK | fs.constants.R_OK); | ||
| return true; | ||
| } | ||
| catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| return false; | ||
| }); | ||
| } | ||
| fileIsWritable(filePath) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| const dirName = path.dirname(filePath); | ||
| const dirExists = yield this.dirExists(dirName); | ||
| if (dirExists) { | ||
| try { | ||
| yield fs.access(filePath, fs.constants.F_OK | fs.constants.R_OK); | ||
| this.logger.info(`File "${filePath}" already exists.`, this.options.force ? 'Forcing overwrite.' : 'Not overwriting.'); | ||
| return this.options.force; | ||
| } | ||
| catch (error) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| }); | ||
| } | ||
| writeFile(data, filePath) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| const fileIsWritable = yield this.fileIsWritable(filePath); | ||
| if (fileIsWritable) { | ||
| yield fs.writeFile(filePath, data); | ||
| return this; | ||
| } | ||
| throw new Error(`File "${this.options.outputEntry}" already exists.`); | ||
| }); | ||
| } | ||
| } | ||
| exports.FileService = FileService; | ||
| //# sourceMappingURL=FileService.js.map |
| {"version":3,"file":"FileService.js","sourceRoot":"","sources":["../src/FileService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAA+B;AAC/B,mCAAmC;AACnC,6BAA6B;AAG7B,MAAa,WAAW;IAGtB,YAAY,OAAkC;QAC5C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,uBAAuB,EAAE;YAC7C,MAAM,EAAE,OAAO;YACf,QAAQ,EAAE,KAAK;SAChB,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;IACrD,CAAC;IAEY,SAAS,CAAC,OAAe;;YACpC,IAAI;gBACF,MAAM,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;gBAC5C,IAAI;oBACF,MAAM,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;oBAC5C,OAAO,IAAI,CAAC;iBACb;gBAAC,OAAO,KAAK,EAAE;oBACd,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,OAAO,+BAA+B,CAAC,CAAC;oBACvE,OAAO,KAAK,CAAC;iBACd;aACF;YAAC,OAAO,KAAK,EAAE;gBACd,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,OAAO,kBAAkB,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,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oBACd,OAAO,IAAI,CAAC;iBACb;aACF;YACD,OAAO,KAAK,CAAC;QACf,CAAC;KAAA;IAEY,SAAS,CAAC,IAAY,EAAE,QAAgB;;YACnD,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;YAC3D,IAAI,cAAc,EAAE;gBAClB,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;gBACnC,OAAO,IAAI,CAAC;aACb;YACD,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,CAAC,OAAO,CAAC,WAAW,mBAAmB,CAAC,CAAC;QACxE,CAAC;KAAA;CACF;AAvED,kCAuEC"} |
| export * from './JSZipCLI'; | ||
| export * from './interfaces'; |
-19
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| __exportStar(require("./JSZipCLI"), exports); | ||
| __exportStar(require("./interfaces"), exports); | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,+CAA6B"} |
| export interface TerminalOptions { | ||
| /** The compression level to use (0 = save only, 9 = best compression) (default: 5). */ | ||
| compressionLevel?: number; | ||
| /** Use a configuration file (default: .jsziprc.json). */ | ||
| configFile?: string | boolean; | ||
| /** Whether to dereference (follow) symlinks (default: false). */ | ||
| dereferenceLinks?: boolean; | ||
| /** Force overwriting files and directories when extracting (default: false). */ | ||
| force?: boolean; | ||
| /** Ignore entries (e.g. `*.js.map`). */ | ||
| ignoreEntries?: Array<string | RegExp>; | ||
| /** Set the output directory (default: stdout). */ | ||
| outputEntry?: string | null; | ||
| /** Don't log anything excluding errors (default: false). */ | ||
| quiet?: boolean; | ||
| /** Enable verbose logging (default: false). */ | ||
| verbose?: boolean; | ||
| } | ||
| export interface ConfigFileOptions extends TerminalOptions { | ||
| /** Which files or directories to add. */ | ||
| entries: string[]; | ||
| /** Add or extract files. */ | ||
| mode: 'add' | 'extract'; | ||
| } | ||
| export interface Entry { | ||
| resolvedPath: string; | ||
| zipPath: string; | ||
| } |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| //# sourceMappingURL=interfaces.js.map |
| {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":""} |
| import { BuildService } from './BuildService'; | ||
| import { ExtractService } from './ExtractService'; | ||
| import type { TerminalOptions } from './interfaces'; | ||
| export declare class JSZipCLI { | ||
| private readonly buildService; | ||
| private readonly configExplorer; | ||
| private readonly configFile?; | ||
| private readonly extractService; | ||
| private readonly logger; | ||
| private options; | ||
| private readonly terminalOptions?; | ||
| constructor(options?: TerminalOptions); | ||
| /** | ||
| * Add files and directories to the ZIP file. | ||
| * @param rawEntries The entries (files, directories) to add. | ||
| * If not specified, entries from configuration file are used. | ||
| */ | ||
| add(rawEntries?: string[]): BuildService; | ||
| /** | ||
| * Add files and directories to the ZIP file. | ||
| * @param rawEntries The entries (files, directories) to extract. | ||
| * If not specified, entries from configuration file are used. | ||
| */ | ||
| extract(rawEntries?: string[]): Promise<ExtractService>; | ||
| /** | ||
| * Run in file mode - reads entries and settings from configuration file. | ||
| * Options from the constructor still take precedence. | ||
| */ | ||
| fileMode(): Promise<JSZipCLI>; | ||
| save(): Promise<BuildService>; | ||
| private checkConfigFile; | ||
| } |
-137
| "use strict"; | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
| }); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.JSZipCLI = void 0; | ||
| const cosmiconfig_1 = require("cosmiconfig"); | ||
| const logdown = require("logdown"); | ||
| const BuildService_1 = require("./BuildService"); | ||
| const ExtractService_1 = require("./ExtractService"); | ||
| const defaultOptions = { | ||
| compressionLevel: 5, | ||
| configFile: true, | ||
| dereferenceLinks: false, | ||
| force: false, | ||
| ignoreEntries: [], | ||
| outputEntry: null, | ||
| quiet: false, | ||
| verbose: false, | ||
| }; | ||
| class JSZipCLI { | ||
| constructor(options) { | ||
| this.terminalOptions = options; | ||
| this.logger = logdown('jszip-cli/index', { | ||
| logger: console, | ||
| markdown: false, | ||
| }); | ||
| this.configExplorer = (0, cosmiconfig_1.cosmiconfigSync)('jszip'); | ||
| this.options = Object.assign(Object.assign({}, defaultOptions), this.terminalOptions); | ||
| this.logger.state.isEnabled = this.options.verbose; | ||
| this.logger.info('Merged options', this.options); | ||
| this.checkConfigFile(); | ||
| this.logger.info('Loaded options', this.options); | ||
| this.buildService = new BuildService_1.BuildService(this.options); | ||
| this.extractService = new ExtractService_1.ExtractService(this.options); | ||
| } | ||
| /** | ||
| * Add files and directories to the ZIP file. | ||
| * @param rawEntries The entries (files, directories) to add. | ||
| * If not specified, entries from configuration file are used. | ||
| */ | ||
| add(rawEntries) { | ||
| if (!rawEntries || !rawEntries.length) { | ||
| if (this.options.entries) { | ||
| rawEntries = this.options.entries; | ||
| } | ||
| else { | ||
| throw new Error('No entries to add.'); | ||
| } | ||
| } | ||
| return this.buildService.add(rawEntries); | ||
| } | ||
| /** | ||
| * Add files and directories to the ZIP file. | ||
| * @param rawEntries The entries (files, directories) to extract. | ||
| * If not specified, entries from configuration file are used. | ||
| */ | ||
| extract(rawEntries) { | ||
| if (!rawEntries || !rawEntries.length) { | ||
| if (this.options.entries) { | ||
| rawEntries = this.options.entries; | ||
| } | ||
| else { | ||
| throw new Error('No entries to extract.'); | ||
| } | ||
| } | ||
| return this.extractService.extract(rawEntries); | ||
| } | ||
| /** | ||
| * Run in file mode - reads entries and settings from configuration file. | ||
| * Options from the constructor still take precedence. | ||
| */ | ||
| fileMode() { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| if (!this.options.mode && !this.configFile) { | ||
| throw new Error('No configuration file and no mode specified.'); | ||
| } | ||
| if (this.options.mode === 'add') { | ||
| const { outputFile, compressedFilesCount } = yield this.add().save(); | ||
| if (this.options.outputEntry && !this.options.quiet) { | ||
| console.info(`Done compressing ${compressedFilesCount} files to "${outputFile}".`); | ||
| } | ||
| return this; | ||
| } | ||
| else if (this.options.mode === 'extract') { | ||
| const { outputDir, extractedFilesCount } = yield this.extract(); | ||
| if (this.options.outputEntry && !this.options.quiet) { | ||
| console.info(`Done extracting ${extractedFilesCount} files to "${outputDir}".`); | ||
| } | ||
| return this; | ||
| } | ||
| throw new Error('No or invalid mode in configuration file defined.'); | ||
| }); | ||
| } | ||
| save() { | ||
| return this.buildService.save(); | ||
| } | ||
| checkConfigFile() { | ||
| if (!this.options.configFile) { | ||
| this.logger.info('Not using any configuration file.'); | ||
| return; | ||
| } | ||
| let configResult = null; | ||
| if (typeof this.options.configFile === 'string') { | ||
| try { | ||
| configResult = this.configExplorer.load(this.options.configFile); | ||
| } | ||
| catch (error) { | ||
| throw new Error(`Can't read configuration file: ${error.message}`); | ||
| } | ||
| } | ||
| else if (this.options.configFile === true) { | ||
| try { | ||
| configResult = this.configExplorer.search(); | ||
| } | ||
| catch (error) { | ||
| this.logger.error(error); | ||
| } | ||
| } | ||
| if (!configResult || configResult.isEmpty) { | ||
| this.logger.info('Not using any configuration file.'); | ||
| return; | ||
| } | ||
| const configFileData = configResult.config; | ||
| this.logger.info(`Using configuration file ${configResult.filepath}`); | ||
| this.options = Object.assign(Object.assign(Object.assign({}, defaultOptions), configFileData), this.terminalOptions); | ||
| this.logger.state.isEnabled = this.options.verbose; | ||
| } | ||
| } | ||
| exports.JSZipCLI = JSZipCLI; | ||
| //# sourceMappingURL=JSZipCLI.js.map |
| {"version":3,"file":"JSZipCLI.js","sourceRoot":"","sources":["../src/JSZipCLI.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA4C;AAE5C,mCAAmC;AAEnC,iDAA4C;AAC5C,qDAAgD;AAGhD,MAAM,cAAc,GAA8B;IAChD,gBAAgB,EAAE,CAAC;IACnB,UAAU,EAAE,IAAI;IAChB,gBAAgB,EAAE,KAAK;IACvB,KAAK,EAAE,KAAK;IACZ,aAAa,EAAE,EAAE;IACjB,WAAW,EAAE,IAAI;IACjB,KAAK,EAAE,KAAK;IACZ,OAAO,EAAE,KAAK;CACf,CAAC;AAEF,MAAa,QAAQ;IASnB,YAAY,OAAyB;QACnC,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,iBAAiB,EAAE;YACvC,MAAM,EAAE,OAAO;YACf,QAAQ,EAAE,KAAK;SAChB,CAAC,CAAC;QACH,IAAI,CAAC,cAAc,GAAG,IAAA,6BAAe,EAAC,OAAO,CAAC,CAAC;QAE/C,IAAI,CAAC,OAAO,mCAAO,cAAc,GAAK,IAAI,CAAC,eAAe,CAAC,CAAC;QAC5D,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,GAAG,IAAI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,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;aAClE;YAAC,OAAO,KAAK,EAAE;gBACd,MAAM,IAAI,KAAK,CAAC,kCAAmC,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;aAC/E;SACF;aAAM,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,KAAK,IAAI,EAAE;YAC3C,IAAI;gBACF,YAAY,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC;aAC7C;YAAC,OAAO,KAAK,EAAE;gBACd,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;aAC1B;SACF;QAED,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,OAAO,EAAE;YACzC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;YACtD,OAAO;SACR;QAED,MAAM,cAAc,GAAG,YAAY,CAAC,MAA2B,CAAC;QAEhE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,4BAA4B,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEtE,IAAI,CAAC,OAAO,iDAAO,cAAc,GAAK,cAAc,GAAK,IAAI,CAAC,eAAe,CAAC,CAAC;QAC/E,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;IACrD,CAAC;CACF;AA/HD,4BA+HC"} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
97459
-0.61%1
Infinity%+ Added
- Removed
- Removed
Updated