docs-util: created docblock-generator tool (#6096)
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import path from "path"
|
||||
import DocblockGenerator from "../classes/docblock-generator.js"
|
||||
import getMonorepoRoot from "../utils/get-monorepo-root.js"
|
||||
import promiseExec from "../utils/promise-exec.js"
|
||||
import filterFiles from "../utils/filter-files.js"
|
||||
|
||||
export default async function runGitChanges() {
|
||||
const monorepoPath = getMonorepoRoot()
|
||||
// retrieve the changed files under `packages` in the monorepo root.
|
||||
const childProcess = await promiseExec(
|
||||
`git diff --name-only -- "packages/**/**.ts" "packages/**/*.js" "packages/**/*.tsx" "packages/**/*.jsx"`,
|
||||
{
|
||||
cwd: monorepoPath,
|
||||
}
|
||||
)
|
||||
|
||||
let files = filterFiles(
|
||||
childProcess.stdout.toString().split("\n").filter(Boolean)
|
||||
)
|
||||
|
||||
if (!files.length) {
|
||||
console.log(`No file changes detected.`)
|
||||
return
|
||||
}
|
||||
|
||||
console.log(
|
||||
`${files.length} files have changed. Running generator on them...`
|
||||
)
|
||||
|
||||
files = files.map((filePath) => path.resolve(monorepoPath, filePath))
|
||||
|
||||
// generate docblocks for each of the files.
|
||||
const docblockGenerator = new DocblockGenerator({
|
||||
paths: files,
|
||||
})
|
||||
|
||||
await docblockGenerator.run()
|
||||
|
||||
console.log(`Finished generating docs for ${files.length} files.`)
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import { Octokit } from "@octokit/core"
|
||||
import filterFiles from "../utils/filter-files.js"
|
||||
import path from "path"
|
||||
import getMonorepoRoot from "../utils/get-monorepo-root.js"
|
||||
import DocblockGenerator from "../classes/docblock-generator.js"
|
||||
|
||||
export default async function (commitSha: string) {
|
||||
const monorepoPath = getMonorepoRoot()
|
||||
// retrieve the files changed in the commit
|
||||
const octokit = new Octokit({
|
||||
auth: process.env.GH_TOKEN,
|
||||
})
|
||||
|
||||
const {
|
||||
data: { files },
|
||||
} = await octokit.request("GET /repos/{owner}/{repo}/commits/{ref}", {
|
||||
owner: "medusajs",
|
||||
repo: "medusa",
|
||||
ref: commitSha,
|
||||
headers: {
|
||||
"X-GitHub-Api-Version": "2022-11-28",
|
||||
},
|
||||
})
|
||||
|
||||
// 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.
|
||||
const docblockGenerator = new DocblockGenerator({
|
||||
paths: filteredFiles,
|
||||
})
|
||||
|
||||
await docblockGenerator.run()
|
||||
|
||||
console.log(`Finished generating docs for ${filteredFiles.length} files.`)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import DocblockGenerator, { Options } from "../classes/docblock-generator.js"
|
||||
|
||||
export default async function run(
|
||||
paths: string[],
|
||||
options: Omit<Options, "paths">
|
||||
) {
|
||||
console.log("Running...")
|
||||
|
||||
const docblockGenerator = new DocblockGenerator({
|
||||
paths,
|
||||
...options,
|
||||
})
|
||||
|
||||
await docblockGenerator.run()
|
||||
|
||||
console.log(`Finished running.`)
|
||||
}
|
||||
Reference in New Issue
Block a user