@weapp-tailwindcss/hbuilderx-runner 0.0.3 → 0.0.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/dist/index.cjs +68 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.mjs +66 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -492,6 +492,71 @@ function assertIosSimulatorToolchain(env = node_process.default.env) {
|
|
|
492
492
|
"如果 firstLaunchStatus 不是 ready,请先打开 Xcode 完成首次组件安装,或执行 sudo xcodebuild -runFirstLaunch。"
|
|
493
493
|
].join("\n"));
|
|
494
494
|
}
|
|
495
|
+
function parseIosSimulatorDevices(output) {
|
|
496
|
+
const jsonStart = output.indexOf("{");
|
|
497
|
+
const jsonEnd = output.lastIndexOf("}");
|
|
498
|
+
if (jsonStart < 0 || jsonEnd < jsonStart) return [];
|
|
499
|
+
let value;
|
|
500
|
+
try {
|
|
501
|
+
value = JSON.parse(output.slice(jsonStart, jsonEnd + 1));
|
|
502
|
+
} catch {
|
|
503
|
+
return [];
|
|
504
|
+
}
|
|
505
|
+
if (!value || typeof value !== "object" || !("devices" in value)) return [];
|
|
506
|
+
const devices = value.devices;
|
|
507
|
+
if (!devices || typeof devices !== "object") return [];
|
|
508
|
+
return Object.values(devices).flatMap((runtimeDevices) => {
|
|
509
|
+
if (!Array.isArray(runtimeDevices)) return [];
|
|
510
|
+
return runtimeDevices.flatMap((device) => {
|
|
511
|
+
if (!device || typeof device !== "object" || !("udid" in device) || typeof device.udid !== "string" || "isAvailable" in device && device.isAvailable === false) return [];
|
|
512
|
+
return [{
|
|
513
|
+
..."lastBootedAt" in device && typeof device.lastBootedAt === "string" ? { lastBootedAt: device.lastBootedAt } : {},
|
|
514
|
+
name: "name" in device && typeof device.name === "string" ? device.name : device.udid,
|
|
515
|
+
state: "state" in device && typeof device.state === "string" ? device.state : "Unknown",
|
|
516
|
+
udid: device.udid
|
|
517
|
+
}];
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
function selectPreferredIosSimulatorDevice(devices) {
|
|
522
|
+
return [...devices].sort((left, right) => {
|
|
523
|
+
const stateDifference = Number(right.state === "Booted") - Number(left.state === "Booted");
|
|
524
|
+
if (stateDifference !== 0) return stateDifference;
|
|
525
|
+
const leftLastBootedAt = Date.parse(left.lastBootedAt ?? "");
|
|
526
|
+
const rightLastBootedAt = Date.parse(right.lastBootedAt ?? "");
|
|
527
|
+
const lastBootedDifference = (Number.isNaN(rightLastBootedAt) ? 0 : rightLastBootedAt) - (Number.isNaN(leftLastBootedAt) ? 0 : leftLastBootedAt);
|
|
528
|
+
if (lastBootedDifference !== 0) return lastBootedDifference;
|
|
529
|
+
return Number(/^iPhone\b/.test(right.name)) - Number(/^iPhone\b/.test(left.name));
|
|
530
|
+
})[0];
|
|
531
|
+
}
|
|
532
|
+
function resolveIosSimulatorDeviceId(env = node_process.default.env) {
|
|
533
|
+
const explicitDeviceId = env.E2E_HBUILDERX_IOS_DEVICE_ID;
|
|
534
|
+
if (explicitDeviceId) return explicitDeviceId;
|
|
535
|
+
const booted = runTool("xcrun", [
|
|
536
|
+
"simctl",
|
|
537
|
+
"list",
|
|
538
|
+
"devices",
|
|
539
|
+
"booted",
|
|
540
|
+
"--json"
|
|
541
|
+
]);
|
|
542
|
+
const bootedDevice = selectPreferredIosSimulatorDevice(booted.ok ? parseIosSimulatorDevices(booted.output) : []);
|
|
543
|
+
if (bootedDevice) return bootedDevice.udid;
|
|
544
|
+
const available = runTool("xcrun", [
|
|
545
|
+
"simctl",
|
|
546
|
+
"list",
|
|
547
|
+
"devices",
|
|
548
|
+
"available",
|
|
549
|
+
"--json"
|
|
550
|
+
]);
|
|
551
|
+
const availableDevice = selectPreferredIosSimulatorDevice(available.ok ? parseIosSimulatorDevices(available.output) : []);
|
|
552
|
+
if (availableDevice) return availableDevice.udid;
|
|
553
|
+
throw new Error([
|
|
554
|
+
"未找到可用于 HBuilderX app-ios E2E 的 iOS 模拟器。",
|
|
555
|
+
`booted: ${booted.output || "empty"}`,
|
|
556
|
+
`available: ${available.output || "empty"}`,
|
|
557
|
+
"请先在 Xcode 中安装并启动一个模拟器,或设置 E2E_HBUILDERX_IOS_DEVICE_ID。"
|
|
558
|
+
].join("\n"));
|
|
559
|
+
}
|
|
495
560
|
function resolveHdcCommand(env = node_process.default.env) {
|
|
496
561
|
const candidates = [
|
|
497
562
|
env.DEMO_VISUAL_HARMONY_HDC_PATH,
|
|
@@ -552,15 +617,18 @@ exports.killProcessTree = killProcessTree;
|
|
|
552
617
|
exports.launchProject = launchProject;
|
|
553
618
|
exports.openProject = openProject;
|
|
554
619
|
exports.parseHdcTargets = parseHdcTargets;
|
|
620
|
+
exports.parseIosSimulatorDevices = parseIosSimulatorDevices;
|
|
555
621
|
exports.prepareProject = prepareProject;
|
|
556
622
|
exports.readUtf8 = readUtf8;
|
|
557
623
|
exports.resolveAdbCommand = resolveAdbCommand;
|
|
558
624
|
exports.resolveHBuilderXCli = resolveHBuilderXCli;
|
|
559
625
|
exports.resolveHBuilderXCliInfo = resolveHBuilderXCliInfo;
|
|
560
626
|
exports.resolveHdcCommand = resolveHdcCommand;
|
|
627
|
+
exports.resolveIosSimulatorDeviceId = resolveIosSimulatorDeviceId;
|
|
561
628
|
exports.runCommand = runCommand;
|
|
562
629
|
exports.runPnpmCommand = runPnpmCommand;
|
|
563
630
|
exports.runTool = runTool;
|
|
631
|
+
exports.selectPreferredIosSimulatorDevice = selectPreferredIosSimulatorDevice;
|
|
564
632
|
exports.spawnCommand = spawnCommand;
|
|
565
633
|
exports.spawnPnpmCommand = spawnPnpmCommand;
|
|
566
634
|
exports.startLaunch = startLaunch;
|
package/dist/index.d.ts
CHANGED
|
@@ -137,8 +137,17 @@ declare function runTool(command: string, args: string[]): ToolResult;
|
|
|
137
137
|
declare function resolveAdbCommand(env?: NodeJS.ProcessEnv): AndroidToolchain;
|
|
138
138
|
declare function assertAndroidToolchain(env?: NodeJS.ProcessEnv): Record<string, string> | undefined;
|
|
139
139
|
declare function assertIosSimulatorToolchain(env?: NodeJS.ProcessEnv): void;
|
|
140
|
+
interface IosSimulatorDevice {
|
|
141
|
+
lastBootedAt?: string;
|
|
142
|
+
name: string;
|
|
143
|
+
state: string;
|
|
144
|
+
udid: string;
|
|
145
|
+
}
|
|
146
|
+
declare function parseIosSimulatorDevices(output: string): IosSimulatorDevice[];
|
|
147
|
+
declare function selectPreferredIosSimulatorDevice(devices: IosSimulatorDevice[]): IosSimulatorDevice | undefined;
|
|
148
|
+
declare function resolveIosSimulatorDeviceId(env?: NodeJS.ProcessEnv): string;
|
|
140
149
|
declare function resolveHdcCommand(env?: NodeJS.ProcessEnv): string;
|
|
141
150
|
declare function parseHdcTargets(output: string): string[];
|
|
142
151
|
declare function assertHarmonyToolchain(env?: NodeJS.ProcessEnv, deviceId?: string): string;
|
|
143
152
|
//#endregion
|
|
144
|
-
export { AndroidToolchain, CommandExit, HBuilderXAppPlatform, HBuilderXCliResolution, HBuilderXCliResolutionSource, HBuilderXCommandError, HBuilderXCommandOptions, HBuilderXCommandResult, HBuilderXIssue, HBuilderXIssueKind, HBuilderXLaunchOptions, HBuilderXMiniProgramPlatform, HBuilderXPlatform, HBuilderXProjectOptions, SpawnedHBuilderXCommand, ToolResult, assertAndroidToolchain, assertHarmonyToolchain, assertIosSimulatorToolchain, classifyHBuilderXOutput, closeProject, collectProcessOutput, createHBuilderXEnv, createLaunchArgs, createLogBuffer, createProcessExitTracker, createTimeoutIssue, extractHBuilderXExecutableFromProcessOutput, extractHBuilderXMacOSExecutable, extractHBuilderXWindowsExecutable, fileExists, findRunningHBuilderXCli, formatRecentLogs, getDefaultHBuilderXCliCandidates, hbuilderxPnpmArgs, killProcessTree, launchProject, openProject, parseHdcTargets, prepareProject, readUtf8, resolveAdbCommand, resolveHBuilderXCli, resolveHBuilderXCliInfo, resolveHdcCommand, runCommand, runPnpmCommand, runTool, spawnCommand, spawnPnpmCommand, startLaunch, wait };
|
|
153
|
+
export { AndroidToolchain, CommandExit, HBuilderXAppPlatform, HBuilderXCliResolution, HBuilderXCliResolutionSource, HBuilderXCommandError, HBuilderXCommandOptions, HBuilderXCommandResult, HBuilderXIssue, HBuilderXIssueKind, HBuilderXLaunchOptions, HBuilderXMiniProgramPlatform, HBuilderXPlatform, HBuilderXProjectOptions, IosSimulatorDevice, SpawnedHBuilderXCommand, ToolResult, assertAndroidToolchain, assertHarmonyToolchain, assertIosSimulatorToolchain, classifyHBuilderXOutput, closeProject, collectProcessOutput, createHBuilderXEnv, createLaunchArgs, createLogBuffer, createProcessExitTracker, createTimeoutIssue, extractHBuilderXExecutableFromProcessOutput, extractHBuilderXMacOSExecutable, extractHBuilderXWindowsExecutable, fileExists, findRunningHBuilderXCli, formatRecentLogs, getDefaultHBuilderXCliCandidates, hbuilderxPnpmArgs, killProcessTree, launchProject, openProject, parseHdcTargets, parseIosSimulatorDevices, prepareProject, readUtf8, resolveAdbCommand, resolveHBuilderXCli, resolveHBuilderXCliInfo, resolveHdcCommand, resolveIosSimulatorDeviceId, runCommand, runPnpmCommand, runTool, selectPreferredIosSimulatorDevice, spawnCommand, spawnPnpmCommand, startLaunch, wait };
|
package/dist/index.mjs
CHANGED
|
@@ -466,6 +466,71 @@ function assertIosSimulatorToolchain(env = process.env) {
|
|
|
466
466
|
"如果 firstLaunchStatus 不是 ready,请先打开 Xcode 完成首次组件安装,或执行 sudo xcodebuild -runFirstLaunch。"
|
|
467
467
|
].join("\n"));
|
|
468
468
|
}
|
|
469
|
+
function parseIosSimulatorDevices(output) {
|
|
470
|
+
const jsonStart = output.indexOf("{");
|
|
471
|
+
const jsonEnd = output.lastIndexOf("}");
|
|
472
|
+
if (jsonStart < 0 || jsonEnd < jsonStart) return [];
|
|
473
|
+
let value;
|
|
474
|
+
try {
|
|
475
|
+
value = JSON.parse(output.slice(jsonStart, jsonEnd + 1));
|
|
476
|
+
} catch {
|
|
477
|
+
return [];
|
|
478
|
+
}
|
|
479
|
+
if (!value || typeof value !== "object" || !("devices" in value)) return [];
|
|
480
|
+
const devices = value.devices;
|
|
481
|
+
if (!devices || typeof devices !== "object") return [];
|
|
482
|
+
return Object.values(devices).flatMap((runtimeDevices) => {
|
|
483
|
+
if (!Array.isArray(runtimeDevices)) return [];
|
|
484
|
+
return runtimeDevices.flatMap((device) => {
|
|
485
|
+
if (!device || typeof device !== "object" || !("udid" in device) || typeof device.udid !== "string" || "isAvailable" in device && device.isAvailable === false) return [];
|
|
486
|
+
return [{
|
|
487
|
+
..."lastBootedAt" in device && typeof device.lastBootedAt === "string" ? { lastBootedAt: device.lastBootedAt } : {},
|
|
488
|
+
name: "name" in device && typeof device.name === "string" ? device.name : device.udid,
|
|
489
|
+
state: "state" in device && typeof device.state === "string" ? device.state : "Unknown",
|
|
490
|
+
udid: device.udid
|
|
491
|
+
}];
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
function selectPreferredIosSimulatorDevice(devices) {
|
|
496
|
+
return [...devices].sort((left, right) => {
|
|
497
|
+
const stateDifference = Number(right.state === "Booted") - Number(left.state === "Booted");
|
|
498
|
+
if (stateDifference !== 0) return stateDifference;
|
|
499
|
+
const leftLastBootedAt = Date.parse(left.lastBootedAt ?? "");
|
|
500
|
+
const rightLastBootedAt = Date.parse(right.lastBootedAt ?? "");
|
|
501
|
+
const lastBootedDifference = (Number.isNaN(rightLastBootedAt) ? 0 : rightLastBootedAt) - (Number.isNaN(leftLastBootedAt) ? 0 : leftLastBootedAt);
|
|
502
|
+
if (lastBootedDifference !== 0) return lastBootedDifference;
|
|
503
|
+
return Number(/^iPhone\b/.test(right.name)) - Number(/^iPhone\b/.test(left.name));
|
|
504
|
+
})[0];
|
|
505
|
+
}
|
|
506
|
+
function resolveIosSimulatorDeviceId(env = process.env) {
|
|
507
|
+
const explicitDeviceId = env.E2E_HBUILDERX_IOS_DEVICE_ID;
|
|
508
|
+
if (explicitDeviceId) return explicitDeviceId;
|
|
509
|
+
const booted = runTool("xcrun", [
|
|
510
|
+
"simctl",
|
|
511
|
+
"list",
|
|
512
|
+
"devices",
|
|
513
|
+
"booted",
|
|
514
|
+
"--json"
|
|
515
|
+
]);
|
|
516
|
+
const bootedDevice = selectPreferredIosSimulatorDevice(booted.ok ? parseIosSimulatorDevices(booted.output) : []);
|
|
517
|
+
if (bootedDevice) return bootedDevice.udid;
|
|
518
|
+
const available = runTool("xcrun", [
|
|
519
|
+
"simctl",
|
|
520
|
+
"list",
|
|
521
|
+
"devices",
|
|
522
|
+
"available",
|
|
523
|
+
"--json"
|
|
524
|
+
]);
|
|
525
|
+
const availableDevice = selectPreferredIosSimulatorDevice(available.ok ? parseIosSimulatorDevices(available.output) : []);
|
|
526
|
+
if (availableDevice) return availableDevice.udid;
|
|
527
|
+
throw new Error([
|
|
528
|
+
"未找到可用于 HBuilderX app-ios E2E 的 iOS 模拟器。",
|
|
529
|
+
`booted: ${booted.output || "empty"}`,
|
|
530
|
+
`available: ${available.output || "empty"}`,
|
|
531
|
+
"请先在 Xcode 中安装并启动一个模拟器,或设置 E2E_HBUILDERX_IOS_DEVICE_ID。"
|
|
532
|
+
].join("\n"));
|
|
533
|
+
}
|
|
469
534
|
function resolveHdcCommand(env = process.env) {
|
|
470
535
|
const candidates = [
|
|
471
536
|
env.DEMO_VISUAL_HARMONY_HDC_PATH,
|
|
@@ -502,4 +567,4 @@ function assertHarmonyToolchain(env = process.env, deviceId) {
|
|
|
502
567
|
return hdc;
|
|
503
568
|
}
|
|
504
569
|
//#endregion
|
|
505
|
-
export { HBuilderXCommandError, assertAndroidToolchain, assertHarmonyToolchain, assertIosSimulatorToolchain, classifyHBuilderXOutput, closeProject, collectProcessOutput, createHBuilderXEnv, createLaunchArgs, createLogBuffer, createProcessExitTracker, createTimeoutIssue, extractHBuilderXExecutableFromProcessOutput, extractHBuilderXMacOSExecutable, extractHBuilderXWindowsExecutable, fileExists, findRunningHBuilderXCli, formatRecentLogs, getDefaultHBuilderXCliCandidates, hbuilderxPnpmArgs, killProcessTree, launchProject, openProject, parseHdcTargets, prepareProject, readUtf8, resolveAdbCommand, resolveHBuilderXCli, resolveHBuilderXCliInfo, resolveHdcCommand, runCommand, runPnpmCommand, runTool, spawnCommand, spawnPnpmCommand, startLaunch, wait };
|
|
570
|
+
export { HBuilderXCommandError, assertAndroidToolchain, assertHarmonyToolchain, assertIosSimulatorToolchain, classifyHBuilderXOutput, closeProject, collectProcessOutput, createHBuilderXEnv, createLaunchArgs, createLogBuffer, createProcessExitTracker, createTimeoutIssue, extractHBuilderXExecutableFromProcessOutput, extractHBuilderXMacOSExecutable, extractHBuilderXWindowsExecutable, fileExists, findRunningHBuilderXCli, formatRecentLogs, getDefaultHBuilderXCliCandidates, hbuilderxPnpmArgs, killProcessTree, launchProject, openProject, parseHdcTargets, parseIosSimulatorDevices, prepareProject, readUtf8, resolveAdbCommand, resolveHBuilderXCli, resolveHBuilderXCliInfo, resolveHdcCommand, resolveIosSimulatorDeviceId, runCommand, runPnpmCommand, runTool, selectPreferredIosSimulatorDevice, spawnCommand, spawnPnpmCommand, startLaunch, wait };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-tailwindcss/hbuilderx-runner",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"description": "Stable HBuilderX CLI runner utilities for weapp-tailwindcss local e2e workflows.",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|