@let-value/translate-extract 1.0.9 → 1.0.10
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 +2 -2
- package/dist/bin/cli.js +2 -2
- package/dist/bin/cli.js.map +1 -1
- package/dist/run-8jCGSKUe.cjs +184 -0
- package/dist/run-CMzN4vHt.js +150 -0
- package/dist/run-CMzN4vHt.js.map +1 -0
- package/dist/src/index.cjs +282 -120
- package/dist/src/index.d.cts +141 -62
- package/dist/src/index.d.cts.map +1 -1
- package/dist/src/index.d.ts +142 -63
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +281 -118
- package/dist/src/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/run-BMvkoNJ4.js +0 -192
- package/dist/run-BMvkoNJ4.js.map +0 -1
- package/dist/run-CbsVUbM3.cjs +0 -226
package/dist/bin/cli.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const require_run = require('../run-
|
|
2
|
+
const require_run = require('../run-8jCGSKUe.cjs');
|
|
3
3
|
let node_util = require("node:util");
|
|
4
4
|
node_util = require_run.__toESM(node_util);
|
|
5
5
|
let cosmiconfig = require("cosmiconfig");
|
|
@@ -53,7 +53,7 @@ async function main() {
|
|
|
53
53
|
config.logLevel = logLevel ?? config.logLevel;
|
|
54
54
|
logger.level = config.logLevel;
|
|
55
55
|
const tasks = [];
|
|
56
|
-
for (const
|
|
56
|
+
for (const entrypoint of config.entrypoints) tasks.push(require_run.run(entrypoint, {
|
|
57
57
|
config,
|
|
58
58
|
logger
|
|
59
59
|
}));
|
package/dist/bin/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { run } from "../run-
|
|
2
|
+
import { run } from "../run-CMzN4vHt.js";
|
|
3
3
|
import { parseArgs } from "node:util";
|
|
4
4
|
import { cosmiconfig } from "cosmiconfig";
|
|
5
5
|
import pino from "pino";
|
|
@@ -50,7 +50,7 @@ async function main() {
|
|
|
50
50
|
config.logLevel = logLevel ?? config.logLevel;
|
|
51
51
|
logger.level = config.logLevel;
|
|
52
52
|
const tasks = [];
|
|
53
|
-
for (const
|
|
53
|
+
for (const entrypoint of config.entrypoints) tasks.push(run(entrypoint, {
|
|
54
54
|
config,
|
|
55
55
|
logger
|
|
56
56
|
}));
|
package/dist/bin/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
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) ?? config.logLevel;\n logger.level = config.logLevel;\n\n const tasks: Promise<unknown>[] = [];\n for (const entrypoint of config.entrypoints) {\n tasks.push(run(entrypoint, { config, logger }));\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,YAAgC,OAAO;AAC1D,QAAO,QAAQ,OAAO;CAEtB,MAAMA,QAA4B;AAClC,MAAK,MAAM,cAAc,OAAO,YAC5B,OAAM,KAAK,IAAI,YAAY;EAAE;EAAQ;;AAGzC,OAAM,QAAQ,IAAI;;AAGjB,OAAO,OAAO,QAAQ;CACvB,MAAM,SAAS;AACf,QAAO,MAAM;AACb,SAAQ,KAAK"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
let glob = require("glob");
|
|
25
|
+
glob = __toESM(glob);
|
|
26
|
+
|
|
27
|
+
//#region src/defer.ts
|
|
28
|
+
var Defer = class {
|
|
29
|
+
pending = 0;
|
|
30
|
+
promise = Promise.resolve();
|
|
31
|
+
resolve;
|
|
32
|
+
enqueue() {
|
|
33
|
+
if (this.pending++ === 0) this.promise = new Promise((res) => {
|
|
34
|
+
this.resolve = res;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
dequeue() {
|
|
38
|
+
if (this.pending > 0 && --this.pending === 0) this.resolve?.();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/run.ts
|
|
44
|
+
async function run(entrypoint, { config, logger }) {
|
|
45
|
+
const destination = entrypoint?.destination ?? config.destination;
|
|
46
|
+
const obsolete = entrypoint?.obsolete ?? config.obsolete;
|
|
47
|
+
const exclude = entrypoint?.exclude ?? config.exclude;
|
|
48
|
+
const walk = entrypoint?.walk ?? config.walk;
|
|
49
|
+
const context = {
|
|
50
|
+
config: {
|
|
51
|
+
...config,
|
|
52
|
+
destination,
|
|
53
|
+
obsolete,
|
|
54
|
+
exclude,
|
|
55
|
+
walk
|
|
56
|
+
},
|
|
57
|
+
generatedAt: /* @__PURE__ */ new Date(),
|
|
58
|
+
logger
|
|
59
|
+
};
|
|
60
|
+
logger?.info({ entrypoint }, "starting extraction");
|
|
61
|
+
const resolvers = [];
|
|
62
|
+
const loaders = [];
|
|
63
|
+
const processors = [];
|
|
64
|
+
const hooks = {
|
|
65
|
+
resolve: resolvers,
|
|
66
|
+
load: loaders,
|
|
67
|
+
process: processors
|
|
68
|
+
};
|
|
69
|
+
const pending = /* @__PURE__ */ new Map();
|
|
70
|
+
const queue = [];
|
|
71
|
+
function getDeferred(namespace) {
|
|
72
|
+
let defer$1 = pending.get(namespace);
|
|
73
|
+
if (defer$1 === void 0) {
|
|
74
|
+
defer$1 = new Defer();
|
|
75
|
+
pending.set(namespace, defer$1);
|
|
76
|
+
}
|
|
77
|
+
return defer$1;
|
|
78
|
+
}
|
|
79
|
+
function defer(namespace) {
|
|
80
|
+
const defer$1 = getDeferred(namespace);
|
|
81
|
+
return defer$1.promise;
|
|
82
|
+
}
|
|
83
|
+
function resolve(args) {
|
|
84
|
+
if (args.path !== args.entrypoint && (!context.config.walk || context.config.exclude.some((ex) => typeof ex === "function" ? ex(args) : ex.test(args.path)))) return;
|
|
85
|
+
queue.push({
|
|
86
|
+
type: "resolve",
|
|
87
|
+
args
|
|
88
|
+
});
|
|
89
|
+
getDeferred(args.namespace).enqueue();
|
|
90
|
+
}
|
|
91
|
+
function load(args) {
|
|
92
|
+
queue.push({
|
|
93
|
+
type: "load",
|
|
94
|
+
args
|
|
95
|
+
});
|
|
96
|
+
getDeferred(args.namespace).enqueue();
|
|
97
|
+
}
|
|
98
|
+
function process(args) {
|
|
99
|
+
queue.push({
|
|
100
|
+
type: "process",
|
|
101
|
+
args
|
|
102
|
+
});
|
|
103
|
+
getDeferred(args.namespace).enqueue();
|
|
104
|
+
}
|
|
105
|
+
const build = {
|
|
106
|
+
context,
|
|
107
|
+
resolve,
|
|
108
|
+
load,
|
|
109
|
+
process,
|
|
110
|
+
defer,
|
|
111
|
+
onResolve(filter, hook) {
|
|
112
|
+
resolvers.push({
|
|
113
|
+
filter,
|
|
114
|
+
hook
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
onLoad(filter, hook) {
|
|
118
|
+
loaders.push({
|
|
119
|
+
filter,
|
|
120
|
+
hook
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
onProcess(filter, hook) {
|
|
124
|
+
processors.push({
|
|
125
|
+
filter,
|
|
126
|
+
hook
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
for (const plugin of config.plugins) {
|
|
131
|
+
logger?.debug({ plugin: plugin.name }, "setting up plugin");
|
|
132
|
+
plugin.setup(build);
|
|
133
|
+
}
|
|
134
|
+
const paths = (0, glob.globSync)(entrypoint.entrypoint, { nodir: true });
|
|
135
|
+
if (paths.length === 0) resolve({
|
|
136
|
+
entrypoint: entrypoint.entrypoint,
|
|
137
|
+
path: entrypoint.entrypoint,
|
|
138
|
+
namespace: "source"
|
|
139
|
+
});
|
|
140
|
+
else for (const path of paths) resolve({
|
|
141
|
+
entrypoint: entrypoint.entrypoint,
|
|
142
|
+
path,
|
|
143
|
+
namespace: "source"
|
|
144
|
+
});
|
|
145
|
+
async function processTask(task) {
|
|
146
|
+
const { type } = task;
|
|
147
|
+
let args = task.args;
|
|
148
|
+
for (const { filter: { filter, namespace }, hook } of hooks[type]) {
|
|
149
|
+
if (namespace !== args.namespace) continue;
|
|
150
|
+
if (filter && !filter.test(args.path)) continue;
|
|
151
|
+
const result = await hook(args);
|
|
152
|
+
if (result !== void 0) args = result;
|
|
153
|
+
}
|
|
154
|
+
if (args !== void 0) {
|
|
155
|
+
if (type === "resolve") load(args);
|
|
156
|
+
else if (type === "load") process(args);
|
|
157
|
+
}
|
|
158
|
+
getDeferred(task.args.namespace).dequeue();
|
|
159
|
+
}
|
|
160
|
+
while (queue.length || Array.from(pending.values()).some((d) => d.pending > 0)) {
|
|
161
|
+
while (queue.length) {
|
|
162
|
+
const task = queue.shift();
|
|
163
|
+
if (!task) break;
|
|
164
|
+
await processTask(task);
|
|
165
|
+
}
|
|
166
|
+
await Promise.all(Array.from(pending.values()).map((d) => d.promise));
|
|
167
|
+
await Promise.resolve();
|
|
168
|
+
}
|
|
169
|
+
logger?.info({ entrypoint }, "extraction completed");
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
//#endregion
|
|
173
|
+
Object.defineProperty(exports, '__toESM', {
|
|
174
|
+
enumerable: true,
|
|
175
|
+
get: function () {
|
|
176
|
+
return __toESM;
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
Object.defineProperty(exports, 'run', {
|
|
180
|
+
enumerable: true,
|
|
181
|
+
get: function () {
|
|
182
|
+
return run;
|
|
183
|
+
}
|
|
184
|
+
});
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { globSync } from "glob";
|
|
2
|
+
|
|
3
|
+
//#region src/defer.ts
|
|
4
|
+
var Defer = class {
|
|
5
|
+
pending = 0;
|
|
6
|
+
promise = Promise.resolve();
|
|
7
|
+
resolve;
|
|
8
|
+
enqueue() {
|
|
9
|
+
if (this.pending++ === 0) this.promise = new Promise((res) => {
|
|
10
|
+
this.resolve = res;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
dequeue() {
|
|
14
|
+
if (this.pending > 0 && --this.pending === 0) this.resolve?.();
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/run.ts
|
|
20
|
+
async function run(entrypoint, { config, logger }) {
|
|
21
|
+
const destination = entrypoint?.destination ?? config.destination;
|
|
22
|
+
const obsolete = entrypoint?.obsolete ?? config.obsolete;
|
|
23
|
+
const exclude = entrypoint?.exclude ?? config.exclude;
|
|
24
|
+
const walk = entrypoint?.walk ?? config.walk;
|
|
25
|
+
const context = {
|
|
26
|
+
config: {
|
|
27
|
+
...config,
|
|
28
|
+
destination,
|
|
29
|
+
obsolete,
|
|
30
|
+
exclude,
|
|
31
|
+
walk
|
|
32
|
+
},
|
|
33
|
+
generatedAt: /* @__PURE__ */ new Date(),
|
|
34
|
+
logger
|
|
35
|
+
};
|
|
36
|
+
logger?.info({ entrypoint }, "starting extraction");
|
|
37
|
+
const resolvers = [];
|
|
38
|
+
const loaders = [];
|
|
39
|
+
const processors = [];
|
|
40
|
+
const hooks = {
|
|
41
|
+
resolve: resolvers,
|
|
42
|
+
load: loaders,
|
|
43
|
+
process: processors
|
|
44
|
+
};
|
|
45
|
+
const pending = /* @__PURE__ */ new Map();
|
|
46
|
+
const queue = [];
|
|
47
|
+
function getDeferred(namespace) {
|
|
48
|
+
let defer$1 = pending.get(namespace);
|
|
49
|
+
if (defer$1 === void 0) {
|
|
50
|
+
defer$1 = new Defer();
|
|
51
|
+
pending.set(namespace, defer$1);
|
|
52
|
+
}
|
|
53
|
+
return defer$1;
|
|
54
|
+
}
|
|
55
|
+
function defer(namespace) {
|
|
56
|
+
const defer$1 = getDeferred(namespace);
|
|
57
|
+
return defer$1.promise;
|
|
58
|
+
}
|
|
59
|
+
function resolve(args) {
|
|
60
|
+
if (args.path !== args.entrypoint && (!context.config.walk || context.config.exclude.some((ex) => typeof ex === "function" ? ex(args) : ex.test(args.path)))) return;
|
|
61
|
+
queue.push({
|
|
62
|
+
type: "resolve",
|
|
63
|
+
args
|
|
64
|
+
});
|
|
65
|
+
getDeferred(args.namespace).enqueue();
|
|
66
|
+
}
|
|
67
|
+
function load(args) {
|
|
68
|
+
queue.push({
|
|
69
|
+
type: "load",
|
|
70
|
+
args
|
|
71
|
+
});
|
|
72
|
+
getDeferred(args.namespace).enqueue();
|
|
73
|
+
}
|
|
74
|
+
function process(args) {
|
|
75
|
+
queue.push({
|
|
76
|
+
type: "process",
|
|
77
|
+
args
|
|
78
|
+
});
|
|
79
|
+
getDeferred(args.namespace).enqueue();
|
|
80
|
+
}
|
|
81
|
+
const build = {
|
|
82
|
+
context,
|
|
83
|
+
resolve,
|
|
84
|
+
load,
|
|
85
|
+
process,
|
|
86
|
+
defer,
|
|
87
|
+
onResolve(filter, hook) {
|
|
88
|
+
resolvers.push({
|
|
89
|
+
filter,
|
|
90
|
+
hook
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
onLoad(filter, hook) {
|
|
94
|
+
loaders.push({
|
|
95
|
+
filter,
|
|
96
|
+
hook
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
onProcess(filter, hook) {
|
|
100
|
+
processors.push({
|
|
101
|
+
filter,
|
|
102
|
+
hook
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
for (const plugin of config.plugins) {
|
|
107
|
+
logger?.debug({ plugin: plugin.name }, "setting up plugin");
|
|
108
|
+
plugin.setup(build);
|
|
109
|
+
}
|
|
110
|
+
const paths = globSync(entrypoint.entrypoint, { nodir: true });
|
|
111
|
+
if (paths.length === 0) resolve({
|
|
112
|
+
entrypoint: entrypoint.entrypoint,
|
|
113
|
+
path: entrypoint.entrypoint,
|
|
114
|
+
namespace: "source"
|
|
115
|
+
});
|
|
116
|
+
else for (const path of paths) resolve({
|
|
117
|
+
entrypoint: entrypoint.entrypoint,
|
|
118
|
+
path,
|
|
119
|
+
namespace: "source"
|
|
120
|
+
});
|
|
121
|
+
async function processTask(task) {
|
|
122
|
+
const { type } = task;
|
|
123
|
+
let args = task.args;
|
|
124
|
+
for (const { filter: { filter, namespace }, hook } of hooks[type]) {
|
|
125
|
+
if (namespace !== args.namespace) continue;
|
|
126
|
+
if (filter && !filter.test(args.path)) continue;
|
|
127
|
+
const result = await hook(args);
|
|
128
|
+
if (result !== void 0) args = result;
|
|
129
|
+
}
|
|
130
|
+
if (args !== void 0) {
|
|
131
|
+
if (type === "resolve") load(args);
|
|
132
|
+
else if (type === "load") process(args);
|
|
133
|
+
}
|
|
134
|
+
getDeferred(task.args.namespace).dequeue();
|
|
135
|
+
}
|
|
136
|
+
while (queue.length || Array.from(pending.values()).some((d) => d.pending > 0)) {
|
|
137
|
+
while (queue.length) {
|
|
138
|
+
const task = queue.shift();
|
|
139
|
+
if (!task) break;
|
|
140
|
+
await processTask(task);
|
|
141
|
+
}
|
|
142
|
+
await Promise.all(Array.from(pending.values()).map((d) => d.promise));
|
|
143
|
+
await Promise.resolve();
|
|
144
|
+
}
|
|
145
|
+
logger?.info({ entrypoint }, "extraction completed");
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
//#endregion
|
|
149
|
+
export { run };
|
|
150
|
+
//# sourceMappingURL=run-CMzN4vHt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-CMzN4vHt.js","names":["context: Context","resolvers: { filter: Filter; hook: ResolveHook }[]","loaders: { filter: Filter; hook: LoadHook }[]","processors: { filter: Filter; hook: ProcessHook }[]","queue: Task[]","defer","build: Build"],"sources":["../src/defer.ts","../src/run.ts"],"sourcesContent":["export class Defer {\n pending = 0;\n promise: Promise<void> = Promise.resolve();\n resolve?: () => void;\n\n enqueue() {\n if (this.pending++ === 0) {\n this.promise = new Promise<void>((res) => {\n this.resolve = res;\n });\n }\n }\n dequeue() {\n if (this.pending > 0 && --this.pending === 0) {\n this.resolve?.();\n }\n }\n}\n","import { globSync } from \"glob\";\nimport type { ResolvedConfig, ResolvedEntrypoint } from \"./configuration.ts\";\nimport { Defer } from \"./defer.ts\";\nimport type { Logger } from \"./logger.ts\";\nimport type {\n Build,\n Context,\n Filter,\n LoadArgs,\n LoadHook,\n ProcessArgs,\n ProcessHook,\n ResolveArgs,\n ResolveHook,\n} from \"./plugin.ts\";\n\nexport type Task =\n | {\n type: \"resolve\";\n args: ResolveArgs;\n }\n | {\n type: \"load\";\n args: LoadArgs;\n }\n | {\n type: \"process\";\n args: ProcessArgs;\n };\n\nexport async function run(\n entrypoint: ResolvedEntrypoint,\n { config, logger }: { config: ResolvedConfig; logger?: Logger },\n) {\n const destination = entrypoint?.destination ?? config.destination;\n const obsolete = entrypoint?.obsolete ?? config.obsolete;\n const exclude = entrypoint?.exclude ?? config.exclude;\n const walk = entrypoint?.walk ?? config.walk;\n\n const context: Context = {\n config: { ...config, destination, obsolete, exclude, walk },\n generatedAt: new Date(),\n logger,\n };\n\n logger?.info({ entrypoint }, \"starting extraction\");\n\n const resolvers: { filter: Filter; hook: ResolveHook }[] = [];\n const loaders: { filter: Filter; hook: LoadHook }[] = [];\n const processors: { filter: Filter; hook: ProcessHook }[] = [];\n const hooks = {\n resolve: resolvers,\n load: loaders,\n process: processors,\n };\n\n const pending = new Map<string, Defer>();\n const queue: Task[] = [];\n\n function getDeferred(namespace: string) {\n let defer = pending.get(namespace);\n if (defer === undefined) {\n defer = new Defer();\n pending.set(namespace, defer);\n }\n return defer;\n }\n\n function defer(namespace: string) {\n const defer = getDeferred(namespace);\n return defer.promise;\n }\n\n function resolve(args: ResolveArgs) {\n if (\n args.path !== args.entrypoint &&\n (!context.config.walk ||\n context.config.exclude.some((ex) => (typeof ex === \"function\" ? ex(args) : ex.test(args.path))))\n ) {\n return;\n }\n queue.push({ type: \"resolve\", args });\n getDeferred(args.namespace).enqueue();\n }\n\n function load(args: LoadArgs) {\n queue.push({ type: \"load\", args });\n getDeferred(args.namespace).enqueue();\n }\n\n function process(args: ProcessArgs) {\n queue.push({ type: \"process\", args });\n getDeferred(args.namespace).enqueue();\n }\n\n const build: Build = {\n context,\n resolve,\n load,\n process,\n defer,\n onResolve(filter, hook) {\n resolvers.push({ filter, hook });\n },\n onLoad(filter, hook) {\n loaders.push({ filter, hook });\n },\n onProcess(filter, hook) {\n processors.push({ filter, hook });\n },\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 paths = globSync(entrypoint.entrypoint, { nodir: true });\n if (paths.length === 0) {\n resolve({ entrypoint: entrypoint.entrypoint, path: entrypoint.entrypoint, namespace: \"source\" });\n } else {\n for (const path of paths) {\n resolve({ entrypoint: entrypoint.entrypoint, path, namespace: \"source\" });\n }\n }\n\n async function processTask(task: Task) {\n const { type } = task;\n let args = task.args;\n\n for (const {\n filter: { filter, namespace },\n hook,\n } of hooks[type]) {\n if (namespace !== args.namespace) continue;\n if (filter && !filter.test(args.path)) continue;\n\n const result = await hook(args as never);\n if (result !== undefined) {\n args = result as never;\n }\n }\n\n if (args !== undefined) {\n if (type === \"resolve\") {\n load(args as never);\n } else if (type === \"load\") {\n process(args as never);\n }\n }\n\n getDeferred(task.args.namespace).dequeue();\n }\n\n while (queue.length || Array.from(pending.values()).some((d) => d.pending > 0)) {\n while (queue.length) {\n const task = queue.shift();\n if (!task) {\n break;\n }\n\n await processTask(task);\n }\n\n await Promise.all(Array.from(pending.values()).map((d) => d.promise));\n await Promise.resolve();\n }\n\n logger?.info({ entrypoint }, \"extraction completed\");\n}\n"],"mappings":";;;AAAA,IAAa,QAAb,MAAmB;CACf,UAAU;CACV,UAAyB,QAAQ;CACjC;CAEA,UAAU;AACN,MAAI,KAAK,cAAc,EACnB,MAAK,UAAU,IAAI,SAAe,QAAQ;AACtC,QAAK,UAAU;;;CAI3B,UAAU;AACN,MAAI,KAAK,UAAU,KAAK,EAAE,KAAK,YAAY,EACvC,MAAK;;;;;;ACgBjB,eAAsB,IAClB,YACA,EAAE,QAAQ,UACZ;CACE,MAAM,cAAc,YAAY,eAAe,OAAO;CACtD,MAAM,WAAW,YAAY,YAAY,OAAO;CAChD,MAAM,UAAU,YAAY,WAAW,OAAO;CAC9C,MAAM,OAAO,YAAY,QAAQ,OAAO;CAExC,MAAMA,UAAmB;EACrB,QAAQ;GAAE,GAAG;GAAQ;GAAa;GAAU;GAAS;;EACrD,6BAAa,IAAI;EACjB;;AAGJ,SAAQ,KAAK,EAAE,cAAc;CA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