@let-value/translate-extract 1.0.6-beta.3 → 1.0.6

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 CHANGED
@@ -1,11 +1,35 @@
1
1
  #!/usr/bin/env node
2
- const require_run = require('../run-Ds6SfSE_.cjs');
2
+ const require_run = require('../run-DmgUA6g-.cjs');
3
+ let node_util = require("node:util");
4
+ node_util = require_run.__toESM(node_util);
3
5
  let cosmiconfig = require("cosmiconfig");
4
6
  cosmiconfig = require_run.__toESM(cosmiconfig);
7
+ let pino = require("pino");
8
+ pino = require_run.__toESM(pino);
5
9
 
10
+ //#region src/logger.ts
11
+ function createLogger(level = "info") {
12
+ return (0, pino.default)({
13
+ level,
14
+ transport: {
15
+ target: "pino-pretty",
16
+ options: { colorize: true }
17
+ }
18
+ });
19
+ }
20
+
21
+ //#endregion
6
22
  //#region bin/cli.ts
7
23
  const moduleName = "translate";
8
24
  async function main() {
25
+ const { values: { logLevel } } = (0, node_util.parseArgs)({
26
+ args: process.argv.slice(2),
27
+ options: { logLevel: {
28
+ type: "string",
29
+ short: "l"
30
+ } }
31
+ });
32
+ const logger = createLogger(logLevel);
9
33
  const explorer = (0, cosmiconfig.cosmiconfig)(moduleName, { searchPlaces: [
10
34
  `.${moduleName}rc.js`,
11
35
  `.${moduleName}rc.ts`,
@@ -22,19 +46,23 @@ async function main() {
22
46
  ] });
23
47
  const result = await explorer.search();
24
48
  if (!result || !result.config) {
25
- console.error("No configuration file found");
49
+ logger.error("No configuration file found");
26
50
  process.exit(1);
27
51
  }
28
52
  const config = result.config;
53
+ config.logLevel = logLevel ?? config.logLevel;
54
+ logger.level = config.logLevel;
29
55
  const tasks = [];
30
56
  for (const locale of config.locales) for (const ep of config.entrypoints) tasks.push(require_run.run(ep.entrypoint, {
31
57
  locale,
32
- config
58
+ config,
59
+ logger
33
60
  }));
34
61
  await Promise.all(tasks);
35
62
  }
36
63
  main().catch((err) => {
37
- console.error(err);
64
+ const logger = createLogger();
65
+ logger.error(err);
38
66
  process.exit(1);
39
67
  });
40
68
 
package/dist/bin/cli.js CHANGED
@@ -1,10 +1,32 @@
1
1
  #!/usr/bin/env node
2
- import { run } from "../run-BVwl2cwo.js";
2
+ import { run } from "../run-CDoyE55S.js";
3
+ import { parseArgs } from "node:util";
3
4
  import { cosmiconfig } from "cosmiconfig";
5
+ import pino from "pino";
4
6
 
7
+ //#region src/logger.ts
8
+ function createLogger(level = "info") {
9
+ return pino({
10
+ level,
11
+ transport: {
12
+ target: "pino-pretty",
13
+ options: { colorize: true }
14
+ }
15
+ });
16
+ }
17
+
18
+ //#endregion
5
19
  //#region bin/cli.ts
6
20
  const moduleName = "translate";
7
21
  async function main() {
22
+ const { values: { logLevel } } = parseArgs({
23
+ args: process.argv.slice(2),
24
+ options: { logLevel: {
25
+ type: "string",
26
+ short: "l"
27
+ } }
28
+ });
29
+ const logger = createLogger(logLevel);
8
30
  const explorer = cosmiconfig(moduleName, { searchPlaces: [
9
31
  `.${moduleName}rc.js`,
10
32
  `.${moduleName}rc.ts`,
@@ -21,19 +43,23 @@ async function main() {
21
43
  ] });
22
44
  const result = await explorer.search();
23
45
  if (!result || !result.config) {
24
- console.error("No configuration file found");
46
+ logger.error("No configuration file found");
25
47
  process.exit(1);
26
48
  }
27
49
  const config = result.config;
50
+ config.logLevel = logLevel ?? config.logLevel;
51
+ logger.level = config.logLevel;
28
52
  const tasks = [];
29
53
  for (const locale of config.locales) for (const ep of config.entrypoints) tasks.push(run(ep.entrypoint, {
30
54
  locale,
31
- config
55
+ config,
56
+ logger
32
57
  }));
33
58
  await Promise.all(tasks);
34
59
  }
35
60
  main().catch((err) => {
36
- console.error(err);
61
+ const logger = createLogger();
62
+ logger.error(err);
37
63
  process.exit(1);
38
64
  });
39
65
 
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","names":["tasks: Promise<unknown>[]"],"sources":["../../bin/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { cosmiconfig } from \"cosmiconfig\";\nimport type { ResolvedConfig } from \"../src/configuration.ts\";\nimport { run } from \"../src/run.ts\";\n\nconst moduleName = \"translate\";\n\nasync function main() {\n const explorer = cosmiconfig(moduleName, {\n searchPlaces: [\n `.${moduleName}rc.js`,\n `.${moduleName}rc.ts`,\n `.${moduleName}rc.mjs`,\n `.${moduleName}rc.cjs`,\n `.config/${moduleName}rc.js`,\n `.config/${moduleName}rc.ts`,\n `.config/${moduleName}rc.mjs`,\n `.config/${moduleName}rc.cjs`,\n `${moduleName}.config.js`,\n `${moduleName}.config.ts`,\n `${moduleName}.config.mjs`,\n `${moduleName}.config.cjs`,\n ],\n });\n\n const result = await explorer.search();\n if (!result || !result.config) {\n console.error(\"No configuration file found\");\n process.exit(1);\n }\n\n const config = result.config as ResolvedConfig;\n const tasks: Promise<unknown>[] = [];\n for (const locale of config.locales) {\n for (const ep of config.entrypoints) {\n tasks.push(run(ep.entrypoint, { locale, config }));\n }\n }\n\n await Promise.all(tasks);\n}\n\nvoid main().catch((err) => {\n console.error(err);\n process.exit(1);\n});\n"],"mappings":";;;;;AAKA,MAAM,aAAa;AAEnB,eAAe,OAAO;CAClB,MAAM,WAAW,YAAY,YAAY,EACrC,cAAc;EACV,IAAI,WAAW;EACf,IAAI,WAAW;EACf,IAAI,WAAW;EACf,IAAI,WAAW;EACf,WAAW,WAAW;EACtB,WAAW,WAAW;EACtB,WAAW,WAAW;EACtB,WAAW,WAAW;EACtB,GAAG,WAAW;EACd,GAAG,WAAW;EACd,GAAG,WAAW;EACd,GAAG,WAAW;;CAItB,MAAM,SAAS,MAAM,SAAS;AAC9B,KAAI,CAAC,UAAU,CAAC,OAAO,QAAQ;AAC3B,UAAQ,MAAM;AACd,UAAQ,KAAK;;CAGjB,MAAM,SAAS,OAAO;CACtB,MAAMA,QAA4B;AAClC,MAAK,MAAM,UAAU,OAAO,QACxB,MAAK,MAAM,MAAM,OAAO,YACpB,OAAM,KAAK,IAAI,GAAG,YAAY;EAAE;EAAQ;;AAIhD,OAAM,QAAQ,IAAI;;AAGjB,OAAO,OAAO,QAAQ;AACvB,SAAQ,MAAM;AACd,SAAQ,KAAK"}
1
+ {"version":3,"file":"cli.js","names":["tasks: Promise<unknown>[]"],"sources":["../../src/logger.ts","../../bin/cli.ts"],"sourcesContent":["import pino, { type LevelWithSilent, type Logger } from \"pino\";\n\nexport function createLogger(level: LevelWithSilent = \"info\"): Logger {\n return pino({\n level,\n transport: {\n target: \"pino-pretty\",\n options: {\n colorize: true,\n },\n },\n });\n}\n\nexport type { Logger, LevelWithSilent };\n","#!/usr/bin/env node\nimport { parseArgs } from \"node:util\";\nimport { cosmiconfig } from \"cosmiconfig\";\nimport type { ResolvedConfig } from \"../src/configuration.ts\";\nimport { createLogger, type LevelWithSilent } from \"../src/logger.ts\";\nimport { run } from \"../src/run.ts\";\n\nconst moduleName = \"translate\";\n\nasync function main() {\n const {\n values: { logLevel },\n } = parseArgs({\n args: process.argv.slice(2),\n options: {\n logLevel: { type: \"string\", short: \"l\" },\n },\n });\n\n const logger = createLogger(logLevel as LevelWithSilent | undefined);\n\n const explorer = cosmiconfig(moduleName, {\n searchPlaces: [\n `.${moduleName}rc.js`,\n `.${moduleName}rc.ts`,\n `.${moduleName}rc.mjs`,\n `.${moduleName}rc.cjs`,\n `.config/${moduleName}rc.js`,\n `.config/${moduleName}rc.ts`,\n `.config/${moduleName}rc.mjs`,\n `.config/${moduleName}rc.cjs`,\n `${moduleName}.config.js`,\n `${moduleName}.config.ts`,\n `${moduleName}.config.mjs`,\n `${moduleName}.config.cjs`,\n ],\n });\n\n const result = await explorer.search();\n if (!result || !result.config) {\n logger.error(\"No configuration file found\");\n process.exit(1);\n }\n\n const config = result.config as ResolvedConfig;\n config.logLevel = (logLevel as LevelWithSilent | undefined) ?? config.logLevel;\n logger.level = config.logLevel;\n const tasks: Promise<unknown>[] = [];\n for (const locale of config.locales) {\n for (const ep of config.entrypoints) {\n tasks.push(run(ep.entrypoint, { locale, config, logger }));\n }\n }\n\n await Promise.all(tasks);\n}\n\nvoid main().catch((err) => {\n const logger = createLogger();\n logger.error(err);\n process.exit(1);\n});\n"],"mappings":";;;;;;;AAEA,SAAgB,aAAa,QAAyB,QAAgB;AAClE,QAAO,KAAK;EACR;EACA,WAAW;GACP,QAAQ;GACR,SAAS,EACL,UAAU;;;;;;;ACD1B,MAAM,aAAa;AAEnB,eAAe,OAAO;CAClB,MAAM,EACF,QAAQ,EAAE,eACV,UAAU;EACV,MAAM,QAAQ,KAAK,MAAM;EACzB,SAAS,EACL,UAAU;GAAE,MAAM;GAAU,OAAO;;;CAI3C,MAAM,SAAS,aAAa;CAE5B,MAAM,WAAW,YAAY,YAAY,EACrC,cAAc;EACV,IAAI,WAAW;EACf,IAAI,WAAW;EACf,IAAI,WAAW;EACf,IAAI,WAAW;EACf,WAAW,WAAW;EACtB,WAAW,WAAW;EACtB,WAAW,WAAW;EACtB,WAAW,WAAW;EACtB,GAAG,WAAW;EACd,GAAG,WAAW;EACd,GAAG,WAAW;EACd,GAAG,WAAW;;CAItB,MAAM,SAAS,MAAM,SAAS;AAC9B,KAAI,CAAC,UAAU,CAAC,OAAO,QAAQ;AAC3B,SAAO,MAAM;AACb,UAAQ,KAAK;;CAGjB,MAAM,SAAS,OAAO;AACtB,QAAO,WAAY,YAA4C,OAAO;AACtE,QAAO,QAAQ,OAAO;CACtB,MAAMA,QAA4B;AAClC,MAAK,MAAM,UAAU,OAAO,QACxB,MAAK,MAAM,MAAM,OAAO,YACpB,OAAM,KAAK,IAAI,GAAG,YAAY;EAAE;EAAQ;EAAQ;;AAIxD,OAAM,QAAQ,IAAI;;AAGjB,OAAO,OAAO,QAAQ;CACvB,MAAM,SAAS;AACf,QAAO,MAAM;AACb,SAAQ,KAAK"}
@@ -1,24 +1,28 @@
1
- import { join } from "node:path";
2
-
3
1
  //#region src/run.ts
