@cspell/cspell-tools 7.0.0-alpha.1 → 7.0.0
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.
- package/bin.js +6 -6
- package/cspell-tools.config.schema.json +12 -0
- package/dist/AppOptions.d.ts +4 -1
- package/dist/AppOptions.js +1 -2
- package/dist/FeatureFlags/FeatureFlags.js +4 -11
- package/dist/FeatureFlags/index.d.ts +2 -2
- package/dist/FeatureFlags/index.js +2 -9
- package/dist/FeatureFlags/parseFlags.d.ts +1 -1
- package/dist/FeatureFlags/parseFlags.js +3 -7
- package/dist/app.d.ts +1 -1
- package/dist/app.js +52 -43
- package/dist/build.d.ts +7 -2
- package/dist/build.js +18 -41
- package/dist/compile.d.ts +3 -2
- package/dist/compile.js +34 -17
- package/dist/compiler/CompileOptions.js +1 -2
- package/dist/compiler/Reader.d.ts +1 -1
- package/dist/compiler/Reader.js +8 -12
- package/dist/compiler/SourceReader.d.ts +1 -1
- package/dist/compiler/SourceReader.js +5 -9
- package/dist/compiler/WordsCollection.js +2 -5
- package/dist/compiler/compile.d.ts +16 -2
- package/dist/compiler/compile.js +92 -66
- package/dist/compiler/createCompileRequest.d.ts +3 -3
- package/dist/compiler/createCompileRequest.js +36 -38
- package/dist/compiler/createWordsCollection.d.ts +2 -2
- package/dist/compiler/createWordsCollection.js +12 -21
- package/dist/compiler/fileWriter.d.ts +1 -1
- package/dist/compiler/fileWriter.js +4 -9
- package/dist/compiler/index.d.ts +4 -4
- package/dist/compiler/index.js +3 -11
- package/dist/compiler/legacyLineToWords.d.ts +1 -1
- package/dist/compiler/legacyLineToWords.js +5 -10
- package/dist/compiler/logWithTimestamp.d.ts +1 -1
- package/dist/compiler/logWithTimestamp.js +1 -5
- package/dist/compiler/logger.js +2 -7
- package/dist/compiler/readers/ReaderOptions.js +1 -2
- package/dist/compiler/readers/readHunspellFiles.d.ts +1 -1
- package/dist/compiler/readers/readHunspellFiles.js +10 -37
- package/dist/compiler/readers/readTextFile.js +7 -35
- package/dist/compiler/readers/textFileReader.d.ts +1 -1
- package/dist/compiler/readers/textFileReader.js +3 -7
- package/dist/compiler/readers/trieFileReader.d.ts +1 -1
- package/dist/compiler/readers/trieFileReader.js +5 -9
- package/dist/compiler/splitCamelCaseIfAllowed.d.ts +1 -1
- package/dist/compiler/splitCamelCaseIfAllowed.js +7 -34
- package/dist/compiler/streamSourceWordsFromFile.d.ts +1 -1
- package/dist/compiler/streamSourceWordsFromFile.js +3 -7
- package/dist/compiler/text.js +1 -5
- package/dist/compiler/wordListCompiler.d.ts +1 -1
- package/dist/compiler/wordListCompiler.js +17 -45
- package/dist/compiler/wordListParser.d.ts +2 -2
- package/dist/compiler/wordListParser.js +19 -25
- package/dist/compiler/writeTextToFile.js +7 -35
- package/dist/config/config.d.ts +10 -0
- package/dist/config/config.js +1 -2
- package/dist/config/configUtils.d.ts +1 -1
- package/dist/config/configUtils.js +3 -9
- package/dist/config/index.d.ts +3 -3
- package/dist/config/index.js +2 -9
- package/dist/config/normalizeConfig.js +2 -29
- package/dist/gzip/compressFiles.d.ts +2 -0
- package/dist/gzip/compressFiles.js +14 -0
- package/dist/gzip/gzip.d.ts +2 -0
- package/dist/gzip/gzip.js +10 -0
- package/dist/gzip/index.d.ts +3 -0
- package/dist/gzip/index.js +3 -0
- package/dist/shasum/checksum.d.ts +8 -0
- package/dist/shasum/checksum.js +19 -0
- package/dist/shasum/index.d.ts +3 -0
- package/dist/shasum/index.js +3 -0
- package/dist/shasum/shasum.d.ts +38 -0
- package/dist/shasum/shasum.js +148 -0
- package/dist/test/TestHelper.d.ts +3 -3
- package/dist/test/TestHelper.js +19 -49
- package/dist/test/console.d.ts +0 -3
- package/dist/test/console.js +14 -13
- package/dist/test/escapeRegEx.js +1 -5
- package/dist/test/normalizeOutput.js +9 -35
- package/dist/util/errors.d.ts +6 -0
- package/dist/util/errors.js +11 -0
- package/dist/util/globP.d.ts +7 -0
- package/dist/util/globP.js +7 -0
- package/dist/util/index.d.ts +2 -0
- package/dist/util/index.js +4 -0
- package/package.json +15 -15
- package/dist/compiler/globP.d.ts +0 -2
- package/dist/compiler/globP.js +0 -16
- package/dist/compiler/inlineSettings.d.ts +0 -7
- package/dist/compiler/inlineSettings.js +0 -39
package/bin.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { program, CommanderError } from 'commander';
|
|
4
|
+
import { run } from './dist/app.js';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
app.run(program, process.argv).catch((e) => {
|
|
9
|
-
if (!(e instanceof program.CommanderError)) {
|
|
6
|
+
run(program, process.argv).catch((e) => {
|
|
7
|
+
if (!(e instanceof CommanderError)) {
|
|
10
8
|
console.log(e);
|
|
9
|
+
} else {
|
|
10
|
+
console.log(e.message);
|
|
11
11
|
}
|
|
12
12
|
process.exitCode = 1;
|
|
13
13
|
});
|
|
@@ -195,6 +195,11 @@
|
|
|
195
195
|
}
|
|
196
196
|
},
|
|
197
197
|
"properties": {
|
|
198
|
+
"$schema": {
|
|
199
|
+
"default": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/packages/cspell-tools/cspell-tools.config.schema.json",
|
|
200
|
+
"description": "Url to JSON Schema",
|
|
201
|
+
"type": "string"
|
|
202
|
+
},
|
|
198
203
|
"allowedSplitWords": {
|
|
199
204
|
"anyOf": [
|
|
200
205
|
{
|
|
@@ -209,6 +214,13 @@
|
|
|
209
214
|
],
|
|
210
215
|
"description": "Words in the `allowedSplitWords` are considered correct and can be used as a basis for splitting compound words.\n\nIf entries can be split so that all the words in the entry are allowed, then only the individual words are added, otherwise the entire entry is added. This is to prevent misspellings in CamelCase words from being introduced into the dictionary."
|
|
211
216
|
},
|
|
217
|
+
"checksumFile": {
|
|
218
|
+
"description": "Path to checksum file. `true` - defaults to `./checksum.txt`.",
|
|
219
|
+
"type": [
|
|
220
|
+
"string",
|
|
221
|
+
"boolean"
|
|
222
|
+
]
|
|
223
|
+
},
|
|
212
224
|
"generateNonStrict": {
|
|
213
225
|
"default": true,
|
|
214
226
|
"description": "Generate lower case / accent free versions of words.",
|
package/dist/AppOptions.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export interface CompileCommonAppOptions {
|
|
|
7
7
|
max_depth?: string;
|
|
8
8
|
maxDepth?: string;
|
|
9
9
|
merge?: string;
|
|
10
|
-
experimental
|
|
10
|
+
experimental?: string[];
|
|
11
11
|
split?: boolean;
|
|
12
12
|
sort?: boolean;
|
|
13
13
|
keepRawCase?: boolean;
|
|
@@ -15,7 +15,10 @@ export interface CompileCommonAppOptions {
|
|
|
15
15
|
trie3?: boolean;
|
|
16
16
|
trie4?: boolean;
|
|
17
17
|
trieBase?: string;
|
|
18
|
+
listFile?: string[];
|
|
18
19
|
useLegacySplitter?: boolean;
|
|
20
|
+
/** Indicate that a config file should be created instead of building. */
|
|
21
|
+
init?: boolean;
|
|
19
22
|
}
|
|
20
23
|
export interface CompileAppOptions extends CompileCommonAppOptions {
|
|
21
24
|
sort: boolean;
|
package/dist/AppOptions.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createFeatureFlags = exports.getSystemFeatureFlags = exports.UnknownFeatureFlagError = exports.FeatureFlags = void 0;
|
|
4
1
|
let systemFeatureFlags;
|
|
5
2
|
/**
|
|
6
3
|
* Feature Flags are used to turn on/off features.
|
|
7
4
|
* These are primarily used before a feature has been fully released.
|
|
8
5
|
*/
|
|
9
|
-
class FeatureFlags {
|
|
6
|
+
export class FeatureFlags {
|
|
10
7
|
constructor(flags = []) {
|
|
11
8
|
this.flagValues = new Map();
|
|
12
9
|
this.flags = new Map(flags.map((f) => [f.name, f]));
|
|
@@ -63,22 +60,18 @@ class FeatureFlags {
|
|
|
63
60
|
return fork;
|
|
64
61
|
}
|
|
65
62
|
}
|
|
66
|
-
|
|
67
|
-
class UnknownFeatureFlagError extends Error {
|
|
63
|
+
export class UnknownFeatureFlagError extends Error {
|
|
68
64
|
constructor(flag) {
|
|
69
65
|
super(`Unknown feature flag: ${flag}`);
|
|
70
66
|
this.flag = flag;
|
|
71
67
|
}
|
|
72
68
|
}
|
|
73
|
-
|
|
74
|
-
function getSystemFeatureFlags() {
|
|
69
|
+
export function getSystemFeatureFlags() {
|
|
75
70
|
return systemFeatureFlags || (systemFeatureFlags = createFeatureFlags());
|
|
76
71
|
}
|
|
77
|
-
|
|
78
|
-
function createFeatureFlags() {
|
|
72
|
+
export function createFeatureFlags() {
|
|
79
73
|
return new FeatureFlags();
|
|
80
74
|
}
|
|
81
|
-
exports.createFeatureFlags = createFeatureFlags;
|
|
82
75
|
const boolValues = {
|
|
83
76
|
0: false,
|
|
84
77
|
1: true,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { FeatureFlag, FeatureFlags, getSystemFeatureFlags, UnknownFeatureFlagError } from './FeatureFlags';
|
|
2
|
-
export { parseFlags } from './parseFlags';
|
|
1
|
+
export { FeatureFlag, FeatureFlags, getSystemFeatureFlags, UnknownFeatureFlagError } from './FeatureFlags.js';
|
|
2
|
+
export { parseFlags } from './parseFlags.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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; } });
|
|
1
|
+
export { FeatureFlags, getSystemFeatureFlags, UnknownFeatureFlagError } from './FeatureFlags.js';
|
|
2
|
+
export { parseFlags } from './parseFlags.js';
|
|
10
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseFlags = void 0;
|
|
4
|
-
const FeatureFlags_1 = require("./FeatureFlags");
|
|
1
|
+
import { UnknownFeatureFlagError } from './FeatureFlags.js';
|
|
5
2
|
const splitFlag = /[:=]/;
|
|
6
3
|
const leadingEql = /^=/;
|
|
7
|
-
function parseFlags(ff, flags) {
|
|
4
|
+
export function parseFlags(ff, flags) {
|
|
8
5
|
for (const flag of flags) {
|
|
9
6
|
const [name, value] = flag.replace(leadingEql, '').split(splitFlag, 2);
|
|
10
7
|
try {
|
|
11
8
|
ff.setFlag(name, value);
|
|
12
9
|
}
|
|
13
10
|
catch (e) {
|
|
14
|
-
if (e instanceof
|
|
11
|
+
if (e instanceof UnknownFeatureFlagError) {
|
|
15
12
|
console.error(e.message);
|
|
16
13
|
console.error(ff.help());
|
|
17
14
|
}
|
|
@@ -20,5 +17,4 @@ function parseFlags(ff, flags) {
|
|
|
20
17
|
}
|
|
21
18
|
return ff;
|
|
22
19
|
}
|
|
23
|
-
exports.parseFlags = parseFlags;
|
|
24
20
|
//# sourceMappingURL=parseFlags.js.map
|
package/dist/app.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type * as program from 'commander';
|
|
2
|
-
import type { FeatureFlags } from './FeatureFlags';
|
|
2
|
+
import type { FeatureFlags } from './FeatureFlags/index.js';
|
|
3
3
|
export declare function run(program: program.Command, argv: string[], flags?: FeatureFlags): Promise<void>;
|
|
4
4
|
//# sourceMappingURL=app.d.ts.map
|
package/dist/app.js
CHANGED
|
@@ -1,38 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// For large dictionaries, it is necessary to increase the memory limit.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
-
if (mod && mod.__esModule) return mod;
|
|
21
|
-
var result = {};
|
|
22
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
-
__setModuleDefault(result, mod);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.run = void 0;
|
|
28
|
-
const path = __importStar(require("path"));
|
|
29
|
-
const build_1 = require("./build");
|
|
30
|
-
const compile_1 = require("./compile");
|
|
31
|
-
const compiler = __importStar(require("./compiler"));
|
|
32
|
-
const logWithTimestamp_1 = require("./compiler/logWithTimestamp");
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
34
|
-
const npmPackage = require(path.join(__dirname, '..', 'package.json'));
|
|
35
|
-
compiler.setLogger(logWithTimestamp_1.logWithTimestamp);
|
|
2
|
+
import { CommanderError, Option } from 'commander';
|
|
3
|
+
import { readFileSync } from 'fs';
|
|
4
|
+
import { build } from './build.js';
|
|
5
|
+
import { processCompileAction } from './compile.js';
|
|
6
|
+
import * as compiler from './compiler/index.js';
|
|
7
|
+
import { logWithTimestamp } from './compiler/logWithTimestamp.js';
|
|
8
|
+
import { gzip } from './gzip/index.js';
|
|
9
|
+
import { reportCheckChecksumFile, reportChecksumForFiles, updateChecksumForFiles } from './shasum/shasum.js';
|
|
10
|
+
import { toError } from './util/errors.js';
|
|
11
|
+
const npmPackageRaw = readFileSync(new URL('../package.json', import.meta.url), 'utf8');
|
|
12
|
+
const npmPackage = JSON.parse(npmPackageRaw);
|
|
13
|
+
compiler.setLogger(logWithTimestamp);
|
|
36
14
|
function collect(value, previous) {
|
|
37
15
|
return previous.concat([value]);
|
|
38
16
|
}
|
|
@@ -49,29 +27,60 @@ function addCompileOptions(compileCommand) {
|
|
|
49
27
|
.option('-x, --experimental <flag>', 'Experimental flags, used for testing new concepts. Flags: compound', collect, [])
|
|
50
28
|
.option('--trie3', 'Use file format trie3', false)
|
|
51
29
|
.option('--trie4', 'Use file format trie4', false)
|
|
52
|
-
.option('--trie-base <number>', 'Advanced: Set the trie base number. A value between 10 and 36')
|
|
30
|
+
.option('--trie-base <number>', 'Advanced: Set the trie base number. A value between 10 and 36')
|
|
31
|
+
.option('--list-file <filename...>', 'Path to a file that contains the list of files to compile. A list file contains one file per line.')
|
|
32
|
+
.option('--init', 'Create a build command `cspell-tools.config.yaml` file based upon the options given instead of building.');
|
|
53
33
|
}
|
|
54
|
-
async function run(program, argv, flags) {
|
|
34
|
+
export async function run(program, argv, flags) {
|
|
35
|
+
async function handleGzip(files) {
|
|
36
|
+
try {
|
|
37
|
+
await gzip(files);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
const err = toError(error);
|
|
41
|
+
program.error(err.message);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function shasum(files, options) {
|
|
45
|
+
const report = options.check
|
|
46
|
+
? await reportCheckChecksumFile(options.check, files, options)
|
|
47
|
+
: options.update
|
|
48
|
+
? await updateChecksumForFiles(options.update, files, options)
|
|
49
|
+
: await reportChecksumForFiles(files, options);
|
|
50
|
+
console.log('%s', report.report);
|
|
51
|
+
if (!report.passed) {
|
|
52
|
+
throw new CommanderError(1, 'Failed Checksum', 'One or more files had issues.');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
55
|
program.exitOverride();
|
|
56
56
|
program.version(npmPackage.version);
|
|
57
|
-
addCompileOptions(program.command('compile
|
|
57
|
+
addCompileOptions(program.command('compile [src...]').description('Compile words into a cspell dictionary files.'))
|
|
58
58
|
.option('--trie', 'Compile into a trie file.', false)
|
|
59
59
|
.option('--no-sort', 'Do not sort the result')
|
|
60
60
|
.action((src, options) => {
|
|
61
|
-
return
|
|
61
|
+
return processCompileAction(src, options, flags);
|
|
62
62
|
});
|
|
63
63
|
addCompileOptions(program
|
|
64
|
-
.command('compile-trie
|
|
64
|
+
.command('compile-trie [src...]')
|
|
65
65
|
.description('Compile words lists or Hunspell dictionary into trie files used by cspell.\nAlias of `compile --trie`')).action((src, options) => {
|
|
66
|
-
return
|
|
66
|
+
return processCompileAction(src, { ...options, trie: true }, flags);
|
|
67
67
|
});
|
|
68
68
|
program
|
|
69
|
-
.command('build [targets]')
|
|
69
|
+
.command('build [targets...]')
|
|
70
70
|
.description('Build the targets defined in the run configuration.')
|
|
71
71
|
.option('-c, --config <path to run configuration>', 'Specify the run configuration file.')
|
|
72
|
+
.option('--conditional', 'Conditional build.')
|
|
72
73
|
.option('-r, --root <directory>', 'Specify the run directory')
|
|
73
|
-
.action(
|
|
74
|
+
.action(build);
|
|
75
|
+
program.command('gzip <files...>').description('GZip files while keeping the original.').action(handleGzip);
|
|
76
|
+
program
|
|
77
|
+
.command('shasum [files...]')
|
|
78
|
+
.description('Calculate the checksum for files.')
|
|
79
|
+
.option('--list-file <list-file.txt...>', 'Specify one or more files that contain paths of files to check.')
|
|
80
|
+
.option('-c, --check <checksum.txt>', 'Verify the checksum of files against those stored in the checksum.txt file.')
|
|
81
|
+
.addOption(new Option('-u, --update <checksum.txt>', 'Update checksums found in the file.').conflicts('--check'))
|
|
82
|
+
.option('-r, --root <root>', 'Specify the root to use for relative paths. The current working directory is used by default.')
|
|
83
|
+
.action(shasum);
|
|
74
84
|
await program.parseAsync(argv);
|
|
75
85
|
}
|
|
76
|
-
exports.run = run;
|
|
77
86
|
//# sourceMappingURL=app.js.map
|
package/dist/build.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
export interface BuildOptions {
|
|
2
2
|
/** Optional path to config file */
|
|
3
|
-
config?: string;
|
|
4
|
-
|
|
3
|
+
config?: string | undefined;
|
|
4
|
+
/** Used to resolve relative paths in the config. */
|
|
5
|
+
root?: string | undefined;
|
|
6
|
+
/** Current working directory */
|
|
7
|
+
cwd?: string | undefined;
|
|
8
|
+
/** Conditional build based upon the targets matching the `checksum.txt` file. */
|
|
9
|
+
conditional?: boolean;
|
|
5
10
|
}
|
|
6
11
|
export declare function build(targets: string[] | undefined, options: BuildOptions): Promise<void>;
|
|
7
12
|
//# sourceMappingURL=build.d.ts.map
|
package/dist/build.js
CHANGED
|
@@ -1,33 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.build = void 0;
|
|
27
|
-
const cosmiconfig_1 = require("cosmiconfig");
|
|
28
|
-
const path = __importStar(require("path"));
|
|
29
|
-
const compiler_1 = require("./compiler");
|
|
30
|
-
const config_1 = require("./config");
|
|
1
|
+
import { cosmiconfig } from 'cosmiconfig';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { compile } from './compiler/index.js';
|
|
4
|
+
import { normalizeConfig } from './config/index.js';
|
|
31
5
|
const moduleName = 'cspell-tools';
|
|
32
6
|
const searchPlaces = [
|
|
33
7
|
`${moduleName}.config.json`,
|
|
@@ -35,25 +9,28 @@ const searchPlaces = [
|
|
|
35
9
|
`${moduleName}.config.yml`,
|
|
36
10
|
'package.json',
|
|
37
11
|
];
|
|
38
|
-
async function build(targets, options) {
|
|
12
|
+
export async function build(targets, options) {
|
|
39
13
|
const allowedTargets = new Set(targets || []);
|
|
40
14
|
function filter(target) {
|
|
41
|
-
return !
|
|
42
|
-
}
|
|
43
|
-
if (options.root) {
|
|
44
|
-
process.chdir(path.resolve(options.root));
|
|
15
|
+
return !allowedTargets.size || allowedTargets.has(target.name);
|
|
45
16
|
}
|
|
46
|
-
const
|
|
17
|
+
const searchDir = path.resolve(options.root || options.cwd || '.');
|
|
18
|
+
const explorer = cosmiconfig(moduleName, {
|
|
47
19
|
searchPlaces,
|
|
48
|
-
stopDir:
|
|
49
|
-
transform:
|
|
20
|
+
stopDir: searchDir,
|
|
21
|
+
transform: normalizeConfig,
|
|
50
22
|
});
|
|
51
|
-
const config = await (options.config ? explorer.load(options.config) : explorer.search(
|
|
23
|
+
const config = await (options.config ? explorer.load(options.config) : explorer.search(searchDir));
|
|
52
24
|
if (!config?.config) {
|
|
53
25
|
console.error('root: %s', options.root);
|
|
54
26
|
throw 'cspell-tools.config not found.';
|
|
55
27
|
}
|
|
56
|
-
|
|
28
|
+
const configDir = path.dirname(config.filepath);
|
|
29
|
+
const buildInfo = normalizeRequest(config.config, path.resolve(configDir, options.root || configDir));
|
|
30
|
+
await compile(buildInfo, { filter, cwd: options.cwd, conditionalBuild: options.conditional || false });
|
|
31
|
+
}
|
|
32
|
+
function normalizeRequest(buildInfo, root) {
|
|
33
|
+
const { rootDir = root, targets = [], checksumFile } = buildInfo;
|
|
34
|
+
return { rootDir: path.resolve(rootDir), targets, checksumFile };
|
|
57
35
|
}
|
|
58
|
-
exports.build = build;
|
|
59
36
|
//# sourceMappingURL=build.js.map
|
package/dist/compile.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { CompileCommonAppOptions } from './AppOptions';
|
|
2
|
-
import type { FeatureFlags } from './FeatureFlags';
|
|
1
|
+
import type { CompileCommonAppOptions } from './AppOptions.js';
|
|
2
|
+
import type { FeatureFlags } from './FeatureFlags/index.js';
|
|
3
|
+
export declare const configFileHeader: string;
|
|
3
4
|
export declare function processCompileAction(src: string[], options: CompileCommonAppOptions, featureFlags: FeatureFlags | undefined): Promise<void>;
|
|
4
5
|
//# sourceMappingURL=compile.d.ts.map
|
package/dist/compile.js
CHANGED
|
@@ -1,24 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { writeFile } from 'node:fs/promises';
|
|
2
|
+
import { opConcatMap, pipe } from '@cspell/cspell-pipe/sync';
|
|
3
|
+
import YAML from 'yaml';
|
|
4
|
+
import { compile } from './compiler/compile.js';
|
|
5
|
+
import { createCompileRequest } from './compiler/createCompileRequest.js';
|
|
6
|
+
import { configFileSchemaURL } from './config/config.js';
|
|
7
|
+
import { getSystemFeatureFlags, parseFlags } from './FeatureFlags/index.js';
|
|
8
|
+
import { globP } from './util/globP.js';
|
|
9
|
+
getSystemFeatureFlags().register('compound', 'Enable compound dictionary sources.');
|
|
10
|
+
const defaultConfigFile = 'cspell-tools.config.yaml';
|
|
11
|
+
export const configFileHeader = `# yaml-language-server: $schema=${configFileSchemaURL}\n\n`;
|
|
12
|
+
export async function processCompileAction(src, options, featureFlags) {
|
|
13
|
+
const ff = featureFlags || getSystemFeatureFlags();
|
|
14
|
+
parseFlags(ff, options.experimental || []);
|
|
13
15
|
return useCompile(src, options);
|
|
14
16
|
}
|
|
15
|
-
exports.processCompileAction = processCompileAction;
|
|
16
17
|
async function useCompile(src, options) {
|
|
17
|
-
console.log('Compile:\n output: %s\n compress: %s\n files:\n %s
|
|
18
|
-
|
|
18
|
+
console.log('Compile:\n output: %s\n compress: %s\n files:\n %s ', options.output || 'default', options.compress ? 'true' : 'false', src.join('\n '));
|
|
19
|
+
if (options.listFile && options.listFile.length) {
|
|
20
|
+
console.log(' list files:\n %s', options.listFile.join('\n '));
|
|
21
|
+
}
|
|
22
|
+
console.log('\n\n');
|
|
23
|
+
const globResults = await Promise.all(src.map((s) => globP(s)));
|
|
19
24
|
const sources = [
|
|
20
|
-
...
|
|
25
|
+
...pipe(globResults, opConcatMap((a) => a)),
|
|
21
26
|
];
|
|
22
|
-
|
|
27
|
+
const request = createCompileRequest(sources, options);
|
|
28
|
+
return options.init ? initConfig(request) : compile(request);
|
|
29
|
+
}
|
|
30
|
+
async function initConfig(runConfig) {
|
|
31
|
+
const { $schema = configFileSchemaURL, ...cfg } = runConfig;
|
|
32
|
+
const config = { $schema, ...cfg };
|
|
33
|
+
const content = configFileHeader + YAML.stringify(config, null, 2);
|
|
34
|
+
console.log('Writing config file: %s', defaultConfigFile);
|
|
35
|
+
await writeFile(defaultConfigFile, content);
|
|
36
|
+
console.log(`Init complete.
|
|
37
|
+
To build, use:
|
|
38
|
+
cspell-tools-cli build
|
|
39
|
+
`);
|
|
23
40
|
}
|
|
24
41
|
//# sourceMappingURL=compile.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Reader, ReaderOptions } from './readers/ReaderOptions';
|
|
1
|
+
import type { Reader, ReaderOptions } from './readers/ReaderOptions.js';
|
|
2
2
|
export declare const regHunspellFile: RegExp;
|
|
3
3
|
export declare function createReader(filename: string, options: ReaderOptions): Promise<Reader>;
|
|
4
4
|
//# sourceMappingURL=Reader.d.ts.map
|
package/dist/compiler/Reader.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const textFileReader_1 = require("./readers/textFileReader");
|
|
6
|
-
const trieFileReader_1 = require("./readers/trieFileReader");
|
|
7
|
-
exports.regHunspellFile = /\.(dic|aff)$/i;
|
|
1
|
+
import { readHunspellFiles } from './readers/readHunspellFiles.js';
|
|
2
|
+
import { textFileReader } from './readers/textFileReader.js';
|
|
3
|
+
import { trieFileReader } from './readers/trieFileReader.js';
|
|
4
|
+
export const regHunspellFile = /\.(dic|aff)$/i;
|
|
8
5
|
// Readers first match wins
|
|
9
6
|
const readers = [
|
|
10
|
-
{ test: /\.trie\b/, method:
|
|
11
|
-
{ test:
|
|
7
|
+
{ test: /\.trie\b/, method: trieFileReader },
|
|
8
|
+
{ test: regHunspellFile, method: readHunspellFiles },
|
|
12
9
|
];
|
|
13
10
|
function findMatchingReader(filename, options) {
|
|
14
11
|
for (const reader of readers) {
|
|
@@ -16,13 +13,12 @@ function findMatchingReader(filename, options) {
|
|
|
16
13
|
return reader.method(filename, options);
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
|
-
return
|
|
16
|
+
return textFileReader(filename);
|
|
20
17
|
}
|
|
21
|
-
async function createReader(filename, options) {
|
|
18
|
+
export async function createReader(filename, options) {
|
|
22
19
|
const baseReader = await findMatchingReader(filename, options);
|
|
23
20
|
return Object.assign(baseReader, {
|
|
24
21
|
[Symbol.iterator]: () => baseReader.lines[Symbol.iterator](),
|
|
25
22
|
});
|
|
26
23
|
}
|
|
27
|
-
exports.createReader = createReader;
|
|
28
24
|
//# sourceMappingURL=Reader.js.map
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const wordListParser_1 = require("./wordListParser");
|
|
6
|
-
async function createSourceReader(filename, options) {
|
|
7
|
-
const reader = await (0, Reader_1.createReader)(filename, options);
|
|
1
|
+
import { createReader } from './Reader.js';
|
|
2
|
+
import { parseFileLines } from './wordListParser.js';
|
|
3
|
+
export async function createSourceReader(filename, options) {
|
|
4
|
+
const reader = await createReader(filename, options);
|
|
8
5
|
if (reader.type !== 'TextFile') {
|
|
9
6
|
return {
|
|
10
7
|
words: reader.lines,
|
|
@@ -15,10 +12,9 @@ async function createSourceReader(filename, options) {
|
|
|
15
12
|
}
|
|
16
13
|
return textFileReader(reader, options);
|
|
17
14
|
}
|
|
18
|
-
exports.createSourceReader = createSourceReader;
|
|
19
15
|
async function textFileReader(reader, options) {
|
|
20
16
|
const { legacy, splitWords: split, allowedSplitWords } = options;
|
|
21
|
-
const words = [...
|
|
17
|
+
const words = [...parseFileLines(reader, { legacy, split, allowedSplitWords })];
|
|
22
18
|
return {
|
|
23
19
|
size: words.length,
|
|
24
20
|
words,
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
Object.
|
|
3
|
-
exports.defaultExcludeWordsCollection = exports.defaultAllowedSplitWords = void 0;
|
|
4
|
-
exports.defaultAllowedSplitWords = Object.freeze({ size: 0, has: () => true });
|
|
5
|
-
exports.defaultExcludeWordsCollection = Object.freeze({ size: 0, has: () => false });
|
|
1
|
+
export const defaultAllowedSplitWords = Object.freeze({ size: 0, has: () => true });
|
|
2
|
+
export const defaultExcludeWordsCollection = Object.freeze({ size: 0, has: () => false });
|
|
6
3
|
//# sourceMappingURL=WordsCollection.js.map
|
|
@@ -1,11 +1,25 @@
|
|
|
1
|
-
import type { CompileRequest, CompileSourceOptions, Target } from '../config';
|
|
1
|
+
import type { CompileRequest, CompileSourceOptions as CompileSourceConfig, Target } from '../config/index.js';
|
|
2
2
|
interface CompileOptions {
|
|
3
3
|
/**
|
|
4
4
|
* Optional filter function to filter targets.
|
|
5
5
|
*/
|
|
6
6
|
filter?: (target: Target) => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* The current working directory. Defaults to process.cwd()
|
|
9
|
+
*/
|
|
10
|
+
cwd?: string;
|
|
11
|
+
/**
|
|
12
|
+
* `true` - only build if files do not match checksum.
|
|
13
|
+
*/
|
|
14
|
+
conditionalBuild: boolean;
|
|
7
15
|
}
|
|
8
16
|
export declare function compile(request: CompileRequest, options?: CompileOptions): Promise<void>;
|
|
9
|
-
|
|
17
|
+
interface CompileTargetOptions {
|
|
18
|
+
rootDir: string;
|
|
19
|
+
cwd: string | undefined;
|
|
20
|
+
conditional: boolean;
|
|
21
|
+
checksumFile: string | undefined;
|
|
22
|
+
}
|
|
23
|
+
export declare function compileTarget(target: Target, options: CompileSourceConfig, compileOptions: CompileTargetOptions): Promise<string[]>;
|
|
10
24
|
export {};
|
|
11
25
|
//# sourceMappingURL=compile.d.ts.map
|