@autifyhq/autify-cli 0.51.0 → 0.52.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/README.md +100 -37
- package/dist/autify/connect/accessPointConfig.js +2 -2
- package/dist/autify/connect/client-manager/ClientManager.d.ts +2 -2
- package/dist/autify/connect/client-manager/ClientManager.js +4 -4
- package/dist/autify/connect/client-manager/DebugServerClient.js +3 -3
- package/dist/autify/connect/installClient.d.ts +2 -2
- package/dist/autify/connect/installClient.js +10 -10
- package/dist/autify/mobile/createZip.js +3 -3
- package/dist/autify/mobile/inspectBuildFile.js +3 -3
- package/dist/autify/mobile/mobilelink/installBinary.d.ts +8 -0
- package/dist/autify/mobile/mobilelink/installBinary.js +133 -0
- package/dist/autify/mobile/mobilelink/mobile-link-manager/Logger.d.ts +11 -0
- package/dist/autify/mobile/mobilelink/mobile-link-manager/Logger.js +47 -0
- package/dist/autify/mobile/mobilelink/mobile-link-manager/MobileLinkManager.d.ts +47 -0
- package/dist/autify/mobile/mobilelink/mobile-link-manager/MobileLinkManager.js +204 -0
- package/dist/autify/mobile/mobilelink/mobile-link-manager/StateMachine.d.ts +51 -0
- package/dist/autify/mobile/mobilelink/mobile-link-manager/StateMachine.js +120 -0
- package/dist/autify/mobile/parseTestPlanUrl.js +2 -2
- package/dist/autify/mobile/parseTestResultUrl.js +2 -2
- package/dist/autify/mobile/uploadBuild.js +2 -2
- package/dist/autify/mobile/waitTestResult.js +2 -2
- package/dist/autify/web/parseAutifyTestUrl.js +2 -2
- package/dist/autify/web/parseTestResultUrl.js +2 -2
- package/dist/autify/web/runTest.js +6 -6
- package/dist/autify/web/waitTestResult.js +3 -3
- package/dist/commands/connect/access-point/set.js +2 -2
- package/dist/commands/mobile/auth/login.js +2 -2
- package/dist/commands/mobile/link/exec.d.ts +10 -0
- package/dist/commands/mobile/link/exec.js +23 -0
- package/dist/commands/mobile/link/install.d.ts +7 -0
- package/dist/commands/mobile/link/install.js +22 -0
- package/dist/commands/mobile/link/start.d.ts +11 -0
- package/dist/commands/mobile/link/start.js +37 -0
- package/dist/commands/mobile/test/run.js +2 -3
- package/dist/commands/web/auth/login.js +2 -2
- package/dist/commands/web/test/run.js +2 -3
- package/dist/config.d.ts +1 -1
- package/oclif.manifest.json +727 -643
- package/package.json +20 -22
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.installBinary = exports.getInstallVersion = exports.getBinaryPath = exports.getInstallPath = exports.getMobileLinkSourceUrl = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
/* eslint-disable unicorn/filename-case */
|
|
6
|
+
const core_1 = require("@oclif/core");
|
|
7
|
+
const node_process_1 = require("node:process");
|
|
8
|
+
const node_fs_1 = require("node:fs");
|
|
9
|
+
const node_stream_1 = require("node:stream");
|
|
10
|
+
const node_util_1 = require("node:util");
|
|
11
|
+
const node_path_1 = require("node:path");
|
|
12
|
+
const unzip_stream_1 = require("unzip-stream");
|
|
13
|
+
const node_child_process_1 = require("node:child_process");
|
|
14
|
+
const tar = tslib_1.__importStar(require("tar"));
|
|
15
|
+
const config_1 = require("../../../config");
|
|
16
|
+
const getOs = () => {
|
|
17
|
+
const os = node_process_1.platform;
|
|
18
|
+
if (os === "linux")
|
|
19
|
+
return "linux";
|
|
20
|
+
if (os === "darwin")
|
|
21
|
+
return "darwin";
|
|
22
|
+
if (os === "win32")
|
|
23
|
+
return "windows";
|
|
24
|
+
throw new core_1.Errors.CLIError(`Unsupported OS: ${os}`);
|
|
25
|
+
};
|
|
26
|
+
const getArch = () => {
|
|
27
|
+
if (node_process_1.arch === "ia32")
|
|
28
|
+
return "386";
|
|
29
|
+
if (node_process_1.arch === "x64")
|
|
30
|
+
return "amd64";
|
|
31
|
+
if (node_process_1.arch === "arm64")
|
|
32
|
+
return "arm64";
|
|
33
|
+
throw new core_1.Errors.CLIError(`Unsupported Architecture: ${node_process_1.arch}`);
|
|
34
|
+
};
|
|
35
|
+
const getExt = () => (getOs() === "windows" ? "zip" : "tar.gz");
|
|
36
|
+
const getMobileLinkSourceUrl = (configDir) => {
|
|
37
|
+
const customUrl = (0, config_1.get)(configDir, "AUTIFY_MOBILE_LINK_SOURCE_URL");
|
|
38
|
+
if (customUrl) {
|
|
39
|
+
return new URL(customUrl);
|
|
40
|
+
}
|
|
41
|
+
const baseUrl = "https://d21jojv86oc6d1.cloudfront.net/mobilelink/channels/stable";
|
|
42
|
+
const prefix = "mobilelink";
|
|
43
|
+
const os = getOs();
|
|
44
|
+
const arch = getArch();
|
|
45
|
+
const ext = getExt();
|
|
46
|
+
return new URL(`${baseUrl}/${prefix}-${os}-${arch}.${ext}`);
|
|
47
|
+
};
|
|
48
|
+
exports.getMobileLinkSourceUrl = getMobileLinkSourceUrl;
|
|
49
|
+
const download = async (workspaceDir, url) => {
|
|
50
|
+
const downloadPath = (0, node_path_1.join)(workspaceDir, (0, node_path_1.basename)(url.pathname));
|
|
51
|
+
const response = await fetch(url);
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
const b = await response.text();
|
|
54
|
+
console.log("response doby!!!", b);
|
|
55
|
+
throw new core_1.Errors.CLIError(`Failed to fetch ${url}: ${response.status}`);
|
|
56
|
+
}
|
|
57
|
+
const streamPipeline = (0, node_util_1.promisify)(node_stream_1.pipeline);
|
|
58
|
+
if (response.body) {
|
|
59
|
+
await streamPipeline(response.body, (0, node_fs_1.createWriteStream)(downloadPath));
|
|
60
|
+
}
|
|
61
|
+
return downloadPath;
|
|
62
|
+
};
|
|
63
|
+
const extract = async (downloadPath) => {
|
|
64
|
+
const dir = (0, node_path_1.dirname)(downloadPath);
|
|
65
|
+
if (downloadPath.endsWith(".tar.gz")) {
|
|
66
|
+
const streamPipeline = (0, node_util_1.promisify)(node_stream_1.pipeline);
|
|
67
|
+
await streamPipeline((0, node_fs_1.createReadStream)(downloadPath), tar.x({ cwd: dir }));
|
|
68
|
+
}
|
|
69
|
+
else if (downloadPath.endsWith(".zip")) {
|
|
70
|
+
const streamPipeline = (0, node_util_1.promisify)(node_stream_1.pipeline);
|
|
71
|
+
await streamPipeline((0, node_fs_1.createReadStream)(downloadPath),
|
|
72
|
+
// eslint-disable-next-line new-cap
|
|
73
|
+
(0, unzip_stream_1.Extract)({ path: dir }));
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
throw new core_1.Errors.CLIError(`Unsupported file format: ${downloadPath}`);
|
|
77
|
+
}
|
|
78
|
+
const binDir = (0, node_path_1.join)(dir, "mobilelink", "bin");
|
|
79
|
+
const files = (0, node_fs_1.readdirSync)(binDir);
|
|
80
|
+
const binary = files.find((file) => file.startsWith("mobilelink"));
|
|
81
|
+
if (!binary)
|
|
82
|
+
throw new core_1.Errors.CLIError(`Cannot find any mobilelink binary in ${binDir}`);
|
|
83
|
+
return (0, node_path_1.join)(dir, "mobilelink");
|
|
84
|
+
};
|
|
85
|
+
const getWorkspaceDir = (cacheDir) => (0, node_path_1.join)(cacheDir, "mobilelink-install-workspace");
|
|
86
|
+
const getInstallPath = (cacheDir) => {
|
|
87
|
+
const directoryName = "mobilelink";
|
|
88
|
+
return (0, node_path_1.join)(cacheDir, directoryName);
|
|
89
|
+
};
|
|
90
|
+
exports.getInstallPath = getInstallPath;
|
|
91
|
+
const getBinaryPath = (cacheDir) => {
|
|
92
|
+
return (0, node_path_1.join)((0, exports.getInstallPath)(cacheDir), "bin", "mobilelink");
|
|
93
|
+
};
|
|
94
|
+
exports.getBinaryPath = getBinaryPath;
|
|
95
|
+
const getInstallVersion = async (path) => {
|
|
96
|
+
if (!(0, node_fs_1.existsSync)(path)) {
|
|
97
|
+
throw new core_1.Errors.CLIError(`MobileLink isn't installed yet at ${path}. Run \`autify mobile link install\` first.`);
|
|
98
|
+
}
|
|
99
|
+
const { stdout } = await (0, node_util_1.promisify)(node_child_process_1.execFile)(path, ["--version"], {
|
|
100
|
+
env: node_process_1.env,
|
|
101
|
+
});
|
|
102
|
+
const version = stdout.trim();
|
|
103
|
+
if (version === "")
|
|
104
|
+
throw new core_1.Errors.CLIError("Version is empty");
|
|
105
|
+
return version;
|
|
106
|
+
};
|
|
107
|
+
exports.getInstallVersion = getInstallVersion;
|
|
108
|
+
const installBinary = async (cacheDir, url) => {
|
|
109
|
+
const workspaceDir = getWorkspaceDir(cacheDir);
|
|
110
|
+
// Clean up workspace in case something is left by previous command.
|
|
111
|
+
if ((0, node_fs_1.existsSync)(workspaceDir))
|
|
112
|
+
(0, node_fs_1.rmSync)(workspaceDir, { recursive: true, force: true });
|
|
113
|
+
(0, node_fs_1.mkdirSync)(workspaceDir, { recursive: true });
|
|
114
|
+
const downloadPath = await download(workspaceDir, url);
|
|
115
|
+
const extractPath = await extract(downloadPath);
|
|
116
|
+
const installPath = (0, exports.getInstallPath)(cacheDir);
|
|
117
|
+
(0, node_fs_1.rmSync)(installPath, { recursive: true, force: true });
|
|
118
|
+
(0, node_fs_1.renameSync)(extractPath, installPath);
|
|
119
|
+
const binaryPath = (0, exports.getBinaryPath)(cacheDir);
|
|
120
|
+
const versionString = await (0, exports.getInstallVersion)(binaryPath);
|
|
121
|
+
// Clean up workspace. Ignore any exception as install is already done.
|
|
122
|
+
try {
|
|
123
|
+
(0, node_fs_1.rmSync)(workspaceDir, { recursive: true, force: true });
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
console.error(`Workspace clean up failed. Ignoring because already installed. (error: ${error})`);
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
version: versionString,
|
|
130
|
+
path: installPath,
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
exports.installBinary = installBinary;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ChildProcessWithoutNullStreams } from "node:child_process";
|
|
2
|
+
import { Logger, LoggerOptions } from "winston";
|
|
3
|
+
type ClientLog = Readonly<{
|
|
4
|
+
level: string;
|
|
5
|
+
timestamp: string;
|
|
6
|
+
message: string;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const createManagerLogger: (options: LoggerOptions) => Logger;
|
|
9
|
+
export declare const createMobileLinkLogger: (options: LoggerOptions, filename?: string) => Logger;
|
|
10
|
+
export declare const setupMobileLinkOutputLogger: (childProcess: ChildProcessWithoutNullStreams, callback: (log: ClientLog) => void) => void;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupMobileLinkOutputLogger = exports.createMobileLinkLogger = exports.createManagerLogger = void 0;
|
|
4
|
+
const node_readline_1 = require("node:readline");
|
|
5
|
+
const winston_1 = require("winston");
|
|
6
|
+
const logFormatConsole = (prefix) => winston_1.format.combine(winston_1.format.colorize(), winston_1.format.timestamp(), winston_1.format.printf(({ timestamp, level, message }) => `${prefix.padEnd(25)} ${timestamp}\t${level}\t${message}`));
|
|
7
|
+
const logFormatFile = () => winston_1.format.combine(winston_1.format.timestamp(), winston_1.format.printf(({ timestamp, level, message }) => `${timestamp}\t${level}\t${message}`));
|
|
8
|
+
const createManagerLogger = (options) => {
|
|
9
|
+
return (0, winston_1.createLogger)(options).add(new winston_1.transports.Console({
|
|
10
|
+
format: logFormatConsole("[Mobile Link Manager]"),
|
|
11
|
+
}));
|
|
12
|
+
};
|
|
13
|
+
exports.createManagerLogger = createManagerLogger;
|
|
14
|
+
const createMobileLinkLogger = (options, filename) => {
|
|
15
|
+
const logger = (0, winston_1.createLogger)(options);
|
|
16
|
+
filename
|
|
17
|
+
? logger.add(new winston_1.transports.File({
|
|
18
|
+
format: logFormatFile(),
|
|
19
|
+
filename,
|
|
20
|
+
}))
|
|
21
|
+
: logger.add(new winston_1.transports.Console({
|
|
22
|
+
format: logFormatConsole("[Mobile Link] "),
|
|
23
|
+
}));
|
|
24
|
+
return logger;
|
|
25
|
+
};
|
|
26
|
+
exports.createMobileLinkLogger = createMobileLinkLogger;
|
|
27
|
+
const setupMobileLinkOutputLogger = (childProcess, callback) => {
|
|
28
|
+
// stdout
|
|
29
|
+
(0, node_readline_1.createInterface)({
|
|
30
|
+
input: childProcess.stdout,
|
|
31
|
+
crlfDelay: Number.POSITIVE_INFINITY,
|
|
32
|
+
}).on("line", (line) => {
|
|
33
|
+
try {
|
|
34
|
+
callback(JSON.parse(line));
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
callback({
|
|
38
|
+
level: "info",
|
|
39
|
+
timestamp: new Date().toISOString(),
|
|
40
|
+
message: line,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
// stderr
|
|
45
|
+
childProcess.stderr.pipe(process.stderr);
|
|
46
|
+
};
|
|
47
|
+
exports.setupMobileLinkOutputLogger = setupMobileLinkOutputLogger;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Errors } from "@oclif/core";
|
|
2
|
+
import TypedEmitter from "typed-emitter";
|
|
3
|
+
export type MobileLinkEvents = TypedEmitter<{
|
|
4
|
+
log: (msg: string) => void;
|
|
5
|
+
starting: (msg: string) => void;
|
|
6
|
+
ready: (msg: string) => void;
|
|
7
|
+
reconnecting: (msg: string) => void;
|
|
8
|
+
error: (error: Error) => void;
|
|
9
|
+
}>;
|
|
10
|
+
export type ProcessExit = Readonly<{
|
|
11
|
+
code: number | null;
|
|
12
|
+
signal: NodeJS.Signals | null;
|
|
13
|
+
}>;
|
|
14
|
+
export declare class StateMachineTimeoutError extends Errors.CLIError {
|
|
15
|
+
constructor(state: string);
|
|
16
|
+
}
|
|
17
|
+
type MobileLinkManagerOptions = Readonly<{
|
|
18
|
+
configDir: string;
|
|
19
|
+
cacheDir: string;
|
|
20
|
+
}>;
|
|
21
|
+
export declare class MobileLinkManager {
|
|
22
|
+
private readonly options;
|
|
23
|
+
exec(argv: string[]): Promise<void>;
|
|
24
|
+
start(workspaceId?: string): Promise<void>;
|
|
25
|
+
onceReady(): Promise<void>;
|
|
26
|
+
onceTerminating(): Promise<void>;
|
|
27
|
+
onceDone(): Promise<number | null>;
|
|
28
|
+
exit(options?: {
|
|
29
|
+
ignoreError: boolean;
|
|
30
|
+
}): Promise<number | null>;
|
|
31
|
+
private readonly clientEvents;
|
|
32
|
+
private readonly logger;
|
|
33
|
+
private readonly clientLogger;
|
|
34
|
+
private readonly service;
|
|
35
|
+
private childProcess?;
|
|
36
|
+
constructor(options: MobileLinkManagerOptions);
|
|
37
|
+
private spawn;
|
|
38
|
+
private linkStart;
|
|
39
|
+
private terminate;
|
|
40
|
+
private kill;
|
|
41
|
+
private cleanup;
|
|
42
|
+
private once;
|
|
43
|
+
private get mobileLinkPath();
|
|
44
|
+
private getMobiieLinkVersion;
|
|
45
|
+
private get autifyConnectPath();
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MobileLinkManager = exports.StateMachineTimeoutError = void 0;
|
|
4
|
+
/* eslint-disable unicorn/filename-case */
|
|
5
|
+
const core_1 = require("@oclif/core");
|
|
6
|
+
const node_child_process_1 = require("node:child_process");
|
|
7
|
+
const node_process_1 = require("node:process");
|
|
8
|
+
const node_stream_1 = require("node:stream");
|
|
9
|
+
const installBinary_1 = require("../installBinary");
|
|
10
|
+
const installClient_1 = require("../../../connect/installClient");
|
|
11
|
+
const waitFor_1 = require("xstate/lib/waitFor");
|
|
12
|
+
const StateMachine_1 = require("./StateMachine");
|
|
13
|
+
const Logger_1 = require("./Logger");
|
|
14
|
+
class StateMachineTimeoutError extends core_1.Errors.CLIError {
|
|
15
|
+
constructor(state) {
|
|
16
|
+
super(`MobileLink Manager faced timeout at ${state} state.`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.StateMachineTimeoutError = StateMachineTimeoutError;
|
|
20
|
+
class MobileLinkManager {
|
|
21
|
+
async exec(argv) {
|
|
22
|
+
this.logger.debug("exec");
|
|
23
|
+
const version = await this.getMobiieLinkVersion();
|
|
24
|
+
this.logger.info(`Executing MobileLink (path: ${this.mobileLinkPath}, version: ${version})`);
|
|
25
|
+
this.spawn(argv);
|
|
26
|
+
}
|
|
27
|
+
async start(workspaceId) {
|
|
28
|
+
try {
|
|
29
|
+
this.logger.debug("start");
|
|
30
|
+
const version = await this.getMobiieLinkVersion();
|
|
31
|
+
this.logger.info(`Executing MobileLink (path: ${this.mobileLinkPath}, version: ${version})`);
|
|
32
|
+
this.service.send("START", { workspaceId });
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
this.service.send("FAIL", { error });
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async onceReady() {
|
|
40
|
+
this.logger.debug("onceReady");
|
|
41
|
+
await this.once("ready");
|
|
42
|
+
}
|
|
43
|
+
async onceTerminating() {
|
|
44
|
+
this.logger.debug("onceTerminating");
|
|
45
|
+
await this.once("terminating");
|
|
46
|
+
}
|
|
47
|
+
async onceDone() {
|
|
48
|
+
this.logger.debug("onceDone");
|
|
49
|
+
const { context: { processExit }, } = await this.once("done");
|
|
50
|
+
if (!processExit) {
|
|
51
|
+
this.logger.warn("MobileLink exited but unable to capture the exit status");
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
this.logger.info(`MobileLinkt exited (code: ${processExit.code}, signal: ${processExit.signal})`);
|
|
55
|
+
return processExit.code;
|
|
56
|
+
}
|
|
57
|
+
async exit(options) {
|
|
58
|
+
var _a;
|
|
59
|
+
try {
|
|
60
|
+
this.logger.debug("exit");
|
|
61
|
+
const snapshot = this.service.getSnapshot();
|
|
62
|
+
if (snapshot.done) {
|
|
63
|
+
this.logger.debug("Already exited.");
|
|
64
|
+
return ((_a = snapshot.context.processExit) === null || _a === void 0 ? void 0 : _a.code) || null;
|
|
65
|
+
}
|
|
66
|
+
this.service.send("TERMINATE");
|
|
67
|
+
return await this.onceDone();
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
if (options === null || options === void 0 ? void 0 : options.ignoreError) {
|
|
71
|
+
this.logger.warn(`Ignoring exit error: ${error}`);
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
constructor(options) {
|
|
78
|
+
this.options = options;
|
|
79
|
+
this.clientEvents = new node_stream_1.EventEmitter();
|
|
80
|
+
const level = "info";
|
|
81
|
+
this.logger = (0, Logger_1.createManagerLogger)({ level });
|
|
82
|
+
this.clientLogger = (0, Logger_1.createMobileLinkLogger)({ level });
|
|
83
|
+
this.service = (0, StateMachine_1.createService)({
|
|
84
|
+
start: (workspaceId) => this.linkStart(workspaceId),
|
|
85
|
+
terminate: () => this.terminate(),
|
|
86
|
+
kill: () => this.kill(),
|
|
87
|
+
cleanup: () => this.cleanup(),
|
|
88
|
+
errors: [],
|
|
89
|
+
}).onTransition((state, event) => {
|
|
90
|
+
if (!state.changed)
|
|
91
|
+
return;
|
|
92
|
+
this.logger.debug(`Transition to: ${state.value}, event: ${JSON.stringify(event)}`);
|
|
93
|
+
});
|
|
94
|
+
process.on("SIGINT", () => this.service.send("TERMINATE"));
|
|
95
|
+
process.on("SIGTERM", () => this.service.send("TERMINATE"));
|
|
96
|
+
this.clientEvents.on("ready", () => {
|
|
97
|
+
this.service.send("READY");
|
|
98
|
+
});
|
|
99
|
+
this.clientEvents.on("log", (msg) => {
|
|
100
|
+
// Guardrail in case debug server isn't working well.
|
|
101
|
+
if (msg.includes("Local devices are ready for use") ||
|
|
102
|
+
msg.includes("起動しました。ローカルデバイスを利用する準備ができました。")) {
|
|
103
|
+
this.clientEvents.emit("ready", msg);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
this.clientEvents.on("error", (error) => {
|
|
107
|
+
this.logger.warn(`Ignoring client error: ${error}`);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
spawn(argv, extraEnv = {}, connectConsole = true) {
|
|
111
|
+
this.childProcess = (0, node_child_process_1.spawn)(this.mobileLinkPath, argv, {
|
|
112
|
+
env: {
|
|
113
|
+
...node_process_1.env,
|
|
114
|
+
...extraEnv,
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
if (connectConsole) {
|
|
118
|
+
this.childProcess.stdout.on("data", (data) => {
|
|
119
|
+
process.stdout.write(data);
|
|
120
|
+
});
|
|
121
|
+
this.childProcess.stderr.on("data", (data) => {
|
|
122
|
+
process.stderr.write(data);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
linkStart(workspaceId) {
|
|
127
|
+
try {
|
|
128
|
+
const argv = ["link", "start"];
|
|
129
|
+
if (workspaceId)
|
|
130
|
+
argv.push(workspaceId);
|
|
131
|
+
this.spawn(argv, {
|
|
132
|
+
AUTIFY_CONNECT_BIN_PATH: this.autifyConnectPath,
|
|
133
|
+
}, false);
|
|
134
|
+
if (this.childProcess) {
|
|
135
|
+
this.childProcess.on("exit", (code, signal) => {
|
|
136
|
+
this.service.send("EXIT", { processExit: { code, signal } });
|
|
137
|
+
});
|
|
138
|
+
(0, Logger_1.setupMobileLinkOutputLogger)(this.childProcess, (log) => {
|
|
139
|
+
this.clientLogger.log(log.level, log.message);
|
|
140
|
+
this.clientEvents.emit("log", log.message);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
this.logger.warn(`Ignoring start error: ${error}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async terminate() {
|
|
149
|
+
try {
|
|
150
|
+
this.logger.debug("terminate");
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
this.logger.warn(`Ignoring terminate error: ${error}`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
kill() {
|
|
157
|
+
var _a;
|
|
158
|
+
try {
|
|
159
|
+
this.logger.debug("kill");
|
|
160
|
+
(_a = this.childProcess) === null || _a === void 0 ? void 0 : _a.kill();
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
this.logger.warn(`Ignoring kill error: ${error}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async cleanup() {
|
|
167
|
+
try {
|
|
168
|
+
this.logger.debug("cleanup start");
|
|
169
|
+
this.logger.debug("cleanup done");
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
this.logger.warn(`Ignoring cleanup error: ${error}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
async once(waitState) {
|
|
176
|
+
let state;
|
|
177
|
+
try {
|
|
178
|
+
state = await (0, waitFor_1.waitFor)(this.service, (state) => state.matches(waitState) ||
|
|
179
|
+
state.matches("done") ||
|
|
180
|
+
state.matches("failed"), {
|
|
181
|
+
timeout: Number.POSITIVE_INFINITY,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
throw new core_1.Errors.CLIError(`Unknown state transition: ${this.service.getSnapshot().value}`);
|
|
186
|
+
}
|
|
187
|
+
if (state.value === "failed")
|
|
188
|
+
this.logger.warn(`Failed (${state.context.errors})`);
|
|
189
|
+
const timeoutError = state.context.errors.find((error) => error instanceof StateMachineTimeoutError);
|
|
190
|
+
if (timeoutError)
|
|
191
|
+
throw timeoutError;
|
|
192
|
+
return state;
|
|
193
|
+
}
|
|
194
|
+
get mobileLinkPath() {
|
|
195
|
+
return (0, installBinary_1.getBinaryPath)(this.options.cacheDir);
|
|
196
|
+
}
|
|
197
|
+
async getMobiieLinkVersion() {
|
|
198
|
+
return (0, installBinary_1.getInstallVersion)(this.mobileLinkPath);
|
|
199
|
+
}
|
|
200
|
+
get autifyConnectPath() {
|
|
201
|
+
return (0, installClient_1.getInstallPath)(this.options.configDir, this.options.cacheDir);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
exports.MobileLinkManager = MobileLinkManager;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Interpreter } from "xstate";
|
|
2
|
+
import { ProcessExit } from "./MobileLinkManager";
|
|
3
|
+
type MobileLinkStateMachineContext = {
|
|
4
|
+
start: (workspaceId?: string) => void;
|
|
5
|
+
terminate: () => Promise<void>;
|
|
6
|
+
kill: () => void;
|
|
7
|
+
cleanup: () => Promise<void>;
|
|
8
|
+
processExit?: ProcessExit;
|
|
9
|
+
errors: Error[];
|
|
10
|
+
};
|
|
11
|
+
type MobileLinkStateMachineEvent = {
|
|
12
|
+
type: "START";
|
|
13
|
+
workspaceId?: string;
|
|
14
|
+
} | {
|
|
15
|
+
type: "READY";
|
|
16
|
+
} | {
|
|
17
|
+
type: "TERMINATE";
|
|
18
|
+
} | {
|
|
19
|
+
type: "FAIL";
|
|
20
|
+
error: Error;
|
|
21
|
+
} | {
|
|
22
|
+
type: "EXIT";
|
|
23
|
+
processExit: ProcessExit;
|
|
24
|
+
};
|
|
25
|
+
type MobileLinkStateMachineState = {
|
|
26
|
+
value: "init";
|
|
27
|
+
context: MobileLinkStateMachineContext;
|
|
28
|
+
} | {
|
|
29
|
+
value: "starting";
|
|
30
|
+
context: MobileLinkStateMachineContext;
|
|
31
|
+
} | {
|
|
32
|
+
value: "ready";
|
|
33
|
+
context: MobileLinkStateMachineContext;
|
|
34
|
+
} | {
|
|
35
|
+
value: "terminating";
|
|
36
|
+
context: MobileLinkStateMachineContext;
|
|
37
|
+
} | {
|
|
38
|
+
value: "killing";
|
|
39
|
+
context: MobileLinkStateMachineContext;
|
|
40
|
+
} | {
|
|
41
|
+
value: "timeout";
|
|
42
|
+
context: MobileLinkStateMachineContext;
|
|
43
|
+
} | {
|
|
44
|
+
value: "done";
|
|
45
|
+
context: MobileLinkStateMachineContext & {
|
|
46
|
+
processExit: ProcessExit;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
export type MobileLinkStateMachineService = Interpreter<MobileLinkStateMachineContext, any, MobileLinkStateMachineEvent, MobileLinkStateMachineState, any>;
|
|
50
|
+
export declare const createService: (context: MobileLinkStateMachineContext) => MobileLinkStateMachineService;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createService = void 0;
|
|
4
|
+
/* eslint-disable unicorn/filename-case */
|
|
5
|
+
const xstate_1 = require("xstate");
|
|
6
|
+
const MobileLinkManager_1 = require("./MobileLinkManager");
|
|
7
|
+
const createService = (context) => {
|
|
8
|
+
const machine = (0, xstate_1.createMachine)({
|
|
9
|
+
predictableActionArguments: true,
|
|
10
|
+
schema: {
|
|
11
|
+
context: {},
|
|
12
|
+
},
|
|
13
|
+
context,
|
|
14
|
+
initial: "init",
|
|
15
|
+
states: {
|
|
16
|
+
init: {
|
|
17
|
+
on: {
|
|
18
|
+
START: { target: "starting" },
|
|
19
|
+
FAIL: {
|
|
20
|
+
target: "done",
|
|
21
|
+
actions: (0, xstate_1.assign)({
|
|
22
|
+
errors: (context, event) => {
|
|
23
|
+
context.errors.push(event.error);
|
|
24
|
+
return context.errors;
|
|
25
|
+
},
|
|
26
|
+
}),
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
starting: {
|
|
31
|
+
entry: (context, event) => {
|
|
32
|
+
if (event.type !== "START")
|
|
33
|
+
return;
|
|
34
|
+
context.start(event.workspaceId);
|
|
35
|
+
},
|
|
36
|
+
on: {
|
|
37
|
+
READY: { target: "ready" },
|
|
38
|
+
TERMINATE: { target: "terminating" },
|
|
39
|
+
EXIT: {
|
|
40
|
+
target: "done",
|
|
41
|
+
actions: (0, xstate_1.assign)({
|
|
42
|
+
processExit: (_, event) => event.processExit,
|
|
43
|
+
}),
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
after: {
|
|
47
|
+
10000: {
|
|
48
|
+
target: "terminating",
|
|
49
|
+
actions: (0, xstate_1.assign)({
|
|
50
|
+
errors: (context) => {
|
|
51
|
+
context.errors.push(new MobileLinkManager_1.StateMachineTimeoutError("starting"));
|
|
52
|
+
return context.errors;
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
ready: {
|
|
59
|
+
on: {
|
|
60
|
+
TERMINATE: { target: "terminating" },
|
|
61
|
+
EXIT: {
|
|
62
|
+
target: "done",
|
|
63
|
+
actions: (0, xstate_1.assign)({
|
|
64
|
+
processExit: (_, event) => event.processExit,
|
|
65
|
+
}),
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
terminating: {
|
|
70
|
+
invoke: {
|
|
71
|
+
src: (context) => context.terminate(),
|
|
72
|
+
},
|
|
73
|
+
on: {
|
|
74
|
+
TERMINATE: { target: "killing" },
|
|
75
|
+
EXIT: {
|
|
76
|
+
target: "done",
|
|
77
|
+
actions: (0, xstate_1.assign)({
|
|
78
|
+
processExit: (_, event) => event.processExit,
|
|
79
|
+
}),
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
after: {
|
|
83
|
+
10000: { target: "killing" },
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
killing: {
|
|
87
|
+
entry: (context) => context.kill(),
|
|
88
|
+
on: {
|
|
89
|
+
TERMINATE: { target: "done" },
|
|
90
|
+
EXIT: {
|
|
91
|
+
target: "done",
|
|
92
|
+
actions: (0, xstate_1.assign)({
|
|
93
|
+
processExit: (_, event) => event.processExit,
|
|
94
|
+
}),
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
after: {
|
|
98
|
+
2000: {
|
|
99
|
+
target: "failed",
|
|
100
|
+
actions: (0, xstate_1.assign)({
|
|
101
|
+
errors: (context) => {
|
|
102
|
+
context.errors.push(new MobileLinkManager_1.StateMachineTimeoutError("killing"));
|
|
103
|
+
return context.errors;
|
|
104
|
+
},
|
|
105
|
+
}),
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
done: {
|
|
110
|
+
type: "final",
|
|
111
|
+
},
|
|
112
|
+
failed: {
|
|
113
|
+
type: "final",
|
|
114
|
+
entry: (context) => context.kill(),
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
return (0, xstate_1.interpret)(machine).start();
|
|
119
|
+
};
|
|
120
|
+
exports.createService = createService;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseTestPlanUrl = void 0;
|
|
4
4
|
/* eslint-disable unicorn/filename-case */
|
|
5
|
-
const
|
|
5
|
+
const core_1 = require("@oclif/core");
|
|
6
6
|
const parseTestPlanUrl = (url) => {
|
|
7
7
|
var _a, _b;
|
|
8
8
|
const { pathname } = new URL(url);
|
|
@@ -11,7 +11,7 @@ const parseTestPlanUrl = (url) => {
|
|
|
11
11
|
const workspaceId = (_a = match === null || match === void 0 ? void 0 : match.groups) === null || _a === void 0 ? void 0 : _a.workspaceId;
|
|
12
12
|
const testPlanId = (_b = match === null || match === void 0 ? void 0 : match.groups) === null || _b === void 0 ? void 0 : _b.testPlanId;
|
|
13
13
|
if (!workspaceId || !testPlanId)
|
|
14
|
-
throw new
|
|
14
|
+
throw new core_1.Errors.CLIError(`Invalid URL: ${url}`);
|
|
15
15
|
return { workspaceId, testPlanId };
|
|
16
16
|
};
|
|
17
17
|
exports.parseTestPlanUrl = parseTestPlanUrl;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseTestResultUrl = void 0;
|
|
4
4
|
/* eslint-disable unicorn/filename-case */
|
|
5
|
-
const
|
|
5
|
+
const core_1 = require("@oclif/core");
|
|
6
6
|
const parseTestResultUrl = (url) => {
|
|
7
7
|
var _a, _b;
|
|
8
8
|
const { pathname } = new URL(url);
|
|
@@ -11,7 +11,7 @@ const parseTestResultUrl = (url) => {
|
|
|
11
11
|
const workspaceId = (_a = match === null || match === void 0 ? void 0 : match.groups) === null || _a === void 0 ? void 0 : _a.workspaceId;
|
|
12
12
|
const resultId = (_b = match === null || match === void 0 ? void 0 : match.groups) === null || _b === void 0 ? void 0 : _b.resultId;
|
|
13
13
|
if (!workspaceId || !resultId)
|
|
14
|
-
throw new
|
|
14
|
+
throw new core_1.Errors.CLIError(`Invalid URL: ${url}`);
|
|
15
15
|
return { workspaceId, resultId };
|
|
16
16
|
};
|
|
17
17
|
exports.parseTestResultUrl = parseTestResultUrl;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.uploadBuild = void 0;
|
|
4
|
-
const
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
5
5
|
const inspectBuildFile_1 = require("./inspectBuildFile");
|
|
6
6
|
const uploadBuild = async (client, workspaceId, buildPath) => {
|
|
7
7
|
const [uploadPath, os] = await (0, inspectBuildFile_1.inspectBuildFile)(buildPath);
|
|
8
8
|
const res = await client.uploadBuild(workspaceId, uploadPath);
|
|
9
9
|
if (!res.data.id)
|
|
10
|
-
throw new
|
|
10
|
+
throw new core_1.Errors.CLIError(`Failed to upload ${buildPath}.`);
|
|
11
11
|
return [res.data.id, os];
|
|
12
12
|
};
|
|
13
13
|
exports.uploadBuild = uploadBuild;
|