Skip to content

Commit 4d8f3d6

Browse files
authored
fix: Add $schema field to the cspell-tools config (#4708)
1 parent a14dbe3 commit 4d8f3d6

File tree

6 files changed

+24
-14
lines changed

6 files changed

+24
-14
lines changed

packages/cspell-tools/cspell-tools.config.schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@
195195
}
196196
},
197197
"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+
},
198203
"allowedSplitWords": {
199204
"anyOf": [
200205
{

packages/cspell-tools/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@
6363
},
6464
"devDependencies": {
6565
"@types/glob": "^8.1.0",
66-
"@types/jest": "^29.5.3",
6766
"@types/shelljs": "^0.8.12",
68-
"jest": "^29.6.2",
6967
"lorem-ipsum": "^2.0.8",
7068
"shelljs": "^0.8.5",
7169
"ts-json-schema-generator": "^1.2.0"

packages/cspell-tools/src/compile.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { writeFile } from 'node:fs/promises';
33
import { describe, expect, test, vi } from 'vitest';
44

55
import { configFileHeader, processCompileAction } from './compile.js';
6+
import { configFileSchemaURL } from './config/config.js';
67

78
vi.mock('node:fs/promises', () => ({
89
writeFile: vi.fn().mockImplementation(() => Promise.resolve(undefined)),
@@ -25,6 +26,7 @@ describe('compile', () => {
2526
const expected =
2627
configFileHeader +
2728
`\
29+
$schema: ${configFileSchemaURL}
2830
targets:
2931
- name: public-licenses
3032
targetDirectory: .
@@ -53,6 +55,7 @@ targets:
5355
const expected =
5456
configFileHeader +
5557
`\
58+
$schema: ${configFileSchemaURL}
5659
targets:
5760
- name: nl-nl
5861
targetDirectory: .

packages/cspell-tools/src/compile.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import YAML from 'yaml';
66
import type { CompileCommonAppOptions } from './AppOptions.js';
77
import { compile } from './compiler/compile.js';
88
import { createCompileRequest } from './compiler/createCompileRequest.js';
9-
import type { CompileRequest } from './config/config.js';
9+
import { configFileSchemaURL, type RunConfig } from './config/config.js';
1010
import type { FeatureFlags } from './FeatureFlags/index.js';
1111
import { getSystemFeatureFlags, parseFlags } from './FeatureFlags/index.js';
1212
import { globP } from './util/globP.js';
@@ -15,8 +15,7 @@ getSystemFeatureFlags().register('compound', 'Enable compound dictionary sources
1515

1616
const defaultConfigFile = 'cspell-tools.config.yaml';
1717

18-
export const configFileHeader =
19-
'# yaml-language-server: $schema=https://raw.githubusercontent.com/streetsidesoftware/cspell/main/packages/cspell-tools/cspell-tools.config.schema.json\n\n';
18+
export const configFileHeader = `# yaml-language-server: $schema=${configFileSchemaURL}\n\n`;
2019

2120
export async function processCompileAction(
2221
src: string[],
@@ -52,8 +51,10 @@ async function useCompile(src: string[], options: CompileCommonAppOptions): Prom
5251
return options.init ? initConfig(request) : compile(request);
5352
}
5453

55-
async function initConfig(request: CompileRequest): Promise<void> {
56-
const content = configFileHeader + YAML.stringify(request, null, 2);
54+
async function initConfig(runConfig: RunConfig): Promise<void> {
55+
const { $schema = configFileSchemaURL, ...cfg } = runConfig;
56+
const config = { $schema, ...cfg };
57+
const content = configFileHeader + YAML.stringify(config, null, 2);
5758
console.log('Writing config file: %s', defaultConfigFile);
5859
await writeFile(defaultConfigFile, content);
5960

packages/cspell-tools/src/config/config.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
export interface RunConfig extends Partial<CompileRequest> {
2+
/**
3+
* Url to JSON Schema
4+
* @default "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/packages/cspell-tools/cspell-tools.config.schema.json"
5+
*/
6+
$schema?: string;
7+
28
/**
39
* Optional Target Dictionaries to create.
410
*/
@@ -144,3 +150,6 @@ export interface CompileSourceOptions {
144150

145151
allowedSplitWords?: FilePath | FilePath[] | undefined;
146152
}
153+
154+
export const configFileSchemaURL =
155+
'https://raw.githubusercontent.com/streetsidesoftware/cspell/main/packages/cspell-tools/cspell-tools.config.schema.json';

pnpm-lock.yaml

+1-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)