@fgv/ts-res-browser-cli 5.0.0-2
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/.rush/temp/45629f175c0b2c015132e9451c317583db1c0e2d.tar.log +32 -0
- package/.rush/temp/chunked-rush-logs/ts-res-browser-cli.build.chunks.jsonl +5 -0
- package/.rush/temp/operation/build/all.log +5 -0
- package/.rush/temp/operation/build/log-chunks.jsonl +5 -0
- package/.rush/temp/operation/build/state.json +3 -0
- package/.rush/temp/shrinkwrap-deps.json +651 -0
- package/README.md +131 -0
- package/bin/ts-res-browser-cli.js +40 -0
- package/config/rig.json +16 -0
- package/lib/browserLauncher.d.ts +53 -0
- package/lib/browserLauncher.d.ts.map +1 -0
- package/lib/browserLauncher.js +347 -0
- package/lib/browserLauncher.js.map +1 -0
- package/lib/cli.d.ts +37 -0
- package/lib/cli.d.ts.map +1 -0
- package/lib/cli.js +373 -0
- package/lib/cli.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +42 -0
- package/lib/index.js.map +1 -0
- package/lib/options.d.ts +95 -0
- package/lib/options.d.ts.map +1 -0
- package/lib/options.js +24 -0
- package/lib/options.js.map +1 -0
- package/lib/zipArchiver.d.ts +35 -0
- package/lib/zipArchiver.d.ts.map +1 -0
- package/lib/zipArchiver.js +148 -0
- package/lib/zipArchiver.js.map +1 -0
- package/package.json +49 -0
- package/rush-logs/ts-res-browser-cli.build.cache.log +3 -0
- package/rush-logs/ts-res-browser-cli.build.log +5 -0
- package/src/browserLauncher.ts +366 -0
- package/src/cli.ts +423 -0
- package/src/index.ts +26 -0
- package/src/options.ts +133 -0
- package/src/zipArchiver.ts +153 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Result } from '@fgv/ts-utils';
|
|
2
|
+
export interface ZipArchiveOptions {
|
|
3
|
+
input?: string;
|
|
4
|
+
config?: string;
|
|
5
|
+
outputDir?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ZipArchiveResult {
|
|
8
|
+
zipPath: string;
|
|
9
|
+
manifest: ZipManifest;
|
|
10
|
+
}
|
|
11
|
+
export interface ZipManifest {
|
|
12
|
+
timestamp: string;
|
|
13
|
+
input?: {
|
|
14
|
+
type: 'file' | 'directory';
|
|
15
|
+
originalPath: string;
|
|
16
|
+
archivePath: string;
|
|
17
|
+
};
|
|
18
|
+
config?: {
|
|
19
|
+
type: 'file';
|
|
20
|
+
originalPath: string;
|
|
21
|
+
archivePath: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export declare class ZipArchiver {
|
|
25
|
+
/**
|
|
26
|
+
* Create a ZIP archive containing the specified input and config files/directories
|
|
27
|
+
*/
|
|
28
|
+
createArchive(options: ZipArchiveOptions): Promise<Result<ZipArchiveResult>>;
|
|
29
|
+
/**
|
|
30
|
+
* Get the default downloads directory path
|
|
31
|
+
*/
|
|
32
|
+
getDefaultDownloadsDir(): string;
|
|
33
|
+
}
|
|
34
|
+
export declare const zipArchiver: ZipArchiver;
|
|
35
|
+
//# sourceMappingURL=zipArchiver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zipArchiver.d.ts","sourceRoot":"","sources":["../src/zipArchiver.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAiB,MAAM,eAAe,CAAC;AAEtD,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,WAAW,CAAC;CACvB;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;QAC3B,YAAY,EAAE,MAAM,CAAC;QACrB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,MAAM,CAAC,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,YAAY,EAAE,MAAM,CAAC;QACrB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;CACH;AAED,qBAAa,WAAW;IACtB;;OAEG;IACG,aAAa,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;IA4GlF;;OAEG;IACH,sBAAsB,IAAI,MAAM;CAGjC;AAGD,eAAO,MAAM,WAAW,aAAoB,CAAC"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.zipArchiver = exports.ZipArchiver = void 0;
|
|
37
|
+
const archiver = __importStar(require("archiver"));
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
const os = __importStar(require("os"));
|
|
41
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
42
|
+
class ZipArchiver {
|
|
43
|
+
/**
|
|
44
|
+
* Create a ZIP archive containing the specified input and config files/directories
|
|
45
|
+
*/
|
|
46
|
+
async createArchive(options) {
|
|
47
|
+
try {
|
|
48
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
49
|
+
const outputDir = options.outputDir || path.join(os.homedir(), 'Downloads');
|
|
50
|
+
const zipFileName = `ts-res-bundle-${timestamp}.zip`;
|
|
51
|
+
const zipPath = path.join(outputDir, zipFileName);
|
|
52
|
+
// Ensure output directory exists
|
|
53
|
+
if (!fs.existsSync(outputDir)) {
|
|
54
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
55
|
+
}
|
|
56
|
+
const output = fs.createWriteStream(zipPath);
|
|
57
|
+
const archive = archiver.create('zip', {
|
|
58
|
+
zlib: { level: 6 } // Good compression level
|
|
59
|
+
});
|
|
60
|
+
// Create manifest
|
|
61
|
+
const manifest = {
|
|
62
|
+
timestamp: new Date().toISOString()
|
|
63
|
+
};
|
|
64
|
+
// Promise to handle async archiving
|
|
65
|
+
const archivePromise = new Promise((resolve, reject) => {
|
|
66
|
+
output.on('close', () => {
|
|
67
|
+
resolve();
|
|
68
|
+
});
|
|
69
|
+
output.on('error', (err) => {
|
|
70
|
+
reject(err);
|
|
71
|
+
});
|
|
72
|
+
archive.on('error', (err) => {
|
|
73
|
+
reject(err);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
// Pipe archive data to the file
|
|
77
|
+
archive.pipe(output);
|
|
78
|
+
// Add input files/directory
|
|
79
|
+
if (options.input) {
|
|
80
|
+
const inputPath = path.resolve(options.input);
|
|
81
|
+
if (!fs.existsSync(inputPath)) {
|
|
82
|
+
return (0, ts_utils_1.fail)(`Input path does not exist: ${inputPath}`);
|
|
83
|
+
}
|
|
84
|
+
const stats = fs.statSync(inputPath);
|
|
85
|
+
if (stats.isDirectory()) {
|
|
86
|
+
// Add entire directory recursively, preserving structure
|
|
87
|
+
const dirName = path.basename(inputPath);
|
|
88
|
+
archive.directory(inputPath, `input/${dirName}`);
|
|
89
|
+
manifest.input = {
|
|
90
|
+
type: 'directory',
|
|
91
|
+
originalPath: inputPath,
|
|
92
|
+
archivePath: `input/${dirName}`
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
else if (stats.isFile()) {
|
|
96
|
+
// Add single file
|
|
97
|
+
const fileName = path.basename(inputPath);
|
|
98
|
+
archive.file(inputPath, { name: `input/${fileName}` });
|
|
99
|
+
manifest.input = {
|
|
100
|
+
type: 'file',
|
|
101
|
+
originalPath: inputPath,
|
|
102
|
+
archivePath: `input/${fileName}`
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Add config file
|
|
107
|
+
if (options.config) {
|
|
108
|
+
const configPath = path.resolve(options.config);
|
|
109
|
+
if (!fs.existsSync(configPath)) {
|
|
110
|
+
return (0, ts_utils_1.fail)(`Config file does not exist: ${configPath}`);
|
|
111
|
+
}
|
|
112
|
+
const stats = fs.statSync(configPath);
|
|
113
|
+
if (!stats.isFile()) {
|
|
114
|
+
return (0, ts_utils_1.fail)(`Config path must be a file: ${configPath}`);
|
|
115
|
+
}
|
|
116
|
+
const fileName = path.basename(configPath);
|
|
117
|
+
archive.file(configPath, { name: `config/${fileName}` });
|
|
118
|
+
manifest.config = {
|
|
119
|
+
type: 'file',
|
|
120
|
+
originalPath: configPath,
|
|
121
|
+
archivePath: `config/${fileName}`
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
// Add manifest
|
|
125
|
+
archive.append(JSON.stringify(manifest, null, 2), { name: 'manifest.json' });
|
|
126
|
+
// Finalize the archive
|
|
127
|
+
await archive.finalize();
|
|
128
|
+
await archivePromise;
|
|
129
|
+
return (0, ts_utils_1.succeed)({
|
|
130
|
+
zipPath,
|
|
131
|
+
manifest
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
return (0, ts_utils_1.fail)(`Failed to create ZIP archive: ${error instanceof Error ? error.message : String(error)}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get the default downloads directory path
|
|
140
|
+
*/
|
|
141
|
+
getDefaultDownloadsDir() {
|
|
142
|
+
return path.join(os.homedir(), 'Downloads');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.ZipArchiver = ZipArchiver;
|
|
146
|
+
// Export singleton instance
|
|
147
|
+
exports.zipArchiver = new ZipArchiver();
|
|
148
|
+
//# sourceMappingURL=zipArchiver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zipArchiver.js","sourceRoot":"","sources":["../src/zipArchiver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAqC;AACrC,uCAAyB;AACzB,2CAA6B;AAC7B,uCAAyB;AACzB,4CAAsD;AA2BtD,MAAa,WAAW;IACtB;;OAEG;IACH,KAAK,CAAC,aAAa,CAAC,OAA0B;QAC5C,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,IAAI,IAAI,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OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACzG,CAAC;IACH,CAAC;IAED;;OAEG;IACH,sBAAsB;QACpB,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,CAAC,CAAC;IAC9C,CAAC;CACF;AAtHD,kCAsHC;AAED,4BAA4B;AACf,QAAA,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC","sourcesContent":["import * as archiver from 'archiver';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as os from 'os';\nimport { Result, succeed, fail } from '@fgv/ts-utils';\n\nexport interface ZipArchiveOptions {\n input?: string;\n config?: string;\n outputDir?: string;\n}\n\nexport interface ZipArchiveResult {\n zipPath: string;\n manifest: ZipManifest;\n}\n\nexport interface ZipManifest {\n timestamp: string;\n input?: {\n type: 'file' | 'directory';\n originalPath: string;\n archivePath: string;\n };\n config?: {\n type: 'file';\n originalPath: string;\n archivePath: string;\n };\n}\n\nexport class ZipArchiver {\n /**\n * Create a ZIP archive containing the specified input and config files/directories\n */\n async createArchive(options: ZipArchiveOptions): Promise<Result<ZipArchiveResult>> {\n try {\n const timestamp = new Date().toISOString().replace(/[:.]/g, '-');\n const outputDir = options.outputDir || path.join(os.homedir(), 'Downloads');\n const zipFileName = `ts-res-bundle-${timestamp}.zip`;\n const zipPath = path.join(outputDir, zipFileName);\n\n // Ensure output directory exists\n if (!fs.existsSync(outputDir)) {\n fs.mkdirSync(outputDir, { recursive: true });\n }\n\n const output = fs.createWriteStream(zipPath);\n const archive = archiver.create('zip', {\n zlib: { level: 6 } // Good compression level\n });\n\n // Create manifest\n const manifest: ZipManifest = {\n timestamp: new Date().toISOString()\n };\n\n // Promise to handle async archiving\n const archivePromise = new Promise<void>((resolve, reject) => {\n output.on('close', () => {\n resolve();\n });\n\n output.on('error', (err: Error) => {\n reject(err);\n });\n\n archive.on('error', (err: Error) => {\n reject(err);\n });\n });\n\n // Pipe archive data to the file\n archive.pipe(output);\n\n // Add input files/directory\n if (options.input) {\n const inputPath = path.resolve(options.input);\n\n if (!fs.existsSync(inputPath)) {\n return fail(`Input path does not exist: ${inputPath}`);\n }\n\n const stats = fs.statSync(inputPath);\n if (stats.isDirectory()) {\n // Add entire directory recursively, preserving structure\n const dirName = path.basename(inputPath);\n archive.directory(inputPath, `input/${dirName}`);\n manifest.input = {\n type: 'directory',\n originalPath: inputPath,\n archivePath: `input/${dirName}`\n };\n } else if (stats.isFile()) {\n // Add single file\n const fileName = path.basename(inputPath);\n archive.file(inputPath, { name: `input/${fileName}` });\n manifest.input = {\n type: 'file',\n originalPath: inputPath,\n archivePath: `input/${fileName}`\n };\n }\n }\n\n // Add config file\n if (options.config) {\n const configPath = path.resolve(options.config);\n\n if (!fs.existsSync(configPath)) {\n return fail(`Config file does not exist: ${configPath}`);\n }\n\n const stats = fs.statSync(configPath);\n if (!stats.isFile()) {\n return fail(`Config path must be a file: ${configPath}`);\n }\n\n const fileName = path.basename(configPath);\n archive.file(configPath, { name: `config/${fileName}` });\n manifest.config = {\n type: 'file',\n originalPath: configPath,\n archivePath: `config/${fileName}`\n };\n }\n\n // Add manifest\n archive.append(JSON.stringify(manifest, null, 2), { name: 'manifest.json' });\n\n // Finalize the archive\n await archive.finalize();\n await archivePromise;\n\n return succeed({\n zipPath,\n manifest\n });\n } catch (error) {\n return fail(`Failed to create ZIP archive: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n /**\n * Get the default downloads directory path\n */\n getDefaultDownloadsDir(): string {\n return path.join(os.homedir(), 'Downloads');\n }\n}\n\n// Export singleton instance\nexport const zipArchiver = new ZipArchiver();\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fgv/ts-res-browser-cli",
|
|
3
|
+
"version": "5.0.0-2",
|
|
4
|
+
"description": "Command-line interface to launch ts-res-browser with specified options",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"ts-res-browser-cli": "bin/ts-res-browser-cli.js"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"ts-res",
|
|
12
|
+
"browser",
|
|
13
|
+
"cli",
|
|
14
|
+
"tool",
|
|
15
|
+
"resource",
|
|
16
|
+
"visualization"
|
|
17
|
+
],
|
|
18
|
+
"author": "Erik Fortune",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=20.0.0"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"commander": "^11.0.0",
|
|
25
|
+
"archiver": "~7.0.1",
|
|
26
|
+
"@types/archiver": "~6.0.3",
|
|
27
|
+
"@fgv/ts-res": "5.0.0-2",
|
|
28
|
+
"@fgv/ts-json": "5.0.0-2",
|
|
29
|
+
"@fgv/ts-utils": "5.0.0-2",
|
|
30
|
+
"@fgv/ts-json-base": "5.0.0-2"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@rushstack/heft": "~0.74.0",
|
|
34
|
+
"@rushstack/heft-node-rig": "~2.9.0",
|
|
35
|
+
"@types/jest": "^29.5.14",
|
|
36
|
+
"@types/node": "^20.14.9",
|
|
37
|
+
"eslint": "^8.57.0",
|
|
38
|
+
"jest": "^29.7.0",
|
|
39
|
+
"typescript": "^5.7.3",
|
|
40
|
+
"@fgv/ts-utils-jest": "5.0.0-2"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "heft build --clean",
|
|
44
|
+
"test": "heft test --clean",
|
|
45
|
+
"clean": "heft clean",
|
|
46
|
+
"lint": "eslint src --ext .ts",
|
|
47
|
+
"fixlint": "eslint src --ext .ts --fix"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { exec, spawn, ChildProcess } from 'child_process';
|
|
24
|
+
import * as path from 'path';
|
|
25
|
+
import * as http from 'http';
|
|
26
|
+
import { Result, succeed, fail } from '@fgv/ts-utils';
|
|
27
|
+
import { IBrowseOptions } from './options';
|
|
28
|
+
import { zipArchiver } from './zipArchiver';
|
|
29
|
+
import * as fs from 'fs';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Manages launching the browser application with specified options
|
|
33
|
+
*/
|
|
34
|
+
export class BrowserLauncher {
|
|
35
|
+
private _devServer?: ChildProcess;
|
|
36
|
+
/**
|
|
37
|
+
* Launches the browser with the specified options
|
|
38
|
+
*/
|
|
39
|
+
public async launch(options: IBrowseOptions): Promise<Result<void>> {
|
|
40
|
+
try {
|
|
41
|
+
// Check if we need to create a ZIP archive for file-based inputs
|
|
42
|
+
let zipCreated = false;
|
|
43
|
+
let finalOptions = { ...options };
|
|
44
|
+
|
|
45
|
+
if (this._shouldCreateZip(options)) {
|
|
46
|
+
if (!options.quiet) {
|
|
47
|
+
console.log('Creating ZIP archive for file-based resources...');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const zipResult = await this._createZipArchive(options);
|
|
51
|
+
if (zipResult.isFailure()) {
|
|
52
|
+
return fail(`Failed to create ZIP archive: ${zipResult.message}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!options.quiet) {
|
|
56
|
+
console.log(`ZIP archive created: ${zipResult.value.zipPath}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Modify options to use ZIP loading instead of file paths
|
|
60
|
+
const zipFileName = path.basename(zipResult.value.zipPath);
|
|
61
|
+
finalOptions = {
|
|
62
|
+
...options,
|
|
63
|
+
input: undefined,
|
|
64
|
+
config: undefined,
|
|
65
|
+
// Add ZIP loading parameters
|
|
66
|
+
loadZip: true,
|
|
67
|
+
zipFile: zipFileName,
|
|
68
|
+
zipPath: zipResult.value.zipPath
|
|
69
|
+
};
|
|
70
|
+
zipCreated = true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Start development server if requested
|
|
74
|
+
if (finalOptions.dev && !finalOptions.url) {
|
|
75
|
+
if (!finalOptions.quiet) {
|
|
76
|
+
console.log('Starting TS-RES Browser development server...');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const serverResult = await this._startDevServer(finalOptions);
|
|
80
|
+
if (serverResult.isFailure()) {
|
|
81
|
+
return serverResult;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Wait for server to be ready
|
|
85
|
+
const port = options.port || 3000;
|
|
86
|
+
const readyResult = await this._waitForServerReady(port, options.verbose || false);
|
|
87
|
+
if (readyResult.isFailure()) {
|
|
88
|
+
this._stopDevServer();
|
|
89
|
+
return readyResult;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (!options.quiet) {
|
|
93
|
+
console.log(`Development server started on port ${port}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Build URL with parameters
|
|
98
|
+
const url = this._buildUrl(finalOptions);
|
|
99
|
+
|
|
100
|
+
if (!finalOptions.quiet) {
|
|
101
|
+
console.log('Opening TS-RES Browser...');
|
|
102
|
+
if (zipCreated) {
|
|
103
|
+
console.log('ZIP archive created - browser will load from Downloads folder');
|
|
104
|
+
} else {
|
|
105
|
+
if (finalOptions.input) {
|
|
106
|
+
console.log(`Resource file: ${finalOptions.input}`);
|
|
107
|
+
}
|
|
108
|
+
if (finalOptions.config) {
|
|
109
|
+
console.log(`Configuration: ${finalOptions.config}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (finalOptions.contextFilter) {
|
|
113
|
+
console.log(`Context filter: ${finalOptions.contextFilter}`);
|
|
114
|
+
}
|
|
115
|
+
console.log(`URL: ${url}`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Open browser if requested (default to true)
|
|
119
|
+
const shouldOpen = finalOptions.open !== false;
|
|
120
|
+
if (shouldOpen) {
|
|
121
|
+
const openResult = await this._openBrowser(url, finalOptions.verbose || false);
|
|
122
|
+
if (openResult.isFailure()) {
|
|
123
|
+
return fail(`Could not open browser: ${openResult.message}`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (!finalOptions.quiet) {
|
|
127
|
+
console.log('Browser opened successfully');
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
console.log(`Browser URL: ${url}`);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return succeed(undefined);
|
|
134
|
+
} catch (error) {
|
|
135
|
+
return fail(`Failed to launch browser: ${error}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Opens the browser to the specified URL
|
|
141
|
+
*/
|
|
142
|
+
private async _openBrowser(url: string, verbose: boolean): Promise<Result<void>> {
|
|
143
|
+
return new Promise((resolve) => {
|
|
144
|
+
const command =
|
|
145
|
+
process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start ""' : 'xdg-open';
|
|
146
|
+
|
|
147
|
+
exec(`${command} "${url}"`, (error) => {
|
|
148
|
+
if (error) {
|
|
149
|
+
resolve(fail(`Failed to open browser: ${error.message}`));
|
|
150
|
+
} else {
|
|
151
|
+
if (verbose) {
|
|
152
|
+
console.log(`Opened browser to: ${url}`);
|
|
153
|
+
}
|
|
154
|
+
resolve(succeed(undefined));
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Builds the URL with query parameters based on options
|
|
162
|
+
*/
|
|
163
|
+
private _buildUrl(options: IBrowseOptions): string {
|
|
164
|
+
// Use provided URL or default to localhost
|
|
165
|
+
const baseUrl = options.url || `http://localhost:${options.port || 3000}`;
|
|
166
|
+
const params = new URLSearchParams();
|
|
167
|
+
|
|
168
|
+
if (options.input) {
|
|
169
|
+
params.set('input', options.input);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (options.config) {
|
|
173
|
+
params.set('config', options.config);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (options.contextFilter) {
|
|
177
|
+
params.set('contextFilter', options.contextFilter);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (options.qualifierDefaults) {
|
|
181
|
+
params.set('qualifierDefaults', options.qualifierDefaults);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (options.resourceTypes) {
|
|
185
|
+
params.set('resourceTypes', options.resourceTypes);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (options.maxDistance !== undefined) {
|
|
189
|
+
params.set('maxDistance', options.maxDistance.toString());
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (options.reduceQualifiers) {
|
|
193
|
+
params.set('reduceQualifiers', 'true');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (options.interactive) {
|
|
197
|
+
params.set('interactive', 'true');
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (options.loadZip) {
|
|
201
|
+
params.set('loadZip', 'true');
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (options.zipFile) {
|
|
205
|
+
params.set('zipFile', options.zipFile);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (options.zipPath) {
|
|
209
|
+
params.set('zipPath', options.zipPath);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const queryString = params.toString();
|
|
213
|
+
return queryString ? `${baseUrl}?${queryString}` : baseUrl;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Starts the development server for ts-res-browser
|
|
218
|
+
*/
|
|
219
|
+
private async _startDevServer(options: IBrowseOptions): Promise<Result<void>> {
|
|
220
|
+
try {
|
|
221
|
+
// Find the ts-res-browser project directory
|
|
222
|
+
// Assume we're running from tools/ts-res-browser-cli, so go up and over to tools/ts-res-browser
|
|
223
|
+
const browserProjectPath = path.resolve(__dirname, '../../ts-res-browser');
|
|
224
|
+
|
|
225
|
+
if (options.verbose) {
|
|
226
|
+
console.log(`Looking for ts-res-browser at: ${browserProjectPath}`);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const port = options.port || 3000;
|
|
230
|
+
const env = { ...process.env, PORT: port.toString() };
|
|
231
|
+
|
|
232
|
+
this._devServer = spawn('rushx', ['dev'], {
|
|
233
|
+
cwd: browserProjectPath,
|
|
234
|
+
env,
|
|
235
|
+
stdio: options.verbose ? 'inherit' : ['ignore', 'pipe', 'pipe']
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
this._devServer.on('error', (error) => {
|
|
239
|
+
return fail(`Failed to start development server: ${error}`);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
// Give the server a moment to start
|
|
243
|
+
await this._sleep(3000);
|
|
244
|
+
|
|
245
|
+
if (this._devServer && !this._devServer.killed) {
|
|
246
|
+
if (options.verbose) {
|
|
247
|
+
console.log('Development server process started successfully');
|
|
248
|
+
}
|
|
249
|
+
return succeed(undefined);
|
|
250
|
+
} else {
|
|
251
|
+
return fail('Development server process failed to start');
|
|
252
|
+
}
|
|
253
|
+
} catch (error) {
|
|
254
|
+
return fail(`Failed to start development server: ${error}`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Waits for the development server to be ready by checking HTTP availability
|
|
260
|
+
*/
|
|
261
|
+
private async _waitForServerReady(
|
|
262
|
+
port: number,
|
|
263
|
+
verbose: boolean,
|
|
264
|
+
maxAttempts: number = 60
|
|
265
|
+
): Promise<Result<void>> {
|
|
266
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
267
|
+
try {
|
|
268
|
+
const isReady = await this._checkServerHealth(port);
|
|
269
|
+
if (isReady) {
|
|
270
|
+
if (verbose) {
|
|
271
|
+
console.log(`Server is ready at http://localhost:${port}`);
|
|
272
|
+
}
|
|
273
|
+
return succeed(undefined);
|
|
274
|
+
}
|
|
275
|
+
} catch (error) {
|
|
276
|
+
// Server not ready yet, continue waiting
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (verbose && attempt % 10 === 0) {
|
|
280
|
+
console.log(`Waiting for server to be ready... (attempt ${attempt}/${maxAttempts})`);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
await this._sleep(1000);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return fail(`Server did not become ready after ${maxAttempts} attempts`);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Checks if the server is responding
|
|
291
|
+
*/
|
|
292
|
+
private async _checkServerHealth(port: number): Promise<boolean> {
|
|
293
|
+
return new Promise((resolve) => {
|
|
294
|
+
const request = http.get(`http://localhost:${port}`, (res) => {
|
|
295
|
+
resolve(res.statusCode !== undefined && res.statusCode >= 200 && res.statusCode < 400);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
request.on('error', () => {
|
|
299
|
+
resolve(false);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
request.setTimeout(3000, () => {
|
|
303
|
+
request.destroy();
|
|
304
|
+
resolve(false);
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Stops the development server
|
|
311
|
+
*/
|
|
312
|
+
private _stopDevServer(): void {
|
|
313
|
+
if (this._devServer && !this._devServer.killed) {
|
|
314
|
+
this._devServer.kill('SIGTERM');
|
|
315
|
+
setTimeout(() => {
|
|
316
|
+
if (this._devServer && !this._devServer.killed) {
|
|
317
|
+
this._devServer.kill('SIGKILL');
|
|
318
|
+
}
|
|
319
|
+
}, 5000);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Sleep for the specified number of milliseconds
|
|
325
|
+
*/
|
|
326
|
+
private _sleep(ms: number): Promise<void> {
|
|
327
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Determines if a ZIP archive should be created based on the options
|
|
332
|
+
*/
|
|
333
|
+
private _shouldCreateZip(options: IBrowseOptions): boolean {
|
|
334
|
+
// Create ZIP if input or config are file paths (not predefined names)
|
|
335
|
+
const hasFilePath = (path: string | undefined): boolean => {
|
|
336
|
+
if (!path) return false;
|
|
337
|
+
// Check if it's a file path (contains directory separators or file extensions)
|
|
338
|
+
return path.includes('/') || path.includes('\\') || (path.includes('.') && !path.startsWith('.'));
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
return hasFilePath(options.input) || hasFilePath(options.config);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Creates a ZIP archive containing the input and config files
|
|
346
|
+
*/
|
|
347
|
+
private async _createZipArchive(
|
|
348
|
+
options: IBrowseOptions
|
|
349
|
+
): Promise<Result<{ zipPath: string; manifest: any }>> {
|
|
350
|
+
try {
|
|
351
|
+
return await zipArchiver.createArchive({
|
|
352
|
+
input: options.input,
|
|
353
|
+
config: options.config
|
|
354
|
+
});
|
|
355
|
+
} catch (error) {
|
|
356
|
+
return fail(`Failed to create ZIP archive: ${error instanceof Error ? error.message : String(error)}`);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Graceful shutdown - stops development server if running
|
|
362
|
+
*/
|
|
363
|
+
public shutdown(): void {
|
|
364
|
+
this._stopDevServer();
|
|
365
|
+
}
|
|
366
|
+
}
|