@cspell/cspell-tools 6.12.0 → 6.13.1

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 (62) hide show
  1. package/cspell-tools.config.schema.json +203 -0
  2. package/dist/AppOptions.d.ts +28 -0
  3. package/dist/AppOptions.js +3 -0
  4. package/dist/FeatureFlags/FeatureFlags.d.ts +34 -0
  5. package/dist/FeatureFlags/FeatureFlags.js +99 -0
  6. package/dist/FeatureFlags/index.d.ts +3 -0
  7. package/dist/FeatureFlags/index.js +10 -0
  8. package/dist/FeatureFlags/parseFlags.d.ts +3 -0
  9. package/dist/FeatureFlags/parseFlags.js +24 -0
  10. package/dist/app.d.ts +2 -21
  11. package/dist/app.js +25 -144
  12. package/dist/build.d.ts +7 -0
  13. package/dist/build.js +59 -0
  14. package/dist/compile.d.ts +4 -0
  15. package/dist/compile.js +24 -0
  16. package/dist/compiler/CompileOptions.d.ts +12 -0
  17. package/dist/compiler/CompileOptions.js +3 -0
  18. package/dist/compiler/Reader.d.ts +16 -11
  19. package/dist/compiler/Reader.js +38 -91
  20. package/dist/compiler/compile.d.ts +11 -0
  21. package/dist/compiler/compile.js +157 -0
  22. package/dist/compiler/createCompileRequest.d.ts +4 -0
  23. package/dist/compiler/createCompileRequest.js +86 -0
  24. package/dist/compiler/fileWriter.d.ts +2 -3
  25. package/dist/compiler/fileWriter.js +5 -7
  26. package/dist/compiler/globP.d.ts +2 -0
  27. package/dist/compiler/globP.js +16 -0
  28. package/dist/compiler/index.d.ts +4 -1
  29. package/dist/compiler/index.js +9 -15
  30. package/dist/compiler/iterateWordsFromFile.d.ts +1 -2
  31. package/dist/compiler/iterateWordsFromFile.js +1 -1
  32. package/dist/compiler/legacyLineToWords.d.ts +3 -0
  33. package/dist/compiler/legacyLineToWords.js +54 -0
  34. package/dist/compiler/logWithTimestamp.d.ts +3 -0
  35. package/dist/compiler/logWithTimestamp.js +9 -0
  36. package/dist/compiler/logger.d.ts +4 -0
  37. package/dist/compiler/logger.js +14 -0
  38. package/dist/compiler/readTextFile.d.ts +3 -0
  39. package/dist/compiler/readTextFile.js +45 -0
  40. package/dist/compiler/wordListCompiler.d.ts +3 -33
  41. package/dist/compiler/wordListCompiler.js +13 -169
  42. package/dist/compiler/wordListParser.d.ts +46 -0
  43. package/dist/compiler/wordListParser.js +174 -0
  44. package/dist/compiler/writeTextToFile.d.ts +3 -0
  45. package/dist/compiler/writeTextToFile.js +44 -0
  46. package/dist/config/config.d.ts +109 -0
  47. package/dist/config/config.js +3 -0
  48. package/dist/config/configUtils.d.ts +5 -0
  49. package/dist/config/configUtils.js +20 -0
  50. package/dist/config/index.d.ts +4 -0
  51. package/dist/config/index.js +10 -0
  52. package/dist/config/normalizeConfig.d.ts +8 -0
  53. package/dist/config/normalizeConfig.js +40 -0
  54. package/dist/test/TestHelper.d.ts +42 -0
  55. package/dist/test/TestHelper.js +131 -0
  56. package/dist/test/console.d.ts +10 -0
  57. package/dist/test/console.js +23 -0
  58. package/dist/test/escapeRegEx.d.ts +7 -0
  59. package/dist/test/escapeRegEx.js +13 -0
  60. package/dist/test/normalizeOutput.d.ts +3 -0
  61. package/dist/test/normalizeOutput.js +46 -0
  62. package/package.json +16 -11
