@barodoc/core 0.0.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.
- package/LICENSE +21 -0
- package/dist/chunk-JQRBNHRZ.js +103 -0
- package/dist/chunk-QMKA7OJU.js +61 -0
- package/dist/chunk-UICDSNBG.js +68 -0
- package/dist/config/index.d.ts +211 -0
- package/dist/config/index.js +10 -0
- package/dist/i18n/index.d.ts +14 -0
- package/dist/i18n/index.js +16 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +100 -0
- package/dist/plugins/index.d.ts +27 -0
- package/dist/plugins/index.js +14 -0
- package/dist/types-DaMSwPOk.d.ts +151 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Barocss
|
|
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.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// src/config/schema.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var navItemSchema = z.object({
|
|
4
|
+
group: z.string(),
|
|
5
|
+
pages: z.array(z.string())
|
|
6
|
+
}).passthrough();
|
|
7
|
+
var i18nConfigSchema = z.object({
|
|
8
|
+
defaultLocale: z.string(),
|
|
9
|
+
locales: z.array(z.string()),
|
|
10
|
+
labels: z.record(z.string()).optional()
|
|
11
|
+
}).optional();
|
|
12
|
+
var themeColorsSchema = z.object({
|
|
13
|
+
primary: z.string().optional(),
|
|
14
|
+
background: z.string().optional(),
|
|
15
|
+
backgroundDark: z.string().optional(),
|
|
16
|
+
text: z.string().optional(),
|
|
17
|
+
textDark: z.string().optional(),
|
|
18
|
+
border: z.string().optional(),
|
|
19
|
+
borderDark: z.string().optional()
|
|
20
|
+
}).optional();
|
|
21
|
+
var themeConfigSchema = z.object({
|
|
22
|
+
colors: themeColorsSchema,
|
|
23
|
+
fonts: z.object({
|
|
24
|
+
heading: z.string().optional(),
|
|
25
|
+
body: z.string().optional(),
|
|
26
|
+
code: z.string().optional()
|
|
27
|
+
}).optional(),
|
|
28
|
+
radius: z.string().optional()
|
|
29
|
+
}).optional();
|
|
30
|
+
var topbarSchema = z.object({
|
|
31
|
+
github: z.string().optional(),
|
|
32
|
+
discord: z.string().optional(),
|
|
33
|
+
twitter: z.string().optional()
|
|
34
|
+
}).optional();
|
|
35
|
+
var searchSchema = z.object({
|
|
36
|
+
enabled: z.boolean().optional()
|
|
37
|
+
}).optional();
|
|
38
|
+
var barodocConfigSchema = z.object({
|
|
39
|
+
name: z.string(),
|
|
40
|
+
logo: z.string().optional(),
|
|
41
|
+
favicon: z.string().optional(),
|
|
42
|
+
theme: themeConfigSchema,
|
|
43
|
+
i18n: i18nConfigSchema,
|
|
44
|
+
navigation: z.array(navItemSchema),
|
|
45
|
+
topbar: topbarSchema,
|
|
46
|
+
search: searchSchema,
|
|
47
|
+
customCss: z.array(z.string()).optional()
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// src/config/loader.ts
|
|
51
|
+
import fs from "fs";
|
|
52
|
+
import path from "path";
|
|
53
|
+
async function loadConfig(configPath, root) {
|
|
54
|
+
const absolutePath = path.isAbsolute(configPath) ? configPath : path.resolve(root, configPath);
|
|
55
|
+
if (!fs.existsSync(absolutePath)) {
|
|
56
|
+
throw new Error(`Barodoc config not found: ${absolutePath}`);
|
|
57
|
+
}
|
|
58
|
+
const content = fs.readFileSync(absolutePath, "utf-8");
|
|
59
|
+
const rawConfig = JSON.parse(content);
|
|
60
|
+
const result = barodocConfigSchema.safeParse(rawConfig);
|
|
61
|
+
if (!result.success) {
|
|
62
|
+
const errors = result.error.errors.map((e) => ` - ${e.path.join(".")}: ${e.message}`).join("\n");
|
|
63
|
+
throw new Error(`Invalid barodoc.config.json:
|
|
64
|
+
${errors}`);
|
|
65
|
+
}
|
|
66
|
+
const config = result.data;
|
|
67
|
+
if (!config.i18n) {
|
|
68
|
+
config.i18n = {
|
|
69
|
+
defaultLocale: "en",
|
|
70
|
+
locales: ["en"]
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (!config.search) {
|
|
74
|
+
config.search = { enabled: true };
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
...config,
|
|
78
|
+
_resolved: true,
|
|
79
|
+
_configPath: absolutePath
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function getConfigDefaults() {
|
|
83
|
+
return {
|
|
84
|
+
i18n: {
|
|
85
|
+
defaultLocale: "en",
|
|
86
|
+
locales: ["en"]
|
|
87
|
+
},
|
|
88
|
+
search: {
|
|
89
|
+
enabled: true
|
|
90
|
+
},
|
|
91
|
+
theme: {
|
|
92
|
+
colors: {
|
|
93
|
+
primary: "#0070f3"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export {
|
|
100
|
+
barodocConfigSchema,
|
|
101
|
+
loadConfig,
|
|
102
|
+
getConfigDefaults
|
|
103
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/i18n/utils.ts
|
|
2
|
+
function getLocaleFromPath(path, i18n) {
|
|
3
|
+
const segments = path.split("/").filter(Boolean);
|
|
4
|
+
const firstSegment = segments[0];
|
|
5
|
+
if (firstSegment && i18n.locales.includes(firstSegment)) {
|
|
6
|
+
return firstSegment;
|
|
7
|
+
}
|
|
8
|
+
return i18n.defaultLocale;
|
|
9
|
+
}
|
|
10
|
+
function removeLocaleFromPath(path, i18n) {
|
|
11
|
+
const segments = path.split("/").filter(Boolean);
|
|
12
|
+
const firstSegment = segments[0];
|
|
13
|
+
if (firstSegment && i18n.locales.includes(firstSegment)) {
|
|
14
|
+
return "/" + segments.slice(1).join("/");
|
|
15
|
+
}
|
|
16
|
+
return path;
|
|
17
|
+
}
|
|
18
|
+
function getLocalizedPath(path, locale, i18n) {
|
|
19
|
+
const cleanPath = removeLocaleFromPath(path, i18n);
|
|
20
|
+
if (locale === i18n.defaultLocale) {
|
|
21
|
+
return cleanPath;
|
|
22
|
+
}
|
|
23
|
+
return `/${locale}${cleanPath}`;
|
|
24
|
+
}
|
|
25
|
+
function getLocalizedNavGroup(item, locale, defaultLocale) {
|
|
26
|
+
if (locale === defaultLocale) {
|
|
27
|
+
return item.group;
|
|
28
|
+
}
|
|
29
|
+
const localizedKey = `group:${locale}`;
|
|
30
|
+
return item[localizedKey] || item.group;
|
|
31
|
+
}
|
|
32
|
+
function getLocaleLabel(locale, labels) {
|
|
33
|
+
if (labels && labels[locale]) {
|
|
34
|
+
return labels[locale];
|
|
35
|
+
}
|
|
36
|
+
const defaultLabels = {
|
|
37
|
+
en: "English",
|
|
38
|
+
ko: "\uD55C\uAD6D\uC5B4",
|
|
39
|
+
ja: "\u65E5\u672C\u8A9E",
|
|
40
|
+
zh: "\u4E2D\u6587",
|
|
41
|
+
es: "Espa\xF1ol",
|
|
42
|
+
fr: "Fran\xE7ais",
|
|
43
|
+
de: "Deutsch"
|
|
44
|
+
};
|
|
45
|
+
return defaultLabels[locale] || locale.toUpperCase();
|
|
46
|
+
}
|
|
47
|
+
function getAllLocalePaths(basePath, i18n) {
|
|
48
|
+
return i18n.locales.map((locale) => ({
|
|
49
|
+
locale,
|
|
50
|
+
path: getLocalizedPath(basePath, locale, i18n)
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export {
|
|
55
|
+
getLocaleFromPath,
|
|
56
|
+
removeLocaleFromPath,
|
|
57
|
+
getLocalizedPath,
|
|
58
|
+
getLocalizedNavGroup,
|
|
59
|
+
getLocaleLabel,
|
|
60
|
+
getAllLocalePaths
|
|
61
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// src/plugins/loader.ts
|
|
2
|
+
async function loadPlugins(pluginConfigs, context) {
|
|
3
|
+
const resolved = [];
|
|
4
|
+
for (const config of pluginConfigs) {
|
|
5
|
+
const [name, options] = Array.isArray(config) ? config : [config, void 0];
|
|
6
|
+
try {
|
|
7
|
+
const pluginModule = await import(
|
|
8
|
+
/* @vite-ignore */
|
|
9
|
+
name
|
|
10
|
+
);
|
|
11
|
+
const pluginFactory = pluginModule.default || pluginModule;
|
|
12
|
+
if (typeof pluginFactory !== "function") {
|
|
13
|
+
throw new Error(`Plugin ${name} does not export a factory function`);
|
|
14
|
+
}
|
|
15
|
+
const plugin = options ? pluginFactory(options) : pluginFactory();
|
|
16
|
+
resolved.push({
|
|
17
|
+
name,
|
|
18
|
+
plugin,
|
|
19
|
+
options
|
|
20
|
+
});
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.warn(`Failed to load plugin ${name}:`, error);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return resolved;
|
|
26
|
+
}
|
|
27
|
+
async function runHook(plugins, hookName, ...args) {
|
|
28
|
+
for (const { plugin, name } of plugins) {
|
|
29
|
+
const hook = plugin.hooks?.[hookName];
|
|
30
|
+
if (hook) {
|
|
31
|
+
try {
|
|
32
|
+
await hook(...args);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error(`Error in plugin ${name} hook ${hookName}:`, error);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function runConfigHook(plugins, config, context) {
|
|
40
|
+
let result = config;
|
|
41
|
+
for (const { plugin, name } of plugins) {
|
|
42
|
+
const hook = plugin.hooks?.["config:loaded"];
|
|
43
|
+
if (hook) {
|
|
44
|
+
try {
|
|
45
|
+
result = await hook(result, context);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error(`Error in plugin ${name} config:loaded hook:`, error);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
function getPluginIntegrations(plugins, context) {
|
|
54
|
+
return plugins.filter((p) => p.plugin.astroIntegration).map((p) => p.plugin.astroIntegration(context));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/plugins/index.ts
|
|
58
|
+
function definePlugin(factory) {
|
|
59
|
+
return factory;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export {
|
|
63
|
+
loadPlugins,
|
|
64
|
+
runHook,
|
|
65
|
+
runConfigHook,
|
|
66
|
+
getPluginIntegrations,
|
|
67
|
+
definePlugin
|
|
68
|
+
};
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { R as ResolvedBarodocConfig, a as BarodocConfig } from '../types-DaMSwPOk.js';
|
|
3
|
+
import 'astro';
|
|
4
|
+
|
|
5
|
+
declare const barodocConfigSchema: z.ZodObject<{
|
|
6
|
+
name: z.ZodString;
|
|
7
|
+
logo: z.ZodOptional<z.ZodString>;
|
|
8
|
+
favicon: z.ZodOptional<z.ZodString>;
|
|
9
|
+
theme: z.ZodOptional<z.ZodObject<{
|
|
10
|
+
colors: z.ZodOptional<z.ZodObject<{
|
|
11
|
+
primary: z.ZodOptional<z.ZodString>;
|
|
12
|
+
background: z.ZodOptional<z.ZodString>;
|
|
13
|
+
backgroundDark: z.ZodOptional<z.ZodString>;
|
|
14
|
+
text: z.ZodOptional<z.ZodString>;
|
|
15
|
+
textDark: z.ZodOptional<z.ZodString>;
|
|
16
|
+
border: z.ZodOptional<z.ZodString>;
|
|
17
|
+
borderDark: z.ZodOptional<z.ZodString>;
|
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
primary?: string | undefined;
|
|
20
|
+
background?: string | undefined;
|
|
21
|
+
backgroundDark?: string | undefined;
|
|
22
|
+
text?: string | undefined;
|
|
23
|
+
textDark?: string | undefined;
|
|
24
|
+
border?: string | undefined;
|
|
25
|
+
borderDark?: string | undefined;
|
|
26
|
+
}, {
|
|
27
|
+
primary?: string | undefined;
|
|
28
|
+
background?: string | undefined;
|
|
29
|
+
backgroundDark?: string | undefined;
|
|
30
|
+
text?: string | undefined;
|
|
31
|
+
textDark?: string | undefined;
|
|
32
|
+
border?: string | undefined;
|
|
33
|
+
borderDark?: string | undefined;
|
|
34
|
+
}>>;
|
|
35
|
+
fonts: z.ZodOptional<z.ZodObject<{
|
|
36
|
+
heading: z.ZodOptional<z.ZodString>;
|
|
37
|
+
body: z.ZodOptional<z.ZodString>;
|
|
38
|
+
code: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
code?: string | undefined;
|
|
41
|
+
heading?: string | undefined;
|
|
42
|
+
body?: string | undefined;
|
|
43
|
+
}, {
|
|
44
|
+
code?: string | undefined;
|
|
45
|
+
heading?: string | undefined;
|
|
46
|
+
body?: string | undefined;
|
|
47
|
+
}>>;
|
|
48
|
+
radius: z.ZodOptional<z.ZodString>;
|
|
49
|
+
}, "strip", z.ZodTypeAny, {
|
|
50
|
+
colors?: {
|
|
51
|
+
primary?: string | undefined;
|
|
52
|
+
background?: string | undefined;
|
|
53
|
+
backgroundDark?: string | undefined;
|
|
54
|
+
text?: string | undefined;
|
|
55
|
+
textDark?: string | undefined;
|
|
56
|
+
border?: string | undefined;
|
|
57
|
+
borderDark?: string | undefined;
|
|
58
|
+
} | undefined;
|
|
59
|
+
fonts?: {
|
|
60
|
+
code?: string | undefined;
|
|
61
|
+
heading?: string | undefined;
|
|
62
|
+
body?: string | undefined;
|
|
63
|
+
} | undefined;
|
|
64
|
+
radius?: string | undefined;
|
|
65
|
+
}, {
|
|
66
|
+
colors?: {
|
|
67
|
+
primary?: string | undefined;
|
|
68
|
+
background?: string | undefined;
|
|
69
|
+
backgroundDark?: string | undefined;
|
|
70
|
+
text?: string | undefined;
|
|
71
|
+
textDark?: string | undefined;
|
|
72
|
+
border?: string | undefined;
|
|
73
|
+
borderDark?: string | undefined;
|
|
74
|
+
} | undefined;
|
|
75
|
+
fonts?: {
|
|
76
|
+
code?: string | undefined;
|
|
77
|
+
heading?: string | undefined;
|
|
78
|
+
body?: string | undefined;
|
|
79
|
+
} | undefined;
|
|
80
|
+
radius?: string | undefined;
|
|
81
|
+
}>>;
|
|
82
|
+
i18n: z.ZodOptional<z.ZodObject<{
|
|
83
|
+
defaultLocale: z.ZodString;
|
|
84
|
+
locales: z.ZodArray<z.ZodString, "many">;
|
|
85
|
+
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
86
|
+
}, "strip", z.ZodTypeAny, {
|
|
87
|
+
defaultLocale: string;
|
|
88
|
+
locales: string[];
|
|
89
|
+
labels?: Record<string, string> | undefined;
|
|
90
|
+
}, {
|
|
91
|
+
defaultLocale: string;
|
|
92
|
+
locales: string[];
|
|
93
|
+
labels?: Record<string, string> | undefined;
|
|
94
|
+
}>>;
|
|
95
|
+
navigation: z.ZodArray<z.ZodObject<{
|
|
96
|
+
group: z.ZodString;
|
|
97
|
+
pages: z.ZodArray<z.ZodString, "many">;
|
|
98
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
99
|
+
group: z.ZodString;
|
|
100
|
+
pages: z.ZodArray<z.ZodString, "many">;
|
|
101
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
102
|
+
group: z.ZodString;
|
|
103
|
+
pages: z.ZodArray<z.ZodString, "many">;
|
|
104
|
+
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
105
|
+
topbar: z.ZodOptional<z.ZodObject<{
|
|
106
|
+
github: z.ZodOptional<z.ZodString>;
|
|
107
|
+
discord: z.ZodOptional<z.ZodString>;
|
|
108
|
+
twitter: z.ZodOptional<z.ZodString>;
|
|
109
|
+
}, "strip", z.ZodTypeAny, {
|
|
110
|
+
github?: string | undefined;
|
|
111
|
+
discord?: string | undefined;
|
|
112
|
+
twitter?: string | undefined;
|
|
113
|
+
}, {
|
|
114
|
+
github?: string | undefined;
|
|
115
|
+
discord?: string | undefined;
|
|
116
|
+
twitter?: string | undefined;
|
|
117
|
+
}>>;
|
|
118
|
+
search: z.ZodOptional<z.ZodObject<{
|
|
119
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
120
|
+
}, "strip", z.ZodTypeAny, {
|
|
121
|
+
enabled?: boolean | undefined;
|
|
122
|
+
}, {
|
|
123
|
+
enabled?: boolean | undefined;
|
|
124
|
+
}>>;
|
|
125
|
+
customCss: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
126
|
+
}, "strip", z.ZodTypeAny, {
|
|
127
|
+
name: string;
|
|
128
|
+
navigation: z.objectOutputType<{
|
|
129
|
+
group: z.ZodString;
|
|
130
|
+
pages: z.ZodArray<z.ZodString, "many">;
|
|
131
|
+
}, z.ZodTypeAny, "passthrough">[];
|
|
132
|
+
logo?: string | undefined;
|
|
133
|
+
favicon?: string | undefined;
|
|
134
|
+
theme?: {
|
|
135
|
+
colors?: {
|
|
136
|
+
primary?: string | undefined;
|
|
137
|
+
background?: string | undefined;
|
|
138
|
+
backgroundDark?: string | undefined;
|
|
139
|
+
text?: string | undefined;
|
|
140
|
+
textDark?: string | undefined;
|
|
141
|
+
border?: string | undefined;
|
|
142
|
+
borderDark?: string | undefined;
|
|
143
|
+
} | undefined;
|
|
144
|
+
fonts?: {
|
|
145
|
+
code?: string | undefined;
|
|
146
|
+
heading?: string | undefined;
|
|
147
|
+
body?: string | undefined;
|
|
148
|
+
} | undefined;
|
|
149
|
+
radius?: string | undefined;
|
|
150
|
+
} | undefined;
|
|
151
|
+
i18n?: {
|
|
152
|
+
defaultLocale: string;
|
|
153
|
+
locales: string[];
|
|
154
|
+
labels?: Record<string, string> | undefined;
|
|
155
|
+
} | undefined;
|
|
156
|
+
topbar?: {
|
|
157
|
+
github?: string | undefined;
|
|
158
|
+
discord?: string | undefined;
|
|
159
|
+
twitter?: string | undefined;
|
|
160
|
+
} | undefined;
|
|
161
|
+
search?: {
|
|
162
|
+
enabled?: boolean | undefined;
|
|
163
|
+
} | undefined;
|
|
164
|
+
customCss?: string[] | undefined;
|
|
165
|
+
}, {
|
|
166
|
+
name: string;
|
|
167
|
+
navigation: z.objectInputType<{
|
|
168
|
+
group: z.ZodString;
|
|
169
|
+
pages: z.ZodArray<z.ZodString, "many">;
|
|
170
|
+
}, z.ZodTypeAny, "passthrough">[];
|
|
171
|
+
logo?: string | undefined;
|
|
172
|
+
favicon?: string | undefined;
|
|
173
|
+
theme?: {
|
|
174
|
+
colors?: {
|
|
175
|
+
primary?: string | undefined;
|
|
176
|
+
background?: string | undefined;
|
|
177
|
+
backgroundDark?: string | undefined;
|
|
178
|
+
text?: string | undefined;
|
|
179
|
+
textDark?: string | undefined;
|
|
180
|
+
border?: string | undefined;
|
|
181
|
+
borderDark?: string | undefined;
|
|
182
|
+
} | undefined;
|
|
183
|
+
fonts?: {
|
|
184
|
+
code?: string | undefined;
|
|
185
|
+
heading?: string | undefined;
|
|
186
|
+
body?: string | undefined;
|
|
187
|
+
} | undefined;
|
|
188
|
+
radius?: string | undefined;
|
|
189
|
+
} | undefined;
|
|
190
|
+
i18n?: {
|
|
191
|
+
defaultLocale: string;
|
|
192
|
+
locales: string[];
|
|
193
|
+
labels?: Record<string, string> | undefined;
|
|
194
|
+
} | undefined;
|
|
195
|
+
topbar?: {
|
|
196
|
+
github?: string | undefined;
|
|
197
|
+
discord?: string | undefined;
|
|
198
|
+
twitter?: string | undefined;
|
|
199
|
+
} | undefined;
|
|
200
|
+
search?: {
|
|
201
|
+
enabled?: boolean | undefined;
|
|
202
|
+
} | undefined;
|
|
203
|
+
customCss?: string[] | undefined;
|
|
204
|
+
}>;
|
|
205
|
+
type BarodocConfigInput = z.input<typeof barodocConfigSchema>;
|
|
206
|
+
type BarodocConfigOutput = z.output<typeof barodocConfigSchema>;
|
|
207
|
+
|
|
208
|
+
declare function loadConfig(configPath: string, root: string): Promise<ResolvedBarodocConfig>;
|
|
209
|
+
declare function getConfigDefaults(): Partial<BarodocConfig>;
|
|
210
|
+
|
|
211
|
+
export { type BarodocConfigInput, type BarodocConfigOutput, barodocConfigSchema, getConfigDefaults, loadConfig };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { b as BarodocI18nConfig, c as BarodocNavItem } from '../types-DaMSwPOk.js';
|
|
2
|
+
import 'astro';
|
|
3
|
+
|
|
4
|
+
declare function getLocaleFromPath(path: string, i18n: BarodocI18nConfig): string;
|
|
5
|
+
declare function removeLocaleFromPath(path: string, i18n: BarodocI18nConfig): string;
|
|
6
|
+
declare function getLocalizedPath(path: string, locale: string, i18n: BarodocI18nConfig): string;
|
|
7
|
+
declare function getLocalizedNavGroup(item: BarodocNavItem, locale: string, defaultLocale: string): string;
|
|
8
|
+
declare function getLocaleLabel(locale: string, labels?: Record<string, string>): string;
|
|
9
|
+
declare function getAllLocalePaths(basePath: string, i18n: BarodocI18nConfig): Array<{
|
|
10
|
+
locale: string;
|
|
11
|
+
path: string;
|
|
12
|
+
}>;
|
|
13
|
+
|
|
14
|
+
export { getAllLocalePaths, getLocaleFromPath, getLocaleLabel, getLocalizedNavGroup, getLocalizedPath, removeLocaleFromPath };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getAllLocalePaths,
|
|
3
|
+
getLocaleFromPath,
|
|
4
|
+
getLocaleLabel,
|
|
5
|
+
getLocalizedNavGroup,
|
|
6
|
+
getLocalizedPath,
|
|
7
|
+
removeLocaleFromPath
|
|
8
|
+
} from "../chunk-QMKA7OJU.js";
|
|
9
|
+
export {
|
|
10
|
+
getAllLocalePaths,
|
|
11
|
+
getLocaleFromPath,
|
|
12
|
+
getLocaleLabel,
|
|
13
|
+
getLocalizedNavGroup,
|
|
14
|
+
getLocalizedPath,
|
|
15
|
+
removeLocaleFromPath
|
|
16
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AstroIntegration } from 'astro';
|
|
2
|
+
import { B as BarodocOptions } from './types-DaMSwPOk.js';
|
|
3
|
+
export { a as BarodocConfig, b as BarodocI18nConfig, c as BarodocNavItem, d as BarodocPlugin, e as BarodocPluginFactory, f as BarodocPluginHooks, g as BarodocThemeColors, h as BarodocThemeConfig, i as BuildContext, C as ContentContext, P as PluginConfig, j as PluginContext, R as ResolvedBarodocConfig, k as ResolvedPlugin, T as ThemeExport } from './types-DaMSwPOk.js';
|
|
4
|
+
export { barodocConfigSchema, loadConfig } from './config/index.js';
|
|
5
|
+
export { getLocaleFromPath, getLocaleLabel, getLocalizedNavGroup, getLocalizedPath, removeLocaleFromPath } from './i18n/index.js';
|
|
6
|
+
export { definePlugin, getPluginIntegrations, loadPlugins, runConfigHook, runHook } from './plugins/index.js';
|
|
7
|
+
import 'zod';
|
|
8
|
+
|
|
9
|
+
declare function barodoc(options: BarodocOptions): AstroIntegration;
|
|
10
|
+
|
|
11
|
+
export { BarodocOptions, barodoc as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {
|
|
2
|
+
barodocConfigSchema,
|
|
3
|
+
loadConfig
|
|
4
|
+
} from "./chunk-JQRBNHRZ.js";
|
|
5
|
+
import {
|
|
6
|
+
getLocaleFromPath,
|
|
7
|
+
getLocaleLabel,
|
|
8
|
+
getLocalizedNavGroup,
|
|
9
|
+
getLocalizedPath,
|
|
10
|
+
removeLocaleFromPath
|
|
11
|
+
} from "./chunk-QMKA7OJU.js";
|
|
12
|
+
import {
|
|
13
|
+
definePlugin,
|
|
14
|
+
getPluginIntegrations,
|
|
15
|
+
loadPlugins,
|
|
16
|
+
runConfigHook,
|
|
17
|
+
runHook
|
|
18
|
+
} from "./chunk-UICDSNBG.js";
|
|
19
|
+
|
|
20
|
+
// src/integration.ts
|
|
21
|
+
var VIRTUAL_CONFIG_ID = "virtual:barodoc/config";
|
|
22
|
+
var VIRTUAL_I18N_ID = "virtual:barodoc/i18n";
|
|
23
|
+
function resolveVirtualId(id) {
|
|
24
|
+
return `\0${id}`;
|
|
25
|
+
}
|
|
26
|
+
function createVirtualModulesPlugin(config) {
|
|
27
|
+
return {
|
|
28
|
+
name: "barodoc:virtual-modules",
|
|
29
|
+
resolveId(id) {
|
|
30
|
+
if (id === VIRTUAL_CONFIG_ID || id === VIRTUAL_I18N_ID) {
|
|
31
|
+
return resolveVirtualId(id);
|
|
32
|
+
}
|
|
33
|
+
return void 0;
|
|
34
|
+
},
|
|
35
|
+
load(id) {
|
|
36
|
+
if (id === resolveVirtualId(VIRTUAL_CONFIG_ID)) {
|
|
37
|
+
return `export default ${JSON.stringify(config)};`;
|
|
38
|
+
}
|
|
39
|
+
if (id === resolveVirtualId(VIRTUAL_I18N_ID)) {
|
|
40
|
+
return `
|
|
41
|
+
export const i18n = ${JSON.stringify(config.i18n)};
|
|
42
|
+
export const defaultLocale = "${config.i18n?.defaultLocale || "en"}";
|
|
43
|
+
export const locales = ${JSON.stringify(config.i18n?.locales || ["en"])};
|
|
44
|
+
`;
|
|
45
|
+
}
|
|
46
|
+
return void 0;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function barodoc(options) {
|
|
51
|
+
const configPath = options.config || "barodoc.config.json";
|
|
52
|
+
let resolvedConfig;
|
|
53
|
+
return {
|
|
54
|
+
name: "@barodoc/core",
|
|
55
|
+
hooks: {
|
|
56
|
+
"astro:config:setup": async ({
|
|
57
|
+
config,
|
|
58
|
+
updateConfig,
|
|
59
|
+
logger
|
|
60
|
+
}) => {
|
|
61
|
+
logger.info("Loading Barodoc configuration...");
|
|
62
|
+
const rootPath = config.root instanceof URL ? config.root.pathname : String(config.root);
|
|
63
|
+
resolvedConfig = await loadConfig(configPath, rootPath);
|
|
64
|
+
logger.info(`Loaded config: ${resolvedConfig.name}`);
|
|
65
|
+
const i18nConfig = resolvedConfig.i18n || {
|
|
66
|
+
defaultLocale: "en",
|
|
67
|
+
locales: ["en"]
|
|
68
|
+
};
|
|
69
|
+
const themeIntegration = options.theme.integration();
|
|
70
|
+
updateConfig({
|
|
71
|
+
vite: {
|
|
72
|
+
plugins: [createVirtualModulesPlugin(resolvedConfig)]
|
|
73
|
+
},
|
|
74
|
+
integrations: [themeIntegration]
|
|
75
|
+
});
|
|
76
|
+
logger.info(
|
|
77
|
+
`i18n configured: ${i18nConfig.locales.length} locale(s)`
|
|
78
|
+
);
|
|
79
|
+
},
|
|
80
|
+
"astro:config:done": ({ logger }) => {
|
|
81
|
+
logger.info("Barodoc setup complete");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export {
|
|
87
|
+
barodocConfigSchema,
|
|
88
|
+
barodoc as default,
|
|
89
|
+
definePlugin,
|
|
90
|
+
getLocaleFromPath,
|
|
91
|
+
getLocaleLabel,
|
|
92
|
+
getLocalizedNavGroup,
|
|
93
|
+
getLocalizedPath,
|
|
94
|
+
getPluginIntegrations,
|
|
95
|
+
loadConfig,
|
|
96
|
+
loadPlugins,
|
|
97
|
+
removeLocaleFromPath,
|
|
98
|
+
runConfigHook,
|
|
99
|
+
runHook
|
|
100
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { k as ResolvedPlugin, j as PluginContext, P as PluginConfig, R as ResolvedBarodocConfig, f as BarodocPluginHooks, d as BarodocPlugin } from '../types-DaMSwPOk.js';
|
|
2
|
+
export { e as BarodocPluginFactory, i as BuildContext, C as ContentContext } from '../types-DaMSwPOk.js';
|
|
3
|
+
import * as astro from 'astro';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Load plugins from config
|
|
7
|
+
*/
|
|
8
|
+
declare function loadPlugins(pluginConfigs: PluginConfig[], context: PluginContext): Promise<ResolvedPlugin[]>;
|
|
9
|
+
/**
|
|
10
|
+
* Run a specific hook for all plugins
|
|
11
|
+
*/
|
|
12
|
+
declare function runHook<K extends keyof BarodocPluginHooks>(plugins: ResolvedPlugin[], hookName: K, ...args: Parameters<NonNullable<BarodocPluginHooks[K]>>): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Run config:loaded hook and return modified config
|
|
15
|
+
*/
|
|
16
|
+
declare function runConfigHook(plugins: ResolvedPlugin[], config: ResolvedBarodocConfig, context: PluginContext): Promise<ResolvedBarodocConfig>;
|
|
17
|
+
/**
|
|
18
|
+
* Get Astro integrations from plugins
|
|
19
|
+
*/
|
|
20
|
+
declare function getPluginIntegrations(plugins: ResolvedPlugin[], context: PluginContext): astro.AstroIntegration[];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Helper to define a plugin with type safety
|
|
24
|
+
*/
|
|
25
|
+
declare function definePlugin<T = void>(factory: T extends void ? () => BarodocPlugin : (options: T) => BarodocPlugin): T extends void ? () => BarodocPlugin : (options: T) => BarodocPlugin;
|
|
26
|
+
|
|
27
|
+
export { BarodocPlugin, BarodocPluginHooks, PluginConfig, PluginContext, ResolvedPlugin, definePlugin, getPluginIntegrations, loadPlugins, runConfigHook, runHook };
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { AstroIntegration } from 'astro';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Plugin hook context
|
|
5
|
+
*/
|
|
6
|
+
interface PluginContext {
|
|
7
|
+
config: ResolvedBarodocConfig;
|
|
8
|
+
root: string;
|
|
9
|
+
mode: "development" | "production";
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Content transformation context
|
|
13
|
+
*/
|
|
14
|
+
interface ContentContext {
|
|
15
|
+
filePath: string;
|
|
16
|
+
content: string;
|
|
17
|
+
frontmatter: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Build context
|
|
21
|
+
*/
|
|
22
|
+
interface BuildContext {
|
|
23
|
+
outDir: string;
|
|
24
|
+
pages: string[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Plugin hooks
|
|
28
|
+
*/
|
|
29
|
+
interface BarodocPluginHooks {
|
|
30
|
+
/**
|
|
31
|
+
* Called after config is loaded
|
|
32
|
+
* Can modify the config
|
|
33
|
+
*/
|
|
34
|
+
"config:loaded"?: (config: ResolvedBarodocConfig, context: PluginContext) => ResolvedBarodocConfig | Promise<ResolvedBarodocConfig>;
|
|
35
|
+
/**
|
|
36
|
+
* Called for each content file
|
|
37
|
+
* Can transform content
|
|
38
|
+
*/
|
|
39
|
+
"content:transform"?: (context: ContentContext) => ContentContext | Promise<ContentContext>;
|
|
40
|
+
/**
|
|
41
|
+
* Called before build starts
|
|
42
|
+
*/
|
|
43
|
+
"build:start"?: (context: PluginContext) => void | Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Called after build completes
|
|
46
|
+
*/
|
|
47
|
+
"build:done"?: (buildContext: BuildContext, context: PluginContext) => void | Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Barodoc plugin definition
|
|
51
|
+
*/
|
|
52
|
+
interface BarodocPlugin {
|
|
53
|
+
/**
|
|
54
|
+
* Plugin name (should be unique)
|
|
55
|
+
*/
|
|
56
|
+
name: string;
|
|
57
|
+
/**
|
|
58
|
+
* Plugin hooks
|
|
59
|
+
*/
|
|
60
|
+
hooks?: BarodocPluginHooks;
|
|
61
|
+
/**
|
|
62
|
+
* Astro integration to add
|
|
63
|
+
*/
|
|
64
|
+
astroIntegration?: (context: PluginContext) => AstroIntegration;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Plugin factory function
|
|
68
|
+
*/
|
|
69
|
+
type BarodocPluginFactory<T = void> = T extends void ? () => BarodocPlugin : (options: T) => BarodocPlugin;
|
|
70
|
+
/**
|
|
71
|
+
* Plugin configuration in barodoc.config.json
|
|
72
|
+
* Can be:
|
|
73
|
+
* - string: plugin name (e.g., "@barodoc/plugin-sitemap")
|
|
74
|
+
* - [string, object]: plugin with options (e.g., ["@barodoc/plugin-analytics", { id: "G-XXX" }])
|
|
75
|
+
*/
|
|
76
|
+
type PluginConfig = string | [string, Record<string, unknown>];
|
|
77
|
+
/**
|
|
78
|
+
* Resolved plugin with options
|
|
79
|
+
*/
|
|
80
|
+
interface ResolvedPlugin {
|
|
81
|
+
name: string;
|
|
82
|
+
plugin: BarodocPlugin;
|
|
83
|
+
options?: Record<string, unknown>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface BarodocNavItem {
|
|
87
|
+
group: string;
|
|
88
|
+
"group:ko"?: string;
|
|
89
|
+
"group:ja"?: string;
|
|
90
|
+
[key: `group:${string}`]: string | undefined;
|
|
91
|
+
pages: string[];
|
|
92
|
+
}
|
|
93
|
+
interface BarodocI18nConfig {
|
|
94
|
+
defaultLocale: string;
|
|
95
|
+
locales: string[];
|
|
96
|
+
labels?: Record<string, string>;
|
|
97
|
+
}
|
|
98
|
+
interface BarodocThemeColors {
|
|
99
|
+
primary?: string;
|
|
100
|
+
background?: string;
|
|
101
|
+
backgroundDark?: string;
|
|
102
|
+
text?: string;
|
|
103
|
+
textDark?: string;
|
|
104
|
+
border?: string;
|
|
105
|
+
borderDark?: string;
|
|
106
|
+
}
|
|
107
|
+
interface BarodocThemeConfig {
|
|
108
|
+
colors?: BarodocThemeColors;
|
|
109
|
+
fonts?: {
|
|
110
|
+
heading?: string;
|
|
111
|
+
body?: string;
|
|
112
|
+
code?: string;
|
|
113
|
+
};
|
|
114
|
+
radius?: string;
|
|
115
|
+
}
|
|
116
|
+
interface BarodocConfig {
|
|
117
|
+
name: string;
|
|
118
|
+
logo?: string;
|
|
119
|
+
favicon?: string;
|
|
120
|
+
theme?: BarodocThemeConfig;
|
|
121
|
+
i18n?: BarodocI18nConfig;
|
|
122
|
+
navigation: BarodocNavItem[];
|
|
123
|
+
topbar?: {
|
|
124
|
+
github?: string;
|
|
125
|
+
discord?: string;
|
|
126
|
+
twitter?: string;
|
|
127
|
+
};
|
|
128
|
+
search?: {
|
|
129
|
+
enabled?: boolean;
|
|
130
|
+
};
|
|
131
|
+
plugins?: PluginConfig[];
|
|
132
|
+
customCss?: string[];
|
|
133
|
+
}
|
|
134
|
+
interface ThemeExport {
|
|
135
|
+
name: string;
|
|
136
|
+
integration: () => AstroIntegration;
|
|
137
|
+
pages?: Record<string, () => Promise<unknown>>;
|
|
138
|
+
layouts?: Record<string, () => Promise<unknown>>;
|
|
139
|
+
components?: Record<string, () => Promise<unknown>>;
|
|
140
|
+
styles?: string[];
|
|
141
|
+
}
|
|
142
|
+
interface BarodocOptions {
|
|
143
|
+
config?: string;
|
|
144
|
+
theme: ThemeExport;
|
|
145
|
+
}
|
|
146
|
+
interface ResolvedBarodocConfig extends BarodocConfig {
|
|
147
|
+
_resolved: true;
|
|
148
|
+
_configPath: string;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export type { BarodocOptions as B, ContentContext as C, PluginConfig as P, ResolvedBarodocConfig as R, ThemeExport as T, BarodocConfig as a, BarodocI18nConfig as b, BarodocNavItem as c, BarodocPlugin as d, BarodocPluginFactory as e, BarodocPluginHooks as f, BarodocThemeColors as g, BarodocThemeConfig as h, BuildContext as i, PluginContext as j, ResolvedPlugin as k };
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@barodoc/core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Core integration for Barodoc documentation framework",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./config": {
|
|
14
|
+
"types": "./dist/config/index.d.ts",
|
|
15
|
+
"import": "./dist/config/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./i18n": {
|
|
18
|
+
"types": "./dist/i18n/index.d.ts",
|
|
19
|
+
"import": "./dist/i18n/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./plugins": {
|
|
22
|
+
"types": "./dist/plugins/index.d.ts",
|
|
23
|
+
"import": "./dist/plugins/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"zod": "^3.24.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"astro": "^5.0.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/node": "^22.0.0",
|
|
37
|
+
"astro": "^5.0.0",
|
|
38
|
+
"tsup": "^8.3.0",
|
|
39
|
+
"typescript": "^5.7.0"
|
|
40
|
+
},
|
|
41
|
+
"keywords": [
|
|
42
|
+
"astro",
|
|
43
|
+
"astro-integration",
|
|
44
|
+
"documentation",
|
|
45
|
+
"barodoc"
|
|
46
|
+
],
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "https://github.com/barocss/barodoc.git",
|
|
51
|
+
"directory": "packages/core"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsup",
|
|
55
|
+
"dev": "tsup --watch"
|
|
56
|
+
}
|
|
57
|
+
}
|