@ffflorian/jszip-cli 3.5.4 → 3.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/{cjs/BuildService.d.ts → BuildService.d.ts} +1 -1
  2. package/dist/{cjs/BuildService.js → BuildService.js} +50 -20
  3. package/dist/{esm/ExtractService.d.ts → ExtractService.d.ts} +1 -1
  4. package/dist/{cjs/ExtractService.js → ExtractService.js} +27 -20
  5. package/dist/{cjs/FileService.d.ts → FileService.d.ts} +2 -2
  6. package/dist/{cjs/FileService.js → FileService.js} +20 -13
  7. package/dist/{cjs/JSZipCLI.d.ts → JSZipCLI.d.ts} +3 -3
  8. package/dist/{cjs/JSZipCLI.js → JSZipCLI.js} +16 -9
  9. package/dist/{cjs/cli.js → cli.js} +25 -23
  10. package/dist/index.d.ts +2 -0
  11. package/dist/index.js +18 -0
  12. package/dist/interfaces.js +2 -0
  13. package/package.json +5 -10
  14. package/dist/cjs/ExtractService.d.ts +0 -11
  15. package/dist/cjs/index.d.ts +0 -2
  16. package/dist/cjs/index.js +0 -2
  17. package/dist/cjs/interfaces.js +0 -1
  18. package/dist/cjs/package.json +0 -3
  19. package/dist/esm/BuildService.d.ts +0 -27
  20. package/dist/esm/BuildService.js +0 -201
  21. package/dist/esm/ExtractService.js +0 -84
  22. package/dist/esm/FileService.d.ts +0 -11
  23. package/dist/esm/FileService.js +0 -70
  24. package/dist/esm/JSZipCLI.d.ts +0 -32
  25. package/dist/esm/JSZipCLI.js +0 -121
  26. package/dist/esm/cli.d.ts +0 -2
  27. package/dist/esm/cli.js +0 -112
  28. package/dist/esm/index.d.ts +0 -2
  29. package/dist/esm/index.js +0 -2
  30. package/dist/esm/interfaces.d.ts +0 -28
  31. package/dist/esm/interfaces.js +0 -1
  32. package/dist/esm/package.json +0 -3
  33. /package/dist/{cjs/cli.d.ts → cli.d.ts} +0 -0
  34. /package/dist/{cjs/interfaces.d.ts → interfaces.d.ts} +0 -0
