chore: reorganize docs apps (#7228)
* reorganize docs apps * add README * fix directory * add condition for old docs
This commit is contained in:
1 parent
224ebb2154
commit
4fe28f5a95
6187 files changed
+601447
-598226
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import { Octokit } from "@octokit/core"
|
||||
import * as core from "@actions/core"
|
||||
|
||||
const octokit = new Octokit({
|
||||
auth: process.env.GH_TOKEN,
|
||||
})
|
||||
|
||||
let prNumber = process.argv.length >= 3 ? process.argv[2] : null
|
||||
const threshold = process.argv.length >= 4 ? parseInt(process.argv[3]) : 300
|
||||
|
||||
async function getPrFilesCount() {
|
||||
if (!prNumber) {
|
||||
throw new Error("Commit SHA is required.")
|
||||
}
|
||||
|
||||
prNumber = prNumber.replace("/merge", "")
|
||||
|
||||
const { data: pr } = await octokit.request(
|
||||
"GET /repos/{owner}/{repo}/pulls/{pull_number}",
|
||||
{
|
||||
owner: process.env.GIT_OWNER || "medusajs",
|
||||
repo: process.env.GIT_REPO || "medusa",
|
||||
pull_number: parseInt(prNumber),
|
||||
headers: {
|
||||
"X-GitHub-Api-Version": "2022-11-28",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
core.setOutput("files_lt_threshold", pr.changed_files < threshold)
|
||||
}
|
||||
|
||||
void getPrFilesCount()
|
||||
@@ -1,94 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { Octokit } from "@octokit/core"
|
||||
import fs from "fs"
|
||||
import path from "path"
|
||||
import { fileURLToPath } from "url"
|
||||
|
||||
const shouldExpire = process.argv.indexOf("--expire") !== -1
|
||||
const octokit = new Octokit({
|
||||
auth: process.env.GH_TOKEN,
|
||||
})
|
||||
|
||||
async function main() {
|
||||
let announcement = {}
|
||||
|
||||
if (shouldExpire) {
|
||||
//check if the file was last updated 6 days ago
|
||||
try {
|
||||
const commitResponse = await octokit.request(
|
||||
"GET /repos/{owner}/{repo}/commits",
|
||||
{
|
||||
owner: "medusajs",
|
||||
repo: "medusa",
|
||||
path: path.join("www", "apps", "docs", "announcement.json"),
|
||||
per_page: 1,
|
||||
}
|
||||
)
|
||||
|
||||
if (
|
||||
commitResponse.data.length &&
|
||||
commitResponse.data[0].commit.committer?.date &&
|
||||
dateDiffInDays(
|
||||
new Date(commitResponse.data[0].commit.committer.date),
|
||||
new Date()
|
||||
) < 6
|
||||
) {
|
||||
console.log("File was edited less than 6 days ago. Expiry canceled.")
|
||||
return
|
||||
}
|
||||
} catch (e) {
|
||||
//continue as if file doesn't exist
|
||||
}
|
||||
} else {
|
||||
//retrieve the latest release
|
||||
const response = await octokit.request(
|
||||
"GET /repos/{owner}/{repo}/releases/latest",
|
||||
{
|
||||
owner: "medusajs",
|
||||
repo: "medusa",
|
||||
}
|
||||
)
|
||||
|
||||
const version = response.data.tag_name
|
||||
|
||||
//add new announcement
|
||||
announcement = {
|
||||
id: response.data.html_url,
|
||||
content: `${version} is out`,
|
||||
isCloseable: true,
|
||||
}
|
||||
}
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = path.dirname(__filename)
|
||||
|
||||
//write new config file
|
||||
fs.writeFileSync(
|
||||
path.join(
|
||||
__dirname,
|
||||
"..",
|
||||
"..",
|
||||
"..",
|
||||
"www",
|
||||
"apps",
|
||||
"docs",
|
||||
"announcement.json"
|
||||
),
|
||||
JSON.stringify(announcement)
|
||||
)
|
||||
console.log(`Announcement Bar has been ${shouldExpire ? "removed" : "added"}`)
|
||||
}
|
||||
|
||||
const _MS_PER_DAY = 1000 * 60 * 60 * 24
|
||||
|
||||
// a and b are javascript Date objects
|
||||
function dateDiffInDays(a: Date, b: Date) {
|
||||
// Discard the time and time-zone information.
|
||||
const utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate())
|
||||
const utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate())
|
||||
|
||||
return Math.floor((utc2 - utc1) / _MS_PER_DAY)
|
||||
}
|
||||
|
||||
void main()
|
||||
@@ -24,8 +24,8 @@ const repoPath = path.join(
|
||||
"..",
|
||||
"www",
|
||||
"apps",
|
||||
"docs",
|
||||
"content"
|
||||
"book",
|
||||
"app"
|
||||
)
|
||||
let freshnessCheckLabelId = ""
|
||||
let documentationTeamId = ""
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
import path from "path"
|
||||
import fs from "fs"
|
||||
import { exec } from "child_process"
|
||||
import { globSync } from "glob"
|
||||
import randomColor from "randomcolor"
|
||||
import chalk, { ChalkInstance } from "chalk"
|
||||
import { createRequire } from "node:module"
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
|
||||
const referenceNames = process.argv.slice(2) || ["all"]
|
||||
const basePath = path.join(require.resolve("typedoc-config"), "..")
|
||||
let generatedCount = 0
|
||||
let totalCount = referenceNames.length
|
||||
let ranMerger = false
|
||||
|
||||
if (!referenceNames.length) {
|
||||
console.error(
|
||||
chalk.red(
|
||||
"No reference names specified. Please specify the name of a reference to generate, or use `all` to generate all references."
|
||||
)
|
||||
)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
referenceNames.forEach((name) => {
|
||||
if (name === "all") {
|
||||
// generate reference for all configration files in
|
||||
// `typedoc-config` directory, except for files starting
|
||||
// with `_`
|
||||
const files = globSync("[^_]**.js", {
|
||||
cwd: basePath,
|
||||
})
|
||||
totalCount = files.length
|
||||
files.forEach((file) => generateReference(file))
|
||||
} else if (name === "merge") {
|
||||
runMerger()
|
||||
} else {
|
||||
generateReference(`${name}.js`)
|
||||
}
|
||||
})
|
||||
|
||||
export function generateReference(referenceName: string) {
|
||||
const configPathName = path.join(basePath, referenceName)
|
||||
|
||||
// check if the config file exists
|
||||
if (!fs.existsSync(configPathName)) {
|
||||
console.log(
|
||||
chalk.red(
|
||||
`Config file for ${referenceName} doesn't exist. Make sure to create it in ${configPathName}`
|
||||
)
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
const colorLog = chalk.hex(randomColor())
|
||||
formatColoredLog(colorLog, referenceName, "Generating reference...")
|
||||
const typedocProcess = exec(`typedoc --options ${configPathName}`)
|
||||
typedocProcess.stdout?.on("data", (chunk: string) => {
|
||||
formatColoredLog(colorLog, referenceName, chunk.trim())
|
||||
})
|
||||
typedocProcess.on("exit", (code) => {
|
||||
formatColoredLog(colorLog, referenceName, "Finished Generating reference.")
|
||||
generatedCount++
|
||||
if (generatedCount >= totalCount && !ranMerger && code !== 1) {
|
||||
runMerger()
|
||||
}
|
||||
})
|
||||
typedocProcess.stderr?.on("data", (chunk: string) => {
|
||||
// split multiline outputs
|
||||
const split: string[] = chunk.split("\n")
|
||||
split.forEach((line: string) => {
|
||||
if (!line.length) {
|
||||
return
|
||||
}
|
||||
|
||||
formatColoredLog(
|
||||
colorLog,
|
||||
referenceName,
|
||||
`${chalk.red("An error occurred")}: ${line.trim()}`
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function formatColoredLog(
|
||||
chalkInstance: ChalkInstance,
|
||||
title: string,
|
||||
message: string
|
||||
) {
|
||||
console.log(`${chalkInstance(title)} -> ${message}`)
|
||||
}
|
||||
|
||||
function runMerger() {
|
||||
// run merger
|
||||
console.log(chalk.bgBlueBright("\n\nRunning Merger\n\n"))
|
||||
ranMerger = true
|
||||
generateReference("_merger.js")
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { execSync } from "child_process"
|
||||
import * as core from "@actions/core"
|
||||
|
||||
const command = `git --no-pager diff --minimal --name-only ../../../www/apps/docs/content/references`
|
||||
const command = `git --no-pager diff --minimal --name-only ../../../www/apps/resources/references`
|
||||
const diffOutput = execSync(command).toString()
|
||||
|
||||
const files = diffOutput.toString().split("\n").filter(Boolean)
|
||||
@@ -10,7 +10,7 @@ const referenceNames: Set<string> = new Set([])
|
||||
|
||||
files.forEach((file) => {
|
||||
const referenceName = file
|
||||
.replace("www/apps/docs/content/references/", "")
|
||||
.replace("www/apps/resources/references/", "")
|
||||
.split("/")[0]
|
||||
|
||||
if (referenceName) {
|
||||
|
||||
@@ -8,12 +8,11 @@
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"generate:announcement": "ts-node ./doc-change-release.ts",
|
||||
"generate:reference": "ts-node ./generate-reference.ts",
|
||||
"merge:references": "yarn generate:reference merge",
|
||||
"check:freshness": "ts-node ./freshness-check.ts",
|
||||
"generate:message": "ts-node ./get-generate-diff-message.ts",
|
||||
"check:release-commit": "node ./dist/check-release-commit.js",
|
||||
"generate:changeset": "node ./dist/run-changeset.js"
|
||||
"generate:changeset": "node ./dist/run-changeset.js",
|
||||
"check:pr-files-count": "node ./dist/check-pr-files-count.js"
|
||||
},
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
@@ -26,15 +25,6 @@
|
||||
"glob": "^10.3.10",
|
||||
"randomcolor": "^0.6.2",
|
||||
"ts-node": "^10.9.1",
|
||||
"typedoc": "^0.25.7",
|
||||
"typedoc-config": "*",
|
||||
"typedoc-monorepo-link-types": "^0.0.2",
|
||||
"typedoc-plugin-custom": "*",
|
||||
"typedoc-plugin-markdown-medusa": "*",
|
||||
"typedoc-plugin-merge-modules": "5.1.0",
|
||||
"typedoc-plugin-missing-exports": "^2.1.0",
|
||||
"typedoc-plugin-reference-excluder": "1.1.3",
|
||||
"typedoc-plugin-rename-defaults": "^0.7.0",
|
||||
"typescript": "5.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
Reference in new issue
Block a user