@mintlify/previewing 4.0.10 → 4.0.11
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.js +16 -16
- package/dist/local-preview/index.js +88 -156
- package/dist/local-preview/listener/generate.js +27 -100
- package/dist/local-preview/listener/index.js +149 -258
- package/dist/local-preview/listener/update.js +12 -59
- package/dist/local-preview/listener/utils.js +27 -82
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/util.js +5 -6
- package/package.json +5 -5
package/dist/constants.js
CHANGED
|
@@ -2,24 +2,24 @@ import os from 'os';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import * as url from 'url';
|
|
4
4
|
// Change this to bump to a newer version of mint's client
|
|
5
|
-
export
|
|
5
|
+
export const TARGET_MINT_VERSION = 'v0.0.148';
|
|
6
6
|
// package installation location
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export
|
|
19
|
-
export
|
|
7
|
+
export const INSTALL_PATH = url.fileURLToPath(new URL('.', import.meta.url));
|
|
8
|
+
export const HOME_DIR = os.homedir();
|
|
9
|
+
export const DOT_MINTLIFY = path.join(HOME_DIR, '.mintlify');
|
|
10
|
+
export const MINT_PATH = path.join(DOT_MINTLIFY, 'mint');
|
|
11
|
+
export const VERSION_PATH = path.join(MINT_PATH, 'mint-version.txt');
|
|
12
|
+
export const CLIENT_PATH = path.join(MINT_PATH, 'client');
|
|
13
|
+
export const NEXT_SERVER_PATH = path.join(MINT_PATH, 'node_modules', 'next', 'dist', 'server', 'next-server.js');
|
|
14
|
+
export const NEXT_STATIC_PATH = path.join(CLIENT_PATH, '.next', 'static');
|
|
15
|
+
export const NEXT_CONFIG_PATH = path.join(CLIENT_PATH, '.next', 'required-server-files.json');
|
|
16
|
+
export const NEXT_PUBLIC_PATH = path.join(CLIENT_PATH, 'public');
|
|
17
|
+
export const NEXT_PROPS_PATH = path.join(CLIENT_PATH, 'src', '_props');
|
|
18
|
+
export const TAR_URL = `https://mint-releases.b-cdn.net/mint-${TARGET_MINT_VERSION.slice(1)}.tar.gz`;
|
|
19
|
+
export const TAR_PATH = path.join(DOT_MINTLIFY, `mint.tar.gz`);
|
|
20
20
|
// command execution location
|
|
21
|
-
export
|
|
22
|
-
export
|
|
21
|
+
export const CMD_EXEC_PATH = process.cwd();
|
|
22
|
+
export const SUPPORTED_MEDIA_EXTENSIONS = [
|
|
23
23
|
'jpeg',
|
|
24
24
|
'jpg',
|
|
25
25
|
'jfif',
|
|
@@ -7,33 +7,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
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
10
|
import { prebuild } from '@mintlify/prebuild';
|
|
38
11
|
import Chalk from 'chalk';
|
|
39
12
|
import express from 'express';
|
|
@@ -49,136 +22,95 @@ import tar from 'tar';
|
|
|
49
22
|
import { CLIENT_PATH, DOT_MINTLIFY, CMD_EXEC_PATH, TARGET_MINT_VERSION, VERSION_PATH, MINT_PATH, NEXT_SERVER_PATH, NEXT_STATIC_PATH, NEXT_CONFIG_PATH, TAR_URL, TAR_PATH, NEXT_PUBLIC_PATH, NEXT_PROPS_PATH, } from '../constants.js';
|
|
50
23
|
import { buildLogger, maybeFixMissingWindowsEnvVar } from '../util.js';
|
|
51
24
|
import listener from './listener/index.js';
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
logger.text = 'Extracting Mintlify framework...';
|
|
62
|
-
tar.x({
|
|
63
|
-
sync: true,
|
|
64
|
-
file: TAR_PATH,
|
|
65
|
-
cwd: DOT_MINTLIFY,
|
|
66
|
-
});
|
|
67
|
-
fse.removeSync(TAR_PATH);
|
|
68
|
-
fse.writeFileSync(VERSION_PATH, TARGET_MINT_VERSION);
|
|
69
|
-
return [2 /*return*/];
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}); };
|
|
73
|
-
var dev = function (argv) { return __awaiter(void 0, void 0, void 0, function () {
|
|
74
|
-
var logger, versionString, shouldDownload, hasInternet, err_1, errorText;
|
|
75
|
-
return __generator(this, function (_a) {
|
|
76
|
-
switch (_a.label) {
|
|
77
|
-
case 0:
|
|
78
|
-
logger = buildLogger('Preparing local Mintlify instance...');
|
|
79
|
-
return [4 /*yield*/, fse.ensureDir(DOT_MINTLIFY)];
|
|
80
|
-
case 1:
|
|
81
|
-
_a.sent();
|
|
82
|
-
return [4 /*yield*/, pathExists(VERSION_PATH)];
|
|
83
|
-
case 2:
|
|
84
|
-
versionString = (_a.sent())
|
|
85
|
-
? fse.readFileSync(VERSION_PATH, 'utf8')
|
|
86
|
-
: null;
|
|
87
|
-
shouldDownload = versionString !== TARGET_MINT_VERSION;
|
|
88
|
-
if (!shouldDownload) return [3 /*break*/, 5];
|
|
89
|
-
return [4 /*yield*/, isOnline()];
|
|
90
|
-
case 3:
|
|
91
|
-
hasInternet = _a.sent();
|
|
92
|
-
if (!hasInternet) {
|
|
93
|
-
logger.fail('Running mintlify dev afer updating requires an internet connection.');
|
|
94
|
-
process.exit(1);
|
|
95
|
-
}
|
|
96
|
-
return [4 /*yield*/, downloadTargetMint(logger)];
|
|
97
|
-
case 4:
|
|
98
|
-
_a.sent();
|
|
99
|
-
_a.label = 5;
|
|
100
|
-
case 5:
|
|
101
|
-
// clear preexisting prebuild files
|
|
102
|
-
fse.emptyDirSync(NEXT_PUBLIC_PATH);
|
|
103
|
-
fse.emptyDirSync(NEXT_PROPS_PATH);
|
|
104
|
-
process.chdir(CLIENT_PATH);
|
|
105
|
-
_a.label = 6;
|
|
106
|
-
case 6:
|
|
107
|
-
_a.trys.push([6, 8, , 9]);
|
|
108
|
-
return [4 /*yield*/, prebuild(CMD_EXEC_PATH)];
|
|
109
|
-
case 7:
|
|
110
|
-
_a.sent();
|
|
111
|
-
return [3 /*break*/, 9];
|
|
112
|
-
case 8:
|
|
113
|
-
err_1 = _a.sent();
|
|
114
|
-
errorText = err_1 instanceof Error && err_1.message ? err_1.message : 'Prebuild step failed';
|
|
115
|
-
logger.fail(errorText);
|
|
116
|
-
process.exit(1);
|
|
117
|
-
return [3 /*break*/, 9];
|
|
118
|
-
case 9:
|
|
119
|
-
logger.succeed('Local Mintlify instance is ready. Launching your site...');
|
|
120
|
-
return [4 /*yield*/, run((argv === null || argv === void 0 ? void 0 : argv.port) || '3000')];
|
|
121
|
-
case 10:
|
|
122
|
-
_a.sent();
|
|
123
|
-
return [2 /*return*/];
|
|
124
|
-
}
|
|
25
|
+
const downloadTargetMint = (logger) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
fse.emptyDirSync(MINT_PATH);
|
|
27
|
+
logger.text = 'Downloading Mintlify framework...';
|
|
28
|
+
yield pipeline(got.stream(TAR_URL), fse.createWriteStream(TAR_PATH));
|
|
29
|
+
logger.text = 'Extracting Mintlify framework...';
|
|
30
|
+
tar.x({
|
|
31
|
+
sync: true,
|
|
32
|
+
file: TAR_PATH,
|
|
33
|
+
cwd: DOT_MINTLIFY,
|
|
125
34
|
});
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
io = new SocketServer(server);
|
|
142
|
-
onChange = function () {
|
|
143
|
-
io.emit('reload');
|
|
144
|
-
};
|
|
145
|
-
// static files don't get served in minimalMode
|
|
146
|
-
app.use('/_next/static', express.static(NEXT_STATIC_PATH));
|
|
147
|
-
app.all('*', function (req, res) { return handler === null || handler === void 0 ? void 0 : handler(req, res); });
|
|
148
|
-
currentPort = parseInt(port, 10) || 3000;
|
|
149
|
-
hostname = process.env.HOSTNAME || 'localhost';
|
|
150
|
-
server.listen(currentPort, function () {
|
|
151
|
-
var nextServer = new NextServer({
|
|
152
|
-
hostname: hostname,
|
|
153
|
-
port: currentPort,
|
|
154
|
-
dir: CLIENT_PATH,
|
|
155
|
-
dev: true,
|
|
156
|
-
minimalMode: true,
|
|
157
|
-
customServer: true,
|
|
158
|
-
conf: config,
|
|
159
|
-
});
|
|
160
|
-
handler = nextServer.getRequestHandler();
|
|
161
|
-
console.log("\uD83C\uDF3F ".concat(Chalk.green("Your local preview is available at http://localhost:".concat(port))));
|
|
162
|
-
console.log("\uD83C\uDF3F ".concat(Chalk.green('Press Ctrl+C any time to stop the local preview.')));
|
|
163
|
-
/**
|
|
164
|
-
* We're running into a known bug with the `open` package, where Windows machines error out because process.env.SYSTEMROOT is not set:
|
|
165
|
-
* https://github.com/sindresorhus/open/issues/292
|
|
166
|
-
*
|
|
167
|
-
* Let's use the same workaround that this project did:
|
|
168
|
-
* https://github.com/sanity-io/sanity/pull/4221/files#diff-aeb574e1becf61f21fdf87fbea709669c93d604d660dad4b0f9e24527a2fb54bR256-R262
|
|
169
|
-
*/
|
|
170
|
-
maybeFixMissingWindowsEnvVar();
|
|
171
|
-
open("http://localhost:".concat(port));
|
|
172
|
-
// exit with successful status
|
|
173
|
-
var onExit = function () {
|
|
174
|
-
process.exit(0);
|
|
175
|
-
};
|
|
176
|
-
process.on('SIGINT', onExit);
|
|
177
|
-
process.on('SIGTERM', onExit);
|
|
178
|
-
});
|
|
179
|
-
listener(onChange);
|
|
180
|
-
return [2 /*return*/];
|
|
35
|
+
fse.removeSync(TAR_PATH);
|
|
36
|
+
fse.writeFileSync(VERSION_PATH, TARGET_MINT_VERSION);
|
|
37
|
+
});
|
|
38
|
+
const dev = (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
const logger = buildLogger('Preparing local Mintlify instance...');
|
|
40
|
+
yield fse.ensureDir(DOT_MINTLIFY);
|
|
41
|
+
const versionString = (yield pathExists(VERSION_PATH))
|
|
42
|
+
? fse.readFileSync(VERSION_PATH, 'utf8')
|
|
43
|
+
: null;
|
|
44
|
+
const shouldDownload = versionString !== TARGET_MINT_VERSION;
|
|
45
|
+
if (shouldDownload) {
|
|
46
|
+
const hasInternet = yield isOnline();
|
|
47
|
+
if (!hasInternet) {
|
|
48
|
+
logger.fail('Running mintlify dev afer updating requires an internet connection.');
|
|
49
|
+
process.exit(1);
|
|
181
50
|
}
|
|
51
|
+
yield downloadTargetMint(logger);
|
|
52
|
+
}
|
|
53
|
+
// clear preexisting prebuild files
|
|
54
|
+
fse.emptyDirSync(NEXT_PUBLIC_PATH);
|
|
55
|
+
fse.emptyDirSync(NEXT_PROPS_PATH);
|
|
56
|
+
process.chdir(CLIENT_PATH);
|
|
57
|
+
try {
|
|
58
|
+
yield prebuild(CMD_EXEC_PATH);
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
const errorText = err instanceof Error && err.message ? err.message : 'Prebuild step failed';
|
|
62
|
+
logger.fail(errorText);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
logger.succeed('Local Mintlify instance is ready. Launching your site...');
|
|
66
|
+
yield run((argv === null || argv === void 0 ? void 0 : argv.port) || '3000');
|
|
67
|
+
});
|
|
68
|
+
const run = (port) => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
+
const { default: Server } = yield import(pathToFileURL(NEXT_SERVER_PATH).href);
|
|
70
|
+
const NextServer = Server.default;
|
|
71
|
+
const { config } = yield JSON.parse(fse.readFileSync(NEXT_CONFIG_PATH, 'utf8'));
|
|
72
|
+
process.chdir(CLIENT_PATH);
|
|
73
|
+
let handler;
|
|
74
|
+
const app = express();
|
|
75
|
+
const server = createServer(app);
|
|
76
|
+
const io = new SocketServer(server);
|
|
77
|
+
const onChange = () => {
|
|
78
|
+
io.emit('reload');
|
|
79
|
+
};
|
|
80
|
+
// static files don't get served in minimalMode
|
|
81
|
+
app.use('/_next/static', express.static(NEXT_STATIC_PATH));
|
|
82
|
+
app.all('*', (req, res) => handler === null || handler === void 0 ? void 0 : handler(req, res));
|
|
83
|
+
const currentPort = parseInt(port, 10) || 3000;
|
|
84
|
+
const hostname = process.env.HOSTNAME || 'localhost';
|
|
85
|
+
server.listen(currentPort, () => {
|
|
86
|
+
const nextServer = new NextServer({
|
|
87
|
+
hostname,
|
|
88
|
+
port: currentPort,
|
|
89
|
+
dir: CLIENT_PATH,
|
|
90
|
+
dev: true,
|
|
91
|
+
minimalMode: true,
|
|
92
|
+
customServer: true,
|
|
93
|
+
conf: config,
|
|
94
|
+
});
|
|
95
|
+
handler = nextServer.getRequestHandler();
|
|
96
|
+
console.log(`🌿 ${Chalk.green(`Your local preview is available at http://localhost:${port}`)}`);
|
|
97
|
+
console.log(`🌿 ${Chalk.green('Press Ctrl+C any time to stop the local preview.')}`);
|
|
98
|
+
/**
|
|
99
|
+
* We're running into a known bug with the `open` package, where Windows machines error out because process.env.SYSTEMROOT is not set:
|
|
100
|
+
* https://github.com/sindresorhus/open/issues/292
|
|
101
|
+
*
|
|
102
|
+
* Let's use the same workaround that this project did:
|
|
103
|
+
* https://github.com/sanity-io/sanity/pull/4221/files#diff-aeb574e1becf61f21fdf87fbea709669c93d604d660dad4b0f9e24527a2fb54bR256-R262
|
|
104
|
+
*/
|
|
105
|
+
maybeFixMissingWindowsEnvVar();
|
|
106
|
+
open(`http://localhost:${port}`);
|
|
107
|
+
// exit with successful status
|
|
108
|
+
const onExit = () => {
|
|
109
|
+
process.exit(0);
|
|
110
|
+
};
|
|
111
|
+
process.on('SIGINT', onExit);
|
|
112
|
+
process.on('SIGTERM', onExit);
|
|
182
113
|
});
|
|
183
|
-
|
|
114
|
+
listener(onChange);
|
|
115
|
+
});
|
|
184
116
|
export default dev;
|
|
@@ -1,14 +1,3 @@
|
|
|
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);
|
|
11
|
-
};
|
|
12
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -18,99 +7,37 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
18
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
8
|
});
|
|
20
9
|
};
|
|
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 };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
10
|
import { generateDecoratedMintNavigationFromPages, getConfigObj, categorizeFiles, createPage, } from '@mintlify/prebuild';
|
|
49
11
|
import { promises as _promises } from 'fs';
|
|
50
12
|
import { outputFile } from 'fs-extra';
|
|
51
13
|
import path from 'path';
|
|
52
14
|
import { CMD_EXEC_PATH } from '../../constants.js';
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return __generator(this, function (_c) {
|
|
68
|
-
switch (_c.label) {
|
|
69
|
-
case 0:
|
|
70
|
-
sourcePath = path.join(contentDirectoryPath, filename);
|
|
71
|
-
return [4 /*yield*/, readFile(sourcePath)];
|
|
72
|
-
case 1:
|
|
73
|
-
contentStr = (_c.sent()).toString();
|
|
74
|
-
return [4 /*yield*/, createPage(filename, contentStr, contentDirectoryPath, openApiFiles)];
|
|
75
|
-
case 2:
|
|
76
|
-
_a = _c.sent(), slug = _a.slug, pageMetadata = _a.pageMetadata, pageContent = _a.pageContent;
|
|
77
|
-
if (!(clientPath && writeFiles)) return [3 /*break*/, 4];
|
|
78
|
-
targetPath = path.join(clientPath, 'src', '_props', filename);
|
|
79
|
-
return [4 /*yield*/, outputFile(targetPath, pageContent, {
|
|
80
|
-
flag: 'w',
|
|
81
|
-
})];
|
|
82
|
-
case 3:
|
|
83
|
-
_c.sent();
|
|
84
|
-
_c.label = 4;
|
|
85
|
-
case 4:
|
|
86
|
-
pagesAcc = __assign(__assign({}, pagesAcc), (_b = {}, _b[slug] = pageMetadata, _b));
|
|
87
|
-
return [2 /*return*/];
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}); })());
|
|
91
|
-
});
|
|
92
|
-
return [4 /*yield*/, Promise.all(contentPromises)];
|
|
93
|
-
case 1:
|
|
94
|
-
_a.sent();
|
|
95
|
-
return [2 /*return*/, pagesAcc];
|
|
15
|
+
const { readFile } = _promises;
|
|
16
|
+
const createFilenamePageMetadataMap = (contentDirectoryPath, contentFilenames, openApiFiles, clientPath, writeFiles = false) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
let pagesAcc = {};
|
|
18
|
+
const contentPromises = [];
|
|
19
|
+
contentFilenames.forEach((filename) => {
|
|
20
|
+
contentPromises.push((() => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
const sourcePath = path.join(contentDirectoryPath, filename);
|
|
22
|
+
const contentStr = (yield readFile(sourcePath)).toString();
|
|
23
|
+
const { slug, pageMetadata, pageContent } = yield createPage(filename, contentStr, contentDirectoryPath, openApiFiles);
|
|
24
|
+
if (clientPath && writeFiles) {
|
|
25
|
+
const targetPath = path.join(clientPath, 'src', '_props', filename);
|
|
26
|
+
yield outputFile(targetPath, pageContent, {
|
|
27
|
+
flag: 'w',
|
|
28
|
+
});
|
|
96
29
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
};
|
|
100
|
-
export var generateNav = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
101
|
-
var _a, contentFilenames, openApiFiles, _b, filenamePageMetadataMap, configObj;
|
|
102
|
-
return __generator(this, function (_c) {
|
|
103
|
-
switch (_c.label) {
|
|
104
|
-
case 0: return [4 /*yield*/, categorizeFiles(CMD_EXEC_PATH)];
|
|
105
|
-
case 1:
|
|
106
|
-
_a = _c.sent(), contentFilenames = _a.contentFilenames, openApiFiles = _a.openApiFiles;
|
|
107
|
-
return [4 /*yield*/, Promise.all([
|
|
108
|
-
createFilenamePageMetadataMap(CMD_EXEC_PATH, contentFilenames, openApiFiles),
|
|
109
|
-
getConfigObj(CMD_EXEC_PATH),
|
|
110
|
-
])];
|
|
111
|
-
case 2:
|
|
112
|
-
_b = _c.sent(), filenamePageMetadataMap = _b[0], configObj = _b[1];
|
|
113
|
-
return [2 /*return*/, generateDecoratedMintNavigationFromPages(filenamePageMetadataMap, configObj === null || configObj === void 0 ? void 0 : configObj.navigation)];
|
|
114
|
-
}
|
|
30
|
+
pagesAcc = Object.assign(Object.assign({}, pagesAcc), { [slug]: pageMetadata });
|
|
31
|
+
}))());
|
|
115
32
|
});
|
|
116
|
-
|
|
33
|
+
yield Promise.all(contentPromises);
|
|
34
|
+
return pagesAcc;
|
|
35
|
+
});
|
|
36
|
+
export const generateNav = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
const { contentFilenames, openApiFiles } = yield categorizeFiles(CMD_EXEC_PATH);
|
|
38
|
+
const [filenamePageMetadataMap, configObj] = yield Promise.all([
|
|
39
|
+
createFilenamePageMetadataMap(CMD_EXEC_PATH, contentFilenames, openApiFiles),
|
|
40
|
+
getConfigObj(CMD_EXEC_PATH),
|
|
41
|
+
]);
|
|
42
|
+
return generateDecoratedMintNavigationFromPages(filenamePageMetadataMap, configObj === null || configObj === void 0 ? void 0 : configObj.navigation);
|
|
43
|
+
});
|