@let-value/translate-extract 1.0.30 → 1.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/dist/bin/cli.cjs +7 -6
- package/dist/bin/cli.js +1 -1
- package/dist/chunk-CUT6urMc.cjs +30 -0
- package/dist/configuration-CTb0EXNF.d.ts +240 -0
- package/dist/configuration-CTb0EXNF.d.ts.map +1 -0
- package/dist/configuration-nsGqA5N9.d.cts +239 -0
- package/dist/configuration-nsGqA5N9.d.cts.map +1 -0
- package/dist/core-ACuLoi2B.d.ts +1 -0
- package/dist/core-CHb_Xdzl.cjs +65 -0
- package/dist/core-CPg6_re5.d.cts +1 -0
- package/dist/core-DR3oxhSq.js +59 -0
- package/dist/core-DR3oxhSq.js.map +1 -0
- package/dist/run-DbV8QpUz.js +1439 -0
- package/dist/run-DbV8QpUz.js.map +1 -0
- package/dist/run-MHj974iT.cjs +1479 -0
- package/dist/src/core.cjs +4 -0
- package/dist/src/core.d.cts +3 -0
- package/dist/src/core.d.ts +3 -0
- package/dist/src/core.js +4 -0
- package/dist/src/index.cjs +9 -1320
- package/dist/src/index.d.cts +3 -209
- package/dist/src/index.d.cts.map +1 -1
- package/dist/src/index.d.ts +3 -210
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -1306
- package/dist/src/static.cjs +6 -0
- package/dist/src/static.d.cts +2 -0
- package/dist/src/static.d.ts +2 -0
- package/dist/src/static.js +3 -0
- package/dist/static-CNiWpXhx.cjs +52 -0
- package/dist/static-DQHT7uqP.js +29 -0
- package/dist/static-DQHT7uqP.js.map +1 -0
- package/package.json +13 -3
- package/dist/run-BonabcP6.cjs +0 -209
- package/dist/run-C_bYec-q.js +0 -175
- package/dist/run-C_bYec-q.js.map +0 -1
- package/dist/src/index.js.map +0 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { cleanup, core, po } from "./static-DQHT7uqP.js";
|
|
2
|
+
import { basename, dirname, extname, join } from "node:path";
|
|
3
|
+
|
|
4
|
+
//#region src/configuration.ts
|
|
5
|
+
const defaultPlugins = {
|
|
6
|
+
core,
|
|
7
|
+
po,
|
|
8
|
+
cleanup
|
|
9
|
+
};
|
|
10
|
+
const defaultDestination = ({ entrypoint, locale }) => join(dirname(entrypoint), "translations", `${basename(entrypoint, extname(entrypoint))}.${locale}.po`);
|
|
11
|
+
const defaultExclude = [
|
|
12
|
+
/(?:^|[\\/])node_modules(?:[\\/]|$)/,
|
|
13
|
+
/(?:^|[\\/])dist(?:[\\/]|$)/,
|
|
14
|
+
/(?:^|[\\/])build(?:[\\/]|$)/
|
|
15
|
+
];
|
|
16
|
+
function normalizeExclude(exclude) {
|
|
17
|
+
if (!exclude) return [];
|
|
18
|
+
return Array.isArray(exclude) ? exclude : [exclude];
|
|
19
|
+
}
|
|
20
|
+
function resolveEntrypoint(ep) {
|
|
21
|
+
if (typeof ep === "string") return { entrypoint: ep };
|
|
22
|
+
const { entrypoint, destination, obsolete, walk, exclude } = ep;
|
|
23
|
+
return {
|
|
24
|
+
entrypoint,
|
|
25
|
+
destination,
|
|
26
|
+
obsolete,
|
|
27
|
+
walk,
|
|
28
|
+
exclude: exclude ? normalizeExclude(exclude) : void 0
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function resolvePlugins(user) {
|
|
32
|
+
if (typeof user === "function") return user(defaultPlugins);
|
|
33
|
+
if (Array.isArray(user)) return [...Object.values(defaultPlugins).map((plugin) => plugin()), ...user];
|
|
34
|
+
return Object.values(defaultPlugins).map((plugin) => plugin());
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Type helper to make it easier to use translate.config.ts
|
|
38
|
+
* @param config - {@link UserConfig}.
|
|
39
|
+
*/
|
|
40
|
+
function defineConfig(config) {
|
|
41
|
+
const defaultLocale = config.defaultLocale ?? "en";
|
|
42
|
+
const plugins = resolvePlugins(config.plugins);
|
|
43
|
+
const entrypoints = (Array.isArray(config.entrypoints) ? config.entrypoints : [config.entrypoints]).map(resolveEntrypoint);
|
|
44
|
+
return {
|
|
45
|
+
plugins,
|
|
46
|
+
entrypoints,
|
|
47
|
+
defaultLocale,
|
|
48
|
+
locales: config.locales ?? [defaultLocale],
|
|
49
|
+
destination: config.destination ?? defaultDestination,
|
|
50
|
+
obsolete: config.obsolete ?? "mark",
|
|
51
|
+
walk: config.walk ?? true,
|
|
52
|
+
logLevel: config.logLevel ?? "info",
|
|
53
|
+
exclude: config.exclude ? normalizeExclude(config.exclude) : defaultExclude
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
export { defineConfig };
|
|
59
|
+
//# sourceMappingURL=core-DR3oxhSq.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-DR3oxhSq.js","names":["defaultDestination: DestinationFn","defaultExclude: Exclude[]"],"sources":["../src/configuration.ts"],"sourcesContent":["import { basename, dirname, extname, join } from \"node:path\";\nimport type { PluralFormsLocale } from \"@let-value/translate\";\nimport type { LogLevel } from \"./logger.ts\";\n\nimport type { UniversalPlugin } from \"./plugin.ts\";\nimport { cleanup, core, po } from \"./static.ts\";\n\nexport type DestinationFn = (args: { locale: string; entrypoint: string; path: string }) => string;\nexport type ExcludeFn = (args: { entrypoint: string; path: string }) => boolean;\nexport type Exclude = RegExp | ExcludeFn;\n\nconst defaultPlugins = { core, po, cleanup };\ntype DefaultPlugins = typeof defaultPlugins;\n\n/**\n * Strategy to handle obsolete translations in existing locale files:\n * - \"mark\": keep obsolete entries in the locale file but mark them as obsolete\n * - \"remove\": remove obsolete entries from the locale file\n */\nexport type ObsoleteStrategy = \"mark\" | \"remove\";\n\nexport interface EntrypointConfig {\n entrypoint: string;\n destination?: DestinationFn;\n obsolete?: ObsoleteStrategy;\n walk?: boolean;\n exclude?: Exclude | Exclude[];\n}\n\nexport interface UserConfig {\n /**\n * Default locale to use as the base for extraction\n * @default \"en\"\n * @see {@link PluralFormsLocale} for available locales\n */\n defaultLocale?: PluralFormsLocale;\n /**\n * Array of locales to extract translations for\n * @default [defaultLocale]\n * @see {@link PluralFormsLocale} for available locales\n */\n locales?: PluralFormsLocale[];\n /**\n * Array of plugins to use or a function to override the default plugins\n * @default DefaultPlugins\n * @see {@link DefaultPlugins} for available plugins\n */\n plugins?: UniversalPlugin[] | ((defaultPlugins: DefaultPlugins) => UniversalPlugin[]);\n /**\n * One or more entrypoints to extract translations from, could be:\n * - file path, will be treated as a single file entrypoint\n * - glob pattern will be expanded to match files, each treated as a separate entrypoint\n * - configuration object with options for the entrypoint\n * @see {@link EntrypointConfig} for configuration options\n */\n entrypoints: string | EntrypointConfig | Array<string | EntrypointConfig>;\n /**\n * Function to determine the destination path for each extracted locale file\n * @default `./translations/entrypoint.locale.po`\n * @see {@link DestinationFn}\n * @see Can be overridden per entrypoint via `destination` in {@link EntrypointConfig\n */\n destination?: DestinationFn;\n /**\n * Strategy to handle obsolete translations in existing locale files\n * @default \"mark\"\n * @see {@link ObsoleteStrategy} for available strategies\n * @see Can be overridden per entrypoint via `obsolete` in {@link EntrypointConfig\n */\n obsolete?: ObsoleteStrategy;\n /**\n * Whether to recursively walk dependencies of the entrypoints\n * @default true\n * @see Can be overridden per entrypoint via `walk` in {@link EntrypointConfig}.\n */\n walk?: boolean;\n /**\n * Paths or patterns to exclude from extraction, applied to all entrypoints\n * @default [/node_modules/, /dist/, /build/]\n * @see Can be overridden per entrypoint via `exclude` in {@link EntrypointConfig}.\n */\n exclude?: Exclude | Exclude[];\n /**\n * Log level for the extraction process\n * @default \"info\"\n */\n logLevel?: LogLevel;\n}\n\nexport interface ResolvedEntrypoint extends Omit<EntrypointConfig, \"exclude\"> {\n exclude?: Exclude[];\n}\n\nexport interface ResolvedConfig {\n plugins: UniversalPlugin[];\n entrypoints: ResolvedEntrypoint[];\n defaultLocale: string;\n locales: string[];\n destination: DestinationFn;\n obsolete: ObsoleteStrategy;\n walk: boolean;\n logLevel: LogLevel;\n exclude: Exclude[];\n}\n\nconst defaultDestination: DestinationFn = ({ entrypoint, locale }) =>\n join(dirname(entrypoint), \"translations\", `${basename(entrypoint, extname(entrypoint))}.${locale}.po`);\n\nconst defaultExclude: Exclude[] = [\n /(?:^|[\\\\/])node_modules(?:[\\\\/]|$)/,\n /(?:^|[\\\\/])dist(?:[\\\\/]|$)/,\n /(?:^|[\\\\/])build(?:[\\\\/]|$)/,\n];\n\nfunction normalizeExclude(exclude?: Exclude | Exclude[]): Exclude[] {\n if (!exclude) return [];\n return Array.isArray(exclude) ? exclude : [exclude];\n}\n\nfunction resolveEntrypoint(ep: string | EntrypointConfig): ResolvedEntrypoint {\n if (typeof ep === \"string\") {\n return { entrypoint: ep };\n }\n const { entrypoint, destination, obsolete, walk, exclude } = ep;\n return { entrypoint, destination, obsolete, walk, exclude: exclude ? normalizeExclude(exclude) : undefined };\n}\n\nfunction resolvePlugins(user?: UserConfig[\"plugins\"]): UniversalPlugin[] {\n if (typeof user === \"function\") {\n return user(defaultPlugins);\n }\n if (Array.isArray(user)) {\n return [...Object.values(defaultPlugins).map((plugin) => plugin()), ...user];\n }\n return Object.values(defaultPlugins).map((plugin) => plugin());\n}\n\n/**\n * Type helper to make it easier to use translate.config.ts\n * @param config - {@link UserConfig}.\n */\nexport function defineConfig(config: UserConfig): ResolvedConfig {\n const defaultLocale = config.defaultLocale ?? \"en\";\n\n const plugins = resolvePlugins(config.plugins);\n\n const raw = Array.isArray(config.entrypoints) ? config.entrypoints : [config.entrypoints];\n const entrypoints = raw.map(resolveEntrypoint);\n\n return {\n plugins,\n entrypoints,\n defaultLocale,\n locales: config.locales ?? [defaultLocale],\n destination: config.destination ?? defaultDestination,\n obsolete: config.obsolete ?? \"mark\",\n walk: config.walk ?? true,\n logLevel: config.logLevel ?? \"info\",\n exclude: config.exclude ? normalizeExclude(config.exclude) : defaultExclude,\n };\n}\n"],"mappings":";;;;AAWA,MAAM,iBAAiB;CAAE;CAAM;CAAI;CAAS;AA8F5C,MAAMA,sBAAqC,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