host-mdx 2.3.0 → 2.3.1

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.
Files changed (3) hide show
  1. package/cli.js +3 -2
  2. package/index.js +12 -10
  3. package/package.json +1 -1
package/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import path from "path";
4
4
  import * as readline from "readline";
5
- import { HostMdx, createSite, TrackChanges, log } from "./index.js";
5
+ import { HostMdx, createSite, TrackChanges, setupConfigs, log } from "./index.js";
6
6
 
7
7
 
8
8
  // Flags
@@ -132,7 +132,8 @@ export async function main() {
132
132
  let toCreateOnly = rawArgs.includes(CREATE_FLAG) || rawArgs.includes(CREATE_SHORT_FLAG);
133
133
  if (toCreateOnly) {
134
134
  try {
135
- await createSite(inputPath, outputPath, null, undefined, { toBeVerbose });
135
+ let configs = await setupConfigs(inputPath);
136
+ await createSite(inputPath, outputPath, null, undefined, { ...configs, toBeVerbose });
136
137
  }
137
138
  catch (err) {
138
139
  process.exitCode = 1; // Exit with error code if not created successfully
package/index.js CHANGED
@@ -84,14 +84,6 @@ function crawlDir(dir) {
84
84
  let entries = fs.readdirSync(absDir, { recursive: true });
85
85
  return entries.map(file => path.join(absDir, file));
86
86
  }
87
- async function setupConfigs(configFilePath) {
88
- if (fs.existsSync(configFilePath)) {
89
- let cleanConfigFilePath = pathToFileURL(configFilePath).href
90
- return await import(cleanConfigFilePath);
91
- }
92
-
93
- return {};
94
- }
95
87
  async function startServer(hostDir, port, errorCallback) { // Starts server at given port
96
88
 
97
89
  // Make sure host dir path is absolute
@@ -177,6 +169,16 @@ export function isPathInside(parentPath, childPath) {
177
169
  relation !== path.resolve(childPath)
178
170
  );
179
171
  }
172
+ export async function setupConfigs(inputPath) {
173
+
174
+ let configFilePath = path.join(inputPath, CONFIG_FILE_NAME);
175
+ if (fs.existsSync(configFilePath)) {
176
+ let cleanConfigFilePath = pathToFileURL(configFilePath).href
177
+ return await import(cleanConfigFilePath);
178
+ }
179
+
180
+ return {};
181
+ }
180
182
  export function createTempDir() {
181
183
  // Create default temp html dir
182
184
  fs.mkdirSync(TEMP_HTML_DIR, { recursive: true });
@@ -271,7 +273,7 @@ export async function createSite(inputPath = "", outputPath = "", pathsToCreate
271
273
  let configFilePath = path.join(inputPath, `./${CONFIG_FILE_NAME}`);
272
274
  let doesConfigFileExists = fs.existsSync(configFilePath);
273
275
  log(`Importing config file ${configFilePath}`, !doesConfigFileExists);
274
- configs = await setupConfigs(configFilePath);
276
+ configs = await setupConfigs(inputPath);
275
277
  }
276
278
 
277
279
 
@@ -481,7 +483,7 @@ export class HostMdx {
481
483
  let configFilePath = path.join(this.inputPath, `./${CONFIG_FILE_NAME}`);
482
484
  let doesConfigFileExists = fs.existsSync(configFilePath);
483
485
  log(`Importing config file ${configFilePath}`, !doesConfigFileExists);
484
- this.configs = { ...(await setupConfigs(configFilePath)), ...this.configs };
486
+ this.configs = { ...(await setupConfigs(this.inputPath)), ...this.configs };
485
487
 
486
488
 
487
489
  // Get port
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "host-mdx",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "description": "A cli tool to create and serve a static html website from a given mdx directory",
5
5
  "main": "index.js",
6
6
  "type": "module",