Skip to content

Commit a778d74

Browse files
authored
Add support for tracking only dictionaries (#67)
* Add support to tracking only dictionaries * Create ten-lions-rush.md
1 parent 8be12b9 commit a778d74

File tree

5 files changed

+69
-54
lines changed

5 files changed

+69
-54
lines changed

.changeset/ten-lions-rush.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@lunariajs/core": patch
3+
---
4+
5+
Add support for tracking only dictionaries

packages/core/config.schema.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@
260260
"additionalProperties": false
261261
}
262262
},
263-
"required": ["label", "lang", "content"],
263+
"required": ["label", "lang"],
264264
"additionalProperties": false
265265
},
266266
"locales": {

packages/core/src/schemas/locale.ts

+22-18
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,28 @@ const ContentSchema = z.object({
4141
.describe('Array of glob patterns to be ignored from matching.'),
4242
});
4343

44-
export const LocaleSchema = z.object({
45-
/** The label of the locale to show in the status dashboard, e.g. `"English"`, `"Português"`, or `"Español"`. */
46-
label: z
47-
.string()
48-
.describe(
49-
'The label of the locale to show in the status dashboard, e.g. `"English"`, `"Português"`, or `"Español"`.'
50-
),
51-
/** The BCP-47 tag of the locale, both to use in smaller widths and to differentiate regional variants, e.g. `"en-US"` (American English) or `"en-GB"` (British English). */
52-
lang: z
53-
.string()
54-
.describe(
55-
'The BCP-47 tag of the locale, both to use in smaller widths and to differentiate regional variants, e.g. `"en-US"` (American English) or `"en-GB"` (British English).'
56-
),
57-
/** Information about any of your UI dictionaries. */
58-
dictionaries: DictionariesSchema,
59-
/** Information about your content. */
60-
content: ContentSchema,
61-
});
44+
export const LocaleSchema = z
45+
.object({
46+
/** The label of the locale to show in the status dashboard, e.g. `"English"`, `"Português"`, or `"Español"`. */
47+
label: z
48+
.string()
49+
.describe(
50+
'The label of the locale to show in the status dashboard, e.g. `"English"`, `"Português"`, or `"Español"`.'
51+
),
52+
/** The BCP-47 tag of the locale, both to use in smaller widths and to differentiate regional variants, e.g. `"en-US"` (American English) or `"en-GB"` (British English). */
53+
lang: z
54+
.string()
55+
.describe(
56+
'The BCP-47 tag of the locale, both to use in smaller widths and to differentiate regional variants, e.g. `"en-US"` (American English) or `"en-GB"` (British English).'
57+
),
58+
/** Information about any of your UI dictionaries. */
59+
dictionaries: DictionariesSchema.optional(),
60+
/** Information about your content. */
61+
content: ContentSchema.optional(),
62+
})
63+
.refine((locale) => locale.content || locale.dictionaries, {
64+
message: 'A locale needs to include a `dictionaries` or `content` field to be tracked.',
65+
});
6266

6367
export type Locale = z.output<typeof LocaleSchema>;
6468
export type OptionalKeys = z.infer<typeof OptionalKeysSchema>;

packages/core/src/tracker.ts

+36-30
Original file line numberDiff line numberDiff line change
@@ -122,35 +122,41 @@ export async function getContentIndex(opts: LunariaConfig, isShallowRepo: boolea
122122
const pathResolver = getPathResolver(routingStrategy, allLangs);
123123

124124
for (const { lang, content, dictionaries } of allLocales) {
125-
const localeContentPaths = await glob(content.location, {
126-
cwd: process.cwd(),
127-
ignore: ['node_modules', ...content.ignore],
128-
});
129-
130-
const genericContentIndex = await Promise.all(
131-
localeContentPaths.sort().map(async (filePath) => {
132-
const sharedPath = pathResolver.toSharedPath(filePath);
133-
134-
return {
135-
lang,
136-
filePath,
137-
sharedPath,
138-
fileData: await getFileData(
139-
filePath,
140-
isShallowRepo,
141-
repository.rootDir,
142-
translatableProperty,
143-
ignoreKeywords
144-
),
145-
additionalData: {
146-
type: 'generic',
147-
},
148-
} as IndexData;
149-
})
150-
);
125+
const genericContentIndex = [];
126+
if (content) {
127+
const { location, ignore } = content;
151128

152-
const dictionaryContentIndex = [];
129+
const localeContentPaths = await glob(location, {
130+
cwd: process.cwd(),
131+
ignore: ['node_modules', ...ignore],
132+
});
153133

134+
genericContentIndex.push(
135+
...(await Promise.all(
136+
localeContentPaths.sort().map(async (filePath) => {
137+
const sharedPath = pathResolver.toSharedPath(filePath);
138+
139+
return {
140+
lang,
141+
filePath,
142+
sharedPath,
143+
fileData: await getFileData(
144+
filePath,
145+
isShallowRepo,
146+
repository.rootDir,
147+
translatableProperty,
148+
ignoreKeywords
149+
),
150+
meta: {
151+
type: 'generic',
152+
},
153+
} as IndexData;
154+
})
155+
))
156+
);
157+
}
158+
159+
const dictionaryContentIndex = [];
154160
if (dictionaries) {
155161
const { location, ignore, optionalKeys } = dictionaries;
156162

@@ -175,7 +181,7 @@ export async function getContentIndex(opts: LunariaConfig, isShallowRepo: boolea
175181
translatableProperty,
176182
ignoreKeywords
177183
),
178-
additionalData: {
184+
meta: {
179185
type: 'dictionary',
180186
optionalKeys: optionalKeys,
181187
},
@@ -186,12 +192,12 @@ export async function getContentIndex(opts: LunariaConfig, isShallowRepo: boolea
186192
}
187193

188194
[...dictionaryContentIndex, ...genericContentIndex].forEach(
189-
({ lang, sharedPath, fileData, additionalData }) => {
195+
({ lang, sharedPath, fileData, meta }) => {
190196
fileContentIndex[lang] = {
191197
...fileContentIndex[lang],
192198
[sharedPath]: {
193199
...fileData,
194-
...additionalData,
200+
...meta,
195201
},
196202
};
197203
}

packages/core/src/types.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@ import type { TemplateResult } from 'lit-html';
22
import type { LunariaConfig } from './schemas/config.js';
33
import type { OptionalKeys } from './schemas/locale.js';
44

5-
type DictionaryContentData = {
5+
type DictionaryContentMeta = {
66
type: 'dictionary';
77
optionalKeys: OptionalKeys;
88
};
99

10-
type GenericContentData = {
10+
type GenericContentMeta = {
1111
type: 'generic';
1212
};
1313

14-
type AdditionalContentData = DictionaryContentData | GenericContentData;
14+
type ContentMeta = DictionaryContentMeta | GenericContentMeta;
1515

1616
export type * from './schemas/config.js';
1717
export type * from './schemas/dashboard.js';
1818
export type * from './schemas/locale.js';
1919
export type * from './schemas/misc.js';
2020

21-
export type AugmentedFileData = FileData & AdditionalContentData;
21+
export type AugmentedFileData = FileData & ContentMeta;
2222
export type FileContentIndex = Record<string, Record<string, AugmentedFileData>>;
2323

2424
export type IndexData = {
2525
lang: string;
2626
filePath: string;
2727
sharedPath: string;
2828
fileData: FileData;
29-
additionalData: AdditionalContentData;
29+
meta: ContentMeta;
3030
};
3131

3232
export type FileData = {

0 commit comments

Comments
 (0)