@jetstart/cli 1.2.0 → 1.5.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.
Files changed (67) hide show
  1. package/dist/cli.js +18 -1
  2. package/dist/commands/android-emulator.d.ts +8 -0
  3. package/dist/commands/android-emulator.js +280 -0
  4. package/dist/commands/create.d.ts +1 -6
  5. package/dist/commands/create.js +119 -0
  6. package/dist/commands/dev.d.ts +1 -7
  7. package/dist/commands/dev.js +69 -10
  8. package/dist/commands/index.d.ts +2 -0
  9. package/dist/commands/index.js +5 -1
  10. package/dist/commands/install-audit.d.ts +9 -0
  11. package/dist/commands/install-audit.js +185 -0
  12. package/dist/types/index.d.ts +22 -0
  13. package/dist/types/index.js +8 -0
  14. package/dist/utils/android-sdk.d.ts +81 -0
  15. package/dist/utils/android-sdk.js +432 -0
  16. package/dist/utils/downloader.d.ts +35 -0
  17. package/dist/utils/downloader.js +214 -0
  18. package/dist/utils/emulator-deployer.d.ts +29 -0
  19. package/dist/utils/emulator-deployer.js +224 -0
  20. package/dist/utils/emulator.d.ts +101 -0
  21. package/dist/utils/emulator.js +410 -0
  22. package/dist/utils/java.d.ts +25 -0
  23. package/dist/utils/java.js +363 -0
  24. package/dist/utils/system-tools.d.ts +93 -0
  25. package/dist/utils/system-tools.js +599 -0
  26. package/dist/utils/template.js +777 -748
  27. package/package.json +7 -3
  28. package/src/cli.ts +20 -2
  29. package/src/commands/android-emulator.ts +304 -0
  30. package/src/commands/create.ts +128 -5
  31. package/src/commands/dev.ts +71 -18
  32. package/src/commands/index.ts +3 -1
  33. package/src/commands/install-audit.ts +227 -0
  34. package/src/types/index.ts +30 -0
  35. package/src/utils/android-sdk.ts +478 -0
  36. package/src/utils/downloader.ts +201 -0
  37. package/src/utils/emulator-deployer.ts +210 -0
  38. package/src/utils/emulator.ts +463 -0
  39. package/src/utils/java.ts +369 -0
  40. package/src/utils/system-tools.ts +648 -0
  41. package/src/utils/template.ts +875 -867
  42. package/dist/cli.d.ts.map +0 -1
  43. package/dist/cli.js.map +0 -1
  44. package/dist/commands/build.d.ts.map +0 -1
  45. package/dist/commands/build.js.map +0 -1
  46. package/dist/commands/create.d.ts.map +0 -1
  47. package/dist/commands/create.js.map +0 -1
  48. package/dist/commands/dev.d.ts.map +0 -1
  49. package/dist/commands/dev.js.map +0 -1
  50. package/dist/commands/index.d.ts.map +0 -1
  51. package/dist/commands/index.js.map +0 -1
  52. package/dist/commands/logs.d.ts.map +0 -1
  53. package/dist/commands/logs.js.map +0 -1
  54. package/dist/index.d.ts.map +0 -1
  55. package/dist/index.js.map +0 -1
  56. package/dist/types/index.d.ts.map +0 -1
  57. package/dist/types/index.js.map +0 -1
  58. package/dist/utils/index.d.ts.map +0 -1
  59. package/dist/utils/index.js.map +0 -1
  60. package/dist/utils/logger.d.ts.map +0 -1
  61. package/dist/utils/logger.js.map +0 -1
  62. package/dist/utils/prompt.d.ts.map +0 -1
  63. package/dist/utils/prompt.js.map +0 -1
  64. package/dist/utils/spinner.d.ts.map +0 -1
  65. package/dist/utils/spinner.js.map +0 -1
  66. package/dist/utils/template.d.ts.map +0 -1
  67. package/dist/utils/template.js.map +0 -1
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Android Emulator Deployment utilities
3
+ */
4
+ export declare class EmulatorDeployer {
5
+ private adbPath;
6
+ private serial;
7
+ constructor(adbPath: string, serial: string);
8
+ /**
9
+ * Install APK on emulator
10
+ */
11
+ installAPK(apkPath: string, packageName?: string): Promise<void>;
12
+ /**
13
+ * Launch app on emulator
14
+ */
15
+ launchApp(packageName: string, activityName?: string): Promise<void>;
16
+ /**
17
+ * Check if device is ready
18
+ */
19
+ isDeviceReady(): Promise<boolean>;
20
+ /**
21
+ * Wait for device to be ready
22
+ */
23
+ waitForDevice(timeout?: number): Promise<void>;
24
+ /**
25
+ * Find or select emulator
26
+ */
27
+ static findOrSelectEmulator(targetAVD?: string): Promise<EmulatorDeployer>;
28
+ }
29
+ //# sourceMappingURL=emulator-deployer.d.ts.map
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+ /**
3
+ * Android Emulator Deployment utilities
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.EmulatorDeployer = void 0;
43
+ const child_process_1 = require("child_process");
44
+ const util_1 = require("util");
45
+ const fs = __importStar(require("fs-extra"));
46
+ const inquirer_1 = __importDefault(require("inquirer"));
47
+ const emulator_1 = require("./emulator");
48
+ const spinner_1 = require("./spinner");
49
+ const logger_1 = require("./logger");
50
+ const execAsync = (0, util_1.promisify)(child_process_1.exec);
51
+ class EmulatorDeployer {
52
+ adbPath;
53
+ serial;
54
+ constructor(adbPath, serial) {
55
+ this.adbPath = adbPath;
56
+ this.serial = serial;
57
+ }
58
+ /**
59
+ * Install APK on emulator
60
+ */
61
+ async installAPK(apkPath, packageName) {
62
+ const spinner = (0, spinner_1.startSpinner)('Installing APK on emulator...');
63
+ try {
64
+ // Verify APK exists
65
+ if (!(await fs.pathExists(apkPath))) {
66
+ throw new Error(`APK not found: ${apkPath}`);
67
+ }
68
+ // Use -r flag to reinstall if already exists
69
+ const { stdout, stderr } = await execAsync(`"${this.adbPath}" -s ${this.serial} install -r "${apkPath}"`);
70
+ if (stderr && stderr.includes('INSTALL_FAILED')) {
71
+ throw new Error(stderr);
72
+ }
73
+ (0, spinner_1.stopSpinner)(spinner, true, 'APK installed on emulator');
74
+ }
75
+ catch (error) {
76
+ (0, spinner_1.stopSpinner)(spinner, false, 'Failed to install APK');
77
+ throw error;
78
+ }
79
+ }
80
+ /**
81
+ * Launch app on emulator
82
+ */
83
+ async launchApp(packageName, activityName = 'MainActivity') {
84
+ const spinner = (0, spinner_1.startSpinner)('Launching app on emulator...');
85
+ try {
86
+ await execAsync(`"${this.adbPath}" -s ${this.serial} shell am start -n ${packageName}/.${activityName}`);
87
+ (0, spinner_1.stopSpinner)(spinner, true, 'App launched on emulator');
88
+ }
89
+ catch (error) {
90
+ (0, spinner_1.stopSpinner)(spinner, false, 'Failed to launch app');
91
+ // Don't throw - launching is optional
92
+ (0, logger_1.error)(`Launch failed: ${error.message}`);
93
+ }
94
+ }
95
+ /**
96
+ * Check if device is ready
97
+ */
98
+ async isDeviceReady() {
99
+ try {
100
+ const { stdout } = await execAsync(`"${this.adbPath}" -s ${this.serial} shell getprop sys.boot_completed`);
101
+ return stdout.trim() === '1';
102
+ }
103
+ catch {
104
+ return false;
105
+ }
106
+ }
107
+ /**
108
+ * Wait for device to be ready
109
+ */
110
+ async waitForDevice(timeout = 120000) {
111
+ const spinner = (0, spinner_1.startSpinner)('Waiting for emulator to boot...');
112
+ const startTime = Date.now();
113
+ while (Date.now() - startTime < timeout) {
114
+ if (await this.isDeviceReady()) {
115
+ (0, spinner_1.stopSpinner)(spinner, true, 'Emulator ready');
116
+ return;
117
+ }
118
+ await new Promise((resolve) => setTimeout(resolve, 2000));
119
+ }
120
+ (0, spinner_1.stopSpinner)(spinner, false, 'Emulator boot timeout');
121
+ throw new Error('Emulator failed to boot within timeout');
122
+ }
123
+ /**
124
+ * Find or select emulator
125
+ */
126
+ static async findOrSelectEmulator(targetAVD) {
127
+ const avdManager = (0, emulator_1.createAVDManager)();
128
+ try {
129
+ // First, try the AVD manager approach
130
+ const avds = await avdManager.listAVDs();
131
+ const runningAVDs = avds.filter((a) => a.running);
132
+ if (runningAVDs.length > 0) {
133
+ let selectedAVD;
134
+ if (targetAVD) {
135
+ // User specified a specific AVD
136
+ selectedAVD = runningAVDs.find((a) => a.name === targetAVD);
137
+ if (!selectedAVD) {
138
+ throw new Error(`Emulator "${targetAVD}" is not running`);
139
+ }
140
+ }
141
+ else if (runningAVDs.length === 1) {
142
+ // Only one running - use it
143
+ selectedAVD = runningAVDs[0];
144
+ (0, logger_1.info)(`Using emulator: ${selectedAVD.name}`);
145
+ }
146
+ else {
147
+ // Multiple running - prompt user
148
+ const { avdName } = await inquirer_1.default.prompt([
149
+ {
150
+ type: 'list',
151
+ name: 'avdName',
152
+ message: 'Multiple emulators running. Select one:',
153
+ choices: runningAVDs.map((a) => ({
154
+ name: `${a.name} (${a.target || 'Unknown'})`,
155
+ value: a.name,
156
+ })),
157
+ },
158
+ ]);
159
+ selectedAVD = runningAVDs.find((a) => a.name === avdName);
160
+ }
161
+ // Get serial for this AVD
162
+ const serial = await avdManager.findEmulatorSerial(selectedAVD.name);
163
+ if (serial) {
164
+ const adbPath = avdManager.getADBPath();
165
+ return new EmulatorDeployer(adbPath, serial);
166
+ }
167
+ }
168
+ }
169
+ catch (err) {
170
+ // Fallback to simpler ADB-based detection
171
+ (0, logger_1.info)('Falling back to ADB device detection...');
172
+ }
173
+ // Fallback: Just use adb devices directly
174
+ const adbPath = avdManager.getADBPath();
175
+ (0, logger_1.info)(`ADB path: ${adbPath}`);
176
+ let stdout;
177
+ try {
178
+ const result = await execAsync(`"${adbPath}" devices`);
179
+ stdout = result.stdout;
180
+ (0, logger_1.info)(`ADB devices output:\n${stdout}`);
181
+ }
182
+ catch (err) {
183
+ (0, logger_1.error)(`Failed to run adb devices: ${err.message}`);
184
+ throw new Error('Failed to detect emulators. Make sure ADB is accessible.');
185
+ }
186
+ const lines = stdout.split('\n');
187
+ const devices = [];
188
+ for (const line of lines) {
189
+ const trimmedLine = line.trim();
190
+ (0, logger_1.info)(`Checking line: "${trimmedLine}"`);
191
+ const match = trimmedLine.match(/^(emulator-\d+)\s+device$/);
192
+ if (match) {
193
+ devices.push(match[1]);
194
+ (0, logger_1.info)(`Found emulator: ${match[1]}`);
195
+ }
196
+ }
197
+ if (devices.length === 0) {
198
+ throw new Error('No running emulators found. Start one with "jetstart android-emulator"');
199
+ }
200
+ let selectedSerial;
201
+ if (devices.length === 1) {
202
+ selectedSerial = devices[0];
203
+ (0, logger_1.info)(`Using emulator: ${selectedSerial}`);
204
+ }
205
+ else {
206
+ // Multiple running - prompt user
207
+ const { serial } = await inquirer_1.default.prompt([
208
+ {
209
+ type: 'list',
210
+ name: 'serial',
211
+ message: 'Multiple emulators running. Select one:',
212
+ choices: devices.map((d) => ({
213
+ name: d,
214
+ value: d,
215
+ })),
216
+ },
217
+ ]);
218
+ selectedSerial = serial;
219
+ }
220
+ return new EmulatorDeployer(adbPath, selectedSerial);
221
+ }
222
+ }
223
+ exports.EmulatorDeployer = EmulatorDeployer;
224
+ //# sourceMappingURL=emulator-deployer.js.map
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Android AVD and Emulator management utilities
3
+ */
4
+ import { ChildProcess } from 'child_process';
5
+ export interface AVDInfo {
6
+ name: string;
7
+ device: string;
8
+ path: string;
9
+ target: string;
10
+ basedOn?: string;
11
+ skin?: string;
12
+ sdcard?: string;
13
+ snapshot: boolean;
14
+ running?: boolean;
15
+ }
16
+ export interface CreateAVDOptions {
17
+ name: string;
18
+ device?: string;
19
+ apiLevel?: number;
20
+ abi?: string;
21
+ force?: boolean;
22
+ }
23
+ export interface EmulatorOptions {
24
+ avdName: string;
25
+ gpu?: 'auto' | 'host' | 'swiftshader_indirect' | 'angle_indirect' | 'guest';
26
+ noSnapshot?: boolean;
27
+ noBootAnim?: boolean;
28
+ wipeData?: boolean;
29
+ }
30
+ /**
31
+ * AVD Manager class
32
+ */
33
+ export declare class AVDManager {
34
+ private sdkRoot;
35
+ constructor(sdkRoot?: string);
36
+ /**
37
+ * Ensure SDK root is set
38
+ */
39
+ private ensureSDKRoot;
40
+ /**
41
+ * Get path to avdmanager executable
42
+ */
43
+ private getAVDManagerPath;
44
+ /**
45
+ * Get path to emulator executable
46
+ */
47
+ private getEmulatorPath;
48
+ /**
49
+ * Get path to adb executable
50
+ */
51
+ private getADBPath;
52
+ /**
53
+ * Run avdmanager command
54
+ */
55
+ private runAVDManager;
56
+ /**
57
+ * List all AVDs
58
+ */
59
+ listAVDs(): Promise<AVDInfo[]>;
60
+ /**
61
+ * Parse avdmanager list avd output
62
+ */
63
+ private parseAVDList;
64
+ /**
65
+ * Create a new AVD
66
+ */
67
+ createAVD(options: CreateAVDOptions): Promise<void>;
68
+ /**
69
+ * Delete an AVD
70
+ */
71
+ deleteAVD(name: string): Promise<void>;
72
+ /**
73
+ * Start an emulator
74
+ */
75
+ startEmulator(options: EmulatorOptions): Promise<ChildProcess>;
76
+ /**
77
+ * Stop an emulator
78
+ */
79
+ stopEmulator(avdName: string): Promise<void>;
80
+ /**
81
+ * Check if an emulator is running
82
+ */
83
+ isEmulatorRunning(avdName: string): Promise<boolean>;
84
+ /**
85
+ * Find emulator serial number by AVD name
86
+ */
87
+ private findEmulatorSerial;
88
+ /**
89
+ * Get list of available system images for emulator
90
+ */
91
+ listSystemImages(): Promise<string[]>;
92
+ /**
93
+ * Create JetStart-optimized AVD
94
+ */
95
+ createJetStartAVD(): Promise<void>;
96
+ }
97
+ /**
98
+ * Create an AVD manager instance
99
+ */
100
+ export declare function createAVDManager(sdkRoot?: string): AVDManager;
101
+ //# sourceMappingURL=emulator.d.ts.map