msfs-layout-generator 0.3.2 → 0.3.4
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/README.MD +66 -2
- package/dist/index.d.ts +6 -4
- package/dist/index.js +6 -5
- package/dist/utils/getAllFiles.js +16 -7
- package/dist/utils/processLayout.d.ts +39 -5
- package/dist/utils/processLayout.js +41 -8
- package/package.json +1 -1
package/README.MD
CHANGED
|
@@ -55,13 +55,77 @@ Use your manager (npm, yarn, bun etc.) to install the package:
|
|
|
55
55
|
```bash
|
|
56
56
|
npm install msfs-layout-generator
|
|
57
57
|
```
|
|
58
|
-
|
|
58
|
+
|
|
59
|
+
### Simple Usage
|
|
60
|
+
|
|
59
61
|
```ts
|
|
60
62
|
import { generateLayout } from 'msfs-layout-generator';
|
|
61
63
|
|
|
62
|
-
// Process a single package
|
|
64
|
+
// Process a single package (throws on errors, uses default options)
|
|
63
65
|
await generateLayout("F:\\fs20\\Community\\my-package");
|
|
64
66
|
```
|
|
67
|
+
|
|
68
|
+
### Advanced Usage with Options
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { processLayout } from 'msfs-layout-generator';
|
|
72
|
+
import type { ProcessOptions, ProcessResult } from 'msfs-layout-generator';
|
|
73
|
+
|
|
74
|
+
// Overwrite existing layout.json silently
|
|
75
|
+
await processLayout("./my-package", { force: true, quiet: true });
|
|
76
|
+
|
|
77
|
+
// Get a result object instead of throwing on errors
|
|
78
|
+
const result = await processLayout("./my-package", {
|
|
79
|
+
returnResult: true,
|
|
80
|
+
force: true
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
if (result.success) {
|
|
84
|
+
console.log(`Processed ${result.fileCount} files (${result.totalSize} bytes)`);
|
|
85
|
+
} else {
|
|
86
|
+
console.error(result.message);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Generate layout without requiring or updating manifest.json
|
|
90
|
+
await processLayout("./my-package", {
|
|
91
|
+
force: true,
|
|
92
|
+
checkManifest: false,
|
|
93
|
+
skipManifestUpdate: true
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Exports
|
|
98
|
+
|
|
99
|
+
| Export | Type | Description |
|
|
100
|
+
|---|---|---|
|
|
101
|
+
| `generateLayout(dir)` | `(dir: string) => Promise<void>` | Simple wrapper — processes a package directory with default options. Throws on errors. |
|
|
102
|
+
| `processLayout(dir, options?)` | `(dir: string, options?: ProcessOptions) => Promise<void \| ProcessResult>` | Full-featured function with configurable options. |
|
|
103
|
+
|
|
104
|
+
### `ProcessOptions`
|
|
105
|
+
|
|
106
|
+
| Option | Type | Default | Description |
|
|
107
|
+
|---|---|---|---|
|
|
108
|
+
| `force` | `boolean` | `false` | Overwrite existing `layout.json` |
|
|
109
|
+
| `quiet` | `boolean` | `false` | Suppress all console output |
|
|
110
|
+
| `debug` | `boolean` | `false` | Enable verbose debug logging |
|
|
111
|
+
| `checkManifest` | `boolean` | `true` | Require `manifest.json` to exist in the package directory |
|
|
112
|
+
| `skipManifestUpdate` | `boolean` | `false` | Skip updating `total_package_size` in `manifest.json` |
|
|
113
|
+
| `returnResult` | `boolean` | `false` | Return a `ProcessResult` object instead of `void`. When `true`, errors are returned in the result instead of thrown. |
|
|
114
|
+
|
|
115
|
+
### `ProcessResult`
|
|
116
|
+
|
|
117
|
+
Returned when `returnResult` is `true`:
|
|
118
|
+
|
|
119
|
+
| Field | Type | Description |
|
|
120
|
+
|---|---|---|
|
|
121
|
+
| `success` | `boolean` | Whether the operation completed successfully |
|
|
122
|
+
| `fileCount` | `number` | Number of files included in `layout.json` |
|
|
123
|
+
| `totalSize` | `number` | Total package size in bytes |
|
|
124
|
+
| `layoutPath` | `string` | Absolute path to the generated `layout.json` |
|
|
125
|
+
| `manifestPath` | `string` | Absolute path to `manifest.json` |
|
|
126
|
+
| `skippedFiles` | `number` | Number of files that were excluded |
|
|
127
|
+
| `message` | `string?` | Error message (when `success` is `false`) |
|
|
128
|
+
|
|
65
129
|
---
|
|
66
130
|
|
|
67
131
|
**Happy Flying! ✈️**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { processLayout } from "./utils/processLayout";
|
|
1
2
|
/**
|
|
2
|
-
* Process an MSFS package directory to generate/update layout.json
|
|
3
|
+
* Process an MSFS package directory to generate/update layout.json (simple API).
|
|
3
4
|
*
|
|
4
|
-
* This
|
|
5
|
-
*
|
|
5
|
+
* This is a convenience wrapper around {@link processLayout} that uses default
|
|
6
|
+
* options and throws on errors. For more control, use {@link processLayout} directly.
|
|
6
7
|
*
|
|
7
8
|
* @param packageDir - Path to the MSFS package directory (must contain manifest.json)
|
|
8
9
|
* @returns Promise that resolves when layout.json has been generated
|
|
@@ -12,7 +13,7 @@
|
|
|
12
13
|
*
|
|
13
14
|
* @example
|
|
14
15
|
* // Basic usage
|
|
15
|
-
* await
|
|
16
|
+
* await generateLayout("F:\\fs20\\Community\\my-package");
|
|
16
17
|
*
|
|
17
18
|
* @example
|
|
18
19
|
* // With error handling
|
|
@@ -24,4 +25,5 @@
|
|
|
24
25
|
* }
|
|
25
26
|
*/
|
|
26
27
|
export declare const generateLayout: (layoutPath: string) => Promise<void>;
|
|
28
|
+
export { processLayout };
|
|
27
29
|
export type { Content, Layout, Manifest, ProcessOptions, ProcessResult } from "./types";
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateLayout = void 0;
|
|
3
|
+
exports.processLayout = exports.generateLayout = void 0;
|
|
4
4
|
const processLayout_1 = require("./utils/processLayout");
|
|
5
|
+
Object.defineProperty(exports, "processLayout", { enumerable: true, get: function () { return processLayout_1.processLayout; } });
|
|
5
6
|
/**
|
|
6
|
-
* Process an MSFS package directory to generate/update layout.json
|
|
7
|
+
* Process an MSFS package directory to generate/update layout.json (simple API).
|
|
7
8
|
*
|
|
8
|
-
* This
|
|
9
|
-
*
|
|
9
|
+
* This is a convenience wrapper around {@link processLayout} that uses default
|
|
10
|
+
* options and throws on errors. For more control, use {@link processLayout} directly.
|
|
10
11
|
*
|
|
11
12
|
* @param packageDir - Path to the MSFS package directory (must contain manifest.json)
|
|
12
13
|
* @returns Promise that resolves when layout.json has been generated
|
|
@@ -16,7 +17,7 @@ const processLayout_1 = require("./utils/processLayout");
|
|
|
16
17
|
*
|
|
17
18
|
* @example
|
|
18
19
|
* // Basic usage
|
|
19
|
-
* await
|
|
20
|
+
* await generateLayout("F:\\fs20\\Community\\my-package");
|
|
20
21
|
*
|
|
21
22
|
* @example
|
|
22
23
|
* // With error handling
|
|
@@ -41,22 +41,31 @@ const getAllFiles = async (dirPath) => {
|
|
|
41
41
|
const files = [];
|
|
42
42
|
async function readDirectory(currentPath) {
|
|
43
43
|
try {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
44
|
+
const directs = await (0, promises_1.readdir)(currentPath, { withFileTypes: true });
|
|
45
|
+
for (const dirent of directs) {
|
|
46
|
+
const itemPath = path.join(currentPath, dirent.name);
|
|
47
|
+
if (dirent.isDirectory()) {
|
|
48
48
|
await readDirectory(itemPath);
|
|
49
49
|
}
|
|
50
|
-
else {
|
|
50
|
+
else if (dirent.isFile()) {
|
|
51
51
|
files.push(itemPath);
|
|
52
52
|
}
|
|
53
|
+
else if (dirent.isSymbolicLink()) {
|
|
54
|
+
const stats = await (0, promises_1.stat)(itemPath);
|
|
55
|
+
if (stats.isDirectory()) {
|
|
56
|
+
await readDirectory(itemPath);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
files.push(itemPath);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
53
62
|
}
|
|
54
63
|
}
|
|
55
64
|
catch (e) {
|
|
56
65
|
if (e instanceof Error) {
|
|
57
|
-
throw new _errors_1.ReadingDirError(`Failed to read directory ${
|
|
66
|
+
throw new _errors_1.ReadingDirError(`Failed to read directory ${currentPath}: ${e.message}.`);
|
|
58
67
|
}
|
|
59
|
-
throw new _errors_1.ReadingDirError(`Failed to read directory. Path: ${
|
|
68
|
+
throw new _errors_1.ReadingDirError(`Failed to read directory. Path: ${currentPath}`);
|
|
60
69
|
}
|
|
61
70
|
}
|
|
62
71
|
await readDirectory(dirPath);
|
|
@@ -1,11 +1,45 @@
|
|
|
1
1
|
import { ProcessOptions, ProcessResult } from "../types";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* Can be used both programmatically and via CLI
|
|
3
|
+
* Process layout files for MSFS packages with full control over behavior.
|
|
5
4
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* Scans all files in the package directory, generates a `layout.json` with
|
|
6
|
+
* file metadata (path, size, date), and optionally updates `total_package_size`
|
|
7
|
+
* in `manifest.json`.
|
|
8
|
+
*
|
|
9
|
+
* @param packageDir - Absolute or relative path to the MSFS package directory
|
|
10
|
+
* @param options - Processing options to control behavior
|
|
11
|
+
* @param options.force - Overwrite existing layout.json (default: `false`)
|
|
12
|
+
* @param options.quiet - Suppress all console output (default: `false`)
|
|
13
|
+
* @param options.debug - Enable verbose debug logging (default: `false`)
|
|
14
|
+
* @param options.checkManifest - Require manifest.json to exist (default: `true`)
|
|
15
|
+
* @param options.skipManifestUpdate - Skip updating total_package_size in manifest.json (default: `false`)
|
|
16
|
+
* @param options.returnResult - Return a {@link ProcessResult} object instead of throwing on errors (default: `false`)
|
|
17
|
+
* @returns `Promise<void>` when `returnResult` is `false`; `Promise<ProcessResult>` when `returnResult` is `true`
|
|
18
|
+
*
|
|
19
|
+
* @throws {Error} If directory doesn't exist (when `returnResult` is `false`)
|
|
20
|
+
* @throws {Error} If manifest.json is missing and `checkManifest` is `true` (when `returnResult` is `false`)
|
|
21
|
+
* @throws {Error} If no valid files are found (when `returnResult` is `false`)
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Overwrite existing layout.json silently
|
|
25
|
+
* await processLayout("./my-package", { force: true, quiet: true });
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // Get a result object instead of throwing
|
|
29
|
+
* const result = await processLayout("./my-package", { returnResult: true, force: true });
|
|
30
|
+
* if (result.success) {
|
|
31
|
+
* console.log(`Processed ${result.fileCount} files (${result.totalSize} bytes)`);
|
|
32
|
+
* } else {
|
|
33
|
+
* console.error(result.message);
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* // Generate layout without requiring or updating manifest.json
|
|
38
|
+
* await processLayout("./my-package", {
|
|
39
|
+
* force: true,
|
|
40
|
+
* checkManifest: false,
|
|
41
|
+
* skipManifestUpdate: true
|
|
42
|
+
* });
|
|
9
43
|
*/
|
|
10
44
|
export declare const processLayout: (packageDir: string, options?: ProcessOptions) => Promise<void | ProcessResult>;
|
|
11
45
|
export declare const doProcessLayoutFile: (layoutPath: string) => Promise<void>;
|
|
@@ -41,12 +41,46 @@ const promises_1 = require("fs/promises");
|
|
|
41
41
|
const getWindowsFileTime_1 = require("./getWindowsFileTime");
|
|
42
42
|
const doUpdateManifest_1 = require("./doUpdateManifest");
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
45
|
-
* Can be used both programmatically and via CLI
|
|
44
|
+
* Process layout files for MSFS packages with full control over behavior.
|
|
46
45
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
46
|
+
* Scans all files in the package directory, generates a `layout.json` with
|
|
47
|
+
* file metadata (path, size, date), and optionally updates `total_package_size`
|
|
48
|
+
* in `manifest.json`.
|
|
49
|
+
*
|
|
50
|
+
* @param packageDir - Absolute or relative path to the MSFS package directory
|
|
51
|
+
* @param options - Processing options to control behavior
|
|
52
|
+
* @param options.force - Overwrite existing layout.json (default: `false`)
|
|
53
|
+
* @param options.quiet - Suppress all console output (default: `false`)
|
|
54
|
+
* @param options.debug - Enable verbose debug logging (default: `false`)
|
|
55
|
+
* @param options.checkManifest - Require manifest.json to exist (default: `true`)
|
|
56
|
+
* @param options.skipManifestUpdate - Skip updating total_package_size in manifest.json (default: `false`)
|
|
57
|
+
* @param options.returnResult - Return a {@link ProcessResult} object instead of throwing on errors (default: `false`)
|
|
58
|
+
* @returns `Promise<void>` when `returnResult` is `false`; `Promise<ProcessResult>` when `returnResult` is `true`
|
|
59
|
+
*
|
|
60
|
+
* @throws {Error} If directory doesn't exist (when `returnResult` is `false`)
|
|
61
|
+
* @throws {Error} If manifest.json is missing and `checkManifest` is `true` (when `returnResult` is `false`)
|
|
62
|
+
* @throws {Error} If no valid files are found (when `returnResult` is `false`)
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* // Overwrite existing layout.json silently
|
|
66
|
+
* await processLayout("./my-package", { force: true, quiet: true });
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* // Get a result object instead of throwing
|
|
70
|
+
* const result = await processLayout("./my-package", { returnResult: true, force: true });
|
|
71
|
+
* if (result.success) {
|
|
72
|
+
* console.log(`Processed ${result.fileCount} files (${result.totalSize} bytes)`);
|
|
73
|
+
* } else {
|
|
74
|
+
* console.error(result.message);
|
|
75
|
+
* }
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* // Generate layout without requiring or updating manifest.json
|
|
79
|
+
* await processLayout("./my-package", {
|
|
80
|
+
* force: true,
|
|
81
|
+
* checkManifest: false,
|
|
82
|
+
* skipManifestUpdate: true
|
|
83
|
+
* });
|
|
50
84
|
*/
|
|
51
85
|
const processLayout = async (packageDir, options = {}) => {
|
|
52
86
|
const { force = false, quiet = false, debug = false, checkManifest = true, skipManifestUpdate = false, returnResult = false // Default: behave like old doProcessLayoutFile
|
|
@@ -196,9 +230,8 @@ const processLayout = async (packageDir, options = {}) => {
|
|
|
196
230
|
layout.content.push(content);
|
|
197
231
|
}
|
|
198
232
|
catch (error) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
233
|
+
const msg = `Error processing file ${file}: ${error.message}`;
|
|
234
|
+
log(msg, debug ? 'info' : 'warn');
|
|
202
235
|
excludedCount++;
|
|
203
236
|
}
|
|
204
237
|
}
|