@@ -0,0 +1,203 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "additionalProperties": false,
4
+ "definitions": {
5
+ "DictionaryFormats": {
6
+ "enum": [
7
+ "plaintext",
8
+ "trie",
9
+ "trie3",
10
+ "trie4"
11
+ ],
12
+ "type": "string"
13
+ },
14
+ "DictionarySource": {
15
+ "anyOf": [
16
+ {
17
+ "$ref": "#/definitions/FilePath"
18
+ },
19
+ {
20
+ "$ref": "#/definitions/FileSource"
21
+ },
22
+ {
23
+ "$ref": "#/definitions/FileListSource"
24
+ }
25
+ ]
26
+ },
27
+ "FileListSource": {
28
+ "additionalProperties": false,
29
+ "properties": {
30
+ "keepRawCase": {
31
+ "default": false,
32
+ "description": "Do not generate lower case / accent free versions of words.",
33
+ "type": "boolean"
34
+ },
35
+ "listFile": {
36
+ "$ref": "#/definitions/FilePath"
37
+ },
38
+ "maxDepth": {
39
+ "description": "Maximum number of nested Hunspell Rules to apply. This is needed for recursive dictionaries like Hebrew.",
40
+ "type": "number"
41
+ },
42
+ "split": {
43
+ "anyOf": [
44
+ {
45
+ "type": "boolean"
46
+ },
47
+ {
48
+ "const": "legacy",
49
+ "type": "string"
50
+ }
51
+ ],
52
+ "default": false,
53
+ "description": "Split lines into words."
54
+ }
55
+ },
56
+ "required": [
57
+ "listFile"
58
+ ],
59
+ "type": "object"
60
+ },
61
+ "FilePath": {
62
+ "description": "Note: All relative paths are relative to the config file location.",
63
+ "type": "string"
64
+ },
65
+ "FileSource": {
66
+ "additionalProperties": false,
67
+ "properties": {
68
+ "filename": {
69
+ "$ref": "#/definitions/FilePath"
70
+ },
71
+ "keepRawCase": {
72
+ "default": false,
73
+ "description": "Do not generate lower case / accent free versions of words.",
74
+ "type": "boolean"
75
+ },
76
+ "maxDepth": {
77
+ "description": "Maximum number of nested Hunspell Rules to apply. This is needed for recursive dictionaries like Hebrew.",
78
+ "type": "number"
79
+ },
80
+ "split": {
81
+ "anyOf": [
82
+ {
83
+ "type": "boolean"
84
+ },
85
+ {
86
+ "const": "legacy",
87
+ "type": "string"
88
+ }
89
+ ],
90
+ "default": false,
91
+ "description": "Split lines into words."
92
+ }
93
+ },
94
+ "required": [
95
+ "filename"
96
+ ],
97
+ "type": "object"
98
+ },
99
+ "Target": {
100
+ "additionalProperties": false,
101
+ "properties": {
102
+ "compress": {
103
+ "default": ": false",
104
+ "description": "gzip the file?",
105
+ "type": "boolean"
106
+ },
107
+ "excludeWordsFrom": {
108
+ "description": "Words from the sources that are found in `excludeWordsFrom` files will not be added to the dictionary.",
109
+ "items": {
110
+ "$ref": "#/definitions/FilePath"
111
+ },
112
+ "type": "array"
113
+ },
114
+ "format": {
115
+ "$ref": "#/definitions/DictionaryFormats",
116
+ "description": "Format of the dictionary."
117
+ },
118
+ "generateNonStrict": {
119
+ "default": true,
120
+ "description": "Generate lower case / accent free versions of words.",
121
+ "type": "boolean"
122
+ },
123
+ "name": {
124
+ "description": "Name of target, used as the basis of target file name.",
125
+ "type": "string"
126
+ },
127
+ "sort": {
128
+ "default": ": true",
129
+ "description": "Sort the words in the resulting dictionary. Does not apply to `trie` based formats.",
130
+ "type": "boolean"
131
+ },
132
+ "sources": {
133
+ "description": "File sources used to build the dictionary.",
134
+ "items": {
135
+ "$ref": "#/definitions/DictionarySource"
136
+ },
137
+ "type": "array"
138
+ },
139
+ "targetDirectory": {
140
+ "$ref": "#/definitions/FilePath",
141
+ "default": "current directory",
142
+ "description": "The target directory"
143
+ },
144
+ "trieBase": {
145
+ "description": "Advanced: Set the trie base number. A value between 10 and 36 Set numeric base to use. 10 is the easiest to read. 16 is common hex format. 36 is the most compact.",
146
+ "type": "number"
147
+ }
148
+ },
149
+ "required": [
150
+ "name",
151
+ "format",
152
+ "sources"
153
+ ],
154
+ "type": "object"
155
+ }
156
+ },
157
+ "properties": {
158
+ "generateNonStrict": {
159
+ "default": true,
160
+ "description": "Generate lower case / accent free versions of words.",
161
+ "type": "boolean"
162
+ },
163
+ "keepRawCase": {
164
+ "default": false,
165
+ "description": "Do not generate lower case / accent free versions of words.",
166
+ "type": "boolean"
167
+ },
168
+ "maxDepth": {
169
+ "description": "Maximum number of nested Hunspell Rules to apply. This is needed for recursive dictionaries like Hebrew.",
170
+ "type": "number"
171
+ },
172
+ "rootDir": {
173
+ "description": "Specify the directory where all relative paths will resolved against. By default, all relative paths are relative to the location of the config file.",
174
+ "type": "string"
175
+ },
176
+ "sort": {
177
+ "default": ": true",
178
+ "description": "Sort the words in the resulting dictionary. Does not apply to `trie` based formats.",
179
+ "type": "boolean"
180
+ },
181
+ "split": {
182
+ "anyOf": [
183
+ {
184
+ "type": "boolean"
185
+ },
186
+ {
187
+ "const": "legacy",
188
+ "type": "string"
189
+ }
190
+ ],
191
+ "default": false,
192
+ "description": "Split lines into words."
193
+ },
194
+ "targets": {
195
+ "description": "Optional Target Dictionaries to create.",
196
+ "items": {
197
+ "$ref": "#/definitions/Target"
198
+ },
199
+ "type": "array"
200
+ }
201
+ },
202
+ "type": "object"
203
+ }
@@ -0,0 +1,28 @@
1
+ export interface CompileCommonAppOptions {
2
+ output?: string;
3
+ compress: boolean;
4
+ /**
5
+ * @deprecated Use maxDepth
6
+ */
7
+ max_depth?: string;
8
+ maxDepth?: string;
9
+ merge?: string;
10
+ experimental: string[];
11
+ split?: boolean;
12
+ sort?: boolean;
13
+ keepRawCase?: boolean;
14
+ trie?: boolean;
15
+ trie3?: boolean;
16
+ trie4?: boolean;
17
+ trieBase?: string;
18
+ useLegacySplitter?: boolean;
19
+ }
20
+ export interface CompileAppOptions extends CompileCommonAppOptions {
21
+ sort: boolean;
22
+ keepRawCase: boolean;
23
+ }
24
+ export interface CompileTrieAppOptions extends CompileCommonAppOptions {
25
+ trie3: boolean;
26
+ trie4: boolean;
27
+ }
28
+ //# sourceMappingURL=AppOptions.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=AppOptions.js.map
@@ -0,0 +1,34 @@
1
+ export interface FeatureFlag {
2
+ name: string;
3
+ description: string;
4
+ }
5
+ declare type FlagTypes = string | boolean;
6
+ /**
7
+ * Feature Flags are used to turn on/off features.
8
+ * These are primarily used before a feature has been fully released.
9
+ */
10
+ export declare class FeatureFlags {
11
+ private flags;
12
+ private flagValues;
13
+ constructor(flags?: FeatureFlag[]);
14
+ register(flag: FeatureFlag): this;
15
+ register(name: string, description: string): this;
16
+ registerFeatures(flags: FeatureFlag[]): this;
17
+ getFlag(flag: string): FlagTypes | undefined;
18
+ getFlagBool(flag: string): boolean | undefined;
19
+ setFlag(flag: string, value?: FlagTypes): this;
20
+ getFlagInfo(flag: string): FeatureFlag | undefined;
21
+ getFlags(): FeatureFlag[];
22
+ getFlagValues(): Map<string, FlagTypes>;
23
+ reset(): this;
24
+ help(): string;
25
+ fork(): FeatureFlags;
26
+ }
27
+ export declare class UnknownFeatureFlagError extends Error {
28
+ readonly flag: string;
29
+ constructor(flag: string);
30
+ }
31
+ export declare function getSystemFeatureFlags(): FeatureFlags;
32
+ export declare function createFeatureFlags(): FeatureFlags;
33
+ export {};
34
+ //# sourceMappingURL=FeatureFlags.d.ts.map
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFeatureFlags = exports.getSystemFeatureFlags = exports.UnknownFeatureFlagError = exports.FeatureFlags = void 0;
4
+ let systemFeatureFlags;
5
+ /**
6
+ * Feature Flags are used to turn on/off features.
7
+ * These are primarily used before a feature has been fully released.
8
+ */
9
+ class FeatureFlags {
10
+ constructor(flags = []) {
11
+ this.flagValues = new Map();
12
+ this.flags = new Map(flags.map((f) => [f.name, f]));
13
+ }
14
+ register(flagOrName, description) {
15
+ if (typeof flagOrName === 'string') {
16
+ return this.register({ name: flagOrName, description: description || '' });
17
+ }
18
+ this.flags.set(flagOrName.name, flagOrName);
19
+ return this;
20
+ }
21
+ registerFeatures(flags) {
22
+ flags.forEach((flag) => this.register(flag));
23
+ return this;
24
+ }
25
+ getFlag(flag) {
26
+ return this.flagValues.get(flag);
27
+ }
28
+ getFlagBool(flag) {
29
+ return toBool(this.getFlag(flag));
30
+ }
31
+ setFlag(flag, value = true) {
32
+ if (!this.flags.has(flag)) {
33
+ throw new UnknownFeatureFlagError(flag);
34
+ }
35
+ this.flagValues.set(flag, toBool(value) ?? value);
36
+ return this;
37
+ }
38
+ getFlagInfo(flag) {
39
+ return this.flags.get(flag);
40
+ }
41
+ getFlags() {
42
+ return [...this.flags.values()];
43
+ }
44
+ getFlagValues() {
45
+ return new Map(this.flagValues);
46
+ }
47
+ reset() {
48
+ this.flagValues.clear();
49
+ return this;
50
+ }
51
+ help() {
52
+ const flags = [{ name: 'Name', description: 'Description' }, ...this.flags.values()].sort((a, b) => a.name < b.name ? -1 : 1);
53
+ const nameColWidth = flags.map((f) => f.name.length).reduce((a, b) => Math.max(a, b), 0) + 1;
54
+ const entries = flags.map((f) => `- ${f.name}${' '.repeat(nameColWidth - f.name.length)} ${f.description}`);
55
+ const text = `Valid Flags:\n${entries.join('\n')}`;
56
+ return text;
57
+ }
58
+ fork() {
59
+ const fork = new FeatureFlags([...this.flags.values()]);
60
+ for (const [key, value] of this.flagValues) {
61
+ fork.flagValues.set(key, value);
62
+ }
63
+ return fork;
64
+ }
65
+ }
66
+ exports.FeatureFlags = FeatureFlags;
67
+ class UnknownFeatureFlagError extends Error {
68
+ constructor(flag) {
69
+ super(`Unknown feature flag: ${flag}`);
70
+ this.flag = flag;
71
+ }
72
+ }
73
+ exports.UnknownFeatureFlagError = UnknownFeatureFlagError;
74
+ function getSystemFeatureFlags() {
75
+ return systemFeatureFlags || (systemFeatureFlags = createFeatureFlags());
76
+ }
77
+ exports.getSystemFeatureFlags = getSystemFeatureFlags;
78
+ function createFeatureFlags() {
79
+ return new FeatureFlags();
80
+ }
81
+ exports.createFeatureFlags = createFeatureFlags;
82
+ const boolValues = {
83
+ 0: false,
84
+ 1: true,
85
+ f: false,
86
+ false: false,
87
+ n: false,
88
+ no: false,
89
+ t: true,
90
+ true: true,
91
+ y: true,
92
+ yes: true,
93
+ };
94
+ function toBool(value) {
95
+ if (typeof value !== 'string')
96
+ return value;
97
+ return boolValues[value.toLowerCase()];
98
+ }
99
+ //# sourceMappingURL=FeatureFlags.js.map
@@ -0,0 +1,3 @@
1
+ export { FeatureFlag, FeatureFlags, getSystemFeatureFlags, UnknownFeatureFlagError } from './FeatureFlags';
2
+ export { parseFlags } from './parseFlags';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseFlags = exports.UnknownFeatureFlagError = exports.getSystemFeatureFlags = exports.FeatureFlags = void 0;
4
+ var FeatureFlags_1 = require("./FeatureFlags");
5
+ Object.defineProperty(exports, "FeatureFlags", { enumerable: true, get: function () { return FeatureFlags_1.FeatureFlags; } });
6
+ Object.defineProperty(exports, "getSystemFeatureFlags", { enumerable: true, get: function () { return FeatureFlags_1.getSystemFeatureFlags; } });
7
+ Object.defineProperty(exports, "UnknownFeatureFlagError", { enumerable: true, get: function () { return FeatureFlags_1.UnknownFeatureFlagError; } });
8
+ var parseFlags_1 = require("./parseFlags");
9
+ Object.defineProperty(exports, "parseFlags", { enumerable: true, get: function () { return parseFlags_1.parseFlags; } });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ import { FeatureFlags } from './FeatureFlags';
2
+ export declare function parseFlags(ff: FeatureFlags, flags: string[]): FeatureFlags;
3
+ //# sourceMappingURL=parseFlags.d.ts.map
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseFlags = void 0;
4
+ const FeatureFlags_1 = require("./FeatureFlags");
5
+ const splitFlag = /[:=]/;
6
+ const leadingEql = /^=/;
7
+ function parseFlags(ff, flags) {
8
+ for (const flag of flags) {
9
+ const [name, value] = flag.replace(leadingEql, '').split(splitFlag, 2);
10
+ try {
11
+ ff.setFlag(name, value);
12
+ }
13
+ catch (e) {
14
+ if (e instanceof FeatureFlags_1.UnknownFeatureFlagError) {
15
+ console.error(e.message);
16
+ console.error(ff.help());
17
+ }
18
+ throw e;
19
+ }
20
+ }
21
+ return ff;
22
+ }
23
+ exports.parseFlags = parseFlags;
24
+ //# sourceMappingURL=parseFlags.js.map
package/dist/app.d.ts CHANGED
@@ -1,23 +1,4 @@
1
1
  import * as program from 'commander';
