@docsalot/previewing 0.1.0-beta.2 → 0.1.0-beta.3

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.
@@ -1,11 +1,56 @@
1
1
  import shell from "shelljs";
2
- import { CLIENT_PATH } from "../../constants.js";
2
+ import fse, { pathExists } from "fs-extra";
3
+ import path from "path";
4
+ import { Octokit } from "@octokit/rest";
5
+ import { isInternetAvailable } from "is-internet-available";
6
+ import { CLIENT_PATH, MINT_PATH, TARGET_CLIENT_VERSION, VERSION_PATH, } from "../../constants.js";
3
7
  import { buildLogger, ensureYarn } from "../../util.js";
8
+ const downloadTargetClient = async (logger) => {
9
+ fse.emptyDirSync(MINT_PATH);
10
+ logger.text = "Downloading DocsALot framework...";
11
+ const octokit = new Octokit();
12
+ const downloadRes = await octokit.repos.downloadTarballArchive({
13
+ owner: "slashml",
14
+ repo: "docsalot",
15
+ ref: TARGET_CLIENT_VERSION,
16
+ });
17
+ logger.text = "Extracting DocsALot framework...";
18
+ const tarPath = path.join(MINT_PATH, "mint.tar.gz");
19
+ const tmpPath = path.join(MINT_PATH, "mint-tmp");
20
+ fse.writeFileSync(tarPath, Buffer.from(downloadRes.data));
21
+ fse.mkdirSync(tmpPath, { recursive: true });
22
+ const untarResult = shell.exec(`tar -xzf "${tarPath}" -C "${tmpPath}" --strip-components 1`, {
23
+ silent: true,
24
+ });
25
+ if (untarResult.code !== 0) {
26
+ logger.fail("Failed to extract DocsALot framework.");
27
+ process.exit(1);
28
+ }
29
+ fse.removeSync(tarPath);
30
+ fse.moveSync(path.join(tmpPath, "client"), CLIENT_PATH);
31
+ fse.writeFileSync(VERSION_PATH, TARGET_CLIENT_VERSION);
32
+ fse.removeSync(tmpPath);
33
+ };
4
34
  const installDeps = async () => {
5
- const logger = buildLogger("");
35
+ const logger = buildLogger("Preparing local DocsALot client...");
6
36
  ensureYarn(logger);
37
+ await fse.ensureDir(MINT_PATH);
38
+ const clientExists = await pathExists(CLIENT_PATH);
39
+ if (!clientExists) {
40
+ const internet = await isInternetAvailable();
41
+ if (!internet) {
42
+ logger.fail("First-time setup requires internet to download the local DocsALot framework.");
43
+ process.exit(1);
44
+ }
45
+ await downloadTargetClient(logger);
46
+ }
47
+ logger.text = "Installing local DocsALot dependencies...";
7
48
  shell.cd(CLIENT_PATH);
8
- shell.exec("yarn");
49
+ const installResult = shell.exec("yarn");
50
+ if (installResult.code !== 0) {
51
+ logger.fail("Failed to install dependencies.");
52
+ process.exit(1);
53
+ }
9
54
  logger.succeed("Dependencies installed.");
10
55
  };
11
56
  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.3",
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.3",
33
+ "@docsalot/validation": "^0.1.0-beta.3",
34
34
  "@octokit/rest": "^19.0.5",
35
35
  "axios": "^1.2.2",
36
36
  "chalk": "^5.1.0",