@mintlify/previewing 3.0.2 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{bin → dist}/constants.js +0 -0
- package/{bin → dist}/constants.js.map +0 -0
- package/{bin → dist}/downloadImage.js +0 -0
- package/{bin → dist}/downloadImage.js.map +0 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/{bin → dist}/local-preview/helper-commands/installDepsCommand.js +0 -0
- package/{bin → dist}/local-preview/helper-commands/installDepsCommand.js.map +0 -0
- package/{bin → dist}/local-preview/index.js +0 -0
- package/{bin → dist}/local-preview/index.js.map +0 -0
- package/{bin → dist}/local-preview/listener/categorize.js +0 -0
- package/{bin → dist}/local-preview/listener/categorize.js.map +0 -0
- package/{bin → dist}/local-preview/listener/generate.js +0 -0
- package/{bin → dist}/local-preview/listener/generate.js.map +0 -0
- package/{bin → dist}/local-preview/listener/index.js +0 -0
- package/{bin → dist}/local-preview/listener/index.js.map +0 -0
- package/{bin → dist}/local-preview/listener/update.js +0 -0
- package/{bin → dist}/local-preview/listener/update.js.map +0 -0
- package/{bin → dist}/local-preview/listener/utils/createPage.js +0 -0
- package/{bin → dist}/local-preview/listener/utils/createPage.js.map +0 -0
- package/{bin → dist}/local-preview/listener/utils/getOpenApiContext.js +0 -0
- package/{bin → dist}/local-preview/listener/utils/getOpenApiContext.js.map +0 -0
- package/{bin → dist}/local-preview/listener/utils/mintConfigFile.js +0 -0
- package/{bin → dist}/local-preview/listener/utils/mintConfigFile.js.map +0 -0
- package/{bin → dist}/local-preview/listener/utils/toTitleCase.js +0 -0
- package/{bin → dist}/local-preview/listener/utils/toTitleCase.js.map +0 -0
- package/{bin → dist}/local-preview/listener/utils/types.js +0 -0
- package/{bin → dist}/local-preview/listener/utils/types.js.map +0 -0
- package/{bin → dist}/local-preview/listener/utils.js +0 -0
- package/{bin → dist}/local-preview/listener/utils.js.map +0 -0
- package/{bin → dist}/util.js +0 -0
- package/{bin → dist}/util.js.map +0 -0
- package/package.json +21 -12
- package/.eslintignore +0 -1
- package/.eslintrc.json +0 -3
- package/CONTRIBUTING.md +0 -17
- package/bin/index.js +0 -19
- package/bin/index.js.map +0 -1
- package/scraper.md +0 -121
- package/src/constants.ts +0 -40
- package/src/downloadImage.ts +0 -102
- package/src/index.ts +0 -35
- package/src/local-preview/helper-commands/installDepsCommand.ts +0 -13
- package/src/local-preview/index.ts +0 -196
- package/src/local-preview/listener/categorize.ts +0 -107
- package/src/local-preview/listener/generate.ts +0 -121
- package/src/local-preview/listener/index.ts +0 -228
- package/src/local-preview/listener/update.ts +0 -27
- package/src/local-preview/listener/utils/createPage.ts +0 -215
- package/src/local-preview/listener/utils/getOpenApiContext.ts +0 -77
- package/src/local-preview/listener/utils/mintConfigFile.ts +0 -28
- package/src/local-preview/listener/utils/toTitleCase.ts +0 -40
- package/src/local-preview/listener/utils/types.ts +0 -14
- package/src/local-preview/listener/utils.ts +0 -87
- package/src/types.d.ts +0 -35
- package/src/util.ts +0 -119
- package/tsconfig.json +0 -19
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,0BAA0B,CAAC;AAC3C,OAAO,kBAAkB,MAAM,uDAAuD,CAAC;AAEvF,OAAO,EAAE,GAAG,EAAE,kBAAkB,EAAE,CAAC"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/{bin → dist}/util.js
RENAMED
|
File without changes
|
package/{bin → dist}/util.js.map
RENAMED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,32 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mintlify/previewing",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "Preview Mintlify docs locally",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18.0.0"
|
|
7
7
|
},
|
|
8
|
-
"license": "Elastic-2.0",
|
|
9
|
-
"scripts": {
|
|
10
|
-
"prepare": "npm run build",
|
|
11
|
-
"build": "tsc",
|
|
12
|
-
"watch": "tsc --watch",
|
|
13
|
-
"lint": "eslint . --cache"
|
|
14
|
-
},
|
|
15
8
|
"author": "Mintlify, Inc.",
|
|
16
9
|
"repository": {
|
|
17
10
|
"type": "git",
|
|
18
11
|
"url": "https://github.com/mintlify/mint",
|
|
19
12
|
"directory": "packages/mintlify-previewing"
|
|
20
13
|
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/mintlify/mint/issues"
|
|
16
|
+
},
|
|
17
|
+
"license": "Elastic-2.0",
|
|
18
|
+
"keywords": [
|
|
19
|
+
"mintlify",
|
|
20
|
+
"mint",
|
|
21
|
+
"previewing"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
21
24
|
"publishConfig": {
|
|
22
25
|
"access": "public",
|
|
23
26
|
"registry": "https://registry.npmjs.org/"
|
|
24
27
|
},
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
+
"main": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"prepare": "npm run build",
|
|
35
|
+
"build": "tsc",
|
|
36
|
+
"watch": "tsc --watch",
|
|
37
|
+
"lint": "eslint . --cache"
|
|
28
38
|
},
|
|
29
|
-
"type": "module",
|
|
30
39
|
"dependencies": {
|
|
31
40
|
"@apidevtools/swagger-parser": "^10.1.0",
|
|
32
41
|
"@mintlify/validation": "^0.1.9",
|
package/.eslintignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
bin/
|
package/.eslintrc.json
DELETED
package/CONTRIBUTING.md
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# Running CLI Locally
|
|
2
|
-
|
|
3
|
-
Note - contributing requires `yarn` and it's recommended you install it as a global installation. If you don't have yarn installed already run `npm install --global yarn` in your terminal.
|
|
4
|
-
|
|
5
|
-
Run `npm run local` to build and install the CLI locally.
|
|
6
|
-
|
|
7
|
-
You need to run the command after every change you want to test.
|
|
8
|
-
|
|
9
|
-
## Updating Version of Mint Client
|
|
10
|
-
|
|
11
|
-
The CLI uses GitHub releases to download specific versions of the client code used in `mintlify dev`. Older CLI versions will continue using the client code they were bundled with. Users need to update to a newer version of the CLI to get the newest client code. CLI contributors bump the client version used by the CLI whenever there are major changes.
|
|
12
|
-
|
|
13
|
-
Here's how to publish new client changes to the CLI:
|
|
14
|
-
|
|
15
|
-
1. Publish a new GitHub release. You can click the releases menu at the right of the repo page. Make the release title the same as the new release tag. Optionally, you can also use the description to keep track of what changed in that release.
|
|
16
|
-
2. Set `TARGET_MINT_VERSION` in `src/constants.ts` to to the new release tag.
|
|
17
|
-
3. Publish a new CLI version to npm.
|
package/bin/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
3
|
-
import yargs from "yargs";
|
|
4
|
-
import { hideBin } from "yargs/helpers";
|
|
5
|
-
import dev from "./local-preview/index.js";
|
|
6
|
-
import installDepsCommand from "./local-preview/helper-commands/installDepsCommand.js";
|
|
7
|
-
yargs(hideBin(process.argv))
|
|
8
|
-
.command("dev", "Runs Mintlify locally (Must run in directory with mint.json)", () => { }, async (argv) => {
|
|
9
|
-
await dev(argv);
|
|
10
|
-
})
|
|
11
|
-
.command("install", "Install dependencies for local Mintlify", () => { }, installDepsCommand)
|
|
12
|
-
// Print the help menu when the user enters an invalid command.
|
|
13
|
-
.strictCommands()
|
|
14
|
-
.demandCommand(1, "Unknown command. See above for the list of supported commands.")
|
|
15
|
-
// Alias option flags --help = -h, --version = -v
|
|
16
|
-
.alias("h", "help")
|
|
17
|
-
.alias("v", "version")
|
|
18
|
-
.parse();
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
package/bin/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,yDAAyD;AAEzD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,GAAG,MAAM,0BAA0B,CAAC;AAC3C,OAAO,kBAAkB,MAAM,uDAAuD,CAAC;AAEvF,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;KACzB,OAAO,CACN,KAAK,EACL,8DAA8D,EAC9D,GAAG,EAAE,GAAE,CAAC,EACR,KAAK,EAAE,IAAI,EAAE,EAAE;IACb,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC;AAClB,CAAC,CACF;KACA,OAAO,CACN,SAAS,EACT,yCAAyC,EACzC,GAAG,EAAE,GAAE,CAAC,EACR,kBAAkB,CACnB;IACD,+DAA+D;KAC9D,cAAc,EAAE;KAChB,aAAa,CACZ,CAAC,EACD,gEAAgE,CACjE;IAED,iDAAiD;KAChD,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC;KAClB,KAAK,CAAC,GAAG,EAAE,SAAS,CAAC;KAErB,KAAK,EAAE,CAAC"}
|
package/scraper.md
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
# CLI Scraping
|
|
2
|
-
|
|
3
|
-
The CLI has many commands. This doc focuses on how we coded scraping websites.
|
|
4
|
-
|
|
5
|
-
## User Interface
|
|
6
|
-
|
|
7
|
-
There are two main commands:
|
|
8
|
-
|
|
9
|
-
`mintlify scrape-page [url]`
|
|
10
|
-
|
|
11
|
-
and
|
|
12
|
-
|
|
13
|
-
`mintlify scrape-section [url]`
|
|
14
|
-
|
|
15
|
-
Scraping a page downloads a single page’s content. Scraping a section goes through the navigation and scrapes each page. The code for downloading a page’s content is shared between the two commands.
|
|
16
|
-
|
|
17
|
-
Important files: `scraping/scrapePageCommands.ts`, `scraping/scrapeSectionAutomatically.ts`
|
|
18
|
-
|
|
19
|
-
We have `scrape-gitbook-page` and similar commands for debugging. Ignore them, they just call internal functions directly. You should not need to use them unless you are debugging issues with Detecting Frameworks.
|
|
20
|
-
|
|
21
|
-
## Overwriting
|
|
22
|
-
|
|
23
|
-
The user has to add a `--overwrite` flag if they want to overwrite their current files.
|
|
24
|
-
|
|
25
|
-
## Sections vs Websites
|
|
26
|
-
|
|
27
|
-
We call the command `scrape-section` instead of `scrape-website` because we cannot scrape pages not in the navigation of the URL first passed in. For example, ReadMe has API Reference and other sections accessible through a separate top-navigation which we do not parse. We only scrape the navigation on the left: [https://docs.readme.com/main/docs](https://docs.readme.com/main/docs)
|
|
28
|
-
|
|
29
|
-
## Detecting Frameworks
|
|
30
|
-
|
|
31
|
-
The commands look in the page HTML to detect what framework scraper to use. For example, all Docusaurus sites have a metatag with the word Docusaurus in it. Some times, the metatag even has the Docusaurus version.
|
|
32
|
-
|
|
33
|
-
Each framework’s scrapers live in `scraping/site-scrapers/`
|
|
34
|
-
|
|
35
|
-
We currently support:
|
|
36
|
-
|
|
37
|
-
- Docusaurus
|
|
38
|
-
- GitBook
|
|
39
|
-
- ReadMe
|
|
40
|
-
- Intercom
|
|
41
|
-
|
|
42
|
-
## Terminal Output
|
|
43
|
-
|
|
44
|
-
We print a line in the terminal for every file we write. `util.ts` has a createPage function that takes care of writing the file and logging.
|
|
45
|
-
|
|
46
|
-
We use a pencil emoji when we successfully write a file. Images get a picture emoji. Likewise, we print a X emoji when we find a file that already exists and the user has not enabled overwriting files. We use emojis so you can tell what the command is doing without reading each file path.
|
|
47
|
-
|
|
48
|
-
We also print the file paths when scraping sections so the user can easily copy paste them into mint.json. Note that pages the user already added in Mintlify are not included in the printed example. We do not generate mint.json completely, we are just giving a small example to help users starting from scratch.
|
|
49
|
-
|
|
50
|
-
```jsx
|
|
51
|
-
Add the following to your navigation in mint.json:
|
|
52
|
-
|
|
53
|
-
{
|
|
54
|
-
"group": "Guides",
|
|
55
|
-
"pages": ["page-we-scraped"]
|
|
56
|
-
}
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
# Navigation Scraping
|
|
60
|
-
|
|
61
|
-
Most sites use JavaScript to open navigation menus which do not automatically include the menu buttons in the HTML. We use Puppeteer to click every nested menu so the site adds the menu buttons to the HTML. For example the original site’s HTML:
|
|
62
|
-
|
|
63
|
-
```jsx
|
|
64
|
-
<div>
|
|
65
|
-
<a id="my-nested-menu"></a>
|
|
66
|
-
</div>
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
can turn into this after opening the nested menu:
|
|
70
|
-
|
|
71
|
-
```jsx
|
|
72
|
-
<div>
|
|
73
|
-
<a id="my-nested-menu" aria-expanded=true></a>
|
|
74
|
-
<div>
|
|
75
|
-
<a href="/page"></a>
|
|
76
|
-
<a href="/other-page"></a>
|
|
77
|
-
</div>
|
|
78
|
-
</div>
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
Ultimately, all section scrapers need to find an array of links to visit then call the scrape page function in a loop.
|
|
82
|
-
|
|
83
|
-
We use axios instead of Puppeteer if a site doesn’t hide links. Puppeteer is slow.
|
|
84
|
-
|
|
85
|
-
# Image File Locations
|
|
86
|
-
|
|
87
|
-
Images go in an `images/` folder because that’s what most users want. Scraping per section uses the same root-level images folder. Scraping per page downloads them to the current location. Thus, scraping a single page from a folder means the user always has to move the images themselves. That’s a trade-off we are comfortable with — trying to detect an existing images folder gets too complicated too fast.
|
|
88
|
-
|
|
89
|
-
# Cheerio
|
|
90
|
-
|
|
91
|
-
Cheerio is a library to scrape/handle the HTML after we have it in a string. Most of the work is using inspect-element to view a website and figure out where the content we want is, then writing the corresponding Cheerio code.
|
|
92
|
-
|
|
93
|
-
# HTML to MDX
|
|
94
|
-
|
|
95
|
-
We use an open-source library to convert HTML to Markdown: https://github.com/crosstype/node-html-markdown
|
|
96
|
-
|
|
97
|
-
The `util.ts` createPage function assembles the MDX metadata, we just need to return an object of the form `{ title, description, content }` from each page scraper.
|
|
98
|
-
|
|
99
|
-
## Parsing Issues
|
|
100
|
-
|
|
101
|
-
Parsing struggles when documentation websites are using non-standard HTML. For example, code blocks are supposed to use. `<pre><code></code></pre>` but GitBook just uses divs.
|
|
102
|
-
|
|
103
|
-
We can write custom translators for the library that determine how we parse certain objects.
|
|
104
|
-
|
|
105
|
-
In some cases, we will want custom translators even if parsing succeeds. For example, ReadMe callouts are using quote syntax
|
|
106
|
-
|
|
107
|
-
```jsx
|
|
108
|
-
> 💡
|
|
109
|
-
> Callout text
|
|
110
|
-
>
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
When we want to convert them to:
|
|
114
|
-
|
|
115
|
-
```jsx
|
|
116
|
-
<Tip>Callout text</Tip>
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
## Regex
|
|
120
|
-
|
|
121
|
-
You can use regex to make small changes where translators are overkill or there’s no obvious component to modify. For example, here’s the end of `scrapeDocusaurusPage.ts`:
|
package/src/constants.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import * as url from "url";
|
|
3
|
-
import os from "os";
|
|
4
|
-
|
|
5
|
-
// Change this to bump to a newer version of mint's client
|
|
6
|
-
export const TARGET_MINT_VERSION = "v0.0.9";
|
|
7
|
-
|
|
8
|
-
// package installation location
|
|
9
|
-
export const INSTALL_PATH = url.fileURLToPath(new URL(".", import.meta.url));
|
|
10
|
-
|
|
11
|
-
export const HOME_DIR = os.homedir();
|
|
12
|
-
|
|
13
|
-
export const DOT_MINTLIFY = path.join(HOME_DIR, ".mintlify");
|
|
14
|
-
|
|
15
|
-
export const VERSION_PATH = path.join(DOT_MINTLIFY, "mint", "mint-version.txt");
|
|
16
|
-
|
|
17
|
-
export const CLIENT_PATH = path.join(DOT_MINTLIFY, "mint", "client");
|
|
18
|
-
|
|
19
|
-
export const MINT_PATH = path.join(DOT_MINTLIFY, "mint");
|
|
20
|
-
|
|
21
|
-
// command execution location
|
|
22
|
-
export const CMD_EXEC_PATH = process.cwd();
|
|
23
|
-
|
|
24
|
-
export const SUPPORTED_MEDIA_EXTENSIONS = [
|
|
25
|
-
"jpeg",
|
|
26
|
-
"jpg",
|
|
27
|
-
"jfif",
|
|
28
|
-
"pjpeg",
|
|
29
|
-
"pjp",
|
|
30
|
-
"png",
|
|
31
|
-
"svg",
|
|
32
|
-
"svgz",
|
|
33
|
-
"ico",
|
|
34
|
-
"webp",
|
|
35
|
-
"gif",
|
|
36
|
-
"apng",
|
|
37
|
-
"avif",
|
|
38
|
-
"bmp",
|
|
39
|
-
"mp4",
|
|
40
|
-
];
|
package/src/downloadImage.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, createWriteStream } from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import axios from "axios";
|
|
4
|
-
import { getFileExtension } from "./util.js";
|
|
5
|
-
import { SUPPORTED_MEDIA_EXTENSIONS } from "./constants.js";
|
|
6
|
-
|
|
7
|
-
async function writeImageToFile(
|
|
8
|
-
imageSrc: string,
|
|
9
|
-
writePath: string,
|
|
10
|
-
overwrite: boolean
|
|
11
|
-
) {
|
|
12
|
-
// Avoid unnecessary downloads
|
|
13
|
-
if (existsSync(writePath) && !overwrite) {
|
|
14
|
-
return Promise.reject({
|
|
15
|
-
code: "EEXIST",
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Create the folders needed if they're missing
|
|
20
|
-
mkdirSync(path.dirname(writePath), { recursive: true });
|
|
21
|
-
|
|
22
|
-
const writer = createWriteStream(writePath);
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
const response = await axios.get(imageSrc, {
|
|
26
|
-
responseType: "stream",
|
|
27
|
-
});
|
|
28
|
-
// wx prevents overwriting an image with the exact same name
|
|
29
|
-
// being created in the time we were downloading
|
|
30
|
-
response.data.pipe(writer, {
|
|
31
|
-
flag: "wx",
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
return new Promise((resolve, reject) => {
|
|
35
|
-
writer.on("finish", resolve);
|
|
36
|
-
writer.on("error", reject);
|
|
37
|
-
});
|
|
38
|
-
} catch (e) {
|
|
39
|
-
return Promise.reject({
|
|
40
|
-
code: "ENOTFOUND",
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function isValidImageSrc(src: string) {
|
|
46
|
-
if (!src) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
// We do not support downloading base64 in-line images.
|
|
50
|
-
if (src.startsWith("data:")) {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const imageHref = removeMetadataFromImageSrc(src);
|
|
55
|
-
const ext = getFileExtension(imageHref);
|
|
56
|
-
|
|
57
|
-
if (ext && !SUPPORTED_MEDIA_EXTENSIONS.includes(ext)) {
|
|
58
|
-
console.error("🚨 We do not support the file extension: " + ext);
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function removeMetadataFromImageSrc(src: string) {
|
|
66
|
-
// Part of the URL standard
|
|
67
|
-
const metadataSymbols = ["?", "#"];
|
|
68
|
-
|
|
69
|
-
metadataSymbols.forEach((dividerSymbol) => {
|
|
70
|
-
// Some frameworks add metadata after the file extension, we need to remove that.
|
|
71
|
-
src = src.split(dividerSymbol)[0];
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
return src;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function cleanImageSrc(src: string, origin: string) {
|
|
78
|
-
// Add origin if the image tags are using relative sources
|
|
79
|
-
return src.startsWith("http") ? src : new URL(src, origin).href;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export default async function downloadImage(
|
|
83
|
-
imageSrc: string,
|
|
84
|
-
writePath: string,
|
|
85
|
-
overwrite = false
|
|
86
|
-
) {
|
|
87
|
-
await writeImageToFile(imageSrc, writePath, overwrite)
|
|
88
|
-
.then(() => {
|
|
89
|
-
console.log("🖼️ - " + writePath);
|
|
90
|
-
})
|
|
91
|
-
.catch((e) => {
|
|
92
|
-
if (e.code === "EEXIST") {
|
|
93
|
-
console.log(`❌ Skipping existing image ${writePath}`);
|
|
94
|
-
} else if (e.code === "ENOTFOUND") {
|
|
95
|
-
console.error(
|
|
96
|
-
`🚨 Cannot download the image, address not found ${imageSrc}`
|
|
97
|
-
);
|
|
98
|
-
} else {
|
|
99
|
-
console.error(e);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
3
|
-
|
|
4
|
-
import yargs from "yargs";
|
|
5
|
-
import { hideBin } from "yargs/helpers";
|
|
6
|
-
import dev from "./local-preview/index.js";
|
|
7
|
-
import installDepsCommand from "./local-preview/helper-commands/installDepsCommand.js";
|
|
8
|
-
|
|
9
|
-
yargs(hideBin(process.argv))
|
|
10
|
-
.command(
|
|
11
|
-
"dev",
|
|
12
|
-
"Runs Mintlify locally (Must run in directory with mint.json)",
|
|
13
|
-
() => {},
|
|
14
|
-
async (argv) => {
|
|
15
|
-
await dev(argv);
|
|
16
|
-
}
|
|
17
|
-
)
|
|
18
|
-
.command(
|
|
19
|
-
"install",
|
|
20
|
-
"Install dependencies for local Mintlify",
|
|
21
|
-
() => {},
|
|
22
|
-
installDepsCommand
|
|
23
|
-
)
|
|
24
|
-
// Print the help menu when the user enters an invalid command.
|
|
25
|
-
.strictCommands()
|
|
26
|
-
.demandCommand(
|
|
27
|
-
1,
|
|
28
|
-
"Unknown command. See above for the list of supported commands."
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
// Alias option flags --help = -h, --version = -v
|
|
32
|
-
.alias("h", "help")
|
|
33
|
-
.alias("v", "version")
|
|
34
|
-
|
|
35
|
-
.parse();
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import shell from "shelljs";
|
|
2
|
-
import { CLIENT_PATH } from "../../constants.js";
|
|
3
|
-
import { buildLogger, ensureYarn } from "../../util.js";
|
|
4
|
-
|
|
5
|
-
const installDeps = async () => {
|
|
6
|
-
const logger = buildLogger("");
|
|
7
|
-
ensureYarn(logger);
|
|
8
|
-
shell.cd(CLIENT_PATH);
|
|
9
|
-
shell.exec("yarn");
|
|
10
|
-
logger.succeed("Dependencies installed.");
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export default installDeps;
|