@cssdoc/config 0.1.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/LICENSE +21 -0
- package/README.md +55 -0
- package/cssdoc.schema.json +41 -0
- package/dist/index.d.mts +126 -0
- package/dist/index.mjs +234 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Danny Wahl
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# @cssdoc/config
|
|
2
|
+
|
|
3
|
+
Load a `cssdoc.json` file into an [`@cssdoc/core`](../core) `CssDocConfiguration` — TSDoc-config, for
|
|
4
|
+
CSS. Model on `@microsoft/tsdoc-config`: a separate package (it needs Node and ajv) that reads the
|
|
5
|
+
config, validates it against a JSON schema, resolves `extends`, and applies it to a parser.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm i -D @cssdoc/config @cssdoc/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { CssDocConfigFile } from "@cssdoc/config";
|
|
17
|
+
import { parseCssDocs } from "@cssdoc/core";
|
|
18
|
+
|
|
19
|
+
const configFile = CssDocConfigFile.loadForFolder(process.cwd());
|
|
20
|
+
if (configFile.hasErrors) console.warn(configFile.getErrorSummary());
|
|
21
|
+
|
|
22
|
+
const model = parseCssDocs(css, { configuration: configFile.toConfiguration() });
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## cssdoc.json
|
|
26
|
+
|
|
27
|
+
```jsonc
|
|
28
|
+
{
|
|
29
|
+
"$schema": "https://cssdoc.dev/cssdoc.schema.json",
|
|
30
|
+
"extends": ["./base.cssdoc.json"],
|
|
31
|
+
"noStandardTags": false,
|
|
32
|
+
"tagDefinitions": [
|
|
33
|
+
{ "tagName": "@token", "syntaxKind": "block", "allowMultiple": true },
|
|
34
|
+
{ "tagName": "@pattern", "syntaxKind": "record", "recordKind": "component" },
|
|
35
|
+
],
|
|
36
|
+
"supportForTags": {
|
|
37
|
+
"@privateRemarks": false,
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
| Field | Meaning |
|
|
43
|
+
| ---------------- | -------------------------------------------------------------------------------------------------------------------------- |
|
|
44
|
+
| `extends` | Paths (local `./…` or package specifiers) to other `cssdoc.json` files to inherit from. |
|
|
45
|
+
| `noStandardTags` | Disable every built-in standard tag; only `tagDefinitions` stay supported. |
|
|
46
|
+
| `tagDefinitions` | Custom tags: `tagName`, `syntaxKind` (`record`/`block`/`modifier`/`inline`), `allowMultiple?`, `recordKind?`, `aliasFor?`. |
|
|
47
|
+
| `supportForTags` | Enable/disable specific tags by name. |
|
|
48
|
+
|
|
49
|
+
`loadForFolder` walks up from a folder to the nearest `cssdoc.json`. A missing file yields a
|
|
50
|
+
`fileNotFound` instance (not an error); a malformed one collects messages on `getErrorSummary()`
|
|
51
|
+
instead of throwing.
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
MIT
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "https://cssdoc.dev/cssdoc.schema.json",
|
|
4
|
+
"title": "cssdoc.json",
|
|
5
|
+
"description": "Configuration for @cssdoc/core: custom tags and inherited configs.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"properties": {
|
|
9
|
+
"$schema": { "type": "string" },
|
|
10
|
+
"extends": {
|
|
11
|
+
"description": "Paths to other cssdoc.json files (or packages) to inherit tag definitions from.",
|
|
12
|
+
"type": "array",
|
|
13
|
+
"items": { "type": "string" }
|
|
14
|
+
},
|
|
15
|
+
"noStandardTags": {
|
|
16
|
+
"description": "Disable every built-in standard tag; only tagDefinitions remain supported.",
|
|
17
|
+
"type": "boolean"
|
|
18
|
+
},
|
|
19
|
+
"tagDefinitions": {
|
|
20
|
+
"description": "Custom tags to register.",
|
|
21
|
+
"type": "array",
|
|
22
|
+
"items": {
|
|
23
|
+
"type": "object",
|
|
24
|
+
"additionalProperties": false,
|
|
25
|
+
"required": ["tagName", "syntaxKind"],
|
|
26
|
+
"properties": {
|
|
27
|
+
"tagName": { "type": "string", "pattern": "^@?[a-zA-Z][a-zA-Z0-9-]*$" },
|
|
28
|
+
"syntaxKind": { "enum": ["record", "block", "modifier", "inline"] },
|
|
29
|
+
"allowMultiple": { "type": "boolean" },
|
|
30
|
+
"recordKind": { "enum": ["component", "utility", "rule", "declaration"] },
|
|
31
|
+
"aliasFor": { "type": "string" }
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"supportForTags": {
|
|
36
|
+
"description": "Enable or disable specific tags by name.",
|
|
37
|
+
"type": "object",
|
|
38
|
+
"additionalProperties": { "type": "boolean" }
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { CssDocConfiguration, CssDocTagDefinition } from "@cssdoc/core";
|
|
2
|
+
|
|
3
|
+
//#region src/CssDocConfigFile.d.ts
|
|
4
|
+
/** The conventional file name loaders look for. */
|
|
5
|
+
declare const CSSDOC_CONFIG_FILENAME = "cssdoc.json";
|
|
6
|
+
/** A loaded `cssdoc.json` (plus the files it `extends`), ready to configure a parser. */
|
|
7
|
+
declare class CssDocConfigFile {
|
|
8
|
+
/** The absolute path the file was loaded from (or would be, when not found). */
|
|
9
|
+
readonly filePath: string;
|
|
10
|
+
/** Whether the file was absent. */
|
|
11
|
+
readonly fileNotFound: boolean;
|
|
12
|
+
/** Parse/validation/resolution messages collected while loading (this file only). */
|
|
13
|
+
readonly messages: readonly string[];
|
|
14
|
+
/** Whether the file disables the standard tags. */
|
|
15
|
+
readonly noStandardTags: boolean;
|
|
16
|
+
/** The custom tag definitions declared by this file. */
|
|
17
|
+
readonly tagDefinitions: readonly CssDocTagDefinition[];
|
|
18
|
+
/** Per-tag support overrides declared by this file. */
|
|
19
|
+
readonly supportForTags: ReadonlyMap<string, boolean>;
|
|
20
|
+
/** The resolved files this one `extends`, in declaration order. */
|
|
21
|
+
readonly extendsFiles: readonly CssDocConfigFile[];
|
|
22
|
+
private constructor();
|
|
23
|
+
/** Whether this file — or any file it extends — reported an error. */
|
|
24
|
+
get hasErrors(): boolean;
|
|
25
|
+
/** A newline-joined summary of every message from this file and its `extends` chain. */
|
|
26
|
+
getErrorSummary(): string;
|
|
27
|
+
/**
|
|
28
|
+
* Apply this file (and its `extends` chain) onto a {@link CssDocConfiguration}. Extended files are
|
|
29
|
+
* applied first so this file's settings win.
|
|
30
|
+
*
|
|
31
|
+
* @param configuration - The configuration to mutate.
|
|
32
|
+
*/
|
|
33
|
+
configureParser(configuration: CssDocConfiguration): void;
|
|
34
|
+
/**
|
|
35
|
+
* Build a {@link CssDocConfiguration} from this file. Convenience for the common case.
|
|
36
|
+
*
|
|
37
|
+
* @returns A fresh configuration with this file applied.
|
|
38
|
+
*/
|
|
39
|
+
toConfiguration(): CssDocConfiguration;
|
|
40
|
+
/**
|
|
41
|
+
* Load a `cssdoc.json` from an exact path. Missing files yield a `fileNotFound` instance (not an
|
|
42
|
+
* error); malformed ones collect messages.
|
|
43
|
+
*
|
|
44
|
+
* @param filePath - The config file path (resolved to absolute).
|
|
45
|
+
* @returns The loaded config file.
|
|
46
|
+
*/
|
|
47
|
+
static loadFile(filePath: string): CssDocConfigFile;
|
|
48
|
+
/**
|
|
49
|
+
* Find and load the nearest `cssdoc.json`, walking upward from `folderPath` to the filesystem root.
|
|
50
|
+
*
|
|
51
|
+
* @param folderPath - The folder to start from.
|
|
52
|
+
* @returns The nearest config file, or a `fileNotFound` instance rooted at `folderPath`.
|
|
53
|
+
*/
|
|
54
|
+
static loadForFolder(folderPath: string): CssDocConfigFile;
|
|
55
|
+
private static _loadFile;
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/schema.d.ts
|
|
59
|
+
/**
|
|
60
|
+
* The JSON Schema for a `cssdoc.json` file — the single source of truth used to validate config files
|
|
61
|
+
* via ajv. A byte-identical copy is shipped at the package root as `cssdoc.schema.json` for editor
|
|
62
|
+
* `$schema` references.
|
|
63
|
+
*
|
|
64
|
+
* @module
|
|
65
|
+
*/
|
|
66
|
+
/** The JSON Schema (draft-07) describing a valid `cssdoc.json`. */
|
|
67
|
+
declare const cssDocSchema: {
|
|
68
|
+
readonly $schema: "http://json-schema.org/draft-07/schema#";
|
|
69
|
+
readonly $id: "https://cssdoc.dev/cssdoc.schema.json";
|
|
70
|
+
readonly title: "cssdoc.json";
|
|
71
|
+
readonly description: "Configuration for @cssdoc/core: custom tags and inherited configs.";
|
|
72
|
+
readonly type: "object";
|
|
73
|
+
readonly additionalProperties: false;
|
|
74
|
+
readonly properties: {
|
|
75
|
+
readonly $schema: {
|
|
76
|
+
readonly type: "string";
|
|
77
|
+
};
|
|
78
|
+
readonly extends: {
|
|
79
|
+
readonly description: "Paths to other cssdoc.json files (or packages) to inherit tag definitions from.";
|
|
80
|
+
readonly type: "array";
|
|
81
|
+
readonly items: {
|
|
82
|
+
readonly type: "string";
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
readonly noStandardTags: {
|
|
86
|
+
readonly description: "Disable every built-in standard tag; only tagDefinitions remain supported.";
|
|
87
|
+
readonly type: "boolean";
|
|
88
|
+
};
|
|
89
|
+
readonly tagDefinitions: {
|
|
90
|
+
readonly description: "Custom tags to register.";
|
|
91
|
+
readonly type: "array";
|
|
92
|
+
readonly items: {
|
|
93
|
+
readonly type: "object";
|
|
94
|
+
readonly additionalProperties: false;
|
|
95
|
+
readonly required: readonly ["tagName", "syntaxKind"];
|
|
96
|
+
readonly properties: {
|
|
97
|
+
readonly tagName: {
|
|
98
|
+
readonly type: "string";
|
|
99
|
+
readonly pattern: "^@?[a-zA-Z][a-zA-Z0-9-]*$";
|
|
100
|
+
};
|
|
101
|
+
readonly syntaxKind: {
|
|
102
|
+
readonly enum: readonly ["record", "block", "modifier", "inline"];
|
|
103
|
+
};
|
|
104
|
+
readonly allowMultiple: {
|
|
105
|
+
readonly type: "boolean";
|
|
106
|
+
};
|
|
107
|
+
readonly recordKind: {
|
|
108
|
+
readonly enum: readonly ["component", "utility", "rule", "declaration"];
|
|
109
|
+
};
|
|
110
|
+
readonly aliasFor: {
|
|
111
|
+
readonly type: "string";
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
readonly supportForTags: {
|
|
117
|
+
readonly description: "Enable or disable specific tags by name.";
|
|
118
|
+
readonly type: "object";
|
|
119
|
+
readonly additionalProperties: {
|
|
120
|
+
readonly type: "boolean";
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
//#endregion
|
|
126
|
+
export { CSSDOC_CONFIG_FILENAME, CssDocConfigFile, cssDocSchema };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { dirname, parse, resolve } from "node:path";
|
|
4
|
+
import { Ajv } from "ajv";
|
|
5
|
+
import { CssDocConfiguration, CssDocTagDefinition } from "@cssdoc/core";
|
|
6
|
+
//#region src/schema.ts
|
|
7
|
+
/**
|
|
8
|
+
* The JSON Schema for a `cssdoc.json` file — the single source of truth used to validate config files
|
|
9
|
+
* via ajv. A byte-identical copy is shipped at the package root as `cssdoc.schema.json` for editor
|
|
10
|
+
* `$schema` references.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
/** The JSON Schema (draft-07) describing a valid `cssdoc.json`. */
|
|
15
|
+
const cssDocSchema = {
|
|
16
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
17
|
+
$id: "https://cssdoc.dev/cssdoc.schema.json",
|
|
18
|
+
title: "cssdoc.json",
|
|
19
|
+
description: "Configuration for @cssdoc/core: custom tags and inherited configs.",
|
|
20
|
+
type: "object",
|
|
21
|
+
additionalProperties: false,
|
|
22
|
+
properties: {
|
|
23
|
+
$schema: { type: "string" },
|
|
24
|
+
extends: {
|
|
25
|
+
description: "Paths to other cssdoc.json files (or packages) to inherit tag definitions from.",
|
|
26
|
+
type: "array",
|
|
27
|
+
items: { type: "string" }
|
|
28
|
+
},
|
|
29
|
+
noStandardTags: {
|
|
30
|
+
description: "Disable every built-in standard tag; only tagDefinitions remain supported.",
|
|
31
|
+
type: "boolean"
|
|
32
|
+
},
|
|
33
|
+
tagDefinitions: {
|
|
34
|
+
description: "Custom tags to register.",
|
|
35
|
+
type: "array",
|
|
36
|
+
items: {
|
|
37
|
+
type: "object",
|
|
38
|
+
additionalProperties: false,
|
|
39
|
+
required: ["tagName", "syntaxKind"],
|
|
40
|
+
properties: {
|
|
41
|
+
tagName: {
|
|
42
|
+
type: "string",
|
|
43
|
+
pattern: "^@?[a-zA-Z][a-zA-Z0-9-]*$"
|
|
44
|
+
},
|
|
45
|
+
syntaxKind: { enum: [
|
|
46
|
+
"record",
|
|
47
|
+
"block",
|
|
48
|
+
"modifier",
|
|
49
|
+
"inline"
|
|
50
|
+
] },
|
|
51
|
+
allowMultiple: { type: "boolean" },
|
|
52
|
+
recordKind: { enum: [
|
|
53
|
+
"component",
|
|
54
|
+
"utility",
|
|
55
|
+
"rule",
|
|
56
|
+
"declaration"
|
|
57
|
+
] },
|
|
58
|
+
aliasFor: { type: "string" }
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
supportForTags: {
|
|
63
|
+
description: "Enable or disable specific tags by name.",
|
|
64
|
+
type: "object",
|
|
65
|
+
additionalProperties: { type: "boolean" }
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/CssDocConfigFile.ts
|
|
71
|
+
/**
|
|
72
|
+
* Load a `cssdoc.json` file into an `@cssdoc/core` {@link CssDocConfiguration} — cssdoc's analog to
|
|
73
|
+
* `@microsoft/tsdoc-config`'s `TSDocConfigFile`. It reads the file, validates it against the JSON
|
|
74
|
+
* schema (via ajv), resolves `extends` chains, and applies the result onto a configuration through
|
|
75
|
+
* {@link CssDocConfigFile.configureParser}. Errors are collected on the instance rather than thrown, so
|
|
76
|
+
* a malformed config degrades gracefully.
|
|
77
|
+
*
|
|
78
|
+
* @module
|
|
79
|
+
*/
|
|
80
|
+
const validateSchema = new Ajv({ allErrors: true }).compile(cssDocSchema);
|
|
81
|
+
/** The conventional file name loaders look for. */
|
|
82
|
+
const CSSDOC_CONFIG_FILENAME = "cssdoc.json";
|
|
83
|
+
/** A loaded `cssdoc.json` (plus the files it `extends`), ready to configure a parser. */
|
|
84
|
+
var CssDocConfigFile = class CssDocConfigFile {
|
|
85
|
+
/** The absolute path the file was loaded from (or would be, when not found). */
|
|
86
|
+
filePath;
|
|
87
|
+
/** Whether the file was absent. */
|
|
88
|
+
fileNotFound;
|
|
89
|
+
/** Parse/validation/resolution messages collected while loading (this file only). */
|
|
90
|
+
messages;
|
|
91
|
+
/** Whether the file disables the standard tags. */
|
|
92
|
+
noStandardTags;
|
|
93
|
+
/** The custom tag definitions declared by this file. */
|
|
94
|
+
tagDefinitions;
|
|
95
|
+
/** Per-tag support overrides declared by this file. */
|
|
96
|
+
supportForTags;
|
|
97
|
+
/** The resolved files this one `extends`, in declaration order. */
|
|
98
|
+
extendsFiles;
|
|
99
|
+
constructor(init) {
|
|
100
|
+
this.filePath = init.filePath;
|
|
101
|
+
this.fileNotFound = init.fileNotFound;
|
|
102
|
+
this.messages = init.messages;
|
|
103
|
+
this.noStandardTags = init.noStandardTags;
|
|
104
|
+
this.tagDefinitions = init.tagDefinitions;
|
|
105
|
+
this.supportForTags = init.supportForTags;
|
|
106
|
+
this.extendsFiles = init.extendsFiles;
|
|
107
|
+
}
|
|
108
|
+
/** Whether this file — or any file it extends — reported an error. */
|
|
109
|
+
get hasErrors() {
|
|
110
|
+
return this.messages.length > 0 || this.extendsFiles.some((f) => f.hasErrors);
|
|
111
|
+
}
|
|
112
|
+
/** A newline-joined summary of every message from this file and its `extends` chain. */
|
|
113
|
+
getErrorSummary() {
|
|
114
|
+
return [...this.messages.map((m) => `${this.filePath}: ${m}`), ...this.extendsFiles.map((f) => f.getErrorSummary())].filter(Boolean).join("\n");
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Apply this file (and its `extends` chain) onto a {@link CssDocConfiguration}. Extended files are
|
|
118
|
+
* applied first so this file's settings win.
|
|
119
|
+
*
|
|
120
|
+
* @param configuration - The configuration to mutate.
|
|
121
|
+
*/
|
|
122
|
+
configureParser(configuration) {
|
|
123
|
+
for (const extended of this.extendsFiles) extended.configureParser(configuration);
|
|
124
|
+
if (this.noStandardTags) configuration.setNoStandardTags();
|
|
125
|
+
configuration.addTagDefinitions(this.tagDefinitions, true);
|
|
126
|
+
for (const [tagName, supported] of this.supportForTags) {
|
|
127
|
+
const definition = configuration.tryGetTagDefinition(tagName);
|
|
128
|
+
if (definition) configuration.setSupportForTag(definition, supported);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Build a {@link CssDocConfiguration} from this file. Convenience for the common case.
|
|
133
|
+
*
|
|
134
|
+
* @returns A fresh configuration with this file applied.
|
|
135
|
+
*/
|
|
136
|
+
toConfiguration() {
|
|
137
|
+
const configuration = new CssDocConfiguration();
|
|
138
|
+
this.configureParser(configuration);
|
|
139
|
+
return configuration;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Load a `cssdoc.json` from an exact path. Missing files yield a `fileNotFound` instance (not an
|
|
143
|
+
* error); malformed ones collect messages.
|
|
144
|
+
*
|
|
145
|
+
* @param filePath - The config file path (resolved to absolute).
|
|
146
|
+
* @returns The loaded config file.
|
|
147
|
+
*/
|
|
148
|
+
static loadFile(filePath) {
|
|
149
|
+
return CssDocConfigFile._loadFile(resolve(filePath), /* @__PURE__ */ new Set());
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Find and load the nearest `cssdoc.json`, walking upward from `folderPath` to the filesystem root.
|
|
153
|
+
*
|
|
154
|
+
* @param folderPath - The folder to start from.
|
|
155
|
+
* @returns The nearest config file, or a `fileNotFound` instance rooted at `folderPath`.
|
|
156
|
+
*/
|
|
157
|
+
static loadForFolder(folderPath) {
|
|
158
|
+
let current = resolve(folderPath);
|
|
159
|
+
const root = parse(current).root;
|
|
160
|
+
for (;;) {
|
|
161
|
+
const candidate = resolve(current, CSSDOC_CONFIG_FILENAME);
|
|
162
|
+
if (existsSync(candidate)) return CssDocConfigFile._loadFile(candidate, /* @__PURE__ */ new Set());
|
|
163
|
+
if (current === root) break;
|
|
164
|
+
current = dirname(current);
|
|
165
|
+
}
|
|
166
|
+
return new CssDocConfigFile({
|
|
167
|
+
filePath: resolve(folderPath, CSSDOC_CONFIG_FILENAME),
|
|
168
|
+
fileNotFound: true,
|
|
169
|
+
messages: [],
|
|
170
|
+
noStandardTags: false,
|
|
171
|
+
tagDefinitions: [],
|
|
172
|
+
supportForTags: /* @__PURE__ */ new Map(),
|
|
173
|
+
extendsFiles: []
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
static _loadFile(filePath, visited) {
|
|
177
|
+
const messages = [];
|
|
178
|
+
const empty = (fileNotFound) => new CssDocConfigFile({
|
|
179
|
+
filePath,
|
|
180
|
+
fileNotFound,
|
|
181
|
+
messages,
|
|
182
|
+
noStandardTags: false,
|
|
183
|
+
tagDefinitions: [],
|
|
184
|
+
supportForTags: /* @__PURE__ */ new Map(),
|
|
185
|
+
extendsFiles: []
|
|
186
|
+
});
|
|
187
|
+
if (visited.has(filePath)) {
|
|
188
|
+
messages.push("Circular extends reference; skipped.");
|
|
189
|
+
return empty(false);
|
|
190
|
+
}
|
|
191
|
+
visited.add(filePath);
|
|
192
|
+
if (!existsSync(filePath)) return empty(true);
|
|
193
|
+
let raw;
|
|
194
|
+
try {
|
|
195
|
+
raw = JSON.parse(readFileSync(filePath, "utf8"));
|
|
196
|
+
} catch (error) {
|
|
197
|
+
messages.push(`Invalid JSON: ${error.message}`);
|
|
198
|
+
return empty(false);
|
|
199
|
+
}
|
|
200
|
+
if (!validateSchema(raw)) {
|
|
201
|
+
for (const err of validateSchema.errors ?? []) messages.push(`Schema error at ${err.instancePath || "/"}: ${err.message ?? "invalid"}`);
|
|
202
|
+
return empty(false);
|
|
203
|
+
}
|
|
204
|
+
const requireFrom = createRequire(filePath);
|
|
205
|
+
const extendsFiles = [];
|
|
206
|
+
for (const ref of raw.extends ?? []) {
|
|
207
|
+
let resolved;
|
|
208
|
+
try {
|
|
209
|
+
resolved = ref.startsWith(".") ? resolve(dirname(filePath), ref) : requireFrom.resolve(ref);
|
|
210
|
+
} catch (error) {
|
|
211
|
+
messages.push(`Cannot resolve extends "${ref}": ${error.message}`);
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
extendsFiles.push(CssDocConfigFile._loadFile(resolved, visited));
|
|
215
|
+
}
|
|
216
|
+
const tagDefinitions = [];
|
|
217
|
+
for (const raw_ of raw.tagDefinitions ?? []) try {
|
|
218
|
+
tagDefinitions.push(new CssDocTagDefinition(raw_));
|
|
219
|
+
} catch (error) {
|
|
220
|
+
messages.push(error.message);
|
|
221
|
+
}
|
|
222
|
+
return new CssDocConfigFile({
|
|
223
|
+
filePath,
|
|
224
|
+
fileNotFound: false,
|
|
225
|
+
messages,
|
|
226
|
+
noStandardTags: raw.noStandardTags ?? false,
|
|
227
|
+
tagDefinitions,
|
|
228
|
+
supportForTags: new Map(Object.entries(raw.supportForTags ?? {})),
|
|
229
|
+
extendsFiles
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
//#endregion
|
|
234
|
+
export { CSSDOC_CONFIG_FILENAME, CssDocConfigFile, cssDocSchema };
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cssdoc/config",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Load a cssdoc.json configuration file (custom tags, extends) into an @cssdoc/core CssDocConfiguration — TSDoc-config, for CSS.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"config",
|
|
7
|
+
"css",
|
|
8
|
+
"cssdoc",
|
|
9
|
+
"documentation",
|
|
10
|
+
"tsdoc"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://cssdoc.dev",
|
|
13
|
+
"bugs": "https://github.com/thedannywahl/cssdoc/issues",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/thedannywahl/cssdoc.git",
|
|
18
|
+
"directory": "packages/config"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"cssdoc.schema.json"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": "./dist/index.mjs",
|
|
27
|
+
"./package.json": "./package.json"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"ajv": "^8.20.0",
|
|
34
|
+
"@cssdoc/core": "0.1.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^24.13.3",
|
|
38
|
+
"publint": "^0.3.21",
|
|
39
|
+
"typescript": "^6.0.3",
|
|
40
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@0.2.4",
|
|
41
|
+
"vite-plus": "0.2.4"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "vp pack",
|
|
45
|
+
"dev": "vp pack --watch",
|
|
46
|
+
"test": "vp test",
|
|
47
|
+
"check": "vp check",
|
|
48
|
+
"publint": "publint"
|
|
49
|
+
}
|
|
50
|
+
}
|