@gesslar/bedoc 1.10.0 → 1.11.0
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/package.json +1 -1
- package/src/cli.js +2 -2
- package/src/core/Configuration.js +3 -3
- package/src/core/Discovery.js +2 -2
- package/src/core/util/ActionUtil.js +18 -9
- package/src/core/util/ModuleUtil.js +0 -40
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -11,7 +11,7 @@ import {ConfigurationParameters} from "./core/ConfigurationParameters.js"
|
|
|
11
11
|
import * as ActionUtil from "./core/util/ActionUtil.js"
|
|
12
12
|
import * as FDUtil from "./core/util/FDUtil.js"
|
|
13
13
|
|
|
14
|
-
const {
|
|
14
|
+
const {loadDataFile} = ActionUtil
|
|
15
15
|
const {resolveFilename,resolveDirectory} = FDUtil
|
|
16
16
|
|
|
17
17
|
// Main entry point
|
|
@@ -20,7 +20,7 @@ const {resolveFilename,resolveDirectory} = FDUtil
|
|
|
20
20
|
// Get package info
|
|
21
21
|
const basePath = resolveDirectory(process.cwd())
|
|
22
22
|
const thisPath = resolveDirectory(fileURLToPath(new URL("..", import.meta.url)))
|
|
23
|
-
const bedocPackageJson =
|
|
23
|
+
const bedocPackageJson = loadDataFile(resolveFilename("package.json", thisPath))
|
|
24
24
|
|
|
25
25
|
// Setup program
|
|
26
26
|
program
|
|
@@ -11,7 +11,7 @@ import * as ActionUtil from "./util/ActionUtil.js"
|
|
|
11
11
|
import * as DataUtil from "./util/DataUtil.js"
|
|
12
12
|
import * as FDUtil from "./util/FDUtil.js"
|
|
13
13
|
|
|
14
|
-
const {
|
|
14
|
+
const {loadDataFile} = ActionUtil
|
|
15
15
|
const {isNothing, isType, mapObject} = DataUtil
|
|
16
16
|
const {getFiles, composeFilename, fileExists} = FDUtil
|
|
17
17
|
const {resolveDirectory, resolveFilename} = FDUtil
|
|
@@ -222,7 +222,7 @@ export default class Configuration {
|
|
|
222
222
|
} else {
|
|
223
223
|
const packageJsonFile = composeFilename(process.cwd(), "package.json")
|
|
224
224
|
if(fileExists(packageJsonFile)) {
|
|
225
|
-
const packageJson =
|
|
225
|
+
const packageJson = loadDataFile(packageJsonFile)
|
|
226
226
|
|
|
227
227
|
if(packageJson.bedoc)
|
|
228
228
|
allOptions.push({source: "packageJson", options: packageJson.bedoc})
|
|
@@ -246,7 +246,7 @@ export default class Configuration {
|
|
|
246
246
|
if(!configFile)
|
|
247
247
|
throw new Error("No config file specified")
|
|
248
248
|
|
|
249
|
-
const configObject =
|
|
249
|
+
const configObject = loadDataFile(configFile)
|
|
250
250
|
const subConfigName =
|
|
251
251
|
entryOptions?.sub ||
|
|
252
252
|
packageJson?.sub ||
|
package/src/core/Discovery.js
CHANGED
|
@@ -9,7 +9,7 @@ import * as DataUtil from "./util/DataUtil.js"
|
|
|
9
9
|
const {composeDirectory,directoryExists,resolveDirectory} = FDUtil
|
|
10
10
|
const {newContract,parse} = ContractManager
|
|
11
11
|
const {ls,fileExists,composeFilename,getFiles} = FDUtil
|
|
12
|
-
const {actionTypes, actionMetaRequirements,
|
|
12
|
+
const {actionTypes, actionMetaRequirements,loadDataFile} = ActionUtil
|
|
13
13
|
const {isType} = DataUtil
|
|
14
14
|
|
|
15
15
|
export default class Discovery {
|
|
@@ -112,7 +112,7 @@ export default class Discovery {
|
|
|
112
112
|
if(!fileExists(packageJsonFile))
|
|
113
113
|
continue
|
|
114
114
|
|
|
115
|
-
const packageJson =
|
|
115
|
+
const packageJson = loadDataFile(packageJsonFile)
|
|
116
116
|
if(!packageJson.bedoc)
|
|
117
117
|
continue
|
|
118
118
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as FDUtil from "./FDUtil.js"
|
|
2
2
|
import process from "node:process"
|
|
3
3
|
import JSON5 from "json5"
|
|
4
|
+
import YAML from "yaml"
|
|
4
5
|
|
|
5
6
|
const {readFile, fileExists, composeFilename} = FDUtil
|
|
6
7
|
|
|
@@ -14,16 +15,24 @@ const actionMetaRequirements = freeze({
|
|
|
14
15
|
})
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
|
-
* Loads
|
|
18
|
+
* Loads an object from JSON or YAML provided a fileMap
|
|
18
19
|
*
|
|
19
|
-
* @param {object}
|
|
20
|
-
*
|
|
20
|
+
* @param {object} fileMap - The FileObj file to load containing
|
|
21
|
+
* JSON or YAML text.
|
|
22
|
+
* @returns {object} The parsed data object.
|
|
21
23
|
*/
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
function loadDataFile(fileMap) {
|
|
25
|
+
const content = readFile(fileMap)
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
return JSON5.parse(content)
|
|
29
|
+
} catch{
|
|
30
|
+
try {
|
|
31
|
+
return YAML.parse(content)
|
|
32
|
+
} catch{
|
|
33
|
+
throw new Error("Content is neither valid JSON nor valid YAML")
|
|
34
|
+
}
|
|
35
|
+
}
|
|
27
36
|
}
|
|
28
37
|
|
|
29
38
|
/**
|
|
@@ -48,6 +57,6 @@ export {
|
|
|
48
57
|
actionMetaRequirements,
|
|
49
58
|
actionTypes,
|
|
50
59
|
// Functions
|
|
51
|
-
|
|
60
|
+
loadDataFile,
|
|
52
61
|
loadPackageJson,
|
|
53
62
|
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import {createRequire} from "module"
|
|
2
|
-
import FDUtil from "./FDUtil.js"
|
|
3
|
-
import JSON5 from "json5"
|
|
4
|
-
|
|
5
|
-
export default class ModuleUtil {
|
|
6
|
-
/**
|
|
7
|
-
* Requires a module synchronously
|
|
8
|
-
*
|
|
9
|
-
* @param {object} fileObject - The file to require
|
|
10
|
-
* @returns {object} The required module
|
|
11
|
-
*/
|
|
12
|
-
static require(fileObject) {
|
|
13
|
-
return createRequire(import.meta.url)(fileObject.absolutePath)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Loads a JSON file asynchronously
|
|
18
|
-
*
|
|
19
|
-
* @param {object} jsonFileObject - The JSON file to load
|
|
20
|
-
* @returns {Promise<object>} The parsed JSON content
|
|
21
|
-
*/
|
|
22
|
-
static async loadJson(jsonFileObject) {
|
|
23
|
-
// Read the file
|
|
24
|
-
const jsonContent = await FDUtil.readFile(jsonFileObject)
|
|
25
|
-
const json = JSON5.parse(jsonContent)
|
|
26
|
-
return json
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Loads the package.json file asynchronously
|
|
31
|
-
*
|
|
32
|
-
* @returns {Promise<object>} The parsed package.json content
|
|
33
|
-
*/
|
|
34
|
-
static async loadPackageJson() {
|
|
35
|
-
const packageJsonFileObject = FDUtil.resolveFilename("./package.json")
|
|
36
|
-
const jsonContent = await FDUtil.readFile(packageJsonFileObject)
|
|
37
|
-
const json = JSON5.parse(jsonContent)
|
|
38
|
-
return json
|
|
39
|
-
}
|
|
40
|
-
}
|