2
- interface CompileCommonOptions {
3
- output?: string;
4
- compress: boolean;
5
- max_depth?: string;
6
- merge?: string;
7
- experimental: string[];
8
- split?: boolean;
9
- sort?: boolean;
10
- keepRawCase?: boolean;
11
- trie?: boolean;
12
- trie3?: boolean;
13
- trie4?: boolean;
14
- trieBase?: string;
15
- useLegacySplitter?: boolean;
16
- }
17
- export declare function run(program: program.Command, argv: string[]): Promise<void>;
18
- declare function processAction(src: string[], options: CompileCommonOptions): Promise<void>;
19
- export declare const __testing__: {
20
- processAction: typeof processAction;
21
- };
22
- export {};
2
+ import { FeatureFlags } from './FeatureFlags';
3
+ export declare function run(program: program.Command, argv: string[], flags?: FeatureFlags): Promise<void>;
23
4
  //# sourceMappingURL=app.d.ts.map
package/dist/app.js CHANGED
@@ -23,33 +23,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  __setModuleDefault(result, mod);
24
24
  return result;
25
25
  };
26
- var __importDefault = (this && this.__importDefault) || function (mod) {
27
- return (mod && mod.__esModule) ? mod : { "default": mod };
28
- };
29
26
  Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.__testing__ = exports.run = void 0;
