@docsalot/previewing 0.1.0-beta.0
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/README.md +17 -0
- package/dist/constants.d.ts +9 -0
- package/dist/constants.js +37 -0
- package/dist/downloadImage.d.ts +4 -0
- package/dist/downloadImage.js +81 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/local-preview/helper-commands/installDepsCommand.d.ts +2 -0
- package/dist/local-preview/helper-commands/installDepsCommand.js +11 -0
- package/dist/local-preview/index.d.ts +3 -0
- package/dist/local-preview/index.js +159 -0
- package/dist/local-preview/listener/categorize.d.ts +8 -0
- package/dist/local-preview/listener/categorize.js +96 -0
- package/dist/local-preview/listener/generate.d.ts +12 -0
- package/dist/local-preview/listener/generate.js +73 -0
- package/dist/local-preview/listener/index.d.ts +2 -0
- package/dist/local-preview/listener/index.js +200 -0
- package/dist/local-preview/listener/update.d.ts +2 -0
- package/dist/local-preview/listener/update.js +23 -0
- package/dist/local-preview/listener/utils/createPage.d.ts +11 -0
- package/dist/local-preview/listener/utils/createPage.js +169 -0
- package/dist/local-preview/listener/utils/getOpenApiContext.d.ts +21 -0
- package/dist/local-preview/listener/utils/getOpenApiContext.js +57 -0
- package/dist/local-preview/listener/utils/mintConfigFile.d.ts +2 -0
- package/dist/local-preview/listener/utils/mintConfigFile.js +21 -0
- package/dist/local-preview/listener/utils/toTitleCase.d.ts +1 -0
- package/dist/local-preview/listener/utils/toTitleCase.js +35 -0
- package/dist/local-preview/listener/utils/types.d.ts +2 -0
- package/dist/local-preview/listener/utils/types.js +1 -0
- package/dist/local-preview/listener/utils.d.ts +13 -0
- package/dist/local-preview/listener/utils.js +53 -0
- package/dist/local-preview/prod.d.ts +3 -0
- package/dist/local-preview/prod.js +130 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/util.d.ts +28 -0
- package/dist/util.js +92 -0
- package/package.json +81 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import Chalk from "chalk";
|
|
3
|
+
import child_process from "child_process";
|
|
4
|
+
import open from "open";
|
|
5
|
+
import fse, { pathExists } from "fs-extra";
|
|
6
|
+
import inquirer from "inquirer";
|
|
7
|
+
import { isInternetAvailable } from "is-internet-available";
|
|
8
|
+
import path from "path";
|
|
9
|
+
import shell from "shelljs";
|
|
10
|
+
import { CLIENT_PATH, HOME_DIR, DOT_MINTLIFY, CMD_EXEC_PATH, MINT_PATH, } from "../constants.js";
|
|
11
|
+
import { buildLogger } from "../util.js";
|
|
12
|
+
import { getConfigPath } from "./listener/utils/mintConfigFile.js";
|
|
13
|
+
const nodeModulesExists = async () => {
|
|
14
|
+
return pathExists(path.join(DOT_MINTLIFY, "client", "node_modules"));
|
|
15
|
+
};
|
|
16
|
+
const promptForYarn = async () => {
|
|
17
|
+
const yarnInstalled = shell.which("yarn");
|
|
18
|
+
if (!yarnInstalled) {
|
|
19
|
+
await inquirer
|
|
20
|
+
.prompt([
|
|
21
|
+
{
|
|
22
|
+
type: "confirm",
|
|
23
|
+
name: "confirm",
|
|
24
|
+
message: "yarn must be globally installed. Install yarn?",
|
|
25
|
+
default: true,
|
|
26
|
+
},
|
|
27
|
+
])
|
|
28
|
+
.then(({ confirm }) => {
|
|
29
|
+
if (confirm) {
|
|
30
|
+
shell.exec("npm install --global yarn");
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
console.log("Installation cancelled.");
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const checkForMintJson = async (logger) => {
|
|
39
|
+
const configPath = await getConfigPath(CMD_EXEC_PATH);
|
|
40
|
+
if (configPath == null) {
|
|
41
|
+
logger.fail("Must be ran in a directory where a mint.json file exists.");
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
return;
|
|
45
|
+
};
|
|
46
|
+
const prod = async (argv) => {
|
|
47
|
+
shell.cd(HOME_DIR);
|
|
48
|
+
await promptForYarn();
|
|
49
|
+
const logger = buildLogger("Preparing production Mintlify instance...");
|
|
50
|
+
await fse.ensureDir(MINT_PATH);
|
|
51
|
+
shell.cd(MINT_PATH);
|
|
52
|
+
const internet = await isInternetAvailable();
|
|
53
|
+
if (!internet && !(await pathExists(CLIENT_PATH))) {
|
|
54
|
+
logger.fail("Running mintlify prod for the first time requires an internet connection.");
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
if (!(await nodeModulesExists())) {
|
|
58
|
+
if (!internet) {
|
|
59
|
+
logger.fail(`Dependencies are missing and you are offline. Connect to the internet and run
|
|
60
|
+
|
|
61
|
+
mintlify install
|
|
62
|
+
|
|
63
|
+
`);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
logger.fail(`Dependencies were not installed correctly, run
|
|
67
|
+
|
|
68
|
+
mintlify install
|
|
69
|
+
|
|
70
|
+
`);
|
|
71
|
+
}
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
await checkForMintJson(logger);
|
|
75
|
+
shell.cd(CLIENT_PATH);
|
|
76
|
+
const relativePath = path.relative(CLIENT_PATH, CMD_EXEC_PATH);
|
|
77
|
+
child_process.spawnSync("yarn preconfigure", [relativePath], { shell: true });
|
|
78
|
+
logger.succeed("Production instance is ready. Launching your site...");
|
|
79
|
+
run(argv.port || "3000");
|
|
80
|
+
};
|
|
81
|
+
const run = (port) => {
|
|
82
|
+
shell.cd(CLIENT_PATH);
|
|
83
|
+
console.log("CLIENT PATH", CLIENT_PATH);
|
|
84
|
+
// Build the production bundle
|
|
85
|
+
console.log(`🔨 ${Chalk.cyan("Building production bundle...")}`);
|
|
86
|
+
const buildResult = child_process.spawnSync("npm run build", {
|
|
87
|
+
cwd: CLIENT_PATH,
|
|
88
|
+
stdio: "inherit",
|
|
89
|
+
shell: true,
|
|
90
|
+
});
|
|
91
|
+
if (buildResult.status !== 0) {
|
|
92
|
+
console.error(`${Chalk.red("Build failed. Please fix the errors and try again.")}`);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
console.log(`✅ ${Chalk.green("Build complete! Starting production server...")}`);
|
|
96
|
+
console.log("");
|
|
97
|
+
// Start the production server (no file watching)
|
|
98
|
+
const mintlifyProdProcess = child_process.spawn("npm run start", {
|
|
99
|
+
env: {
|
|
100
|
+
...process.env,
|
|
101
|
+
PORT: port,
|
|
102
|
+
NODE_ENV: "production",
|
|
103
|
+
},
|
|
104
|
+
cwd: CLIENT_PATH,
|
|
105
|
+
stdio: "pipe",
|
|
106
|
+
shell: true,
|
|
107
|
+
});
|
|
108
|
+
let serverStarted = false;
|
|
109
|
+
mintlifyProdProcess.stdout.on("data", (data) => {
|
|
110
|
+
const output = data.toString();
|
|
111
|
+
console.log(output);
|
|
112
|
+
// Next.js production server outputs "ready" or "started server"
|
|
113
|
+
if (!serverStarted && (output.includes("started server") || output.includes("ready"))) {
|
|
114
|
+
serverStarted = true;
|
|
115
|
+
console.log(`🌿 ${Chalk.green(`Your production preview is available at http://localhost:${port}`)}`);
|
|
116
|
+
console.log(`🌿 ${Chalk.green("Press Ctrl+C any time to stop the production preview.")}`);
|
|
117
|
+
open(`http://localhost:${port}`);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
mintlifyProdProcess.stderr.on("data", (data) => {
|
|
121
|
+
console.error(data.toString());
|
|
122
|
+
});
|
|
123
|
+
const onExit = () => {
|
|
124
|
+
mintlifyProdProcess.kill("SIGINT");
|
|
125
|
+
process.exit(0);
|
|
126
|
+
};
|
|
127
|
+
process.on("SIGINT", onExit);
|
|
128
|
+
process.on("SIGTERM", onExit);
|
|
129
|
+
};
|
|
130
|
+
export default prod;
|