@@ -1,201 +0,0 @@
1
- import * as fs from 'fs-extra';
2
- import JSZip from 'jszip';
3
- import logdown from 'logdown';
4
- import path from 'path';
5
- import progress from 'progress';
6
- import { FileService } from './FileService.js';
7
- import { globSync } from 'glob';
8
- export class BuildService {
9
- constructor(options) {
10
- this.fileService = new FileService(options);
11
- this.jszip = new JSZip();
12
- this.options = options;
13
- this.logger = logdown('jszip-cli/BuildService', {
14
- logger: console,
15
- markdown: false,
16
- });
17
- this.logger.state = { isEnabled: options.verbose };
18
- this.entries = [];
19
- this.ignoreEntries = this.options.ignoreEntries.map(entry => entry instanceof RegExp ? entry : new RegExp(entry.replace(/\*/g, '.*')));
20
- this.outputFile = this.options.outputEntry ? path.resolve(this.options.outputEntry) : null;
21
- this.progressBar = new progress('Compressing [:bar] :percent :elapseds', {
22
- complete: '=',
23
- incomplete: ' ',
24
- total: 100,
25
- width: 20,
26
- });
27
- this.compressedFilesCount = 0;
28
- }
29
- add(rawEntries) {
30
- this.logger.info(`Adding ${rawEntries.length} entr${rawEntries.length === 1 ? 'y' : 'ies'} to ZIP file.`);
31
- const normalizedEntries = this.normalizePaths(rawEntries);
32
- this.entries = globSync(normalizedEntries).map(rawEntry => {
33
- const resolvedPath = path.resolve(rawEntry);
34
- const baseName = path.basename(rawEntry);
35
- return {
36
- resolvedPath,
37
- zipPath: baseName,
38
- };
39
- });
40
- return this;
41
- }
42
- async save() {
43
- await this.checkOutput();
44
- await Promise.all(this.entries.map(entry => this.checkEntry(entry)));
45
- const data = await this.getBuffer();
46
- if (this.outputFile) {
47
- if (!this.outputFile.match(/\.\w+$/)) {
48
- this.outputFile = path.join(this.outputFile, 'data.zip');
49
- }
50
- this.logger.info(`Saving finished zip file to "${this.outputFile}" ...`);
51
- await this.fileService.writeFile(data, this.outputFile);
52
- }
53
- else {
54
- process.stdout.write(data);
55
- }
56
- return this;
57
- }
58
- /**
59
- * Note: glob patterns should always use / as a path separator, even on Windows systems,
60
- * as \ is used to escape glob characters.
61
- * https://github.com/isaacs/node-glob
62
- */
63
- normalizePaths(rawEntries) {
64
- return rawEntries.map(entry => entry.replace(/\\/g, '/'));
65
- }
66
- async addFile(entry, isLink = false) {
67
- const { resolvedPath, zipPath } = entry;
68
- let fileStat;
69
- let fileData;
70
- try {
71
- fileData = isLink ? await fs.readlink(resolvedPath) : await fs.readFile(resolvedPath);
72
- fileStat = await fs.lstat(resolvedPath);
73
- }
74
- catch (error) {
75
- if (!this.options.quiet) {
76
- this.logger.info(`Can't read file "${entry.resolvedPath}". Ignoring.`);
77
- }
78
- this.logger.info(error);
79
- return;
80
- }
81
- this.logger.info(`Adding file "${resolvedPath}" to ZIP file ...`);
82
- this.jszip.file(zipPath, fileData, {
83
- createFolders: true,
84
- date: fileStat.mtime,
85
- // See https://github.com/Stuk/jszip/issues/550
86
- // dosPermissions: fileStat.mode,
87
- unixPermissions: fileStat.mode,
88
- });
89
- this.compressedFilesCount++;
90
- }
91
- async addLink(entry) {
92
- const { resolvedPath, zipPath } = entry;
93
- if (this.options.dereferenceLinks) {
94
- let realPath;
95
- try {
96
- realPath = await fs.realpath(resolvedPath);
97
- }
98
- catch (error) {
99
- if (!this.options.quiet) {
100
- this.logger.info(`Can't read link "${entry.resolvedPath}". Ignoring.`);
101
- }
102
- this.logger.info(error);
103
- return;
104
- }
105
- this.logger.info(`Found real path "${realPath} for symbolic link".`);
106
- await this.checkEntry({
107
- resolvedPath: realPath,
108
- zipPath,
109
- });
110
- }
111
- else {
112
- await this.addFile(entry, true);
113
- }
114
- }
115
- async checkEntry(entry) {
116
- let fileStat;
117
- try {
118
- fileStat = await fs.lstat(entry.resolvedPath);
119
- }
120
- catch (error) {
121
- if (!this.options.quiet) {
122
- this.logger.info(`Can't read file "${entry.resolvedPath}". Ignoring.`);
123
- }
124
- this.logger.info(error);
125
- return;
126
- }
127
- const ignoreEntries = this.ignoreEntries.filter(ignoreEntry => Boolean(entry.resolvedPath.match(ignoreEntry)));
128
- if (ignoreEntries.length) {
129
- this.logger.info(`Found ${entry.resolvedPath}. Not adding since it's on the ignore list:`, ignoreEntries.map(entry => String(entry)));
130
- return;
131
- }
132
- if (fileStat.isDirectory()) {
133
- this.logger.info(`Found directory "${entry.resolvedPath}".`);
134
- await this.walkDir(entry);
135
- }
136
- else if (fileStat.isFile()) {
137
- this.logger.info(`Found file "${entry.resolvedPath}".`);
138
- this.logger.info(`Found file "${entry.resolvedPath}".`);
139
- await this.addFile(entry);
140
- }
141
- else if (fileStat.isSymbolicLink()) {
142
- this.logger.info(`Found symbolic link "${entry.resolvedPath}".`);
143
- await this.addLink(entry);
144
- }
145
- else {
146
- this.logger.info('Unknown file type.', { fileStat });
147
- if (!this.options.quiet) {
148
- this.logger.info(`Can't read file "${entry.resolvedPath}". Ignoring.`);
149
- }
150
- }
151
- }
152
- async checkOutput() {
153
- if (this.outputFile) {
154
- if (this.outputFile.match(/\.\w+$/)) {
155
- const dirExists = await this.fileService.dirExists(path.dirname(this.outputFile));
156
- if (!dirExists) {
157
- throw new Error(`Directory "${path.dirname(this.outputFile)}" doesn't exist or is not writable.`);
158
- }
159
- const fileIsWritable = await this.fileService.fileIsWritable(this.outputFile);
160
- if (!fileIsWritable) {
161
- throw new Error(`File "${this.outputFile}" already exists.`);
162
- }
163
- }
164
- else {
165
- const dirExists = await this.fileService.dirExists(this.outputFile);
166
- if (!dirExists) {
167
- throw new Error(`Directory "${this.outputFile}" doesn't exist or is not writable.`);
168
- }
169
- }
170
- }
171
- }
172
- getBuffer() {
173
- const compressionType = this.options.compressionLevel === 0 ? 'STORE' : 'DEFLATE';
174
- let lastPercent = 0;
175
- return this.jszip.generateAsync({
176
- compression: compressionType,
177
- compressionOptions: {
178
- level: this.options.compressionLevel,
179
- },
180
- type: 'nodebuffer',
181
- }, ({ percent }) => {
182
- const diff = Math.floor(percent) - Math.floor(lastPercent);
183
- if (diff && !this.options.quiet) {
184
- this.progressBar.tick(diff);
185
- lastPercent = Math.floor(percent);
186
- }
187
- });
188
- }
189
- async walkDir(entry) {
190
- this.logger.info(`Walking directory ${entry.resolvedPath} ...`);
191
- const dirEntries = await fs.readdir(entry.resolvedPath);
192
- for (const dirEntry of dirEntries) {
193
- const newZipPath = entry.zipPath === '.' ? dirEntry : `${entry.zipPath}/${dirEntry}`;
194
- const newResolvedPath = path.join(entry.resolvedPath, dirEntry);
195
- await this.checkEntry({
196
- resolvedPath: newResolvedPath,
197
- zipPath: newZipPath,
198
- });
199
- }
200
- }
201
- }
@@ -1,84 +0,0 @@
1
- import fs from 'fs-extra';
2
- import JSZip from 'jszip';
3
- import logdown from 'logdown';
4
- import os from 'os';
5
- import path from 'path';
6
- import progress from 'progress';
7
- export class ExtractService {
8
- constructor(options) {
9
- this.options = options;
10
- this.logger = logdown('jszip-cli/ExtractService', {
11
- logger: console,
12
- markdown: false,
13
- });
14
- this.logger.state.isEnabled = this.options.verbose;
15
- this.outputDir = this.options.outputEntry ? path.resolve(this.options.outputEntry) : null;
16
- this.progressBar = new progress('Extracting [:bar] :percent :elapseds', {
17
- complete: '=',
18
- incomplete: ' ',
19
- total: 100,
20
- width: 20,
21
- });
22
- this.extractedFilesCount = 0;
23
- }
24
- async extract(rawEntries) {
25
- const isWin32 = os.platform() === 'win32';
26
- for (const entry of rawEntries) {
27
- const jszip = new JSZip();
28
- if (this.outputDir) {
29
- await fs.ensureDir(this.outputDir);
30
- }
31
- const resolvedPath = path.resolve(entry);
32
- const data = await fs.readFile(resolvedPath);
33
- const entries = [];
34
- await jszip.loadAsync(data, { createFolders: true });
35
- if (!this.outputDir) {
36
- await this.printStream(jszip.generateNodeStream());
37
- return this;
38
- }
39
- jszip.forEach((filePath, entry) => {
40
- if (filePath.includes('..')) {
41
- this.logger.info(`Skipping bad path "${filePath}"`);
42
- }
43
- else {
44
- entries.push([filePath, entry]);
45
- }
46
- });
47
- let lastPercent = 0;
48
- await Promise.all(entries.map(async ([filePath, entry], index) => {
49
- const resolvedFilePath = path.join(this.outputDir, filePath);
50
- if (entry.dir) {
51
- await fs.ensureDir(resolvedFilePath);
52
- }
53
- else {
54
- const data = await entry.async('nodebuffer');
55
- await fs.writeFile(resolvedFilePath, data, {
56
- encoding: 'utf-8',
57
- });
58
- this.extractedFilesCount++;
59
- const diff = Math.floor(index / entries.length) - Math.floor(lastPercent);
60
- if (diff && !this.options.quiet) {
61
- this.progressBar.tick(diff);
62
- lastPercent = Math.floor(index / entries.length);
63
- }
64
- }
65
- if (isWin32) {
66
- if (entry.dosPermissions) {
67
- await fs.chmod(resolvedFilePath, entry.dosPermissions);
68
- }
69
- }
70
- else if (entry.unixPermissions) {
71
- await fs.chmod(resolvedFilePath, entry.unixPermissions);
72
- }
73
- }));
74
- }
75
- return this;
76
- }
77
- printStream(fileStream) {
78
- return new Promise((resolve, reject) => {
79
- const stream = fileStream.pipe(process.stdout);
80
- stream.on('finish', resolve);
81
- stream.on('error', reject);
82
- });
83
- }
84
- }
@@ -1,11 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- import type { TerminalOptions } from './interfaces.js';
3
- export declare class FileService {
4
- private readonly logger;
5
- private readonly options;
6
- constructor(options: Required<TerminalOptions>);
7
- dirExists(dirPath: string): Promise<boolean>;
8
- fileIsReadable(filePath: string): Promise<boolean>;
9
- fileIsWritable(filePath: string): Promise<boolean>;
10
- writeFile(data: Buffer, filePath: string): Promise<FileService>;
11
- }
@@ -1,70 +0,0 @@
1
- import fs from 'fs-extra';
2
- import logdown from 'logdown';
3
- import path from 'path';
4
- export class FileService {
5
- constructor(options) {
6
- this.options = options;
7
- this.logger = logdown('jszip-cli/FileService', {
8
- logger: console,
9
- markdown: false,
10
- });
11
- this.logger.state.isEnabled = this.options.verbose;
12
- }
13
- async dirExists(dirPath) {
14
- try {
15
- await fs.access(dirPath, fs.constants.F_OK);
16
- try {
17
- await fs.access(dirPath, fs.constants.W_OK);
18
- return true;
19
- }
20
- catch (error) {
21
- this.logger.info(`Directory "${dirPath}" exists but is not writable.`);
22
- return false;
23
- }
24
- }
25
- catch (error) {
26
- this.logger.info(`Directory "${dirPath}" doesn't exist.`, this.options.force ? 'Creating.' : 'Not creating.');
27
- if (this.options.force) {
28
- await fs.ensureDir(dirPath);
29
- return true;
30
- }
31
- return false;
32
- }
33
- }
34
- async fileIsReadable(filePath) {
35
- const dirExists = await this.dirExists(path.dirname(filePath));
36
- if (dirExists) {
37
- try {
38
- await fs.access(filePath, fs.constants.F_OK | fs.constants.R_OK);
39
- return true;
40
- }
41
- catch (error) {
42
- return false;
43
- }
44
- }
45
- return false;
46
- }
47
- async fileIsWritable(filePath) {
48
- const dirName = path.dirname(filePath);
49
- const dirExists = await this.dirExists(dirName);
50
- if (dirExists) {
51
- try {
52
- await fs.access(filePath, fs.constants.F_OK | fs.constants.R_OK);
53
- this.logger.info(`File "${filePath}" already exists.`, this.options.force ? 'Forcing overwrite.' : 'Not overwriting.');
54
- return this.options.force;
55
- }
56
- catch (error) {
57
- return true;
58
- }
59
- }
60
- return false;
61
- }
62
- async writeFile(data, filePath) {
63
- const fileIsWritable = await this.fileIsWritable(filePath);
64
- if (fileIsWritable) {
65
- await fs.writeFile(filePath, data);
66
- return this;
67
- }
68
- throw new Error(`File "${this.options.outputEntry}" already exists.`);
69
- }
70
- }
@@ -1,32 +0,0 @@
1
- import { BuildService } from './BuildService.js';
2
- import { ExtractService } from './ExtractService.js';
3
- import type { TerminalOptions } from './interfaces.js';
4
- export declare class JSZipCLI {
5
- private readonly buildService;
6
- private readonly configExplorer;
7
- private readonly configFile?;
8
- private readonly extractService;
9
- private readonly logger;
10
- private options;
11
- private readonly terminalOptions?;
12
- constructor(options?: TerminalOptions);
13
- /**
14
- * Add files and directories to the ZIP file.
15
- * @param rawEntries The entries (files, directories) to add.
16
- * If not specified, entries from configuration file are used.
17
- */
18
- add(rawEntries?: string[]): BuildService;
19
- /**
20
- * Add files and directories to the ZIP file.
21
- * @param rawEntries The entries (files, directories) to extract.
22
- * If not specified, entries from configuration file are used.
23
- */
24
- extract(rawEntries?: string[]): Promise<ExtractService>;
25
- /**
26
- * Run in file mode - reads entries and settings from configuration file.
27
- * Options from the constructor still take precedence.
28
- */
29
- fileMode(): Promise<JSZipCLI>;
30
- save(): Promise<BuildService>;
31
- private checkConfigFile;
32
- }
@@ -1,121 +0,0 @@
1
- import { cosmiconfigSync } from 'cosmiconfig';
2
- import logdown from 'logdown';
3
- import { BuildService } from './BuildService.js';
4
- import { ExtractService } from './ExtractService.js';
5
- const defaultOptions = {
6
- compressionLevel: 5,
7
- configFile: true,
8
- dereferenceLinks: false,
9
- force: false,
10
- ignoreEntries: [],
11
- outputEntry: null,
12
- quiet: false,
13
- verbose: false,
14
- };
15
- export class JSZipCLI {
16
- constructor(options) {
17
- this.terminalOptions = options;
18
- this.logger = logdown('jszip-cli/index', {
19
- logger: console,
20
- markdown: false,
21
- });
22
- this.configExplorer = cosmiconfigSync('jszip');
23
- this.options = Object.assign(Object.assign({}, defaultOptions), this.terminalOptions);
24
- this.logger.state.isEnabled = this.options.verbose;
25
- this.logger.info('Merged options', this.options);
26
- this.checkConfigFile();
27
- this.logger.info('Loaded options', this.options);
28
- this.buildService = new BuildService(this.options);
29
- this.extractService = new ExtractService(this.options);
30
- }
31
- /**
32
- * Add files and directories to the ZIP file.
33
- * @param rawEntries The entries (files, directories) to add.
34
- * If not specified, entries from configuration file are used.
35
- */
36
- add(rawEntries) {
37
- if (!rawEntries || !rawEntries.length) {
38
- if (this.options.entries) {
39
- rawEntries = this.options.entries;
40
- }
41
- else {
42
- throw new Error('No entries to add.');
43
- }
44
- }
45
- return this.buildService.add(rawEntries);
46
- }
47
- /**
48
- * Add files and directories to the ZIP file.
49
- * @param rawEntries The entries (files, directories) to extract.
50
- * If not specified, entries from configuration file are used.
51
- */
52
- extract(rawEntries) {
53
- if (!rawEntries || !rawEntries.length) {
54
- if (this.options.entries) {
55
- rawEntries = this.options.entries;
56
- }
57
- else {
58
- throw new Error('No entries to extract.');
59
- }
60
- }
61
- return this.extractService.extract(rawEntries);
62
- }
63
- /**
64
- * Run in file mode - reads entries and settings from configuration file.
65
- * Options from the constructor still take precedence.
66
- */
67
- async fileMode() {
68
- if (!this.options.mode && !this.configFile) {
69
- throw new Error('No configuration file and no mode specified.');
70
- }
71
- if (this.options.mode === 'add') {
72
- const { outputFile, compressedFilesCount } = await this.add().save();
73
- if (this.options.outputEntry && !this.options.quiet) {
74
- console.info(`Done compressing ${compressedFilesCount} files to "${outputFile}".`);
75
- }
76
- return this;
77
- }
78
- else if (this.options.mode === 'extract') {
79
- const { outputDir, extractedFilesCount } = await this.extract();
80
- if (this.options.outputEntry && !this.options.quiet) {
81
- console.info(`Done extracting ${extractedFilesCount} files to "${outputDir}".`);
82
- }
83
- return this;
84
- }
85
- throw new Error('No or invalid mode in configuration file defined.');
86
- }
87
- save() {
88
- return this.buildService.save();
89
- }
90
- checkConfigFile() {
91
- if (!this.options.configFile) {
92
- this.logger.info('Not using any configuration file.');
93
- return;
94
- }
95
- let configResult = null;
96
- if (typeof this.options.configFile === 'string') {
97
- try {
98
- configResult = this.configExplorer.load(this.options.configFile);
99
- }
100
- catch (error) {
101
- throw new Error(`Can't read configuration file: ${error.message}`);
102
- }
103
- }
104
- else if (this.options.configFile === true) {
105
- try {
106
- configResult = this.configExplorer.search();
107
- }
108
- catch (error) {
109
- this.logger.error(error);
110
- }
111
- }
112
- if (!configResult || configResult.isEmpty) {
113
- this.logger.info('Not using any configuration file.');
114
- return;
115
- }
116
- const configFileData = configResult.config;
117
- this.logger.info(`Using configuration file ${configResult.filepath}`);
118
- this.options = Object.assign(Object.assign(Object.assign({}, defaultOptions), configFileData), this.terminalOptions);
119
- this.logger.state.isEnabled = this.options.verbose;
120
- }
121
- }
package/dist/esm/cli.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
package/dist/esm/cli.js DELETED
@@ -1,112 +0,0 @@
1
- #!/usr/bin/env node
2
- import { program as commander } from 'commander';
3
- import fs from 'fs-extra';
4
- import path from 'path';
5
- import { fileURLToPath } from 'url';
6
- import { JSZipCLI } from './JSZipCLI.js';
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = path.dirname(__filename);
9
- const defaultPackageJsonPath = path.join(__dirname, '../../package.json');
10
- const packageJsonPath = fs.existsSync(defaultPackageJsonPath)
11
- ? defaultPackageJsonPath
12
- : path.join(__dirname, '../package.json');
13
- const { description, name, version } = fs.readJSONSync(packageJsonPath);
14
- commander
15
- .name(name.replace(/^@[^/]+\//, ''))
16
- .description(description)
17
- .option('--noconfig', "don't look for a configuration file")
18
- .option('-c, --config <path>', 'use a configuration file (default: .jsziprc.json)')
19
- .option('-d, --dereference', 'dereference (follow) links', false)
20
- .option('-f, --force', 'force overwriting files and directories when extracting', false)
21
- .option('-i, --ignore <entry>', 'ignore a file or directory')
22
- .option('-l, --level <number>', 'set the compression level', '5')
23
- .option('-o, --output <dir>', 'set the output file or directory (default: stdout)')
24
- .option('-q, --quiet', "don't log anything", false)
25
- .option('-V, --verbose', 'enable verbose logging', false)
26
- .version(version, '-v, --version')
27
- .on('command:*', args => {
28
- console.error(`\n error: invalid command \`${args[0]}'\n`);
29
- process.exit(1);
30
- });
31
- commander
32
- .command('add')
33
- .alias('a')
34
- .description('add files and directories to a new ZIP archive')
35
- .option('--noconfig', "don't look for a configuration file")
36
- .option('-c, --config <path>', 'use a configuration file')
37
- .option('-d, --dereference', 'dereference (follow) symlinks', false)
38
- .option('-f, --force', 'force overwriting files and directories when extracting', false)
39
- .option('-i, --ignore <entry>', 'ignore a file or directory')
40
- .option('-l, --level <number>', 'set the compression level', '5')
41
- .option('-o, --output <dir>', 'set the output file or directory (default: stdout)')
42
- .option('-q, --quiet', "don't log anything excluding errors", false)
43
- .option('-V, --verbose', 'enable verbose logging', false)
44
- .arguments('[entries...]')
45
- .action(async (entries) => {
46
- const options = commander.opts();
47
- try {
48
- const jszip = new 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 })));
49
- jszip.add(entries);
50
- const { outputFile, compressedFilesCount } = await jszip.save();
51
- if (options.output && !options.quiet) {
52
- console.info(`Done compressing ${compressedFilesCount} files to "${outputFile}".`);
53
- }
54
- }
55
- catch (error) {
56
- console.error('Error:', error.message);
57
- process.exit(1);
58
- }
59
- });
60
- commander
61
- .command('extract')
62
- .alias('e')
63
- .description('extract files and directories from ZIP archive(s)')
64
- .option('--noconfig', "don't look for a configuration file", false)
65
- .option('-c, --config <path>', 'use a configuration file (default: .jsziprc.json)')
66
- .option('-o, --output <dir>', 'set the output file or directory (default: stdout)')
67
- .option('-i, --ignore <entry>', 'ignore a file or directory')
68
- .option('-f, --force', 'force overwriting files and directories', false)
69
- .option('-V, --verbose', 'enable verbose logging', false)
70
- .option('-q, --quiet', "don't log anything excluding errors", false)
71
- .arguments('<archives...>')
72
- .action(async (archives) => {
73
- const options = commander.opts();
74
- try {
75
- const { outputDir, extractedFilesCount } = await new 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);
76
- if (options.output && !options.quiet) {
77
- console.info(`Done extracting ${extractedFilesCount} files to "${outputDir}".`);
78
- }
79
- }
80
- catch (error) {
81
- console.error('Error:', error.message);
82
- process.exit(1);
83
- }
84
- });
85
- commander
86
- .command('fileMode', { hidden: true, isDefault: true })
87
- .option('--noconfig', "don't look for a configuration file", false)
88
- .option('-c, --config <path>', 'use a configuration file (default: .jsziprc.json)')
89
- .option('-o, --output <dir>', 'set the output file or directory (default: stdout)')
90
- .option('-i, --ignore <entry>', 'ignore a file or directory')
91
- .option('-f, --force', 'force overwriting files and directories', false)
92
- .option('-V, --verbose', 'enable verbose logging', false)
93
- .option('-q, --quiet', "don't log anything excluding errors", false)
94
- .action(async () => {
95
- const options = commander.opts();
96
- try {
97
- if (options.noconfig) {
98
- commander.outputHelp();
99
- }
100
- await new 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();
101
- }
102
- catch (error) {
103
- if (error.message.includes('ENOENT')) {
104
- console.error('Error:', `Configuration file "${options.config}" not found and no mode specified.`);
105
- }
106
- else {
107
- console.error('Error:', error.message);
108
- }
109
- process.exit(1);
110
- }
111
- });
112
- commander.parse(process.argv);
@@ -1,2 +0,0 @@
1
- export * from './JSZipCLI.js';
2
- export * from './interfaces.js';
package/dist/esm/index.js DELETED
@@ -1,2 +0,0 @@
1
- export * from './JSZipCLI.js';
2
- export * from './interfaces.js';
@@ -1,28 +0,0 @@
1
- export interface TerminalOptions {
2
- /** The compression level to use (0 = save only, 9 = best compression) (default: 5). */
3
- compressionLevel?: number;
4
- /** Use a configuration file (default: .jsziprc.json). */
5
- configFile?: string | boolean;
6
- /** Whether to dereference (follow) symlinks (default: false). */
7
- dereferenceLinks?: boolean;
8
- /** Force overwriting files and directories when extracting (default: false). */
9
- force?: boolean;
10
- /** Ignore entries (e.g. `*.js.map`). */
11
- ignoreEntries?: Array<string | RegExp>;
12
- /** Set the output directory (default: stdout). */
13
- outputEntry?: string | null;
14
- /** Don't log anything excluding errors (default: false). */
15
- quiet?: boolean;
16
- /** Enable verbose logging (default: false). */
17
- verbose?: boolean;
18
- }
19
- export interface ConfigFileOptions extends TerminalOptions {
20
- /** Which files or directories to add. */
21
- entries: string[];
22
- /** Add or extract files. */
23
- mode: 'add' | 'extract';
24
- }
25
- export interface Entry {
26
- resolvedPath: string;
27
- zipPath: string;
28
- }
@@ -1 +0,0 @@
1
- export {};