31
- const compiler_1 = require("./compiler");
32
- const compiler = __importStar(require("./compiler"));
27
+ exports.run = void 0;
33
28
  const path = __importStar(require("path"));
34
- const glob_1 = __importDefault(require("glob"));
35
- const gensequence_1 = require("gensequence");
36
- const iterateWordsFromFile_1 = require("./compiler/iterateWordsFromFile");
29
+ const compiler = __importStar(require("./compiler"));
30
+ const logWithTimestamp_1 = require("./compiler/logWithTimestamp");
31
+ const compile_1 = require("./compile");
32
+ const build_1 = require("./build");
37
33
  // eslint-disable-next-line @typescript-eslint/no-var-requires
38
34
  const npmPackage = require(path.join(__dirname, '..', 'package.json'));
39
- function globP(pattern) {
40
- // Convert windows separators.
41
- pattern = pattern.replace(/\\/g, '/');
42
- return new Promise((resolve, reject) => {
43
- (0, glob_1.default)(pattern, (err, result) => {
44
- err ? reject(err) : resolve(result);
45
- });
46
- });
47
- }
48
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
- const log = (message, ...optionalParams) => {
50
- console.log(`${new Date().toISOString()} ${message}`, ...optionalParams);
51
- };
52
- compiler.setLogger(log);
35
+ compiler.setLogger(logWithTimestamp_1.logWithTimestamp);
53
36
  function collect(value, previous) {
54
37
  return previous.concat([value]);
55
38
  }
