Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 36 additions & 33 deletions packages/cli/src/commands/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,37 +45,41 @@ export class BuildCommand extends Command {
for (const pkg of targetPackages) {
console.log(`📝 ${pkg.name} processing...`);

const tsConfigPath = getTsConfigPath(projectConfig.root, pkg.location);
const project = getTsProject(tsConfigPath);
const projectSourceFiles = project.getSourceFiles();

const exportSourceFiles = projectSourceFiles.filter(isExportSourceFile);
const exportDeclarationsBySourceFiles = exportSourceFiles.flatMap(
getExportedDeclarationsBySourceFile
);
const excludeBarrelReExport = excludeBarrelReExports(
exportDeclarationsBySourceFiles
);
const targets = excludeBarrelReExport.filter((target) => {
return target.jsDoc && hasJSDocTag(target.declaration, "public");
});

const targetsWithJSDoc = targets.map((target) =>
parseJSDoc(target, parser)
);

const docs = targetsWithJSDoc.map((target) =>
generator.generateDocs(target, pkg.location)
);

console.log(`Generated ${docs.length} documentation files:`);
for (const doc of docs) {
const outputPath = path.join(outputDir, doc.relativePath);
await fs.mkdir(path.dirname(outputPath), { recursive: true });
await fs.writeFile(outputPath, doc.content);
console.log(` - ${doc.relativePath}`);

manifestManager.add(doc.relativePath);
try {
const tsConfigPath = getTsConfigPath(projectConfig.root, pkg.location);
const project = getTsProject(tsConfigPath);
const projectSourceFiles = project.getSourceFiles();

const exportSourceFiles = projectSourceFiles.filter(isExportSourceFile);
const exportDeclarationsBySourceFiles = exportSourceFiles.flatMap(
getExportedDeclarationsBySourceFile
);
const excludeBarrelReExport = excludeBarrelReExports(
exportDeclarationsBySourceFiles
);
const targets = excludeBarrelReExport.filter((target) => {
return target.jsDoc && hasJSDocTag(target.declaration, "public");
});

const targetsWithJSDoc = targets.map((target) =>
parseJSDoc(target, parser)
);

const docs = targetsWithJSDoc.map((target) =>
generator.generateDocs(target, pkg.location)
);

console.log(`Generated ${docs.length} documentation files:`);
for (const doc of docs) {
const outputPath = path.join(outputDir, doc.relativePath);
await fs.mkdir(path.dirname(outputPath), { recursive: true });
await fs.writeFile(outputPath, doc.content);
console.log(` - ${doc.relativePath}`);

manifestManager.add(doc.relativePath);
}
} catch (error) {
console.error(`Failed to build ${pkg.name}: ${error instanceof Error ? error.message : String(error)}`);
}
}

Expand Down Expand Up @@ -133,8 +137,7 @@ async function loadContext() {
);
} catch (error) {
console.error(
`❌ Failed to load plugins: ${
error instanceof Error ? error.message : String(error)
`❌ Failed to load plugins: ${error instanceof Error ? error.message : String(error)
}`
);
}
Expand Down
64 changes: 34 additions & 30 deletions packages/cli/src/commands/check/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,44 @@ export class CheckCommand extends Command {
console.log(`📝 ${pkg.name} processing...`);

const packagePath = path.resolve(projectConfig.root, pkg.location);
const tsConfigPath = getTsConfigPath(projectConfig.root, pkg.location);
const project = getTsProject(tsConfigPath);
try {
const tsConfigPath = getTsConfigPath(projectConfig.root, pkg.location);
const project = getTsProject(tsConfigPath);

const entryPoints =
checkConfig.entryPoints ?? getPackageEntryPoints(packagePath);
const entryPoints =
checkConfig.entryPoints ?? getPackageEntryPoints(packagePath);

const sourceFiles = project.getSourceFiles();
const entryPointFiles = sourceFiles.filter((file) => {
const filePath = file.getFilePath();
return entryPoints.some((entryPoint) => filePath.includes(entryPoint));
});

const exportSourceFiles = entryPointFiles.filter(isExportSourceFile);
const exportDeclarationsBySourceFiles = exportSourceFiles.flatMap(
getExportedDeclarationsBySourceFile
);
const excludeBarrelReExport = excludeBarrelReExports(
exportDeclarationsBySourceFiles
);
const missingJSDocExports = excludeBarrelReExport.filter((target) => {
return !hasJSDocTag(target.declaration, "public");
});
const sourceFiles = project.getSourceFiles();
const entryPointFiles = sourceFiles.filter((file) => {
const filePath = file.getFilePath();
return entryPoints.some((entryPoint) => filePath.includes(entryPoint));
});

if (missingJSDocExports.length > 0) {
console.log(`❌ ${pkg.name} has missing JSDoc:`);
missingJSDocExports.forEach((exportInfo) => {
const relativePath = path.relative(
projectConfig.root,
exportInfo.filePath
);
console.log(` - ${relativePath}:${exportInfo.symbolName}`);
const exportSourceFiles = entryPointFiles.filter(isExportSourceFile);
const exportDeclarationsBySourceFiles = exportSourceFiles.flatMap(
getExportedDeclarationsBySourceFile
);
const excludeBarrelReExport = excludeBarrelReExports(
exportDeclarationsBySourceFiles
);
const missingJSDocExports = excludeBarrelReExport.filter((target) => {
return !hasJSDocTag(target.declaration, "public");
});
} else {
console.log(`✅ ${pkg.name} has JSDoc for all exports`);

if (missingJSDocExports.length > 0) {
console.log(`❌ ${pkg.name} has missing JSDoc:`);
missingJSDocExports.forEach((exportInfo) => {
const relativePath = path.relative(
projectConfig.root,
exportInfo.filePath
);
console.log(` - ${relativePath}:${exportInfo.symbolName}`);
});
} else {
console.log(`✅ ${pkg.name} has JSDoc for all exports`);
}
} catch (error) {
console.error(`Failed to check ${pkg.name}: ${error instanceof Error ? error.message : String(error)}`);
}
}

Expand Down
68 changes: 37 additions & 31 deletions packages/cli/src/commands/generate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,43 @@ export class GenerateCommand extends Command {
const allGenerateTargets = targetPackages.flatMap((pkg) => {
console.log(`📝 ${pkg.name} processing...`);

const tsConfigPath = getTsConfigPath(projectConfig.root, pkg.location);
const project = getTsProject(tsConfigPath);
const projectSourceFiles = project.getSourceFiles();

const exportDeclarationsBySourceFiles = projectSourceFiles.flatMap(
getExportedDeclarationsBySourceFile
);

const excludeBarrelReExport = excludeBarrelReExports(
exportDeclarationsBySourceFiles
);

const generateTargets = excludeBarrelReExport.filter((target) => {
return target.jsDoc && hasJSDocTag(target.declaration, "generate");
});

return generateTargets
.map((target) => {
const signature = extractSignature(target.declaration);
if (!signature) {
return null;
}

return {
...target,
signature,
pkg,
project,
};
})
.filter((target): target is GenerateTarget => target !== null);
try {
const tsConfigPath = getTsConfigPath(projectConfig.root, pkg.location);
const project = getTsProject(tsConfigPath);
const projectSourceFiles = project.getSourceFiles();

const exportDeclarationsBySourceFiles = projectSourceFiles.flatMap(
getExportedDeclarationsBySourceFile
);

const excludeBarrelReExport = excludeBarrelReExports(
exportDeclarationsBySourceFiles
);

const generateTargets = excludeBarrelReExport.filter((target) => {
return target.jsDoc && hasJSDocTag(target.declaration, "generate");
});

return generateTargets
.map((target) => {
const signature = extractSignature(target.declaration);
if (signature == null) {
return null;
}

return {
...target,
signature,
pkg,
project,
};
})
.filter((target): target is GenerateTarget => target != null);
} catch (error) {
console.error(`Failed to process ${pkg.name}: ${error instanceof Error ? error.message : String(error)}`);

return [];
}
});

if (allGenerateTargets.length === 0) {
Expand Down
7 changes: 1 addition & 6 deletions packages/cli/src/core/get-ts-config-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,5 @@ export function getTsConfigPath(root: string, pkg: string) {
return buildConfigPath;
}

const rootConfigPath = path.join(root, "tsconfig.json");
if (existsSync(rootConfigPath)) {
return rootConfigPath;
}

throw new Error(`tsconfig.json not found in ${root} or ${pkg}`);
throw new Error(`tsconfig.json not found in ${pkg}`);
}
7 changes: 2 additions & 5 deletions packages/cli/src/tests/core/get-ts-config-path.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,11 @@ describe("getTsConfigPath", () => {
expect(tsConfigPath).toBe(expectedPath);
});

it("should return root tsconfig.json path when package tsconfig doesn't exist", async () => {
it("should throw error when package tsconfig doesn't exist", async () => {
const projectRoot = workspace.root;
const packageLocation = "packages/non-existent";

const tsConfigPath = getTsConfigPath(projectRoot, packageLocation);
const expectedPath = path.join(projectRoot, "tsconfig.json");

expect(tsConfigPath).toBe(expectedPath);
expect(() => getTsConfigPath(projectRoot, packageLocation)).toThrow();
});

it("should handle absolute paths correctly", async () => {
Expand Down