@docsalot/previewing 0.1.0-beta.4 → 0.1.0-beta.5

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
  import shell from "shelljs";
2
2
  import fse, { pathExists } from "fs-extra";
3
+ import path from "path";
3
4
  import { BUNDLED_CLIENT_TARBALL_PATH, CLIENT_PATH, MINT_PATH, TARGET_CLIENT_VERSION, VERSION_PATH, } from "../../constants.js";
4
5
  import { buildLogger, ensureYarn } from "../../util.js";
5
6
  const bootstrapBundledClient = async (logger) => {
@@ -16,21 +17,37 @@ const bootstrapBundledClient = async (logger) => {
16
17
  }
17
18
  fse.writeFileSync(VERSION_PATH, TARGET_CLIENT_VERSION);
18
19
  };
20
+ const shouldBootstrapClient = async () => {
21
+ const clientExists = await pathExists(CLIENT_PATH);
22
+ if (!clientExists)
23
+ return true;
24
+ if (!(await pathExists(VERSION_PATH)))
25
+ return true;
26
+ const installedVersion = fse.readFileSync(VERSION_PATH, "utf8").trim();
27
+ return installedVersion !== TARGET_CLIENT_VERSION;
28
+ };
19
29
  const installDeps = async () => {
20
30
  const logger = buildLogger("Preparing local DocsALot client...");
21
31
  ensureYarn(logger);
22
32
  await fse.ensureDir(MINT_PATH);
23
- const clientExists = await pathExists(CLIENT_PATH);
24
- if (!clientExists) {
33
+ const needsBootstrap = await shouldBootstrapClient();
34
+ if (needsBootstrap) {
35
+ await fse.remove(CLIENT_PATH);
25
36
  await bootstrapBundledClient(logger);
26
37
  }
27
- logger.text = "Installing local DocsALot dependencies...";
28
- shell.cd(CLIENT_PATH);
29
- const installResult = shell.exec("yarn");
30
- if (installResult.code !== 0) {
31
- logger.fail("Failed to install dependencies.");
32
- process.exit(1);
38
+ const nodeModulesPath = path.join(CLIENT_PATH, "node_modules");
39
+ const dependenciesInstalled = await pathExists(nodeModulesPath);
40
+ if (!dependenciesInstalled || needsBootstrap) {
41
+ logger.text = "Installing local DocsALot dependencies...";
42
+ shell.cd(CLIENT_PATH);
43
+ const installResult = shell.exec("yarn");
44
+ if (installResult.code !== 0) {
45
+ logger.fail("Failed to install dependencies.");
46
+ process.exit(1);
47
+ }
48
+ logger.succeed("Dependencies installed.");
49
+ return;
33
50
  }
34
- logger.succeed("Dependencies installed.");
51
+ logger.succeed("Dependencies already installed.");
35
52
  };
36
53
  export default installDeps;
@@ -7,11 +7,11 @@ import inquirer from "inquirer";
7
7
  import { isInternetAvailable } from "is-internet-available";
8
8
  import path from "path";
9
9
  import shell from "shelljs";
10
- import { Octokit } from "@octokit/rest";
11
- import { CLIENT_PATH, HOME_DIR, DOT_DOCSALOT, CMD_EXEC_PATH, TARGET_CLIENT_VERSION, VERSION_PATH, MINT_PATH, } from "../constants.js";
12
- import { buildLogger, ensureYarn } from "../util.js";
10
+ import { CLIENT_PATH, HOME_DIR, DOT_DOCSALOT, CMD_EXEC_PATH, MINT_PATH, } from "../constants.js";
11
+ import { buildLogger } from "../util.js";
13
12
  import listener from "./listener/index.js";
14
13
  import { getConfigPath } from "./listener/utils/mintConfigFile.js";
14
+ import installDepsCommand from "./helper-commands/installDepsCommand.js";
15
15
  const nodeModulesExists = async () => {
16
16
  return pathExists(path.join(DOT_DOCSALOT, "client", "node_modules"));
17
17
  };
@@ -37,34 +37,6 @@ const promptForYarn = async () => {
37
37
  });
38
38
  }
39
39
  };
