Files
medusa-store/www/utils/packages/docblock-generator/src/commands/run-git-commit.ts
Shahed Nasser d127abbcda docs-util: add docblock generator for models built with DML (#8296)
* docs-util: add docblock generator for models built with DML

* add missing turbo task
2024-07-29 10:11:39 +02:00

66 lines
1.7 KiB
TypeScript

import filterFiles from "../utils/filter-files.js"
import path from "path"
import getMonorepoRoot from "../utils/get-monorepo-root.js"
import DocblockGenerator from "../classes/generators/docblock.js"
import OasGenerator from "../classes/generators/oas.js"
import { CommonCliOptions } from "../types/index.js"
import { GitManager } from "../classes/helpers/git-manager.js"
import DmlGenerator from "../classes/generators/dml.js"
export default async function (
commitSha: string,
{ type, ...options }: CommonCliOptions
) {
const monorepoPath = getMonorepoRoot()
// retrieve the files changed in the commit
const gitManager = new GitManager()
const files = await gitManager.getCommitFiles(commitSha)
// filter changed files
let filteredFiles = filterFiles(files?.map((file) => file.filename) || [])
if (!filteredFiles.length) {
console.log("No applicable files changed. Canceling...")
return
}
console.log(
`${filteredFiles.length} files have changed. Running generator on them...`
)
filteredFiles = filteredFiles.map((filePath) =>
path.resolve(monorepoPath, filePath)
)
// generate docblocks for each of the files.
if (type === "all" || type === "docs") {
const docblockGenerator = new DocblockGenerator({
paths: filteredFiles,
...options,
})
await docblockGenerator.run()
}
if (type === "all" || type === "oas") {
const oasGenerator = new OasGenerator({
paths: filteredFiles,
...options,
})
await oasGenerator.run()
}
if (type === "all" || type === "dml") {
const dmlGenerator = new DmlGenerator({
paths: filteredFiles,
...options,
})
await dmlGenerator.run()
}
console.log(`Finished generating docs for ${filteredFiles.length} files.`)
}