@mobilenext/mobile-mcp 0.0.16 → 0.0.17

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.
@@ -39,38 +39,74 @@ class Simctl {
39
39
  async terminateApp(packageName) {
40
40
  this.simctl("terminate", this.simulatorUuid, packageName);
41
41
  }
42
- parseIOSAppData(inputText) {
42
+ static parseIOSAppData(inputText) {
43
43
  const result = [];
44
- // Remove leading and trailing characters if needed
45
- const cleanText = inputText.trim();
46
- // Extract each app section
47
- const appRegex = /"([^"]+)"\s+=\s+\{([^}]+)\};/g;
48
- let appMatch;
49
- while ((appMatch = appRegex.exec(cleanText)) !== null) {
50
- // const bundleId = appMatch[1];
51
- const appContent = appMatch[2];
52
- const appInfo = {};
53
- // parse simple key-value pairs
54
- const keyValueRegex = /\s+(\w+)\s+=\s+([^;]+);/g;
55
- let keyValueMatch;
56
- while ((keyValueMatch = keyValueRegex.exec(appContent)) !== null) {
57
- const key = keyValueMatch[1];
58
- let value = keyValueMatch[2].trim();
59
- // Handle quoted string values
60
- if (value.startsWith('"') && value.endsWith('"')) {
61
- value = value.substring(1, value.length - 1);
62
- }
63
- if (key !== "GroupContainers" && key !== "SBAppTags") {
64
- appInfo[key] = value;
65
- }
44
+ let ParseState;
45
+ (function (ParseState) {
46
+ ParseState[ParseState["LOOKING_FOR_APP"] = 0] = "LOOKING_FOR_APP";
47
+ ParseState[ParseState["IN_APP"] = 1] = "IN_APP";
48
+ ParseState[ParseState["IN_PROPERTY"] = 2] = "IN_PROPERTY";
49
+ })(ParseState || (ParseState = {}));
50
+ let state = ParseState.LOOKING_FOR_APP;
51
+ let currentApp = {};
52
+ let appIdentifier = "";
53
+ const lines = inputText.split("\n");
54
+ for (let line of lines) {
55
+ line = line.trim();
56
+ if (line === "") {
57
+ continue;
58
+ }
59
+ switch (state) {
60
+ case ParseState.LOOKING_FOR_APP:
61
+ // look for app identifier pattern: "com.example.app" = {
62
+ const appMatch = line.match(/^"?([^"=]+)"?\s*=\s*\{/);
63
+ if (appMatch) {
64
+ appIdentifier = appMatch[1].trim();
65
+ currentApp = {
66
+ CFBundleIdentifier: appIdentifier,
67
+ };
68
+ state = ParseState.IN_APP;
69
+ }
70
+ break;
71
+ case ParseState.IN_APP:
72
+ if (line === "};") {
73
+ result.push(currentApp);
74
+ currentApp = {};
75
+ state = ParseState.LOOKING_FOR_APP;
76
+ }
77
+ else {
78
+ // look for property: PropertyName = Value;
79
+ const propertyMatch = line.match(/^([^=]+)\s*=\s*(.+?);\s*$/);
80
+ if (propertyMatch) {
81
+ const propName = propertyMatch[1].trim();
82
+ let propValue = propertyMatch[2].trim();
83
+ // remove quotes if present (they're optional)
84
+ if (propValue.startsWith('"') && propValue.endsWith('"')) {
85
+ propValue = propValue.substring(1, propValue.length - 1);
86
+ }
87
+ // add property to current app
88
+ currentApp[propName] = propValue;
89
+ }
90
+ else if (line.endsWith("{")) {
91
+ // nested property like GroupContainers = {
92
+ state = ParseState.IN_PROPERTY;
93
+ }
94
+ }
95
+ break;
96
+ case ParseState.IN_PROPERTY:
97
+ if (line === "};") {
98
+ // end of nested property
99
+ state = ParseState.IN_APP;
100
+ }
101
+ // skip content of nested properties, we don't care of those right now
102
+ break;
66
103
  }
67
- result.push(appInfo);
68
104
  }
69
105
  return result;
70
106
  }
71
107
  async listApps() {
72
108
  const text = this.simctl("listapps", this.simulatorUuid).toString();
73
- const apps = this.parseIOSAppData(text);
109
+ const apps = Simctl.parseIOSAppData(text);
74
110
  return apps.map(app => ({
75
111
  packageName: app.CFBundleIdentifier,
76
112
  appName: app.CFBundleDisplayName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mobilenext/mobile-mcp",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "description": "Mobile MCP",
5
5
  "repository": {
6
6
  "type": "git",