ptech-preset 1.1.6 → 1.1.7
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/index.js +35 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12,20 +12,32 @@ async function collectAutoExposes(opts = {}) {
|
|
|
12
12
|
const globs = opts.globs ?? ["src/components/**/*.{ts,tsx}"];
|
|
13
13
|
const baseDir = path.resolve(process.cwd(), opts.baseDir ?? "src");
|
|
14
14
|
const tag = opts.tag ?? "expose";
|
|
15
|
+
const debug = !!opts.debug;
|
|
15
16
|
const files = await fg(globs, {
|
|
16
17
|
cwd: process.cwd(),
|
|
17
18
|
absolute: true,
|
|
18
19
|
ignore: ["**/*.d.ts"]
|
|
19
20
|
});
|
|
21
|
+
const jsdocRe = new RegExp(
|
|
22
|
+
String.raw`/\*\*[\s\S]*?@${tag}(?:\s+([^\s*]+))?[\s\S]*?\*/`,
|
|
23
|
+
"m"
|
|
24
|
+
);
|
|
20
25
|
const exposes = {};
|
|
21
26
|
for (const abs of files) {
|
|
22
27
|
const text = fs.readFileSync(abs, "utf8");
|
|
23
|
-
const m = text.match(
|
|
28
|
+
const m = text.match(jsdocRe);
|
|
24
29
|
if (!m) continue;
|
|
25
30
|
const raw = (m[1] || "").trim();
|
|
26
31
|
const key = raw || path.basename(abs).replace(/\.(tsx?|jsx?)$/, "");
|
|
27
32
|
const rel = path.relative(baseDir, abs).replace(/\\/g, "/");
|
|
28
33
|
exposes[`./${key}`] = `./${rel}`;
|
|
34
|
+
if (debug) {
|
|
35
|
+
console.log(`[mf-auto] JSDoc expose: key="./${key}" -> ${rel}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (debug) {
|
|
39
|
+
const count = Object.keys(exposes).length;
|
|
40
|
+
console.log(`[mf-auto] collectAutoExposes: ${count} expose(s) found`);
|
|
29
41
|
}
|
|
30
42
|
return exposes;
|
|
31
43
|
}
|
|
@@ -33,29 +45,41 @@ async function collectAutoExposesWithWrapper(opts = {}) {
|
|
|
33
45
|
if (opts.enabled === false) return {};
|
|
34
46
|
const globs = opts.globs ?? ["src/components/**/*.{ts,tsx}"];
|
|
35
47
|
const baseDir = path.resolve(process.cwd(), opts.baseDir ?? "src");
|
|
48
|
+
const debug = !!opts.debug;
|
|
36
49
|
const files = await fg(globs, {
|
|
37
50
|
cwd: process.cwd(),
|
|
38
51
|
absolute: true,
|
|
39
52
|
ignore: ["**/*.d.ts"]
|
|
40
53
|
});
|
|
54
|
+
const jsdocRe = new RegExp(
|
|
55
|
+
String.raw`/\*\*[\s\S]*?@expose(?:\s+([^\s*]+))?[\s\S]*?\*/`,
|
|
56
|
+
"m"
|
|
57
|
+
);
|
|
58
|
+
const wrapperRe = /exposeComponent\s*\(\s*[^,]+,\s*['"`]([^'"`]+)['"`]\s*\)/;
|
|
41
59
|
const exposes = {};
|
|
42
60
|
for (const abs of files) {
|
|
43
61
|
const text = fs.readFileSync(abs, "utf8");
|
|
44
|
-
|
|
62
|
+
let key;
|
|
63
|
+
const jsdocMatch = text.match(jsdocRe);
|
|
45
64
|
if (jsdocMatch) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
65
|
+
key = (jsdocMatch[1] || "").trim();
|
|
66
|
+
} else {
|
|
67
|
+
const wrapperMatch = text.match(wrapperRe);
|
|
68
|
+
if (wrapperMatch) key = wrapperMatch[1];
|
|
69
|
+
}
|
|
70
|
+
if (!key) {
|
|
50
71
|
continue;
|
|
51
72
|
}
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
exposes[`./${key}`] = `./${rel}`;
|
|
73
|
+
const rel = path.relative(baseDir, abs).replace(/\\/g, "/");
|
|
74
|
+
exposes[`./${key}`] = `./${rel}`;
|
|
75
|
+
if (debug) {
|
|
76
|
+
console.log(`[mf-auto] Wrapper/JSDoc expose: key="./${key}" -> ${rel}`);
|
|
57
77
|
}
|
|
58
78
|
}
|
|
79
|
+
if (debug) {
|
|
80
|
+
const count = Object.keys(exposes).length;
|
|
81
|
+
console.log(`[mf-auto] collectAutoExposesWithWrapper: ${count} expose(s) found`);
|
|
82
|
+
}
|
|
59
83
|
return exposes;
|
|
60
84
|
}
|
|
61
85
|
|