Skip to content

Commit

Permalink
feat(cli): Readme importer (#5646)
Browse files Browse the repository at this point in the history
* Initial Readme Importer implementation

* Cleanup.

* Fixes.

* upl

* Lint fixes.

* prettier

* Cleanup

* Lint
  • Loading branch information
eyw520 authored Jan 19, 2025
1 parent 7140f79 commit 3853a61
Show file tree
Hide file tree
Showing 76 changed files with 4,292 additions and 19 deletions.
20 changes: 18 additions & 2 deletions packages/cli/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
loadProjectConfig
} from "@fern-api/configuration-loader";
import { AbsoluteFilePath, cwd, doesPathExist, isURL, resolve } from "@fern-api/fs-utils";
import { initializeAPI, initializeDocs, initializeWithMintlify } from "@fern-api/init";
import { initializeAPI, initializeDocs, initializeWithMintlify, initializeWithReadme } from "@fern-api/init";
import { LOG_LEVELS, LogLevel } from "@fern-api/logger";
import { askToLogin, login } from "@fern-api/login";
import { FernCliError, LoggableFernCliError } from "@fern-api/task-context";
Expand Down Expand Up @@ -231,14 +231,30 @@ function addInitCommand(cli: Argv<GlobalCliOptions>, cliContext: CliContext) {
})
.option("mintlify", {
type: "string",
description: "Migrate docs from Mintlify"
description: "Migrate docs from Mintlify provided a path to a mint.json file"
})
.option("readme", {
type: "string",
description: "Migrate docs from Readme provided a URL to a Readme generated docs site"
}),
async (argv) => {
if (argv.organization == null) {
argv.organization = await cliContext.getInput({ message: "Please enter your organization" });
}
if (argv.api != null && argv.docs != null) {
return cliContext.failWithoutThrowing("Cannot specify both --api and --docs. Please choose one.");
} else if (argv.readme != null && argv.mintlify != null) {
return cliContext.failWithoutThrowing(
"Cannot specify both --readme and --mintlify. Please choose one."
);
} else if (argv.readme != null) {
await cliContext.runTask(async (context) => {
await initializeWithReadme({
readmeUrl: argv.readme,
taskContext: context,
versionOfCli: await getLatestVersionOfCli({ cliEnvironment: cliContext.environment })
});
});
} else if (argv.docs != null) {
await cliContext.runTask(async (context) => {
await initializeDocs({
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/docs-importers/readme/.depcheckrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"ignores": ["@types/jest", "globals", "@trivago/prettier-plugin-sort-imports", "@types/node"],
"ignore-patterns": ["lib"]
}
1 change: 1 addition & 0 deletions packages/cli/docs-importers/readme/.prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("../../../../.prettierrc.json");
62 changes: 62 additions & 0 deletions packages/cli/docs-importers/readme/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "@fern-api/readme-importer",
"version": "0.0.0",
"repository": {
"type": "git",
"url": "https://github.com/fern-api/fern.git",
"directory": "packages/cli/docs-importers/readme"
},
"private": true,
"files": [
"lib"
],
"type": "module",
"source": "src/index.ts",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"sideEffects": false,
"scripts": {
"clean": "rm -rf ./lib && tsc --build --clean",
"compile": "tsc --build",
"test": "vitest --run",
"test:update": "vitest --run -u",
"lint:eslint": "eslint --max-warnings 0 . --ignore-pattern=../../../../../.eslintignore",
"lint:eslint:fix": "yarn lint:eslint --fix",
"format": "prettier --write --ignore-unknown --ignore-path ../../../../../shared/.prettierignore \"**\"",
"format:check": "prettier --check --ignore-unknown --ignore-path ../../../../../shared/.prettierignore \"**\"",
"depcheck": "depcheck"
},
"dependencies": {
"@fern-api/configuration": "workspace:*",
"@fern-api/core-utils": "workspace:*",
"@fern-api/docs-importer-commons": "workspace:*",
"@fern-api/fs-utils": "workspace:*",
"@fern-api/task-context": "workspace:*",
"@fern-fern/fdr-cjs-sdk": "0.127.5-c465d2cf0",
"gray-matter": "^4.0.3",
"hast-util-to-mdast": "^10.1.0",
"mdast-util-mdx-jsx": "^3.1.3",
"puppeteer": "^19.7.2",
"rehype-parse": "^9.0.0",
"remark-gfm": "^4.0.0",
"remark-mdx": "^3.0.1",
"remark-stringify": "^11.0.0",
"traverse": "^0.6.10",
"unified": "^11.0.5",
"unist-util-visit": "^5.0.0",
"zod": "^3.20.6"
},
"devDependencies": {
"@fern-api/configs": "workspace:*",
"@types/node": "18.15.3",
"depcheck": "^1.4.7",
"eslint": "^8.56.0",
"prettier": "^3.4.2",
"@trivago/prettier-plugin-sort-imports": "^5.2.1",
"@types/hast": "^3.0.4",
"@types/mdast": "^4.0.4",
"@types/traverse": "^0.6.37",
"typescript": "5.7.2",
"vitest": "^2.1.8"
}
}
Loading

0 comments on commit 3853a61

Please sign in to comment.