@gesslar/bedoc 1.4.1 → 1.4.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.
- package/dist/types/cli.d.ts +2 -2
- package/dist/types/core/ActionManager.d.ts +18 -18
- package/dist/types/core/Configuration.d.ts +10 -10
- package/dist/types/core/ConfigurationParameters.d.ts +24 -24
- package/dist/types/core/Conveyor.d.ts +34 -32
- package/dist/types/core/Core.d.ts +26 -31
- package/dist/types/core/util/FDUtil.d.ts +61 -36
- package/package.json +10 -1
- package/src/core/Configuration.js +7 -4
- package/src/core/Core.js +1 -1
- package/src/core/util/ActionUtil.js +11 -7
- package/src/core/util/FDUtil.js +56 -6
package/dist/types/cli.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
export {}
|
|
3
|
-
//# sourceMappingURL=cli.d.ts.map
|
|
2
|
+
export {}
|
|
3
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -2,26 +2,26 @@ import Logger from './Logger';
|
|
|
2
2
|
import HookManager from './HookManager';
|
|
3
3
|
|
|
4
4
|
export interface ActionDefinition {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
action: string;
|
|
6
|
+
contract: Record<string, unknown>;
|
|
7
|
+
meta: Record<string, unknown>;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export default class ActionManager {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
11
|
+
constructor(actionDefinition: ActionDefinition, logger: Logger);
|
|
12
|
+
get action(): ActionDefinition;
|
|
13
|
+
set hookManager(hookManager: HookManager);
|
|
14
|
+
get hookManager(): HookManager;
|
|
15
|
+
get contract(): Record<string, unknown>;
|
|
16
|
+
get meta(): Record<string, unknown>;
|
|
17
|
+
get log(): Logger;
|
|
18
|
+
setupAction(): Promise<void>;
|
|
19
|
+
runAction({ file, content }: {
|
|
20
|
+
file: string;
|
|
21
|
+
content: string;
|
|
22
|
+
}): Promise<string>;
|
|
23
|
+
cleanupAction(): Promise<void>;
|
|
24
|
+
toString(): string;
|
|
25
|
+
#private;
|
|
26
26
|
}
|
|
27
27
|
//# sourceMappingURL=ActionManager.d.ts.map
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { EnvironmentType } from './Core';
|
|
2
2
|
|
|
3
3
|
interface ConfigurationOption {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
value: unknown;
|
|
5
|
+
source: string;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
interface ConfigurationOptions {
|
|
9
|
-
|
|
9
|
+
[key: string]: ConfigurationOption;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
interface ValidateParams {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
options: ConfigurationOptions;
|
|
14
|
+
source: EnvironmentType;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
interface ValidationResult {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
status: 'success';
|
|
19
|
+
validated: boolean;
|
|
20
|
+
[key: string]: unknown;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export default class Configuration {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
validate({ options, source }: ValidateParams): Promise<ValidationResult>;
|
|
25
|
+
#private;
|
|
26
26
|
}
|
|
27
27
|
//# sourceMappingURL=Configuration.d.ts.map
|
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
import TypeSpec from './util/TypeSpec';
|
|
2
2
|
|
|
3
3
|
interface PathConfig {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
type: 'file' | 'directory';
|
|
5
|
+
mustExist: boolean;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
interface ConfigurationParameter {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
short: string;
|
|
10
|
+
param?: string;
|
|
11
|
+
description: string;
|
|
12
|
+
type: TypeSpec;
|
|
13
|
+
required: boolean;
|
|
14
|
+
default?: boolean | number | string;
|
|
15
|
+
path?: PathConfig;
|
|
16
|
+
exclusiveOf?: string;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
interface ConfigurationParametersType {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
20
|
+
input: ConfigurationParameter;
|
|
21
|
+
exclude: ConfigurationParameter;
|
|
22
|
+
language: ConfigurationParameter;
|
|
23
|
+
format: ConfigurationParameter;
|
|
24
|
+
maxConcurrent: ConfigurationParameter;
|
|
25
|
+
hooks: ConfigurationParameter;
|
|
26
|
+
output: ConfigurationParameter;
|
|
27
|
+
parser: ConfigurationParameter;
|
|
28
|
+
printer: ConfigurationParameter;
|
|
29
|
+
hookTimeout: ConfigurationParameter;
|
|
30
|
+
mock: ConfigurationParameter;
|
|
31
|
+
config: ConfigurationParameter;
|
|
32
|
+
debug: ConfigurationParameter;
|
|
33
|
+
debugLevel: ConfigurationParameter;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export const ConfigurationParameters: Readonly<ConfigurationParametersType>;
|
|
@@ -3,45 +3,47 @@ import Logger from './Logger';
|
|
|
3
3
|
import { FileMap } from './util/FDUtil';
|
|
4
4
|
|
|
5
5
|
interface ProcessResult {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
status: 'success' | 'error' | 'warning';
|
|
7
|
+
file?: FileMap;
|
|
8
|
+
error?: Error;
|
|
9
|
+
warning?: string;
|
|
10
|
+
result?: string;
|
|
11
|
+
destFile?: string;
|
|
12
|
+
content?: string;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
interface ConveyResult {
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
export interface ConveyResult {
|
|
16
|
+
succeeded: Array<{ input: FileMap; output: FileMap }>;
|
|
17
|
+
errored: Array<{ input: FileMap; error: Error }>;
|
|
18
|
+
warned: Array<{ input: FileMap; warning: string }>;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export default class Conveyor {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
constructor(
|
|
23
|
+
parse: ActionManager,
|
|
24
|
+
print: ActionManager,
|
|
25
|
+
logger: Logger,
|
|
26
|
+
output: FileMap
|
|
27
|
+
);
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
readonly parse: ActionManager;
|
|
30
|
+
readonly print: ActionManager;
|
|
31
|
+
readonly logger: Logger;
|
|
32
|
+
readonly output: FileMap;
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Processes files with a concurrency limit.
|
|
36
|
+
*
|
|
37
|
+
* @param files - List of files to process.
|
|
38
|
+
* @param maxConcurrent - Maximum number of concurrent tasks.
|
|
39
|
+
* @returns Resolves when all files are processed.
|
|
40
|
+
*/
|
|
41
|
+
convey(files: FileMap[], maxConcurrent?: number): Promise<ConveyResult>;
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
#succeeded: Array<{ input: FileMap; output: FileMap }>;
|
|
44
|
+
#errored: Array<{ input: FileMap; error: Error }>;
|
|
45
|
+
#warned: Array<{ input: FileMap; warning: string }>;
|
|
46
|
+
#processFile(file: FileMap): Promise<ProcessResult>;
|
|
47
|
+
#writeOutput(destFile: string, content: string): Promise<ProcessResult>;
|
|
46
48
|
}
|
|
47
49
|
//# sourceMappingURL=Conveyor.d.ts.map
|
|
@@ -1,53 +1,48 @@
|
|
|
1
1
|
import Logger from './Logger';
|
|
2
2
|
import ActionManager from './ActionManager';
|
|
3
|
-
import {
|
|
3
|
+
import { ConveyResult} from './Conveyor';
|
|
4
4
|
|
|
5
5
|
export const Environment: Readonly<{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
EXTENSION: 'extension';
|
|
7
|
+
NPM: 'npm';
|
|
8
|
+
ACTION: 'action';
|
|
9
|
+
CLI: 'cli';
|
|
10
10
|
}>;
|
|
11
11
|
|
|
12
12
|
export type EnvironmentType = typeof Environment[keyof typeof Environment];
|
|
13
13
|
|
|
14
14
|
interface CoreOptions {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
debug?: boolean;
|
|
16
|
+
debugLevel?: number;
|
|
17
|
+
name?: string;
|
|
18
|
+
[key: string]: unknown;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
interface CoreConstructorOptions extends CoreOptions {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
hooks?: string;
|
|
23
|
+
hooksTimeout?: number;
|
|
24
|
+
output?: string;
|
|
25
|
+
maxConcurrent?: number;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
interface NewParams {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface ProcessResult {
|
|
34
|
-
succeeded: Array<{ input: FileMap; output: FileMap }>;
|
|
35
|
-
errored: Array<{ input: FileMap; error: Error }>;
|
|
29
|
+
options: CoreOptions;
|
|
30
|
+
source: EnvironmentType;
|
|
36
31
|
}
|
|
37
32
|
|
|
38
33
|
export default class Core {
|
|
39
|
-
|
|
34
|
+
static new({ options, source }: NewParams): Promise<Core>;
|
|
40
35
|
|
|
41
|
-
|
|
36
|
+
constructor(options: CoreConstructorOptions);
|
|
42
37
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
38
|
+
readonly options: CoreConstructorOptions;
|
|
39
|
+
readonly logger: Logger;
|
|
40
|
+
readonly packageJson: Record<string, unknown>;
|
|
41
|
+
readonly debugOptions: {
|
|
42
|
+
name: string | null;
|
|
43
|
+
debugLevel: number;
|
|
44
|
+
};
|
|
45
|
+
readonly actions: Record<string, ActionManager>;
|
|
51
46
|
|
|
52
|
-
|
|
47
|
+
processFiles(glob: string | string[], startTime?: [number, number]): Promise<ConveyResult>;
|
|
53
48
|
}
|
|
@@ -36,46 +36,45 @@ export const fdTypes: readonly FDType[];
|
|
|
36
36
|
/**
|
|
37
37
|
* Compose a directory map from a path
|
|
38
38
|
*
|
|
39
|
-
* @param
|
|
40
|
-
* @returns
|
|
39
|
+
* @param directory - The directory
|
|
40
|
+
* @returns A directory object
|
|
41
41
|
*/
|
|
42
42
|
export function composeDirectory(directory: string): DirMap;
|
|
43
43
|
/**
|
|
44
44
|
* Compose a file path from a directory and a file
|
|
45
45
|
*
|
|
46
|
-
* @param
|
|
47
|
-
* @param
|
|
48
|
-
* @returns
|
|
46
|
+
* @param directoryNameorObject - The directory
|
|
47
|
+
* @param fileName - The file
|
|
48
|
+
* @returns A file object
|
|
49
49
|
*/
|
|
50
50
|
export function composeFilename(directoryNameorObject: string | DirMap, fileName: string): FileMap;
|
|
51
51
|
/**
|
|
52
52
|
* Deconstruct a filename into parts
|
|
53
53
|
*
|
|
54
|
-
* @param
|
|
55
|
-
* @returns
|
|
54
|
+
* @param fileName - The filename to deconstruct
|
|
55
|
+
* @returns The filename parts
|
|
56
56
|
*/
|
|
57
57
|
export function deconstructFilenameToParts(fileName: string): FilenameParts;
|
|
58
58
|
/**
|
|
59
59
|
* Fix slashes in a path
|
|
60
60
|
*
|
|
61
|
-
* @param
|
|
62
|
-
* @returns
|
|
61
|
+
* @param pathName - The path to fix
|
|
62
|
+
* @returns The fixed path
|
|
63
63
|
*/
|
|
64
64
|
export function fixSlashes(pathName: string): string;
|
|
65
65
|
/**
|
|
66
66
|
* Retrieve all files matching a specific glob pattern.
|
|
67
67
|
*
|
|
68
|
-
* @param
|
|
69
|
-
* @returns
|
|
70
|
-
* @throws
|
|
68
|
+
* @param globPattern - The glob pattern(s) to search.
|
|
69
|
+
* @returns An array of file objects
|
|
70
|
+
* @throws Throws an error for invalid input or search failure.
|
|
71
71
|
*/
|
|
72
72
|
export function getFiles(globPattern: string | string[]): Promise<FileMap[]>;
|
|
73
73
|
/**
|
|
74
74
|
* Lists the contents of a directory.
|
|
75
75
|
*
|
|
76
|
-
* @param
|
|
77
|
-
* @returns
|
|
78
|
-
* directories in the directory.
|
|
76
|
+
* @param directory - The directory to list.
|
|
77
|
+
* @returns The files and sub-directories in the directory.
|
|
79
78
|
*/
|
|
80
79
|
export function ls(directory: string): Promise<{
|
|
81
80
|
files: FileMap[];
|
|
@@ -84,63 +83,89 @@ export function ls(directory: string): Promise<{
|
|
|
84
83
|
/**
|
|
85
84
|
* Map a directory to a DirMap
|
|
86
85
|
*
|
|
87
|
-
* @param
|
|
88
|
-
* @returns
|
|
86
|
+
* @param directoryName - The directory to map
|
|
87
|
+
* @returns A directory object
|
|
89
88
|
*/
|
|
90
89
|
export function mapDirectory(directoryName: string): DirMap;
|
|
91
90
|
/**
|
|
92
91
|
* Map a file to a FileMap
|
|
93
92
|
*
|
|
94
93
|
* @param {string} fileName - The file to map
|
|
95
|
-
* @returns
|
|
94
|
+
* @returns A file object
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Check if a file can be read
|
|
99
|
+
*
|
|
100
|
+
* @param fileObject - The file object to check
|
|
101
|
+
* @returns Whether the file can be read
|
|
102
|
+
*/
|
|
103
|
+
export function canReadFile(fileObject: FileMap): boolean;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Check if a file can be written
|
|
107
|
+
*
|
|
108
|
+
* @param fileObject - The file object to check
|
|
109
|
+
* @returns Whether the file can be written
|
|
110
|
+
*/
|
|
111
|
+
export function canWriteFile(fileObject: FileMap): boolean;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Check if a file exists
|
|
115
|
+
*
|
|
116
|
+
* @param fileObject - The file object to check
|
|
117
|
+
* @returns Whether the file exists
|
|
118
|
+
*/
|
|
119
|
+
export function fileExists(fileObject: FileMap): boolean;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Returns a FileMap object for the specified file.
|
|
123
|
+
*
|
|
124
|
+
* @param fileName - The file to map
|
|
125
|
+
* @returns A file object
|
|
96
126
|
*/
|
|
97
127
|
export function mapFilename(fileName: string): FileMap;
|
|
98
128
|
/**
|
|
99
129
|
* Convert a path to a URI
|
|
100
130
|
*
|
|
101
|
-
* @param
|
|
102
|
-
* @returns
|
|
103
|
-
* @throws {Error} If the path is not a valid file path
|
|
131
|
+
* @param pathName - The path to convert
|
|
132
|
+
* @returns The URI
|
|
104
133
|
*/
|
|
105
134
|
export function pathToUri(pathName: string): string;
|
|
106
135
|
/**
|
|
107
136
|
* Reads the content of a file synchronously.
|
|
108
137
|
*
|
|
109
|
-
* @param
|
|
110
|
-
* @returns
|
|
138
|
+
* @param fileObject - The file map containing the file path
|
|
139
|
+
* @returns The file contents
|
|
111
140
|
*/
|
|
112
141
|
export function readFile(fileObject: FileMap): string;
|
|
113
142
|
/**
|
|
114
143
|
* Resolves a path to an absolute path
|
|
115
144
|
*
|
|
116
|
-
* @param
|
|
117
|
-
* @returns
|
|
118
|
-
* @throws {Error}
|
|
145
|
+
* @param directoryName - The path to resolve
|
|
146
|
+
* @returns The directory object
|
|
119
147
|
*/
|
|
120
148
|
export function resolveDirectory(directoryName: string): DirMap;
|
|
121
149
|
/**
|
|
122
150
|
* Resolves a file to an absolute path
|
|
123
151
|
*
|
|
124
|
-
* @param
|
|
125
|
-
* @param
|
|
126
|
-
*
|
|
127
|
-
* @returns {FileMap} A file object (validated)
|
|
128
|
-
* @throws {Error}
|
|
152
|
+
* @param fileName - The file to resolve
|
|
153
|
+
* @param directoryObject - The directory object to resolve the file in
|
|
154
|
+
* @returns A file object (validated)
|
|
129
155
|
*/
|
|
130
156
|
export function resolveFilename(fileName: string, directoryObject?: DirMap | null): FileMap;
|
|
131
157
|
/**
|
|
132
158
|
* Convert a URI to a path
|
|
133
159
|
*
|
|
134
|
-
* @param
|
|
135
|
-
* @returns
|
|
136
|
-
* @throws {Error} If the URI is not a valid file URL
|
|
160
|
+
* @param pathName - The URI to convert
|
|
161
|
+
* @returns The path
|
|
137
162
|
*/
|
|
138
163
|
export function uriToPath(pathName: string): string;
|
|
139
164
|
/**
|
|
140
165
|
* Writes content to a file synchronously.
|
|
141
166
|
*
|
|
142
|
-
* @param
|
|
143
|
-
* @param
|
|
167
|
+
* @param fileObject - The file map containing the file path
|
|
168
|
+
* @param content - The content to write
|
|
144
169
|
*/
|
|
145
170
|
export function writeFile(fileObject: FileMap, content: string): void;
|
|
146
171
|
//# sourceMappingURL=FDUtil.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gesslar/bedoc",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"description": "Pluggable documentation engine for any language and format",
|
|
5
5
|
"publisher": "gesslar",
|
|
6
6
|
"main": "./src/core/Core.js",
|
|
@@ -18,6 +18,13 @@
|
|
|
18
18
|
".": {
|
|
19
19
|
"import": "./src/core/Core.js",
|
|
20
20
|
"types": "./dist/types/core/Core.d.ts"
|
|
21
|
+
},
|
|
22
|
+
"./BeDoc": {
|
|
23
|
+
"import": "./src/core/Core.js",
|
|
24
|
+
"types": "./dist/types/core/Core.d.ts"
|
|
25
|
+
},
|
|
26
|
+
"./*": {
|
|
27
|
+
"types": "./dist/types/*"
|
|
21
28
|
}
|
|
22
29
|
},
|
|
23
30
|
"type": "module",
|
|
@@ -38,6 +45,8 @@
|
|
|
38
45
|
},
|
|
39
46
|
"devDependencies": {
|
|
40
47
|
"@stylistic/eslint-plugin-js": "^3.0.0",
|
|
48
|
+
"@typescript-eslint/eslint-plugin": "^8.22.0",
|
|
49
|
+
"@typescript-eslint/parser": "^8.22.0",
|
|
41
50
|
"axios": "^1.7.9",
|
|
42
51
|
"chokidar": "^4.0.3",
|
|
43
52
|
"eslint": "^9.18.0",
|
|
@@ -12,7 +12,8 @@ import * as FDUtil from "./util/FDUtil.js"
|
|
|
12
12
|
|
|
13
13
|
const {loadJson} = ActionUtil
|
|
14
14
|
const {isNothing, isType, mapObject} = DataUtil
|
|
15
|
-
const {getFiles,
|
|
15
|
+
const {getFiles, composeFilename, fileExists} = FDUtil
|
|
16
|
+
const {resolveDirectory, resolveFilename} = FDUtil
|
|
16
17
|
const {fdType, fdTypes} = FDUtil
|
|
17
18
|
|
|
18
19
|
export default class Configuration {
|
|
@@ -154,9 +155,11 @@ export default class Configuration {
|
|
|
154
155
|
|
|
155
156
|
// Inject packageJson if not available
|
|
156
157
|
if(!options.packageJson) {
|
|
157
|
-
const jsonFile =
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
const jsonFile = composeFilename(dir, "package.json")
|
|
159
|
+
if(fileExists(jsonFile)) {
|
|
160
|
+
const jsonObj = loadJson(jsonFile)
|
|
161
|
+
options.packageJson = {value: jsonObj, source}
|
|
162
|
+
}
|
|
160
163
|
}
|
|
161
164
|
|
|
162
165
|
// Add defaults which are missing
|
package/src/core/Core.js
CHANGED
|
@@ -28,7 +28,7 @@ export default class Core {
|
|
|
28
28
|
this.options = options
|
|
29
29
|
const {debug: debugMode, debugLevel} = options
|
|
30
30
|
this.logger = new Logger({name: "BeDoc", debugMode, debugLevel})
|
|
31
|
-
this.packageJson = loadPackageJson()?.bedoc ?? {}
|
|
31
|
+
this.packageJson = loadPackageJson(options.basePath)?.bedoc ?? {}
|
|
32
32
|
this.debugOptions = this.logger.options
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as FDUtil from "./FDUtil.js"
|
|
2
2
|
|
|
3
|
-
const {readFile,
|
|
3
|
+
const {readFile, fileExists, composeFilename} = FDUtil
|
|
4
4
|
|
|
5
5
|
const freeze = Object.freeze
|
|
6
6
|
|
|
@@ -27,14 +27,18 @@ function loadJson(jsonFileObject) {
|
|
|
27
27
|
/**
|
|
28
28
|
* Loads the package.json file asynchronously
|
|
29
29
|
*
|
|
30
|
-
* @param {string|object} basePath - The base path to use
|
|
31
|
-
* @returns {object} The parsed package.json content
|
|
30
|
+
* @param {string|object|null} basePath - The base path to use
|
|
31
|
+
* @returns {object?} The parsed package.json content or null if the file does
|
|
32
|
+
* not exist
|
|
32
33
|
*/
|
|
33
34
|
function loadPackageJson(basePath = null) {
|
|
34
|
-
const packageJsonFileObject =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
const packageJsonFileObject = composeFilename(basePath, "./package.json")
|
|
36
|
+
if(fileExists(packageJsonFileObject)) {
|
|
37
|
+
const jsonContent = readFile(packageJsonFileObject)
|
|
38
|
+
const json = JSON.parse(jsonContent)
|
|
39
|
+
return json
|
|
40
|
+
} else
|
|
41
|
+
return null
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
export {
|
package/src/core/util/FDUtil.js
CHANGED
|
@@ -42,6 +42,51 @@ function pathToUri(pathName) {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Check if a file can be read. Returns true if the file can be read, false
|
|
47
|
+
*
|
|
48
|
+
* @param {FileMap} FileMap - The file map to check
|
|
49
|
+
* @returns {boolean} Whether the file can be read
|
|
50
|
+
*/
|
|
51
|
+
function canReadFile(FileMap) {
|
|
52
|
+
try {
|
|
53
|
+
fs.accessSync(FileMap.absolutePath, fs.constants.R_OK)
|
|
54
|
+
return true
|
|
55
|
+
} catch(_error) {
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Check if a file can be written. Returns true if the file can be written,
|
|
62
|
+
*
|
|
63
|
+
* @param {FileMap} FileMap - The file map to check
|
|
64
|
+
* @returns {boolean} Whether the file can be written
|
|
65
|
+
*/
|
|
66
|
+
function canWriteFile(FileMap) {
|
|
67
|
+
try {
|
|
68
|
+
fs.accessSync(FileMap.absolutePath, fs.constants.W_OK)
|
|
69
|
+
return true
|
|
70
|
+
} catch(error) {
|
|
71
|
+
return false
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Check if a file exists
|
|
77
|
+
*
|
|
78
|
+
* @param {FileMap} FileMap - The file map to check
|
|
79
|
+
* @returns {boolean} Whether the file exists
|
|
80
|
+
*/
|
|
81
|
+
function fileExists(FileMap) {
|
|
82
|
+
try {
|
|
83
|
+
fs.accessSync(FileMap.absolutePath)
|
|
84
|
+
return true
|
|
85
|
+
} catch(error) {
|
|
86
|
+
return false
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
45
90
|
/**
|
|
46
91
|
* Convert a URI to a path
|
|
47
92
|
*
|
|
@@ -78,14 +123,16 @@ function resolveFilename(fileName, directoryObject = null) {
|
|
|
78
123
|
directoryObject = resolveDirectory(directoryNamePart)
|
|
79
124
|
|
|
80
125
|
const fileObject = composeFilename(directoryObject, fileNamePart)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
} catch(e) {
|
|
84
|
-
void e
|
|
126
|
+
|
|
127
|
+
if(!fileObject)
|
|
85
128
|
throw new Error(
|
|
86
|
-
`Failed to resolve
|
|
129
|
+
`Failed to resolve file: ${fileName}, looking for file: ${fileNamePart}`,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
if(!fileExists(fileObject))
|
|
133
|
+
throw new Error(
|
|
134
|
+
`Failed to resolve file: ${fileObject.absolutePath}`,
|
|
87
135
|
)
|
|
88
|
-
}
|
|
89
136
|
|
|
90
137
|
return {
|
|
91
138
|
...fileObject,
|
|
@@ -305,9 +352,12 @@ export {
|
|
|
305
352
|
fdType,
|
|
306
353
|
fdTypes,
|
|
307
354
|
// Functions
|
|
355
|
+
canReadFile,
|
|
356
|
+
canWriteFile,
|
|
308
357
|
composeDirectory,
|
|
309
358
|
composeFilename,
|
|
310
359
|
deconstructFilenameToParts,
|
|
360
|
+
fileExists,
|
|
311
361
|
fixSlashes,
|
|
312
362
|
getFiles,
|
|
313
363
|
ls,
|