4
- async function run(entrypoint, { dest, locale, config }) {
2
+ async function run(entrypoint, { locale, config, logger }) {
5
3
  const entryConfig = config.entrypoints.find((e) => e.entrypoint === entrypoint);
6
4
  const destination = entryConfig?.destination ?? config.destination;
7
5
  const obsolete = entryConfig?.obsolete ?? config.obsolete;
6
+ const exclude = entryConfig?.exclude ?? config.exclude;
8
7
  const queue = [{
9
8
  entrypoint,
10
9
  path: entrypoint
11
10
  }];
11
+ logger?.info({
12
+ entrypoint,
13
+ locale
14
+ }, "starting extraction");
12
15
  const context = {
13
16
  entry: entrypoint,
14
- dest: dest ?? process.cwd(),
15
17
  config: {
16
18
  ...config,
17
19
  destination,
18
- obsolete
20
+ obsolete,
21
+ exclude
19
22
  },
20
23
  generatedAt: /* @__PURE__ */ new Date(),
21
- locale
24
+ locale,
25
+ logger
22
26
  };
23
27
  const resolves = [];
24
28
  const loads = [];
@@ -26,6 +30,7 @@ async function run(entrypoint, { dest, locale, config }) {
26
30
  const collects = [];
27
31
  const generates = [];
28
32
  function resolvePath(args) {
33
+ for (const ex of context.config.exclude) if (ex instanceof RegExp ? ex.test(args.path) : ex(args.path)) return;
29
34
  if (context.config.walk) queue.push(args);
30
35
  }
31
36
  const build = {
@@ -62,51 +67,73 @@ async function run(entrypoint, { dest, locale, config }) {
62
67
  resolvePath,
63
68
  context
64
69
  };
65
- for (const plugin of config.plugins) plugin.setup(build);
70
+ for (const plugin of config.plugins) {
71
+ logger?.debug({ plugin: plugin.name }, "setting up plugin");
72
+ plugin.setup(build);
73
+ }
66
74
  const visited = /* @__PURE__ */ new Set();
67
75
  const results = [];
68
- async function applyResolve({ entrypoint: entrypoint$1, path: path$1 }) {
76
+ async function applyResolve({ entrypoint: entrypoint$1, path }) {
69
77
  for (const { filter, hook } of resolves) {
70
- if (!filter.test(path$1)) continue;
78
+ if (!filter.test(path)) continue;
71
79
  const result$1 = await hook({
72
80
  entrypoint: entrypoint$1,
73
- path: path$1
81
+ path
74
82
  }, context);
83
+ if (result$1) logger?.debug({
84
+ entrypoint: entrypoint$1,
85
+ path
86
+ }, "resolved");
75
87
  if (result$1) return result$1;
76
88
  }
77
89
  return void 0;
78
90
  }
79
- async function applyLoad({ entrypoint: entrypoint$1, path: path$1 }) {
91
+ async function applyLoad({ entrypoint: entrypoint$1, path }) {
80
92
  for (const { filter, hook } of loads) {
81
- if (!filter.test(path$1)) continue;
93
+ if (!filter.test(path)) continue;
82
94
  const result$1 = await hook({
83
95
  entrypoint: entrypoint$1,
84
- path: path$1
96
+ path
85
97
  }, context);
98
+ if (result$1) logger?.debug({
99
+ entrypoint: entrypoint$1,
100
+ path
101
+ }, "loaded");
86
102
  if (result$1) return result$1;
87
103
  }
88
104
  return void 0;
89
105
  }
90
- async function applyExtract({ entrypoint: entrypoint$1, path: path$1, contents }) {
106
+ async function applyExtract({ entrypoint: entrypoint$1, path, contents }) {
91
107
  for (const { filter, hook } of extracts) {
92
- if (!filter.test(path$1)) continue;
108
+ if (!filter.test(path)) continue;
93
109
  const result$1 = await hook({
94
110
  entrypoint: entrypoint$1,
95
- path: path$1,
111
+ path,
96
112
  contents
97
113
  }, context);
114
+ if (result$1) logger?.debug({
115
+ entrypoint: entrypoint$1,
116
+ path
117
+ }, "extracted");
98
118
  if (result$1) return result$1;
99
119
  }
100
120
  return void 0;
101
121
  }
102
- async function applyCollect({ entrypoint: entrypoint$1, path: path$1, translations }) {
122
+ async function applyCollect({ entrypoint: entrypoint$1, path, translations, destination: destination$1 }) {
103
123
  for (const { filter, hook } of collects) {
104
- if (!filter.test(path$1)) continue;
124
+ if (!filter.test(path)) continue;
105
125
  const result$1 = await hook({
106
126
  entrypoint: entrypoint$1,
107
- path: path$1,
108
- translations
127
+ path,
128
+ translations,
129
+ destination: destination$1
109
130
  }, context);
131
+ if (result$1) logger?.debug({
132
+ entrypoint: entrypoint$1,
133
+ path,
134
+ destination: destination$1,
135
+ ...destination$1 !== result$1.destination && { redirected: result$1.destination }
136
+ }, "collected");
110
137
  if (result$1) return result$1;
111
138
  }
112
139
  return void 0;
@@ -121,31 +148,35 @@ async function run(entrypoint, { dest, locale, config }) {
121
148
  if (!loaded) continue;
122
149
  const extracted = await applyExtract(loaded);
123
150
  if (!extracted) continue;
124
- const collected = await applyCollect(extracted);
151
+ const destination$1 = context.config.destination({
152
+ entrypoint,
153
+ locale,
154
+ path: resolved.path
155
+ });
156
+ const collected = await applyCollect({
157
+ ...extracted,
158
+ destination: destination$1
159
+ });
125
160
  if (!collected) continue;
126
- const destPath = context.config.destination(locale, entrypoint, collected.destination);
127
- const final = {
128
- ...collected,
129
- destination: destPath
130
- };
131
- if (!result[destPath]) result[destPath] = [];
132
- result[destPath].push(final);
161
+ if (!result[collected.destination]) result[collected.destination] = [];
162
+ result[collected.destination].push(collected);
133
163
  }
134
- for (const [path$1, collected] of Object.entries(result)) {
135
- const fullPath = join(context.dest, path$1);
136
- for (const { filter, hook } of generates) {
137
- if (!filter.test(fullPath)) continue;
138
- await hook({
139
- entrypoint,
140
- locale,
141
- path: fullPath,
142
- collected
143
- }, context);
144
- }
164
+ for (const [path, collected] of Object.entries(result)) for (const { filter, hook } of generates) {
165
+ if (!filter.test(path)) continue;
166
+ logger?.info({ path }, "generating output");
167
+ await hook({
168
+ entrypoint,
169
+ path,
170
+ collected
171
+ }, context);
145
172
  }
173
+ logger?.info({
174
+ entrypoint,
175
+ locale
176
+ }, "extraction completed");
146
177
  return results;
147
178
  }
148
179
 
149
180
  //#endregion
150
181
  export { run };
151
- //# sourceMappingURL=run-BVwl2cwo.js.map
182
+ //# sourceMappingURL=run-CDoyE55S.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-CDoyE55S.js","names":["queue: ResolveArgs[]","context: ExtractContext","resolves: { filter: RegExp; hook: ResolveHook }[]","loads: { filter: RegExp; hook: LoadHook }[]","extracts: { filter: RegExp; hook: ExtractHook }[]","collects: { filter: RegExp; hook: CollectHook }[]","generates: { filter: RegExp; hook: GenerateHook }[]","build: ExtractBuild","results: ExtractResult[]","result","destination","result: Record<string, CollectResult[]>"],"sources":["../src/run.ts"],"sourcesContent":["import type { ResolvedConfig } from \"./configuration.ts\";\nimport type { Logger } from \"./logger.ts\";\nimport type {\n CollectArgs,\n CollectHook,\n CollectResult,\n ExtractArgs,\n ExtractBuild,\n ExtractContext,\n ExtractHook,\n ExtractResult,\n GenerateHook,\n LoadArgs,\n LoadHook,\n LoadResult,\n ResolveArgs,\n ResolveHook,\n ResolveResult,\n} from \"./plugin.ts\";\n\nexport async function run(\n entrypoint: string,\n { locale, config, logger }: { locale: string; config: ResolvedConfig; logger?: Logger },\n) {\n const entryConfig = config.entrypoints.find((e) => e.entrypoint === entrypoint);\n const destination = entryConfig?.destination ?? config.destination;\n const obsolete = entryConfig?.obsolete ?? config.obsolete;\n const exclude = entryConfig?.exclude ?? config.exclude;\n\n const queue: ResolveArgs[] = [{ entrypoint, path: entrypoint }];\n\n logger?.info({ entrypoint, locale }, \"starting extraction\");\n\n const context: ExtractContext = {\n entry: entrypoint,\n config: { ...config, destination, obsolete, exclude },\n generatedAt: new Date(),\n locale,\n logger,\n };\n\n const resolves: { filter: RegExp; hook: ResolveHook }[] = [];\n const loads: { filter: RegExp; hook: LoadHook }[] = [];\n const extracts: { filter: RegExp; hook: ExtractHook }[] = [];\n const collects: { filter: RegExp; hook: CollectHook }[] = [];\n const generates: { filter: RegExp; hook: GenerateHook }[] = [];\n\n function resolvePath(args: ResolveArgs) {\n for (const ex of context.config.exclude) {\n if (ex instanceof RegExp ? ex.test(args.path) : ex(args.path)) {\n return;\n }\n }\n if (context.config.walk) {\n queue.push(args);\n }\n }\n\n const build: ExtractBuild = {\n onResolve({ filter }, hook) {\n resolves.push({ filter, hook });\n },\n onLoad({ filter }, hook) {\n loads.push({ filter, hook });\n },\n onExtract({ filter }, hook) {\n extracts.push({ filter, hook });\n },\n onCollect({ filter }, hook) {\n collects.push({ filter, hook });\n },\n onGenerate({ filter }, hook) {\n generates.push({ filter, hook });\n },\n resolvePath,\n context,\n };\n\n for (const plugin of config.plugins) {\n logger?.debug({ plugin: plugin.name }, \"setting up plugin\");\n plugin.setup(build);\n }\n\n const visited = new Set<string>();\n const results: ExtractResult[] = [];\n\n async function applyResolve({ entrypoint, path }: ResolveArgs): Promise<ResolveResult | undefined> {\n for (const { filter, hook } of resolves) {\n if (!filter.test(path)) continue;\n const result = await hook({ entrypoint, path }, context);\n if (result) {\n logger?.debug({ entrypoint, path }, \"resolved\");\n }\n if (result) return result;\n }\n return undefined;\n }\n\n async function applyLoad({ entrypoint, path }: LoadArgs): Promise<LoadResult | undefined> {\n for (const { filter, hook } of loads) {\n if (!filter.test(path)) continue;\n const result = await hook({ entrypoint, path }, context);\n if (result) {\n logger?.debug({ entrypoint, path }, \"loaded\");\n }\n if (result) return result;\n }\n return undefined;\n }\n\n async function applyExtract({ entrypoint, path, contents }: ExtractArgs): Promise<ExtractResult | undefined> {\n for (const { filter, hook } of extracts) {\n if (!filter.test(path)) continue;\n const result = await hook({ entrypoint, path, contents }, context);\n if (result) {\n logger?.debug({ entrypoint, path }, \"extracted\");\n }\n if (result) return result;\n }\n return undefined;\n }\n\n async function applyCollect({\n entrypoint,\n path,\n translations,\n destination,\n }: CollectArgs): Promise<CollectResult | undefined> {\n for (const { filter, hook } of collects) {\n if (!filter.test(path)) continue;\n const result = await hook({ entrypoint, path, translations, destination }, context);\n if (result) {\n logger?.debug(\n {\n entrypoint,\n path,\n destination,\n ...(destination !== result.destination && { redirected: result.destination }),\n },\n \"collected\",\n );\n }\n if (result) return result;\n }\n return undefined;\n }\n\n const result: Record<string, CollectResult[]> = {};\n\n while (queue.length) {\n // biome-ignore lint/style/noNonNullAssertion: queue is checked above\n const args = queue.shift()!;\n const resolved = await applyResolve(args);\n if (!resolved || visited.has(resolved.path)) continue;\n visited.add(resolved.path);\n\n const loaded = await applyLoad(resolved);\n if (!loaded) continue;\n\n const extracted = await applyExtract(loaded);\n if (!extracted) continue;\n\n const destination = context.config.destination({ entrypoint, locale, path: resolved.path });\n const collected = await applyCollect({ ...extracted, destination });\n if (!collected) continue;\n\n if (!result[collected.destination]) {\n result[collected.destination] = [];\n }\n\n result[collected.destination].push(collected);\n }\n\n for (const [path, collected] of Object.entries(result)) {\n for (const { filter, hook } of generates) {\n if (!filter.test(path)) continue;\n logger?.info({ path }, \"generating output\");\n await hook({ entrypoint, path, collected }, context);\n }\n }\n\n logger?.info({ entrypoint, locale }, \"extraction completed\");\n return results;\n}\n"],"mappings":"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"}
@@ -21,28 +21,32 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  }) : target, mod));
22
22
 
23
23
  //#endregion
24
- let node_path = require("node:path");
25
- node_path = __toESM(node_path);
26
24
 
27
25
  //#region src/run.ts
28
- async function run(entrypoint, { dest, locale, config }) {
26
+ async function run(entrypoint, { locale, config, logger }) {
29
27
  const entryConfig = config.entrypoints.find((e) => e.entrypoint === entrypoint);
30
28
  const destination = entryConfig?.destination ?? config.destination;
31
29
  const obsolete = entryConfig?.obsolete ?? config.obsolete;
30
+ const exclude = entryConfig?.exclude ?? config.exclude;
32
31
  const queue = [{
33
32
  entrypoint,
34
33
  path: entrypoint
35
34
  }];
35
+ logger?.info({
36
+ entrypoint,
37
+ locale
38
+ }, "starting extraction");
36
39
  const context = {
37
40
  entry: entrypoint,
38
- dest: dest ?? process.cwd(),
39
41
  config: {
40
42
  ...config,
41
43
  destination,
42
- obsolete
44
+ obsolete,
45
+ exclude
43
46
  },
44
47
  generatedAt: /* @__PURE__ */ new Date(),
45
- locale
48
+ locale,
49
+ logger
46
50
  };
47
51
  const resolves = [];
48
52
  const loads = [];
@@ -50,6 +54,7 @@ async function run(entrypoint, { dest, locale, config }) {
50
54
  const collects = [];
51
55
  const generates = [];
52
56
  function resolvePath(args) {
57
+ for (const ex of context.config.exclude) if (ex instanceof RegExp ? ex.test(args.path) : ex(args.path)) return;
53
58
  if (context.config.walk) queue.push(args);
54
59
  }
55
60
  const build = {
@@ -86,7 +91,10 @@ async function run(entrypoint, { dest, locale, config }) {
86
91
  resolvePath,
87
92
  context
88
93
  };
89
- for (const plugin of config.plugins) plugin.setup(build);
94
+ for (const plugin of config.plugins) {
95
+ logger?.debug({ plugin: plugin.name }, "setting up plugin");
96
+ plugin.setup(build);
97
+ }
90
98
  const visited = /* @__PURE__ */ new Set();
91
99
  const results = [];
92
100
  async function applyResolve({ entrypoint: entrypoint$1, path }) {
@@ -96,6 +104,10 @@ async function run(entrypoint, { dest, locale, config }) {
96
104
  entrypoint: entrypoint$1,
97
105
  path
98
106
  }, context);
107
+ if (result$1) logger?.debug({
108
+ entrypoint: entrypoint$1,
109
+ path
110
+ }, "resolved");
99
111
  if (result$1) return result$1;
100
112
  }
101
113
  return void 0;
@@ -107,6 +119,10 @@ async function run(entrypoint, { dest, locale, config }) {
107
119
  entrypoint: entrypoint$1,
108
120
  path
109
121
  }, context);
122
+ if (result$1) logger?.debug({
123
+ entrypoint: entrypoint$1,
124
+ path
125
+ }, "loaded");
110
126
  if (result$1) return result$1;
111
127
  }
112
128
  return void 0;
@@ -119,18 +135,29 @@ async function run(entrypoint, { dest, locale, config }) {
119
135
  path,
120
136
  contents
121
137
  }, context);
138
+ if (result$1) logger?.debug({
139
+ entrypoint: entrypoint$1,
140
+ path
141
+ }, "extracted");
122
142
  if (result$1) return result$1;
123
143
  }
124
144
  return void 0;
125
145
  }
126
- async function applyCollect({ entrypoint: entrypoint$1, path, translations }) {
146
+ async function applyCollect({ entrypoint: entrypoint$1, path, translations, destination: destination$1 }) {
127
147
  for (const { filter, hook } of collects) {
128
148
  if (!filter.test(path)) continue;
129
149
  const result$1 = await hook({
130
150
  entrypoint: entrypoint$1,
131
151
  path,
132
- translations
152
+ translations,
153
+ destination: destination$1
133
154
  }, context);
155
+ if (result$1) logger?.debug({
156
+ entrypoint: entrypoint$1,
157
+ path,
158
+ destination: destination$1,
159
+ ...destination$1 !== result$1.destination && { redirected: result$1.destination }
160
+ }, "collected");
134
161
  if (result$1) return result$1;
135
162
  }
136
163
  return void 0;
@@ -145,28 +172,32 @@ async function run(entrypoint, { dest, locale, config }) {
145
172
  if (!loaded) continue;
146
173
  const extracted = await applyExtract(loaded);
147
174
  if (!extracted) continue;
148
- const collected = await applyCollect(extracted);
175
+ const destination$1 = context.config.destination({
176
+ entrypoint,
177
+ locale,
178
+ path: resolved.path
179
+ });
180
+ const collected = await applyCollect({
181
+ ...extracted,
182
+ destination: destination$1
183
+ });
149
184
  if (!collected) continue;
150
- const destPath = context.config.destination(locale, entrypoint, collected.destination);
151
- const final = {
152
- ...collected,
153
- destination: destPath
154
- };
155
- if (!result[destPath]) result[destPath] = [];
156
- result[destPath].push(final);
185
+ if (!result[collected.destination]) result[collected.destination] = [];
186
+ result[collected.destination].push(collected);
157
187
  }
158
- for (const [path, collected] of Object.entries(result)) {
159
- const fullPath = (0, node_path.join)(context.dest, path);
160
- for (const { filter, hook } of generates) {
161
- if (!filter.test(fullPath)) continue;
162
- await hook({
163
- entrypoint,
164
- locale,
165
- path: fullPath,
166
- collected
167
- }, context);
168
- }
188
+ for (const [path, collected] of Object.entries(result)) for (const { filter, hook } of generates) {
189
+ if (!filter.test(path)) continue;
190
+ logger?.info({ path }, "generating output");
191
+ await hook({
192
+ entrypoint,
193
+ path,
194
+ collected
195
+ }, context);
169
196
  }
197
+ logger?.info({
198
+ entrypoint,
199
+ locale
200
+ }, "extraction completed");
170
201
  return results;
171
202
  }
172
203
 
@@ -1,4 +1,4 @@
1
- const require_run = require('../run-Ds6SfSE_.cjs');
1
+ const require_run = require('../run-DmgUA6g-.cjs');
2
2
  let node_path = require("node:path");
3
3
  node_path = require_run.__toESM(node_path);
4
4
  let glob = require("glob");
@@ -532,6 +532,7 @@ function core() {
532
532
  return {
533
533
  name: "core",
534
534
  setup(build) {
535
+ build.context.logger?.debug("core plugin initialized");
535
536
  build.onResolve({ filter: /.*/ }, ({ entrypoint, path: path$1 }) => {
536
537
  return {
537
538
  entrypoint,
@@ -598,7 +599,7 @@ function collect(source, locale) {
598
599
  }
599
600
  return translations;
600
601
  }
601
- function merge(locale, sources, existing, strategy = "mark", timestamp = /* @__PURE__ */ new Date()) {
602
+ function merge(sources, existing, obsolete, locale, generatedAt) {
602
603
  let headers = {};
603
604
  let translations = { "": {} };
604
605
  const nplurals = (0, plural_forms.getNPlurals)(locale);
@@ -634,10 +635,10 @@ function merge(locale, sources, existing, strategy = "mark", timestamp = /* @__P
634
635
  "content-type": headers["content-type"] || "text/plain; charset=UTF-8",
635
636
  "plural-forms": `nplurals=${nplurals}; plural=${(0, plural_forms.getFormula)(locale)};`,
636
637
  language: locale,
637
- "pot-creation-date": formatDate(timestamp),
638
+ "pot-creation-date": formatDate(generatedAt),
638
639
  "x-generator": "@let-value/translate-extract"
639
640
  };
640
- if (strategy === "remove") {
641
+ if (obsolete === "remove") {
641
642
  for (const ctx of Object.keys(translations)) for (const id of Object.keys(translations[ctx])) if (translations[ctx][id].obsolete) delete translations[ctx][id];
642
643
  }
643
644
  const poObj = {
@@ -651,19 +652,20 @@ function po() {
651
652
  return {
652
653
  name: "po",
653
654
  setup(build) {
654
- build.onCollect({ filter: /.*/ }, ({ entrypoint, translations,...rest }, ctx) => {
655
+ build.context.logger?.debug("po plugin initialized");
656
+ build.onCollect({ filter: /.*/ }, ({ entrypoint, translations, destination,...rest }, ctx) => {
655
657
  const record = collect(translations, ctx.locale);
656
- const destination = `${(0, node_path.basename)(entrypoint, (0, node_path.extname)(entrypoint))}.po`;
658
+ const redirected = (0, node_path.join)((0, node_path.dirname)(destination), `${(0, node_path.basename)(destination, (0, node_path.extname)(destination))}.po`);
657
659
  return {
658
660
  ...rest,
659
661
  entrypoint,
660
- destination,
662
+ destination: redirected,
661
663
  translations: record
662
664
  };
663
665
  });
664
- build.onGenerate({ filter: /.*\/po$/ }, async ({ path: path$1, locale, collected }, ctx) => {
666
+ build.onGenerate({ filter: /.*\/po$/ }, async ({ path: path$1, collected }, ctx) => {
665
667
  const existing = await node_fs_promises.default.readFile(path$1).catch(() => void 0);
666
- const out = merge(locale, collected, existing, ctx.config.obsolete, ctx.generatedAt);
668
+ const out = merge(collected, existing, ctx.config.obsolete, ctx.locale, ctx.generatedAt);
667
669
  await node_fs_promises.default.mkdir((0, node_path.dirname)(path$1), { recursive: true });
668
670
  await node_fs_promises.default.writeFile(path$1, out);
669
671
  });
@@ -677,7 +679,16 @@ const defaultPlugins = {
677
679
  core,
678
680
  po
679
681
  };
680
- const defaultDestination = (locale, _entrypoint, path$1) => (0, node_path.join)(locale, path$1);
682
+ const defaultDestination = ({ entrypoint, locale }) => (0, node_path.join)((0, node_path.dirname)(entrypoint), "translations", `${(0, node_path.basename)(entrypoint, (0, node_path.extname)(entrypoint))}.${locale}.po`);
683
+ const defaultExclude = [
684
+ /(?:^|[\\/])node_modules(?:[\\/]|$)/,
685
+ /(?:^|[\\/])dist(?:[\\/]|$)/,
686
+ /(?:^|[\\/])build(?:[\\/]|$)/
687
+ ];
688
+ function normalizeExclude(exclude) {
689
+ if (!exclude) return [];
690
+ return Array.isArray(exclude) ? exclude : [exclude];
691
+ }
681
692
  function defineConfig(config) {
682
693
  let plugins;
683
694
  const user = config.plugins;
@@ -691,17 +702,20 @@ function defineConfig(config) {
691
702
  if (paths.length === 0) entrypoints.push({ entrypoint: ep });
692
703
  else for (const path$1 of paths) entrypoints.push({ entrypoint: path$1 });
693
704
  } else {
694
- const { entrypoint, destination: destination$1, obsolete: obsolete$1 } = ep;
705
+ const { entrypoint, destination: destination$1, obsolete: obsolete$1, exclude: exclude$1 } = ep;
695
706
  const paths = (0, glob.globSync)(entrypoint, { nodir: true });
707
+ const epExclude = exclude$1 ? [...defaultExclude, ...normalizeExclude(exclude$1)] : void 0;
696
708
  if (paths.length === 0) entrypoints.push({
697
709
  entrypoint,
698
710
  destination: destination$1,
699
- obsolete: obsolete$1
711
+ obsolete: obsolete$1,
712
+ exclude: epExclude
700
713
  });
701
714
  else for (const path$1 of paths) entrypoints.push({
702
715
  entrypoint: path$1,
703
716
  destination: destination$1,
704
- obsolete: obsolete$1
717
+ obsolete: obsolete$1,
718
+ exclude: epExclude
705
719
  });
706
720
  }
707
721
  const defaultLocale = config.defaultLocale ?? "en";
@@ -709,6 +723,8 @@ function defineConfig(config) {
709
723
  const destination = config.destination ?? defaultDestination;
710
724
  const obsolete = config.obsolete ?? "mark";
711
725
  const walk = config.walk ?? true;
726
+ const logLevel = config.logLevel ?? "info";
727
+ const exclude = [...defaultExclude, ...normalizeExclude(config.exclude)];
712
728
  return {
713
729
  plugins,
714
730
  entrypoints,
@@ -716,7 +732,9 @@ function defineConfig(config) {
716
732
  locales,
717
733
  destination,
718
734
  obsolete,
719
- walk
735
+ walk,
736
+ logLevel,
737
+ exclude
720
738
  };
721
739
  }
722
740
 
@@ -931,6 +949,7 @@ function react() {
931
949
  return {
932
950
  name: "react",
933
951
  setup(build) {
952
+ build.context.logger?.debug("react plugin initialized");
934
953
  build.onResolve({ filter: /.*/ }, ({ entrypoint, path: path$1 }) => {
935
954
  return {
936
955
  entrypoint,