@docsalot/previewing 0.1.0-beta.2 → 0.1.0-beta.4
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/assets/client.tar.gz +0 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/local-preview/helper-commands/installDepsCommand.js +28 -3
- package/dist/local-preview/index.js +3 -3
- package/dist/local-preview/listener/categorize.js +4 -2
- package/dist/local-preview/listener/index.js +4 -4
- package/dist/local-preview/listener/utils/mintConfigFile.js +0 -4
- package/dist/local-preview/prod.js +3 -3
- package/package.json +3 -3
|
Binary file
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare const TARGET_CLIENT_VERSION = "v0.0.9";
|
|
2
2
|
export declare const INSTALL_PATH: string;
|
|
3
|
+
export declare const BUNDLED_CLIENT_TARBALL_PATH: string;
|
|
3
4
|
export declare const HOME_DIR: string;
|
|
4
5
|
export declare const DOT_DOCSALOT: string;
|
|
5
6
|
export declare const VERSION_PATH: string;
|
package/dist/constants.js
CHANGED
|
@@ -7,6 +7,7 @@ import os from "os";
|
|
|
7
7
|
export const TARGET_CLIENT_VERSION = "v0.0.9";
|
|
8
8
|
// package installation location
|
|
9
9
|
export const INSTALL_PATH = url.fileURLToPath(new URL(".", import.meta.url));
|
|
10
|
+
export const BUNDLED_CLIENT_TARBALL_PATH = path.join(INSTALL_PATH, "assets", "client.tar.gz");
|
|
10
11
|
export const HOME_DIR = os.homedir();
|
|
11
12
|
// DOCSALOT_PATH can be overridden via environment variable.
|
|
12
13
|
// Priority: DOCSALOT_PATH env var > ~/.docsalot
|
|
@@ -1,11 +1,36 @@
|
|
|
1
1
|
import shell from "shelljs";
|
|
2
|
-
import {
|
|
2
|
+
import fse, { pathExists } from "fs-extra";
|
|
3
|
+
import { BUNDLED_CLIENT_TARBALL_PATH, CLIENT_PATH, MINT_PATH, TARGET_CLIENT_VERSION, VERSION_PATH, } from "../../constants.js";
|
|
3
4
|
import { buildLogger, ensureYarn } from "../../util.js";
|
|
5
|
+
const bootstrapBundledClient = async (logger) => {
|
|
6
|
+
if (!(await pathExists(BUNDLED_CLIENT_TARBALL_PATH))) {
|
|
7
|
+
logger.fail(`Bundled client tarball is missing at: ${BUNDLED_CLIENT_TARBALL_PATH}`);
|
|
8
|
+
process.exit(1);
|
|
9
|
+
}
|
|
10
|
+
await fse.ensureDir(CLIENT_PATH);
|
|
11
|
+
logger.text = "Extracting bundled DocsALot client...";
|
|
12
|
+
const untarResult = shell.exec(`tar -xzf "${BUNDLED_CLIENT_TARBALL_PATH}" -C "${CLIENT_PATH}" --strip-components 1`, { silent: true });
|
|
13
|
+
if (untarResult.code !== 0) {
|
|
14
|
+
logger.fail("Failed to extract bundled DocsALot client.");
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
fse.writeFileSync(VERSION_PATH, TARGET_CLIENT_VERSION);
|
|
18
|
+
};
|
|
4
19
|
const installDeps = async () => {
|
|
5
|
-
const logger = buildLogger("");
|
|
20
|
+
const logger = buildLogger("Preparing local DocsALot client...");
|
|
6
21
|
ensureYarn(logger);
|
|
22
|
+
await fse.ensureDir(MINT_PATH);
|
|
23
|
+
const clientExists = await pathExists(CLIENT_PATH);
|
|
24
|
+
if (!clientExists) {
|
|
25
|
+
await bootstrapBundledClient(logger);
|
|
26
|
+
}
|
|
27
|
+
logger.text = "Installing local DocsALot dependencies...";
|
|
7
28
|
shell.cd(CLIENT_PATH);
|
|
8
|
-
shell.exec("yarn");
|
|
29
|
+
const installResult = shell.exec("yarn");
|
|
30
|
+
if (installResult.code !== 0) {
|
|
31
|
+
logger.fail("Failed to install dependencies.");
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
9
34
|
logger.succeed("Dependencies installed.");
|
|
10
35
|
};
|
|
11
36
|
export default installDeps;
|
|
@@ -65,10 +65,10 @@ const downloadTargetClient = async (logger) => {
|
|
|
65
65
|
shell.cd(CLIENT_PATH);
|
|
66
66
|
shell.exec("yarn", { silent: true });
|
|
67
67
|
};
|
|
68
|
-
const
|
|
68
|
+
const checkForLayoutJson = async (logger) => {
|
|
69
69
|
const configPath = await getConfigPath(CMD_EXEC_PATH);
|
|
70
70
|
if (configPath == null) {
|
|
71
|
-
logger.fail("Must be ran in a directory where a
|
|
71
|
+
logger.fail("Must be ran in a directory where a layout.json file exists.");
|
|
72
72
|
process.exit(1);
|
|
73
73
|
}
|
|
74
74
|
return;
|
|
@@ -115,7 +115,7 @@ const dev = async (argv) => {
|
|
|
115
115
|
}
|
|
116
116
|
process.exit(1);
|
|
117
117
|
}
|
|
118
|
-
await
|
|
118
|
+
await checkForLayoutJson(logger);
|
|
119
119
|
shell.cd(CLIENT_PATH);
|
|
120
120
|
const relativePath = path.relative(CLIENT_PATH, CMD_EXEC_PATH);
|
|
121
121
|
child_process.spawnSync("yarn preconfigure", [relativePath], { shell: true });
|
|
@@ -34,7 +34,9 @@ export const categorizeFiles = async (contentDirectoryPath) => {
|
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
else if (!filename.endsWith("
|
|
37
|
+
else if (!filename.endsWith("layout.json") &&
|
|
38
|
+
!filename.endsWith("docs.json") &&
|
|
39
|
+
!isOpenApi) {
|
|
38
40
|
// all other files
|
|
39
41
|
staticFilenames.push(filename);
|
|
40
42
|
}
|
|
@@ -64,7 +66,7 @@ const supportedStaticFileExtensions = [
|
|
|
64
66
|
export const getCategory = (filePath) => {
|
|
65
67
|
filePath = filePath.toLowerCase();
|
|
66
68
|
const parsed = path.parse(filePath);
|
|
67
|
-
if (parsed.base === "
|
|
69
|
+
if (parsed.base === "layout.json") {
|
|
68
70
|
return "mintConfig";
|
|
69
71
|
}
|
|
70
72
|
const fileName = parsed.name;
|
|
@@ -86,7 +86,7 @@ const listener = () => {
|
|
|
86
86
|
console.log(`Snippet deleted: ${filename}`);
|
|
87
87
|
break;
|
|
88
88
|
case "mintConfig":
|
|
89
|
-
console.log("⚠️
|
|
89
|
+
console.log("⚠️ layout.json deleted. Please create a new layout.json file as it is mandatory.");
|
|
90
90
|
process.exit(1);
|
|
91
91
|
case "potentialJsonOpenApiSpec":
|
|
92
92
|
case "potentialYamlOpenApiSpec":
|
|
@@ -147,9 +147,9 @@ const onUpdateEvent = async (filename) => {
|
|
|
147
147
|
break;
|
|
148
148
|
case "mintConfig":
|
|
149
149
|
regenerateNav = true;
|
|
150
|
-
const
|
|
150
|
+
const layoutJsonFileContent = (await readFile(filePath)).toString();
|
|
151
151
|
try {
|
|
152
|
-
const mintConfig = JSON.parse(
|
|
152
|
+
const mintConfig = JSON.parse(layoutJsonFileContent);
|
|
153
153
|
const { status, errors, warnings } = mintValidation.validateMintConfig(mintConfig);
|
|
154
154
|
errors.forEach((error) => {
|
|
155
155
|
console.error(`🚨 ${Chalk.red(error)}`);
|
|
@@ -163,7 +163,7 @@ const onUpdateEvent = async (filename) => {
|
|
|
163
163
|
}
|
|
164
164
|
catch (error) {
|
|
165
165
|
if (error.name === "SyntaxError") {
|
|
166
|
-
console.error(`🚨 ${Chalk.red("
|
|
166
|
+
console.error(`🚨 ${Chalk.red("layout.json has invalid JSON. You are likely missing a comma or a bracket. You can paste your layout.json file into https://jsonlint.com/ to get a more specific error message.")}`);
|
|
167
167
|
}
|
|
168
168
|
else {
|
|
169
169
|
console.error(`🚨 ${Chalk.red(error.message)}`);
|
|
@@ -4,10 +4,6 @@ import pathUtil from "path";
|
|
|
4
4
|
const { readFile } = _promises;
|
|
5
5
|
// TODO: Put in prebuild package
|
|
6
6
|
export const getConfigPath = async (contentDirectoryPath) => {
|
|
7
|
-
// Prefer modern config filename, but keep backward compatibility.
|
|
8
|
-
if (await pathExists(pathUtil.join(contentDirectoryPath, "docs.json"))) {
|
|
9
|
-
return pathUtil.join(contentDirectoryPath, "docs.json");
|
|
10
|
-
}
|
|
11
7
|
if (await pathExists(pathUtil.join(contentDirectoryPath, "layout.json"))) {
|
|
12
8
|
return pathUtil.join(contentDirectoryPath, "layout.json");
|
|
13
9
|
}
|
|
@@ -35,10 +35,10 @@ const promptForYarn = async () => {
|
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
const
|
|
38
|
+
const checkForLayoutJson = async (logger) => {
|
|
39
39
|
const configPath = await getConfigPath(CMD_EXEC_PATH);
|
|
40
40
|
if (configPath == null) {
|
|
41
|
-
logger.fail("Must be ran in a directory where a
|
|
41
|
+
logger.fail("Must be ran in a directory where a layout.json file exists.");
|
|
42
42
|
process.exit(1);
|
|
43
43
|
}
|
|
44
44
|
return;
|
|
@@ -71,7 +71,7 @@ const prod = async (argv) => {
|
|
|
71
71
|
}
|
|
72
72
|
process.exit(1);
|
|
73
73
|
}
|
|
74
|
-
await
|
|
74
|
+
await checkForLayoutJson(logger);
|
|
75
75
|
shell.cd(CLIENT_PATH);
|
|
76
76
|
const relativePath = path.relative(CLIENT_PATH, CMD_EXEC_PATH);
|
|
77
77
|
child_process.spawnSync("yarn preconfigure", [relativePath], { shell: true });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docsalot/previewing",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.4",
|
|
4
4
|
"description": "Preview DocsALot docs locally",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18.0.0"
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@apidevtools/swagger-parser": "^10.1.0",
|
|
32
|
-
"@docsalot/prebuild": "^0.1.0-beta.
|
|
33
|
-
"@docsalot/validation": "^0.1.0-beta.
|
|
32
|
+
"@docsalot/prebuild": "^0.1.0-beta.4",
|
|
33
|
+
"@docsalot/validation": "^0.1.0-beta.4",
|
|
34
34
|
"@octokit/rest": "^19.0.5",
|
|
35
35
|
"axios": "^1.2.2",
|
|
36
36
|
"chalk": "^5.1.0",
|