@openpkg-ts/extract 0.14.3 → 0.14.4
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/tspec.js +39 -18
- package/package.json +1 -1
package/dist/bin/tspec.js
CHANGED
|
@@ -1488,10 +1488,24 @@ import { normalize, validateSpec } from "@openpkg-ts/spec";
|
|
|
1488
1488
|
import { Command } from "commander";
|
|
1489
1489
|
function createProgram() {
|
|
1490
1490
|
const program = new Command("tspec").description("Extract TypeScript package API to OpenPkg spec").argument("[entry]", "Entry point file").option("-o, --output <file>", "Output file", "openpkg.json").option("--max-depth <n>", "Max type depth (default: 4)").option("--skip-resolve", "Skip external type resolution").option("--runtime", "Enable Standard Schema runtime extraction").option("-v, --verbose", "Show detailed output").action(async (entry, options) => {
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1491
|
+
let entryFile;
|
|
1492
|
+
let fromDts = false;
|
|
1493
|
+
if (entry) {
|
|
1494
|
+
entryFile = entry;
|
|
1495
|
+
fromDts = entry.endsWith(".d.ts");
|
|
1496
|
+
} else {
|
|
1497
|
+
const found = findEntryPoint(process.cwd());
|
|
1498
|
+
if (!found) {
|
|
1499
|
+
console.error("No entry point found. Please specify an entry file.");
|
|
1500
|
+
process.exit(1);
|
|
1501
|
+
}
|
|
1502
|
+
entryFile = found.path;
|
|
1503
|
+
fromDts = found.fromDts;
|
|
1504
|
+
}
|
|
1505
|
+
if (fromDts) {
|
|
1506
|
+
console.warn("⚠ Using .d.ts file. TSDoc comments may be missing.");
|
|
1507
|
+
console.warn(` Consider: tspec src/index.ts
|
|
1508
|
+
`);
|
|
1495
1509
|
}
|
|
1496
1510
|
const spin = spinner("Extracting...");
|
|
1497
1511
|
const result = await extract({
|
|
@@ -1523,29 +1537,36 @@ function createProgram() {
|
|
|
1523
1537
|
return program;
|
|
1524
1538
|
}
|
|
1525
1539
|
function findEntryPoint(cwd) {
|
|
1540
|
+
const sourceEntries = ["src/index.ts", "index.ts", "lib/index.ts"];
|
|
1541
|
+
for (const entry of sourceEntries) {
|
|
1542
|
+
const fullPath = path.join(cwd, entry);
|
|
1543
|
+
if (fs.existsSync(fullPath))
|
|
1544
|
+
return { path: fullPath, fromDts: false };
|
|
1545
|
+
}
|
|
1526
1546
|
const pkgPath = path.join(cwd, "package.json");
|
|
1527
1547
|
if (fs.existsSync(pkgPath)) {
|
|
1528
1548
|
try {
|
|
1529
1549
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
1530
|
-
if (pkg.types)
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
if (pkg.
|
|
1535
|
-
|
|
1550
|
+
if (pkg.types) {
|
|
1551
|
+
const p = path.join(cwd, pkg.types);
|
|
1552
|
+
return { path: p, fromDts: pkg.types.endsWith(".d.ts") };
|
|
1553
|
+
}
|
|
1554
|
+
if (pkg.typings) {
|
|
1555
|
+
const p = path.join(cwd, pkg.typings);
|
|
1556
|
+
return { path: p, fromDts: pkg.typings.endsWith(".d.ts") };
|
|
1557
|
+
}
|
|
1558
|
+
if (pkg.exports?.["."]?.types) {
|
|
1559
|
+
const p = path.join(cwd, pkg.exports["."].types);
|
|
1560
|
+
return { path: p, fromDts: pkg.exports["."].types.endsWith(".d.ts") };
|
|
1561
|
+
}
|
|
1536
1562
|
if (pkg.main) {
|
|
1537
1563
|
const mainTs = pkg.main.replace(/\.js$/, ".ts");
|
|
1538
|
-
|
|
1539
|
-
|
|
1564
|
+
const fullPath = path.join(cwd, mainTs);
|
|
1565
|
+
if (fs.existsSync(fullPath))
|
|
1566
|
+
return { path: fullPath, fromDts: false };
|
|
1540
1567
|
}
|
|
1541
1568
|
} catch {}
|
|
1542
1569
|
}
|
|
1543
|
-
const fallbacks = ["src/index.ts", "index.ts", "lib/index.ts"];
|
|
1544
|
-
for (const fallback of fallbacks) {
|
|
1545
|
-
const fullPath = path.join(cwd, fallback);
|
|
1546
|
-
if (fs.existsSync(fullPath))
|
|
1547
|
-
return fullPath;
|
|
1548
|
-
}
|
|
1549
1570
|
return null;
|
|
1550
1571
|
}
|
|
1551
1572
|
|