@mintlify/previewing 3.1.1 → 3.1.2
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/dist/constants.d.ts +1 -1
- package/dist/constants.js +27 -28
- package/dist/downloadImage.js +112 -55
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -3
- package/dist/local-preview/helper-commands/installDepsCommand.js +49 -10
- package/dist/local-preview/index.d.ts +1 -1
- package/dist/local-preview/index.js +221 -131
- package/dist/local-preview/listener/categorize.d.ts +1 -1
- package/dist/local-preview/listener/categorize.js +134 -80
- package/dist/local-preview/listener/generate.d.ts +1 -1
- package/dist/local-preview/listener/generate.js +138 -60
- package/dist/local-preview/listener/index.js +289 -172
- package/dist/local-preview/listener/update.js +75 -20
- package/dist/local-preview/listener/utils/createPage.d.ts +1 -1
- package/dist/local-preview/listener/utils/createPage.js +176 -123
- package/dist/local-preview/listener/utils/getOpenApiContext.d.ts +3 -3
- package/dist/local-preview/listener/utils/getOpenApiContext.js +22 -24
- package/dist/local-preview/listener/utils/mintConfigFile.js +71 -19
- package/dist/local-preview/listener/utils/toTitleCase.js +3 -4
- package/dist/local-preview/listener/utils/types.d.ts +2 -2
- package/dist/local-preview/listener/utils/types.js +0 -1
- package/dist/local-preview/listener/utils.d.ts +1 -1
- package/dist/local-preview/listener/utils.js +94 -35
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/util.d.ts +5 -5
- package/dist/util.js +30 -37
- package/package.json +5 -1
- package/dist/constants.js.map +0 -1
- package/dist/downloadImage.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/local-preview/helper-commands/installDepsCommand.js.map +0 -1
- package/dist/local-preview/index.js.map +0 -1
- package/dist/local-preview/listener/categorize.js.map +0 -1
- package/dist/local-preview/listener/generate.js.map +0 -1
- package/dist/local-preview/listener/index.js.map +0 -1
- package/dist/local-preview/listener/update.js.map +0 -1
- package/dist/local-preview/listener/utils/createPage.js.map +0 -1
- package/dist/local-preview/listener/utils/getOpenApiContext.js.map +0 -1
- package/dist/local-preview/listener/utils/mintConfigFile.js.map +0 -1
- package/dist/local-preview/listener/utils/toTitleCase.js.map +0 -1
- package/dist/local-preview/listener/utils/types.js.map +0 -1
- package/dist/local-preview/listener/utils.js.map +0 -1
- package/dist/util.js.map +0 -1
|
@@ -1,154 +1,244 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import { buildLogger, ensureYarn } from "../util.js";
|
|
12
|
-
import listener from "./listener/index.js";
|
|
13
|
-
import { getConfigPath } from "./listener/utils/mintConfigFile.js";
|
|
14
|
-
const nodeModulesExists = async () => {
|
|
15
|
-
return pathExists(path.join(DOT_MINTLIFY, "mint", "client", "node_modules"));
|
|
16
|
-
};
|
|
17
|
-
const promptForYarn = async () => {
|
|
18
|
-
const yarnInstalled = shell.which("yarn");
|
|
19
|
-
if (!yarnInstalled) {
|
|
20
|
-
await inquirer
|
|
21
|
-
.prompt([
|
|
22
|
-
{
|
|
23
|
-
type: "confirm",
|
|
24
|
-
name: "confirm",
|
|
25
|
-
message: "yarn must be globally installed. Install yarn?",
|
|
26
|
-
default: true,
|
|
27
|
-
},
|
|
28
|
-
])
|
|
29
|
-
.then(({ confirm }) => {
|
|
30
|
-
if (confirm) {
|
|
31
|
-
shell.exec("npm install --global yarn");
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
console.log("Installation cancelled.");
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
38
11
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
ref: TARGET_MINT_VERSION,
|
|
47
|
-
});
|
|
48
|
-
logger.text = "Extracting Mintlify framework...";
|
|
49
|
-
const TAR_PATH = path.join(MINT_PATH, "mint.tar.gz");
|
|
50
|
-
fse.writeFileSync(TAR_PATH, Buffer.from(downloadRes.data));
|
|
51
|
-
// strip-components 1 removes the top level directory from the unzipped content
|
|
52
|
-
// which is a folder with the release sha
|
|
53
|
-
fse.mkdirSync(path.join(MINT_PATH, "mint-tmp"));
|
|
54
|
-
shell.exec("tar -xzf mint.tar.gz -C mint-tmp --strip-components 1", {
|
|
55
|
-
silent: true,
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
56
19
|
});
|
|
57
|
-
fse.removeSync(TAR_PATH);
|
|
58
|
-
fse.moveSync(path.join(MINT_PATH, "mint-tmp", "client"), path.join(CLIENT_PATH));
|
|
59
|
-
fse.writeFileSync(VERSION_PATH, TARGET_MINT_VERSION);
|
|
60
|
-
// Delete unnecessary content downloaded from GitHub
|
|
61
|
-
fse.removeSync(path.join(MINT_PATH, "mint-tmp"));
|
|
62
|
-
logger.text = "Installing dependencies...";
|
|
63
|
-
ensureYarn(logger);
|
|
64
|
-
shell.cd(CLIENT_PATH);
|
|
65
|
-
shell.exec("yarn", { silent: true });
|
|
66
20
|
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
72
46
|
}
|
|
73
|
-
return;
|
|
74
47
|
};
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
48
|
+
import { Octokit } from '@octokit/rest';
|
|
49
|
+
import Chalk from 'chalk';
|
|
50
|
+
import child_process from 'child_process';
|
|
51
|
+
import fse, { pathExists } from 'fs-extra';
|
|
52
|
+
import inquirer from 'inquirer';
|
|
53
|
+
import { isInternetAvailable } from 'is-internet-available';
|
|
54
|
+
import open from 'open';
|
|
55
|
+
import path from 'path';
|
|
56
|
+
import shell from 'shelljs';
|
|
57
|
+
import { CLIENT_PATH, HOME_DIR, DOT_MINTLIFY, CMD_EXEC_PATH, TARGET_MINT_VERSION, VERSION_PATH, MINT_PATH, } from '../constants.js';
|
|
58
|
+
import { buildLogger, ensureYarn } from '../util.js';
|
|
59
|
+
import listener from './listener/index.js';
|
|
60
|
+
import { getConfigPath } from './listener/utils/mintConfigFile.js';
|
|
61
|
+
var nodeModulesExists = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
62
|
+
return __generator(this, function (_a) {
|
|
63
|
+
return [2 /*return*/, pathExists(path.join(DOT_MINTLIFY, 'mint', 'client', 'node_modules'))];
|
|
64
|
+
});
|
|
65
|
+
}); };
|
|
66
|
+
var promptForYarn = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
67
|
+
var yarnInstalled;
|
|
68
|
+
return __generator(this, function (_a) {
|
|
69
|
+
switch (_a.label) {
|
|
70
|
+
case 0:
|
|
71
|
+
yarnInstalled = shell.which('yarn');
|
|
72
|
+
if (!!yarnInstalled) return [3 /*break*/, 2];
|
|
73
|
+
return [4 /*yield*/, inquirer
|
|
74
|
+
.prompt([
|
|
75
|
+
{
|
|
76
|
+
type: 'confirm',
|
|
77
|
+
name: 'confirm',
|
|
78
|
+
message: 'yarn must be globally installed. Install yarn?',
|
|
79
|
+
default: true,
|
|
80
|
+
},
|
|
81
|
+
])
|
|
82
|
+
.then(function (_a) {
|
|
83
|
+
var confirm = _a.confirm;
|
|
84
|
+
if (confirm) {
|
|
85
|
+
shell.exec('npm install --global yarn');
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
console.log('Installation cancelled.');
|
|
89
|
+
}
|
|
90
|
+
})];
|
|
91
|
+
case 1:
|
|
92
|
+
_a.sent();
|
|
93
|
+
_a.label = 2;
|
|
94
|
+
case 2: return [2 /*return*/];
|
|
94
95
|
}
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
});
|
|
97
|
+
}); };
|
|
98
|
+
var downloadTargetMint = function (logger) { return __awaiter(void 0, void 0, void 0, function () {
|
|
99
|
+
var octokit, downloadRes, TAR_PATH;
|
|
100
|
+
return __generator(this, function (_a) {
|
|
101
|
+
switch (_a.label) {
|
|
102
|
+
case 0:
|
|
103
|
+
fse.emptyDirSync(MINT_PATH);
|
|
104
|
+
logger.text = 'Downloading Mintlify framework...';
|
|
105
|
+
octokit = new Octokit();
|
|
106
|
+
return [4 /*yield*/, octokit.repos.downloadTarballArchive({
|
|
107
|
+
owner: 'mintlify',
|
|
108
|
+
repo: 'mint',
|
|
109
|
+
ref: TARGET_MINT_VERSION,
|
|
110
|
+
})];
|
|
111
|
+
case 1:
|
|
112
|
+
downloadRes = _a.sent();
|
|
113
|
+
logger.text = 'Extracting Mintlify framework...';
|
|
114
|
+
TAR_PATH = path.join(MINT_PATH, 'mint.tar.gz');
|
|
115
|
+
fse.writeFileSync(TAR_PATH, Buffer.from(downloadRes.data));
|
|
116
|
+
// strip-components 1 removes the top level directory from the unzipped content
|
|
117
|
+
// which is a folder with the release sha
|
|
118
|
+
fse.mkdirSync(path.join(MINT_PATH, 'mint-tmp'));
|
|
119
|
+
shell.exec('tar -xzf mint.tar.gz -C mint-tmp --strip-components 1', {
|
|
120
|
+
silent: true,
|
|
121
|
+
});
|
|
122
|
+
fse.removeSync(TAR_PATH);
|
|
123
|
+
fse.moveSync(path.join(MINT_PATH, 'mint-tmp', 'client'), path.join(CLIENT_PATH));
|
|
124
|
+
fse.writeFileSync(VERSION_PATH, TARGET_MINT_VERSION);
|
|
125
|
+
// Delete unnecessary content downloaded from GitHub
|
|
126
|
+
fse.removeSync(path.join(MINT_PATH, 'mint-tmp'));
|
|
127
|
+
logger.text = 'Installing dependencies...';
|
|
128
|
+
ensureYarn(logger);
|
|
129
|
+
shell.cd(CLIENT_PATH);
|
|
130
|
+
shell.exec('yarn', { silent: true });
|
|
131
|
+
return [2 /*return*/];
|
|
97
132
|
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
133
|
+
});
|
|
134
|
+
}); };
|
|
135
|
+
var checkForMintJson = function (logger) { return __awaiter(void 0, void 0, void 0, function () {
|
|
136
|
+
var configPath;
|
|
137
|
+
return __generator(this, function (_a) {
|
|
138
|
+
switch (_a.label) {
|
|
139
|
+
case 0: return [4 /*yield*/, getConfigPath(CMD_EXEC_PATH)];
|
|
140
|
+
case 1:
|
|
141
|
+
configPath = _a.sent();
|
|
142
|
+
if (configPath == null) {
|
|
143
|
+
logger.fail('Must be ran in a directory where a mint.json file exists.');
|
|
144
|
+
process.exit(1);
|
|
145
|
+
}
|
|
146
|
+
return [2 /*return*/];
|
|
106
147
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
148
|
+
});
|
|
149
|
+
}); };
|
|
150
|
+
var dev = function (argv) { return __awaiter(void 0, void 0, void 0, function () {
|
|
151
|
+
var logger, internet, _a, mintVersionExists, needToDownloadTargetMint, currVersion, relativePath;
|
|
152
|
+
return __generator(this, function (_b) {
|
|
153
|
+
switch (_b.label) {
|
|
154
|
+
case 0:
|
|
155
|
+
shell.cd(HOME_DIR);
|
|
156
|
+
return [4 /*yield*/, promptForYarn()];
|
|
157
|
+
case 1:
|
|
158
|
+
_b.sent();
|
|
159
|
+
logger = buildLogger('Preparing local Mintlify instance...');
|
|
160
|
+
return [4 /*yield*/, fse.ensureDir(MINT_PATH)];
|
|
161
|
+
case 2:
|
|
162
|
+
_b.sent();
|
|
163
|
+
shell.cd(MINT_PATH);
|
|
164
|
+
return [4 /*yield*/, isInternetAvailable()];
|
|
165
|
+
case 3:
|
|
166
|
+
internet = _b.sent();
|
|
167
|
+
_a = !internet;
|
|
168
|
+
if (!_a) return [3 /*break*/, 5];
|
|
169
|
+
return [4 /*yield*/, pathExists(CLIENT_PATH)];
|
|
170
|
+
case 4:
|
|
171
|
+
_a = !(_b.sent());
|
|
172
|
+
_b.label = 5;
|
|
173
|
+
case 5:
|
|
174
|
+
if (_a) {
|
|
175
|
+
logger.fail('Running mintlify dev for the first time requires an internet connection.');
|
|
176
|
+
process.exit(1);
|
|
177
|
+
}
|
|
178
|
+
if (!internet) return [3 /*break*/, 8];
|
|
179
|
+
return [4 /*yield*/, pathExists(VERSION_PATH)];
|
|
180
|
+
case 6:
|
|
181
|
+
mintVersionExists = _b.sent();
|
|
182
|
+
needToDownloadTargetMint = !mintVersionExists;
|
|
183
|
+
if (mintVersionExists) {
|
|
184
|
+
currVersion = fse.readFileSync(VERSION_PATH, 'utf8');
|
|
185
|
+
if (currVersion !== TARGET_MINT_VERSION) {
|
|
186
|
+
needToDownloadTargetMint = true;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (!needToDownloadTargetMint) return [3 /*break*/, 8];
|
|
190
|
+
return [4 /*yield*/, downloadTargetMint(logger)];
|
|
191
|
+
case 7:
|
|
192
|
+
_b.sent();
|
|
193
|
+
_b.label = 8;
|
|
194
|
+
case 8: return [4 /*yield*/, nodeModulesExists()];
|
|
195
|
+
case 9:
|
|
196
|
+
if (!(_b.sent())) {
|
|
197
|
+
if (!internet) {
|
|
198
|
+
logger.fail("Dependencies are missing and you are offline. Connect to the internet and run\n \n mintlify install\n \n ");
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
logger.fail("Dependencies were not installed correctly, run\n \n mintlify install\n \n ");
|
|
202
|
+
}
|
|
203
|
+
process.exit(1);
|
|
204
|
+
}
|
|
205
|
+
return [4 /*yield*/, checkForMintJson(logger)];
|
|
206
|
+
case 10:
|
|
207
|
+
_b.sent();
|
|
208
|
+
shell.cd(CLIENT_PATH);
|
|
209
|
+
relativePath = path.relative(CLIENT_PATH, CMD_EXEC_PATH);
|
|
210
|
+
child_process.spawnSync('yarn preconfigure', [relativePath], { shell: true });
|
|
211
|
+
logger.succeed('Local Mintlify instance is ready. Launching your site...');
|
|
212
|
+
run((argv === null || argv === void 0 ? void 0 : argv.port) || '3000');
|
|
213
|
+
return [2 /*return*/];
|
|
113
214
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
shell.cd(CLIENT_PATH);
|
|
118
|
-
const relativePath = path.relative(CLIENT_PATH, CMD_EXEC_PATH);
|
|
119
|
-
child_process.spawnSync("yarn preconfigure", [relativePath], { shell: true });
|
|
120
|
-
logger.succeed("Local Mintlify instance is ready. Launching your site...");
|
|
121
|
-
run(argv.port || "3000");
|
|
122
|
-
};
|
|
123
|
-
const run = (port) => {
|
|
215
|
+
});
|
|
216
|
+
}); };
|
|
217
|
+
var run = function (port) {
|
|
124
218
|
shell.cd(CLIENT_PATH);
|
|
125
219
|
// next-remote-watch can only receive ports as env variables
|
|
126
220
|
// https://github.com/hashicorp/next-remote-watch/issues/23
|
|
127
|
-
|
|
128
|
-
env: {
|
|
129
|
-
...process.env,
|
|
130
|
-
PORT: port,
|
|
131
|
-
},
|
|
221
|
+
var mintlifyDevProcess = child_process.spawn('npm run dev-watch', {
|
|
222
|
+
env: __assign(__assign({}, process.env), { PORT: port }),
|
|
132
223
|
cwd: CLIENT_PATH,
|
|
133
|
-
stdio:
|
|
224
|
+
stdio: 'pipe',
|
|
134
225
|
shell: true,
|
|
135
226
|
});
|
|
136
|
-
mintlifyDevProcess.stdout.on(
|
|
137
|
-
|
|
227
|
+
mintlifyDevProcess.stdout.on('data', function (data) {
|
|
228
|
+
var output = data.toString();
|
|
138
229
|
console.log(output);
|
|
139
|
-
if (output.startsWith(
|
|
140
|
-
console.log(
|
|
141
|
-
console.log(
|
|
142
|
-
open(
|
|
230
|
+
if (output.startsWith('> Ready on http://localhost:')) {
|
|
231
|
+
console.log("\uD83C\uDF3F ".concat(Chalk.green("Your local preview is available at http://localhost:".concat(port))));
|
|
232
|
+
console.log("\uD83C\uDF3F ".concat(Chalk.green('Press Ctrl+C any time to stop the local preview.')));
|
|
233
|
+
open("http://localhost:".concat(port));
|
|
143
234
|
}
|
|
144
235
|
});
|
|
145
|
-
|
|
146
|
-
mintlifyDevProcess.kill(
|
|
236
|
+
var onExit = function () {
|
|
237
|
+
mintlifyDevProcess.kill('SIGINT');
|
|
147
238
|
process.exit(0);
|
|
148
239
|
};
|
|
149
|
-
process.on(
|
|
150
|
-
process.on(
|
|
240
|
+
process.on('SIGINT', onExit);
|
|
241
|
+
process.on('SIGTERM', onExit);
|
|
151
242
|
listener();
|
|
152
243
|
};
|
|
153
244
|
export default dev;
|
|
154
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,96 +1,150 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const staticFilenames = [];
|
|
9
|
-
const promises = [];
|
|
10
|
-
const openApiFiles = [];
|
|
11
|
-
const snippets = [];
|
|
12
|
-
allFilesInCmdExecutionPath.forEach((filename) => {
|
|
13
|
-
promises.push((async () => {
|
|
14
|
-
const extension = getFileExtension(filename);
|
|
15
|
-
let isOpenApi = false;
|
|
16
|
-
if (extension && (extension === "mdx" || extension === "md")) {
|
|
17
|
-
if (filename.startsWith("/_snippets")) {
|
|
18
|
-
snippets.push(filename);
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
contentFilenames.push(filename);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
else if (extension &&
|
|
25
|
-
(extension === "json" || extension === "yaml" || extension === "yml")) {
|
|
26
|
-
const openApiInfo = await openApiCheck(path.join(contentDirectoryPath, filename));
|
|
27
|
-
isOpenApi = openApiInfo.isOpenApi;
|
|
28
|
-
if (isOpenApi) {
|
|
29
|
-
const fileName = path.parse(filename).base;
|
|
30
|
-
openApiFiles.push({
|
|
31
|
-
filename: fileName.substring(0, fileName.lastIndexOf(".")),
|
|
32
|
-
spec: openApiInfo.spec,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
else if (!filename.endsWith("mint.json") && !isOpenApi) {
|
|
37
|
-
// all other files
|
|
38
|
-
staticFilenames.push(filename);
|
|
39
|
-
}
|
|
40
|
-
})());
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
41
8
|
});
|
|
42
|
-
await Promise.all(promises);
|
|
43
|
-
return { contentFilenames, staticFilenames, openApiFiles, snippets };
|
|
44
9
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
// TODO - put in prebuild package
|
|
38
|
+
import { getFileList } from '@mintlify/prebuild';
|
|
39
|
+
import path from 'path';
|
|
40
|
+
import { getFileExtension, openApiCheck } from './utils.js';
|
|
41
|
+
export var categorizeFiles = function (contentDirectoryPath) { return __awaiter(void 0, void 0, void 0, function () {
|
|
42
|
+
var allFilesInCmdExecutionPath, contentFilenames, staticFilenames, promises, openApiFiles, snippets;
|
|
43
|
+
return __generator(this, function (_a) {
|
|
44
|
+
switch (_a.label) {
|
|
45
|
+
case 0:
|
|
46
|
+
allFilesInCmdExecutionPath = getFileList(contentDirectoryPath);
|
|
47
|
+
contentFilenames = [];
|
|
48
|
+
staticFilenames = [];
|
|
49
|
+
promises = [];
|
|
50
|
+
openApiFiles = [];
|
|
51
|
+
snippets = [];
|
|
52
|
+
allFilesInCmdExecutionPath.forEach(function (filename) {
|
|
53
|
+
promises.push((function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
54
|
+
var extension, isOpenApi, openApiInfo, fileName;
|
|
55
|
+
return __generator(this, function (_a) {
|
|
56
|
+
switch (_a.label) {
|
|
57
|
+
case 0:
|
|
58
|
+
extension = getFileExtension(filename);
|
|
59
|
+
isOpenApi = false;
|
|
60
|
+
if (!(extension && (extension === 'mdx' || extension === 'md'))) return [3 /*break*/, 1];
|
|
61
|
+
if (filename.startsWith('/_snippets')) {
|
|
62
|
+
snippets.push(filename);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
contentFilenames.push(filename);
|
|
66
|
+
}
|
|
67
|
+
return [3 /*break*/, 4];
|
|
68
|
+
case 1:
|
|
69
|
+
if (!(extension &&
|
|
70
|
+
(extension === 'json' || extension === 'yaml' || extension === 'yml'))) return [3 /*break*/, 3];
|
|
71
|
+
return [4 /*yield*/, openApiCheck(path.join(contentDirectoryPath, filename))];
|
|
72
|
+
case 2:
|
|
73
|
+
openApiInfo = _a.sent();
|
|
74
|
+
isOpenApi = openApiInfo.isOpenApi;
|
|
75
|
+
if (isOpenApi) {
|
|
76
|
+
fileName = path.parse(filename).base;
|
|
77
|
+
openApiFiles.push({
|
|
78
|
+
filename: fileName.substring(0, fileName.lastIndexOf('.')),
|
|
79
|
+
spec: openApiInfo.spec,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return [3 /*break*/, 4];
|
|
83
|
+
case 3:
|
|
84
|
+
if (!filename.endsWith('mint.json') && !isOpenApi) {
|
|
85
|
+
// all other files
|
|
86
|
+
staticFilenames.push(filename);
|
|
87
|
+
}
|
|
88
|
+
_a.label = 4;
|
|
89
|
+
case 4: return [2 /*return*/];
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}); })());
|
|
93
|
+
});
|
|
94
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
95
|
+
case 1:
|
|
96
|
+
_a.sent();
|
|
97
|
+
return [2 /*return*/, { contentFilenames: contentFilenames, staticFilenames: staticFilenames, openApiFiles: openApiFiles, snippets: snippets }];
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}); };
|
|
101
|
+
var excludedMdFiles = ['readme', 'license', 'contributing', 'contribute'];
|
|
102
|
+
var supportedStaticFileExtensions = [
|
|
103
|
+
'.jpeg',
|
|
104
|
+
'.jpg',
|
|
105
|
+
'.jfif',
|
|
106
|
+
'.pjpeg',
|
|
107
|
+
'.pjp',
|
|
108
|
+
'.png',
|
|
109
|
+
'.svg',
|
|
110
|
+
'.svgz',
|
|
111
|
+
'.ico',
|
|
112
|
+
'.webp',
|
|
113
|
+
'.gif',
|
|
114
|
+
'.apng',
|
|
115
|
+
'.avif',
|
|
116
|
+
'.bmp',
|
|
117
|
+
'.mp4',
|
|
62
118
|
];
|
|
63
|
-
export
|
|
119
|
+
export var getCategory = function (filePath) {
|
|
64
120
|
filePath = filePath.toLowerCase();
|
|
65
|
-
|
|
66
|
-
if (parsed.base ===
|
|
67
|
-
return
|
|
121
|
+
var parsed = path.parse(filePath);
|
|
122
|
+
if (parsed.base === 'mint.json') {
|
|
123
|
+
return 'mintConfig';
|
|
68
124
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (filePath.startsWith(
|
|
72
|
-
|
|
73
|
-
return "snippet";
|
|
125
|
+
var fileName = parsed.name;
|
|
126
|
+
var extension = parsed.ext;
|
|
127
|
+
if (filePath.startsWith('_snippets') && (extension === '.mdx' || extension === '.md')) {
|
|
128
|
+
return 'snippet';
|
|
74
129
|
}
|
|
75
|
-
else if (extension ===
|
|
76
|
-
return
|
|
130
|
+
else if (extension === '.mdx') {
|
|
131
|
+
return 'page';
|
|
77
132
|
}
|
|
78
|
-
else if (extension ===
|
|
133
|
+
else if (extension === '.md') {
|
|
79
134
|
// Exclude common markdown files people don't want on their docs website
|
|
80
135
|
if (excludedMdFiles.includes(fileName)) {
|
|
81
|
-
throw new Error(
|
|
136
|
+
throw new Error('Excluded Md File');
|
|
82
137
|
}
|
|
83
|
-
return
|
|
138
|
+
return 'page';
|
|
84
139
|
}
|
|
85
|
-
else if (extension ===
|
|
86
|
-
return
|
|
140
|
+
else if (extension === '.yaml' || extension === '.yml') {
|
|
141
|
+
return 'potentialYamlOpenApiSpec';
|
|
87
142
|
}
|
|
88
|
-
else if (extension ===
|
|
89
|
-
return
|
|
143
|
+
else if (extension === '.json') {
|
|
144
|
+
return 'potentialJsonOpenApiSpec';
|
|
90
145
|
}
|
|
91
146
|
else if (supportedStaticFileExtensions.includes(extension)) {
|
|
92
|
-
return
|
|
147
|
+
return 'staticFile';
|
|
93
148
|
}
|
|
94
|
-
throw new Error(
|
|
149
|
+
throw new Error('Unsupported File Type, No change enacted');
|
|
95
150
|
};
|
|
96
|
-
//# sourceMappingURL=categorize.js.map
|
|
@@ -7,6 +7,6 @@ type DecoratedMintNavigationEntry = {
|
|
|
7
7
|
type DecoratedMintNavigationEntryChild = DecoratedMintNavigationEntry | PageMetadata;
|
|
8
8
|
type PageMetadata = Record<PageMetadataKeys, string>;
|
|
9
9
|
declare const pageMetadataKeys: readonly ["title", "description", "sidebarTitle", "href", "api", "openapi", "contentType", "auth", "version", "mode", "hideFooterPagination", "authors", "lastUpdatedDate", "createdDate", "size"];
|
|
10
|
-
type PageMetadataKeys = typeof pageMetadataKeys[number];
|
|
10
|
+
type PageMetadataKeys = (typeof pageMetadataKeys)[number];
|
|
11
11
|
export declare const generateNav: () => Promise<DecoratedMintNavigation>;
|
|
12
12
|
export {};
|