Skip to content

Commit

Permalink
fix: support globs with gzip command. (#4625)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Jul 11, 2023
1 parent ae9df45 commit 17fbc11
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 38 deletions.
4 changes: 2 additions & 2 deletions packages/cspell-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@
"homepage": "https://github.com/streetsidesoftware/cspell#readme",
"dependencies": {
"@cspell/cspell-pipe": "workspace:*",
"commander": "^10.0.1",
"commander": "^11.0.0",
"cosmiconfig": "8.0.0",
"cspell-trie-lib": "workspace:*",
"gensequence": "^5.0.2",
"glob": "^8.1.0",
"glob": "^10.3.3",
"hunspell-reader": "workspace:*"
},
"engines": {
Expand Down
3 changes: 2 additions & 1 deletion packages/cspell-tools/src/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,11 @@ describe('Validate the application', () => {

test('app gzip', async () => {
const commander = getCommander();
const args = argv('gzip', 'README.md', 'package.json');
const args = argv('gzip', '*.md', 'package.json');

await expect(app.run(commander, args)).resolves.toBeUndefined();
expect(mockedCompressFile).toHaveBeenCalledWith('README.md');
expect(mockedCompressFile).toHaveBeenCalledWith('CHANGELOG.md');
expect(mockedCompressFile).toHaveBeenCalledWith('package.json');
});
});
18 changes: 8 additions & 10 deletions packages/cspell-tools/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { processCompileAction } from './compile.js';
import * as compiler from './compiler/index.js';
import { logWithTimestamp } from './compiler/logWithTimestamp.js';
import type { FeatureFlags } from './FeatureFlags/index.js';
import { compressFile } from './gzip/index.js';
import { gzip } from './gzip/index.js';
import { reportCheckChecksumFile, reportChecksumForFiles } from './shasum/shasum.js';
import { toError } from './util/errors.js';

Expand Down Expand Up @@ -53,14 +53,12 @@ interface ShasumOptions {
}

export async function run(program: program.Command, argv: string[], flags?: FeatureFlags): Promise<void> {
async function gzip(files: string[]): Promise<void> {
for (const fileName of files) {
try {
await compressFile(fileName);
} catch (error) {
const err = toError(error);
program.error(err.message);
}
async function handleGzip(files: string[]): Promise<void> {
try {
await gzip(files);
} catch (error) {
const err = toError(error);
program.error(err.message);
}
}

Expand Down Expand Up @@ -103,7 +101,7 @@ export async function run(program: program.Command, argv: string[], flags?: Feat
.option('-r, --root <directory>', 'Specify the run directory')
.action(build);

program.command('gzip <files...>').description('GZip files while keeping the original.').action(gzip);
program.command('gzip <files...>').description('GZip files while keeping the original.').action(handleGzip);

program
.command('shasum [files...]')
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-tools/src/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { opConcatMap, pipe } from '@cspell/cspell-pipe/sync';
import type { CompileCommonAppOptions } from './AppOptions.js';
import { compile } from './compiler/compile.js';
import { createCompileRequest } from './compiler/createCompileRequest.js';
import { globP } from './compiler/globP.js';
import type { FeatureFlags } from './FeatureFlags/index.js';
import { getSystemFeatureFlags, parseFlags } from './FeatureFlags/index.js';
import { globP } from './util/globP.js';

getSystemFeatureFlags().register('compound', 'Enable compound dictionary sources.');

Expand Down
10 changes: 0 additions & 10 deletions packages/cspell-tools/src/compiler/globP.ts

This file was deleted.

11 changes: 11 additions & 0 deletions packages/cspell-tools/src/gzip/gzip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { globP } from '../util/globP.js';
import { compressFile } from './compressFiles.js';

// cspell:ignore nodir

export async function gzip(globs: string[]): Promise<void> {
const files = await globP(globs, { nodir: true });
for (const fileName of files) {
await compressFile(fileName);
}
}
1 change: 1 addition & 0 deletions packages/cspell-tools/src/gzip/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { compressFile } from './compressFiles.js';
export { gzip } from './gzip.js';
12 changes: 12 additions & 0 deletions packages/cspell-tools/src/util/globP.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { glob } from 'glob';

interface Options {
cwd?: string | URL;
nodir?: boolean; // cspell:ignore nodir
}

export function globP(pattern: string | string[], options?: Options): Promise<string[]> {
// Convert windows separators.
const globs = (Array.isArray(pattern) ? pattern : [pattern]).map((pattern) => pattern.replace(/\\/g, '/'));
return glob(globs, options);
}
26 changes: 12 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 17fbc11

Please sign in to comment.