@autifyhq/autify-cli 0.51.0 → 0.53.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 +143 -39
- 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 +53 -0
- package/dist/autify/mobile/mobilelink/mobile-link-manager/MobileLinkManager.js +215 -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/doctor.d.ts +6 -0
- package/dist/commands/mobile/link/doctor.js +19 -0
- 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/setup.d.ts +6 -0
- package/dist/commands/mobile/link/setup.js +45 -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.d.ts +1 -0
- package/dist/commands/mobile/test/run.js +10 -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 +782 -641
- package/package.json +20 -22
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.createZip = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
|
-
const
|
|
6
|
+
const core_1 = require("@oclif/core");
|
|
7
7
|
const node_child_process_1 = require("node:child_process");
|
|
8
8
|
const node_fs_1 = require("node:fs");
|
|
9
9
|
const node_path_1 = require("node:path");
|
|
@@ -15,7 +15,7 @@ const node_os_1 = require("node:os");
|
|
|
15
15
|
const promises_1 = require("node:fs/promises");
|
|
16
16
|
const checkBuildPath = (buildPath) => {
|
|
17
17
|
if (!(0, node_fs_1.lstatSync)(buildPath).isDirectory()) {
|
|
18
|
-
throw new
|
|
18
|
+
throw new core_1.Errors.CLIError(`Build path (${buildPath}) is expected to directory.`);
|
|
19
19
|
}
|
|
20
20
|
const parentPath = (0, node_path_1.resolve)((0, node_path_1.dirname)(buildPath));
|
|
21
21
|
const name = (0, node_path_1.basename)(buildPath);
|
|
@@ -45,7 +45,7 @@ const createZip = async (buildPath) => {
|
|
|
45
45
|
await zipStream.close();
|
|
46
46
|
}
|
|
47
47
|
catch (error) {
|
|
48
|
-
throw new
|
|
48
|
+
throw new core_1.Errors.CLIError(`Failed to create a valid zip file (${zipFile}): ${error}`);
|
|
49
49
|
}
|
|
50
50
|
return zipFile;
|
|
51
51
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.inspectBuildFile = void 0;
|
|
4
4
|
/* eslint-disable unicorn/filename-case */
|
|
5
|
-
const
|
|
5
|
+
const core_1 = require("@oclif/core");
|
|
6
6
|
const node_fs_1 = require("node:fs");
|
|
7
7
|
const createZip_1 = require("./createZip");
|
|
8
8
|
const isIosApp = (buildPath) => {
|
|
@@ -18,7 +18,7 @@ const getOs = (buildPath) => {
|
|
|
18
18
|
return "ios";
|
|
19
19
|
if (isAndroidApp(buildPath))
|
|
20
20
|
return "android";
|
|
21
|
-
throw new
|
|
21
|
+
throw new core_1.Errors.CLIError(`${buildPath} doesn't look like iOS app nor Android apk.`);
|
|
22
22
|
};
|
|
23
23
|
const getUploadPath = async (buildPath, os) => {
|
|
24
24
|
if (os === "ios") {
|
|
@@ -28,7 +28,7 @@ const getUploadPath = async (buildPath, os) => {
|
|
|
28
28
|
}
|
|
29
29
|
if (os === "android")
|
|
30
30
|
return buildPath;
|
|
31
|
-
throw new
|
|
31
|
+
throw new core_1.Errors.CLIError(`Invalid os: ${os}`);
|
|
32
32
|
};
|
|
33
33
|
const inspectBuildFile = async (buildPath) => {
|
|
34
34
|
const os = getOs(buildPath);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const getMobileLinkSourceUrl: (configDir: string) => URL;
|
|
2
|
+
export declare const getInstallPath: (cacheDir: string) => string;
|
|
3
|
+
export declare const getBinaryPath: (cacheDir: string) => string;
|
|
4
|
+
export declare const getInstallVersion: (path: string) => Promise<string>;
|
|
5
|
+
export declare const installBinary: (cacheDir: string, url: URL) => Promise<{
|
|
6
|
+
version: string;
|
|
7
|
+
path: string;
|
|
8
|
+
}>;
|
|
@@ -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,53 @@
|
|
|
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[], extraEnv?: {
|
|
24
|
+
[key: string]: string;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
start(workspaceId?: string): Promise<void>;
|
|
27
|
+
setup(): Promise<void>;
|
|
28
|
+
doctor(): Promise<void>;
|
|
29
|
+
onceReady(): Promise<void>;
|
|
30
|
+
onceTerminating(): Promise<void>;
|
|
31
|
+
onceDone(): Promise<number | null>;
|
|
32
|
+
exit(options?: {
|
|
33
|
+
ignoreError: boolean;
|
|
34
|
+
}): Promise<number | null>;
|
|
35
|
+
private readonly clientEvents;
|
|
36
|
+
private readonly logger;
|
|
37
|
+
private readonly clientLogger;
|
|
38
|
+
private readonly service;
|
|
39
|
+
private childProcess?;
|
|
40
|
+
constructor(options: MobileLinkManagerOptions);
|
|
41
|
+
private spawn;
|
|
42
|
+
private linkStart;
|
|
43
|
+
private terminate;
|
|
44
|
+
private kill;
|
|
45
|
+
private cleanup;
|
|
46
|
+
private once;
|
|
47
|
+
private get mobileLinkPath();
|
|
48
|
+
private getMobiieLinkVersion;
|
|
49
|
+
private get autifyConnectPath();
|
|
50
|
+
private get accessToken();
|
|
51
|
+
private get integrationVariables();
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,215 @@
|
|
|
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
|
+
const config_1 = require("../../../../config");
|
|
15
|
+
class StateMachineTimeoutError extends core_1.Errors.CLIError {
|
|
16
|
+
constructor(state) {
|
|
17
|
+
super(`MobileLink Manager faced timeout at ${state} state.`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.StateMachineTimeoutError = StateMachineTimeoutError;
|
|
21
|
+
class MobileLinkManager {
|
|
22
|
+
async exec(argv, extraEnv = {}) {
|
|
23
|
+
this.logger.debug("exec");
|
|
24
|
+
const version = await this.getMobiieLinkVersion();
|
|
25
|
+
this.logger.info(`Executing MobileLink (path: ${this.mobileLinkPath}, args: ${argv.join(" ")}, version: ${version})`);
|
|
26
|
+
this.spawn(argv, extraEnv);
|
|
27
|
+
}
|
|
28
|
+
async start(workspaceId) {
|
|
29
|
+
try {
|
|
30
|
+
this.logger.debug("start");
|
|
31
|
+
const version = await this.getMobiieLinkVersion();
|
|
32
|
+
this.logger.info(`Executing MobileLink (path: ${this.mobileLinkPath}, args: link start, version: ${version})`);
|
|
33
|
+
this.service.send("START", { workspaceId });
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
this.service.send("FAIL", { error });
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async setup() {
|
|
41
|
+
this.exec(["link", "setup"], this.integrationVariables);
|
|
42
|
+
}
|
|
43
|
+
async doctor() {
|
|
44
|
+
this.exec(["link", "doctor"], this.integrationVariables);
|
|
45
|
+
}
|
|
46
|
+
async onceReady() {
|
|
47
|
+
this.logger.debug("onceReady");
|
|
48
|
+
await this.once("ready");
|
|
49
|
+
}
|
|
50
|
+
async onceTerminating() {
|
|
51
|
+
this.logger.debug("onceTerminating");
|
|
52
|
+
await this.once("terminating");
|
|
53
|
+
}
|
|
54
|
+
async onceDone() {
|
|
55
|
+
this.logger.debug("onceDone");
|
|
56
|
+
const { context: { processExit }, } = await this.once("done");
|
|
57
|
+
if (!processExit) {
|
|
58
|
+
this.logger.warn("MobileLink exited but unable to capture the exit status");
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
this.logger.info(`MobileLinkt exited (code: ${processExit.code}, signal: ${processExit.signal})`);
|
|
62
|
+
return processExit.code;
|
|
63
|
+
}
|
|
64
|
+
async exit(options) {
|
|
65
|
+
var _a;
|
|
66
|
+
try {
|
|
67
|
+
this.logger.debug("exit");
|
|
68
|
+
const snapshot = this.service.getSnapshot();
|
|
69
|
+
if (snapshot.done) {
|
|
70
|
+
this.logger.debug("Already exited.");
|
|
71
|
+
return ((_a = snapshot.context.processExit) === null || _a === void 0 ? void 0 : _a.code) || null;
|
|
72
|
+
}
|
|
73
|
+
this.service.send("TERMINATE");
|
|
74
|
+
return await this.onceDone();
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (options === null || options === void 0 ? void 0 : options.ignoreError) {
|
|
78
|
+
this.logger.warn(`Ignoring exit error: ${error}`);
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
constructor(options) {
|
|
85
|
+
this.options = options;
|
|
86
|
+
this.clientEvents = new node_stream_1.EventEmitter();
|
|
87
|
+
const level = "info";
|
|
88
|
+
this.logger = (0, Logger_1.createManagerLogger)({ level });
|
|
89
|
+
this.clientLogger = (0, Logger_1.createMobileLinkLogger)({ level });
|
|
90
|
+
this.service = (0, StateMachine_1.createService)({
|
|
91
|
+
start: (workspaceId) => this.linkStart(workspaceId),
|
|
92
|
+
terminate: () => this.terminate(),
|
|
93
|
+
kill: () => this.kill(),
|
|
94
|
+
cleanup: () => this.cleanup(),
|
|
95
|
+
errors: [],
|
|
96
|
+
}).onTransition((state, event) => {
|
|
97
|
+
if (!state.changed)
|
|
98
|
+
return;
|
|
99
|
+
this.logger.debug(`Transition to: ${state.value}, event: ${JSON.stringify(event)}`);
|
|
100
|
+
});
|
|
101
|
+
process.on("SIGINT", () => this.service.send("TERMINATE"));
|
|
102
|
+
process.on("SIGTERM", () => this.service.send("TERMINATE"));
|
|
103
|
+
this.clientEvents.on("ready", () => {
|
|
104
|
+
this.service.send("READY");
|
|
105
|
+
});
|
|
106
|
+
this.clientEvents.on("log", (msg) => {
|
|
107
|
+
// Guardrail in case debug server isn't working well.
|
|
108
|
+
if (msg.includes("Local devices are ready for use") ||
|
|
109
|
+
msg.includes("起動しました。ローカルデバイスを利用する準備ができました。")) {
|
|
110
|
+
this.clientEvents.emit("ready", msg);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
this.clientEvents.on("error", (error) => {
|
|
114
|
+
this.logger.warn(`Ignoring client error: ${error}`);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
spawn(argv, extraEnv = {}, connectConsole = true) {
|
|
118
|
+
this.childProcess = (0, node_child_process_1.spawn)(this.mobileLinkPath, argv, {
|
|
119
|
+
env: {
|
|
120
|
+
...node_process_1.env,
|
|
121
|
+
...extraEnv,
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
if (connectConsole) {
|
|
125
|
+
this.childProcess.stdout.pipe(process.stdout);
|
|
126
|
+
this.childProcess.stderr.pipe(process.stderr);
|
|
127
|
+
process.stdin.pipe(this.childProcess.stdin);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
linkStart(workspaceId) {
|
|
131
|
+
try {
|
|
132
|
+
const argv = ["link", "start"];
|
|
133
|
+
if (workspaceId)
|
|
134
|
+
argv.push(workspaceId);
|
|
135
|
+
this.spawn(argv, this.integrationVariables, false);
|
|
136
|
+
if (this.childProcess) {
|
|
137
|
+
this.childProcess.on("exit", (code, signal) => {
|
|
138
|
+
this.service.send("EXIT", { processExit: { code, signal } });
|
|
139
|
+
});
|
|
140
|
+
(0, Logger_1.setupMobileLinkOutputLogger)(this.childProcess, (log) => {
|
|
141
|
+
this.clientLogger.log(log.level, log.message);
|
|
142
|
+
this.clientEvents.emit("log", log.message);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
this.logger.warn(`Ignoring start error: ${error}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async terminate() {
|
|
151
|
+
try {
|
|
152
|
+
this.logger.debug("terminate");
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
this.logger.warn(`Ignoring terminate error: ${error}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
kill() {
|
|
159
|
+
var _a;
|
|
160
|
+
try {
|
|
161
|
+
this.logger.debug("kill");
|
|
162
|
+
(_a = this.childProcess) === null || _a === void 0 ? void 0 : _a.kill();
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
this.logger.warn(`Ignoring kill error: ${error}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async cleanup() {
|
|
169
|
+
try {
|
|
170
|
+
this.logger.debug("cleanup start");
|
|
171
|
+
this.logger.debug("cleanup done");
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
this.logger.warn(`Ignoring cleanup error: ${error}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
async once(waitState) {
|
|
178
|
+
let state;
|
|
179
|
+
try {
|
|
180
|
+
state = await (0, waitFor_1.waitFor)(this.service, (state) => state.matches(waitState) ||
|
|
181
|
+
state.matches("done") ||
|
|
182
|
+
state.matches("failed"), {
|
|
183
|
+
timeout: Number.POSITIVE_INFINITY,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
throw new core_1.Errors.CLIError(`Unknown state transition: ${this.service.getSnapshot().value}`);
|
|
188
|
+
}
|
|
189
|
+
if (state.value === "failed")
|
|
190
|
+
this.logger.warn(`Failed (${state.context.errors})`);
|
|
191
|
+
const timeoutError = state.context.errors.find((error) => error instanceof StateMachineTimeoutError);
|
|
192
|
+
if (timeoutError)
|
|
193
|
+
throw timeoutError;
|
|
194
|
+
return state;
|
|
195
|
+
}
|
|
196
|
+
get mobileLinkPath() {
|
|
197
|
+
return (0, installBinary_1.getBinaryPath)(this.options.cacheDir);
|
|
198
|
+
}
|
|
199
|
+
async getMobiieLinkVersion() {
|
|
200
|
+
return (0, installBinary_1.getInstallVersion)(this.mobileLinkPath);
|
|
201
|
+
}
|
|
202
|
+
get autifyConnectPath() {
|
|
203
|
+
return (0, installClient_1.getInstallPath)(this.options.configDir, this.options.cacheDir);
|
|
204
|
+
}
|
|
205
|
+
get accessToken() {
|
|
206
|
+
return (0, config_1.getOrThrow)(this.options.configDir, "AUTIFY_MOBILE_ACCESS_TOKEN");
|
|
207
|
+
}
|
|
208
|
+
get integrationVariables() {
|
|
209
|
+
return {
|
|
210
|
+
AUTIFY_CONNECT_BIN_PATH: this.autifyConnectPath,
|
|
211
|
+
AUTIFY_MOBILE_ACCESS_TOKEN: this.accessToken,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
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 {};
|