@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.
Binary file
@@ -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 { CLIENT_PATH } from "../../constants.js";
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 checkForDocsJson = async (logger) => {
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 docs.json file exists.");
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 checkForDocsJson(logger);
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("docs.json") && !isOpenApi) {
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 === "docs.json" || parsed.base === "layout.json") {
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("⚠️ docs.json deleted. Please create a new docs.json file as it is mandatory.");
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 mintJsonFileContent = (await readFile(filePath)).toString();
150
+ const layoutJsonFileContent = (await readFile(filePath)).toString();
151
151
  try {
152
- const mintConfig = JSON.parse(mintJsonFileContent);
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("docs.json has invalid JSON. You are likely missing a comma or a bracket. You can paste your docs.json file into https://jsonlint.com/ to get a more specific error message.")}`);
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 checkForDocsJson = async (logger) => {
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 docs.json file exists.");
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 checkForDocsJson(logger);
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.2",
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.2",
33
- "@docsalot/validation": "^0.1.0-beta.2",
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",