@@ -68,129 +51,27 @@ function addCompileOptions(compileCommand) {
68
51
  .option('--trie4', 'Use file format trie4', false)
69
52
  .option('--trie-base <number>', 'Advanced: Set the trie base number. A value between 10 and 36');
70
53
  }
71
- function run(program, argv) {
54
+ async function run(program, argv, flags) {
72
55
  program.exitOverride();
73
- return new Promise((resolve, reject) => {
74
- program.version(npmPackage.version);
75
- addCompileOptions(program.command('compile <src...>').description('Compile words into a cspell dictionary files.'))
76
- .option('--trie', 'Compile into a trie file.', false)
77
- .option('--no-sort', 'Do not sort the result')
78
- .action((src, options) => {
79
- const result = processAction(src, options);
80
- resolve(result);
81
- });
82
- addCompileOptions(program
83
- .command('compile-trie <src...>')
84
- .description('Compile words lists or Hunspell dictionary into trie files used by cspell.\nAlias of `compile --trie`')).action((src, options) => {
85
- const result = processAction(src, { ...options, trie: true });
86
- resolve(result);
87
- });
88
- try {
89
- program.parse(argv);
90
- if (!argv.slice(2).length) {
91
- program.help();
92
- }
93
- }
94
- catch (e) {
95
- reject(e);
96
- }
97
- resolve();
98
- });
99
- }
100
- exports.run = run;
101
- function parseNumber(s) {
102
- const n = parseInt(s ?? '');
103
- return isNaN(n) ? undefined : n;
104
- }
105
- async function processAction(src, options) {
106
- const useTrie = options.trie || options.trie3 || options.trie4 || false;
107
- const fileExt = useTrie ? '.trie' : '.txt';
108
- console.log('Compile:\n output: %s\n compress: %s\n files:\n %s \n\n', options.output || 'default', options.compress ? 'true' : 'false', src.join('\n '));
109
- const experimental = new Set(options.experimental);
110
- const skipNormalization = experimental.has('compound');
111
- const { keepRawCase = false, split: splitWords = false, sort = true, useLegacySplitter: legacy } = options;
112
- const action = useTrie
113
- ? async (words, dst) => {
114
- return (0, compiler_1.compileTrie)(words, dst, {
115
- ...options,
116
- skipNormalization,
117
- splitWords,
118
- keepRawCase,
119
- legacy,
120
- base: parseNumber(options.trieBase),
121
- sort: false,
122
- });
123
- }
124
- : async (src, dst) => {
125
- return (0, compiler_1.compileWordList)(src, dst, {
126
- splitWords,
127
- sort,
128
- skipNormalization,
129
- keepRawCase,
130
- legacy,
131
- }).then(() => src);
132
- };
133
- const ext = fileExt + (options.compress ? '.gz' : '');
134
- const maxDepth = parseNumber(options.max_depth);
135
- const useAnnotation = experimental.has('compound');
136
- const readerOptions = { maxDepth, useAnnotation };
137
- const globResults = await Promise.all(src.map((s) => globP(s)));
138
- const filesToProcess = (0, gensequence_1.genSequence)(globResults)
139
- .concatMap((files) => files)
140
- .map(async (filename) => {
141
- log(`Reading ${path.basename(filename)}`);
142
- const words = await (0, iterateWordsFromFile_1.streamWordsFromFile)(filename, readerOptions);
143
- log(`Done reading ${path.basename(filename)}`);
144
- const f = {
145
- src: filename,
146
- words,
147
- };
148
- return f;
56
+ program.version(npmPackage.version);
57
+ addCompileOptions(program.command('compile <src...>').description('Compile words into a cspell dictionary files.'))
58
+ .option('--trie', 'Compile into a trie file.', false)
59
+ .option('--no-sort', 'Do not sort the result')
60
+ .action((src, options) => {
61
+ return (0, compile_1.processCompileAction)(src, options, flags);
149
62
  });
150
- const r = options.merge
151
- ? processFiles(action, filesToProcess, toMergeTargetFile(options.merge, options.output, ext))
152
- : processFilesIndividually(action, filesToProcess, (s) => toTargetFile(s, options.output, ext));
153
- await r;
154
- log(`Complete.`);
155
- }
156
- function toFilename(name, ext) {
157
- return path.basename(name).replace(/((\.txt|\.dic|\.aff|\.trie)(\.gz)?)?$/, '') + ext;
158
- }
159
- function toTargetFile(filename, destination, ext) {
160
- const outFileName = toFilename(filename, ext);
161
- const dir = destination ?? path.dirname(filename);
162
- return path.join(dir, outFileName);
163
- }
164
- function toMergeTargetFile(filename, destination, ext) {
165
- const outFileName = path.join(path.dirname(filename), toFilename(filename, ext));
166
- return path.resolve(destination ?? '.', outFileName);
167
- }
168
- async function processFilesIndividually(action, filesToProcess, srcToTarget) {
169
- const toProcess = filesToProcess.map(async (pFtp) => {
170
- const { src, words } = await pFtp;
171
- const dst = srcToTarget(src);
172
- log('Process "%s" to "%s"', src, dst);
173
- await action(words, dst);
174
- log('Done "%s" to "%s"', src, dst);
63
+ addCompileOptions(program
64
+ .command('compile-trie <src...>')
65
+ .description('Compile words lists or Hunspell dictionary into trie files used by cspell.\nAlias of `compile --trie`')).action((src, options) => {
66
+ return (0, compile_1.processCompileAction)(src, { ...options, trie: true }, flags);
175
67
  });
176
- for (const p of toProcess) {
177
- await p;
178
- }
179
- }
180
- async function processFiles(action, filesToProcess, mergeTarget) {
181
- const toProcess = await Promise.all([...filesToProcess]);
182
- const dst = mergeTarget;
183
- const words = (0, gensequence_1.genSequence)(toProcess)
184
- .map((ftp) => {
185
- const { src } = ftp;
186
- log('Process "%s" to "%s"', src, dst);
187
- return ftp;
188
- })
189
- .concatMap((ftp) => ftp.words);
190
- await action(words, dst);
191
- log('Done "%s"', dst);
68
+ program
69
+ .command('build [targets]')
70
+ .description('Build the targets defined in the run configuration.')
71
+ .option('-c, --config <path to run configuration>', 'Specify the run configuration file.')
72
+ .option('-r, --root <directory>', 'Specify the run directory')
73
+ .action(build_1.build);
74
+ await program.parseAsync(argv);
192
75
  }
193
- exports.__testing__ = {
194
- processAction,
195
- };
76
+ exports.run = run;
196
77
  //# sourceMappingURL=app.js.map
@@ -0,0 +1,7 @@
1
+ export interface BuildOptions {
2
+ /** Optional path to config file */
3
+ config?: string;
4
+ root?: string;
5
+ }
6
+ export declare function build(targets: string[] | undefined, options: BuildOptions): Promise<void>;
7
+ //# sourceMappingURL=build.d.ts.map