40
- const downloadTargetClient = async (logger) => {
41
- fse.emptyDirSync(MINT_PATH);
42
- logger.text = "Downloading DocsALot framework...";
43
- const octokit = new Octokit();
44
- const downloadRes = await octokit.repos.downloadTarballArchive({
45
- owner: "slashml",
46
- repo: "docsalot",
47
- ref: TARGET_CLIENT_VERSION,
48
- });
49
- logger.text = "Extracting DocsALot framework...";
50
- const TAR_PATH = path.join(MINT_PATH, "mint.tar.gz");
51
- fse.writeFileSync(TAR_PATH, Buffer.from(downloadRes.data));
52
- // strip-components 1 removes the top level directory from the unzipped content
53
- // which is a folder with the release sha
54
- fse.mkdirSync(path.join(MINT_PATH, "mint-tmp"));
55
- shell.exec("tar -xzf mint.tar.gz -C mint-tmp --strip-components 1", {
56
- silent: true,
57
- });
58
- fse.removeSync(TAR_PATH);
59
- fse.moveSync(path.join(MINT_PATH, "mint-tmp", "client"), path.join(CLIENT_PATH));
60
- fse.writeFileSync(VERSION_PATH, TARGET_CLIENT_VERSION);
61
- // Delete unnecessary content downloaded from GitHub
62
- fse.removeSync(path.join(MINT_PATH, "mint-tmp"));
63
- logger.text = "Installing dependencies...";
64
- ensureYarn(logger);
65
- shell.cd(CLIENT_PATH);
66
- shell.exec("yarn", { silent: true });
67
- };
68
40
  const checkForLayoutJson = async (logger) => {
69
41
  const configPath = await getConfigPath(CMD_EXEC_PATH);
70
42
  if (configPath == null) {
@@ -81,23 +53,6 @@ const dev = async (argv) => {
81
53
  await fse.ensureDir(MINT_PATH);
82
54
  shell.cd(MINT_PATH);
83
55
  const internet = await isInternetAvailable();
84
- if (!internet && !(await pathExists(CLIENT_PATH))) {
85
- logger.fail("Running docsalot dev for the first time requires an internet connection.");
86
- process.exit(1);
87
- }
88
- // if (internet) {
89
- // const mintVersionExists = await pathExists(VERSION_PATH);
90
- // let needToDownloadTargetClient = !mintVersionExists;
91
- // if (mintVersionExists) {
92
- // const currVersion = fse.readFileSync(VERSION_PATH, "utf8");
93
- // if (currVersion !== TARGET_CLIENT_VERSION) {
94
- // needToDownloadTargetClient = true;
95
- // }
96
- // }
97
- // if (needToDownloadTargetClient) {
98
- // await downloadTargetClient(logger);
99
- // }
100
- // }
101
56
  if (!(await nodeModulesExists())) {
102
57
  if (!internet) {
103
58
  logger.fail(`Dependencies are missing and you are offline. Connect to the internet and run
@@ -105,15 +60,10 @@ const dev = async (argv) => {
105
60
  docsalot install
106
61
 
107
62
  `);
63
+ process.exit(1);
108
64
  }
109
- else {
110
- logger.fail(`Dependencies were not installed correctly, run
111
-
112
- docsalot install
113
-
114
- `);
115
- }
116
- process.exit(1);
65
+ logger.info("Dependencies missing; running first-time bootstrap...");
66
+ await installDepsCommand();
117
67
  }
118
68
  await checkForLayoutJson(logger);
119
69
  shell.cd(CLIENT_PATH);
@@ -10,6 +10,7 @@ import shell from "shelljs";
10
10
  import { CLIENT_PATH, HOME_DIR, DOT_DOCSALOT, CMD_EXEC_PATH, MINT_PATH, } from "../constants.js";
11
11
  import { buildLogger } from "../util.js";
12
12
  import { getConfigPath } from "./listener/utils/mintConfigFile.js";
13
+ import installDepsCommand from "./helper-commands/installDepsCommand.js";
13
14
  const nodeModulesExists = async () => {
14
15
  return pathExists(path.join(DOT_DOCSALOT, "client", "node_modules"));
15
16
  };
@@ -50,10 +51,6 @@ const prod = async (argv) => {
50
51
  await fse.ensureDir(MINT_PATH);
51
52
  shell.cd(MINT_PATH);
52
53
  const internet = await isInternetAvailable();
53
- if (!internet && !(await pathExists(CLIENT_PATH))) {
54
- logger.fail("Running docsalot prod for the first time requires an internet connection.");
55
- process.exit(1);
56
- }
57
54
  if (!(await nodeModulesExists())) {
58
55
  if (!internet) {
59
56
  logger.fail(`Dependencies are missing and you are offline. Connect to the internet and run
@@ -61,15 +58,10 @@ const prod = async (argv) => {
61
58
  docsalot install
62
59
 
63
60
  `);
61
+ process.exit(1);
64
62
  }
65
- else {
66
- logger.fail(`Dependencies were not installed correctly, run
67
-
68
- docsalot install
69
-
70
- `);
71
- }
72
- process.exit(1);
63
+ logger.info("Dependencies missing; running first-time bootstrap...");
64
+ await installDepsCommand();
73
65
  }
74
66
  await checkForLayoutJson(logger);
75
67
  shell.cd(CLIENT_PATH);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docsalot/previewing",
3
- "version": "0.1.0-beta.4",
3
+ "version": "0.1.0-beta.5",
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.4",
33
- "@docsalot/validation": "^0.1.0-beta.4",
32
+ "@docsalot/prebuild": "^0.1.0-beta.5",
33
+ "@docsalot/validation": "^0.1.0-beta.5",
34
34
  "@octokit/rest": "^19.0.5",
35
35
  "axios": "^1.2.2",
36
36
  "chalk": "^5.1.0",