Skip to content

Commit c432780

Browse files
committed
1 parent 3bed927 commit c432780

File tree

2 files changed

+58
-30
lines changed

2 files changed

+58
-30
lines changed

src/debug-adapter/webKitDebugAdapter.ts

+45-30
Original file line numberDiff line numberDiff line change
@@ -141,41 +141,56 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
141141
this._request = new DebugRequest(args, Services.cli());
142142
Services.extensionClient().analyticsLaunchDebugger({ request: this._request.isSync ? "sync" : args.request, platform: args.platform });
143143

144-
// Run CLI Command
145-
let cliCommand: DebugResult;
146-
if (this._request.isLaunch) {
147-
cliCommand = this._request.project.debug({ stopOnEntry: this._request.launchArgs.stopOnEntry }, this._request.args.tnsArgs);
148-
}
149-
else if (this._request.isSync) {
150-
cliCommand = this._request.project.debugWithSync({ stopOnEntry: this._request.launchArgs.stopOnEntry, syncAllFiles: this._request.launchArgs.syncAllFiles }, this._request.args.tnsArgs);
151-
}
152-
else if (this._request.isAttach) {
153-
cliCommand = this._request.project.attach(this._request.args.tnsArgs);
144+
// FIXME: Workaround for https://github.com/NativeScript/nativescript-cli/issues/2292
145+
let cliBuildCommand = Promise.resolve();
146+
if (this._request.isSync && !fs.existsSync(this._request.project.platformBuildPath())) {
147+
cliBuildCommand = new Promise((resolve, reject) => {
148+
let cliBuildProcess = this._request.project.build([]);
149+
cliBuildProcess.stdout.on('data', data => { Services.logger().log(data.toString(), Tags.FrontendMessage); });
150+
cliBuildProcess.stderr.on('data', data => { Services.logger().error(data.toString(), Tags.FrontendMessage); });
151+
cliBuildProcess.on('close', (code) => {
152+
code ? reject(`The build command exited with code: ${code}`) : resolve();
153+
});
154+
});
154155
}
155156

156-
if (cliCommand.tnsProcess) {
157-
cliCommand.tnsProcess.stdout.on('data', data => { Services.logger().log(data.toString(), Tags.FrontendMessage); });
158-
cliCommand.tnsProcess.stderr.on('data', data => { Services.logger().error(data.toString(), Tags.FrontendMessage); });
159-
cliCommand.tnsProcess.on('close', (code, signal) => { Services.logger().error(`The tns command finished its execution with code ${code}.`, Tags.FrontendMessage); });
160-
}
157+
return cliBuildCommand.then(() => {
158+
// Run CLI Command
159+
let cliCommand: DebugResult;
160+
if (this._request.isLaunch) {
161+
cliCommand = this._request.project.debug({ stopOnEntry: this._request.launchArgs.stopOnEntry }, this._request.args.tnsArgs);
162+
}
163+
else if (this._request.isSync) {
164+
cliCommand = this._request.project.debugWithSync({ stopOnEntry: this._request.launchArgs.stopOnEntry, syncAllFiles: this._request.launchArgs.syncAllFiles }, this._request.args.tnsArgs);
165+
}
166+
else if (this._request.isAttach) {
167+
cliCommand = this._request.project.attach(this._request.args.tnsArgs);
168+
}
169+
170+
if (cliCommand.tnsProcess) {
171+
cliCommand.tnsProcess.stdout.on('data', data => { Services.logger().log(data.toString(), Tags.FrontendMessage); });
172+
cliCommand.tnsProcess.stderr.on('data', data => { Services.logger().error(data.toString(), Tags.FrontendMessage); });
173+
cliCommand.tnsProcess.on('close', (code, signal) => { Services.logger().error(`The tns command finished its execution with code ${code}.`, Tags.FrontendMessage); });
174+
}
161175

162-
let promiseResolve = null;
163-
let promise: Promise<void> = new Promise<void>((res, rej) => { promiseResolve = res; });
164-
// Attach to the running application
165-
cliCommand.tnsOutputEventEmitter.on('readyForConnection', (connectionToken: string | number) => {
166-
connectionToken = this._request.isAndroid ? this._request.androidProject.getDebugPortSync() : connectionToken;
167-
Services.logger().log(`Attaching to application on ${connectionToken}`);
168-
let connection: INSDebugConnection = this._request.isAndroid ? new AndroidConnection() : new IosConnection();
169-
this.setConnection(connection);
170-
let attachPromise = this._request.isAndroid ? (<AndroidConnection>connection).attach(<number>connectionToken, 'localhost') : (<IosConnection>connection).attach(<string>connectionToken);
171-
attachPromise.then(() => {
172-
// Send InitializedEvent
173-
this.fireEvent(new InitializedEvent());
174-
promiseResolve();
176+
let promiseResolve = null;
177+
let promise: Promise<void> = new Promise<void>((res, rej) => { promiseResolve = res; });
178+
// Attach to the running application
179+
cliCommand.tnsOutputEventEmitter.on('readyForConnection', (connectionToken: string | number) => {
180+
connectionToken = this._request.isAndroid ? this._request.androidProject.getDebugPortSync() : connectionToken;
181+
Services.logger().log(`Attaching to application on ${connectionToken}`);
182+
let connection: INSDebugConnection = this._request.isAndroid ? new AndroidConnection() : new IosConnection();
183+
this.setConnection(connection);
184+
let attachPromise = this._request.isAndroid ? (<AndroidConnection>connection).attach(<number>connectionToken, 'localhost') : (<IosConnection>connection).attach(<string>connectionToken);
185+
attachPromise.then(() => {
186+
// Send InitializedEvent
187+
this.fireEvent(new InitializedEvent());
188+
promiseResolve();
189+
});
175190
});
176-
});
177191

178-
return promise;
192+
return promise;
193+
});
179194
});
180195

181196
}

src/project/project.ts

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {ChildProcess} from 'child_process';
22
import {EventEmitter} from 'events';
3+
import * as path from 'path';
34
import {Version} from '../common/version';
45
import {NativeScriptCli} from './nativeScriptCli';
56

@@ -20,6 +21,14 @@ export abstract class Project {
2021

2122
public abstract platformName(): string;
2223

24+
public platformBuildPath(): string {
25+
return path.join(this.appRoot, 'platforms', this.platformName(), 'build');
26+
}
27+
28+
public build(tnsArgs: string[]): ChildProcess {
29+
return this.executeBuildCommand(tnsArgs);
30+
}
31+
2332
public run(tnsArgs?: string[]): ChildProcess {
2433
return this.executeRunCommand(tnsArgs);
2534
}
@@ -34,6 +43,10 @@ export abstract class Project {
3443
return this.cli.execute(["run", this.platformName()].concat(args), this._appRoot);
3544
}
3645

46+
protected executeBuildCommand(args: string[]): ChildProcess {
47+
return this.cli.execute(["build", this.platformName()].concat(args), this._appRoot);
48+
}
49+
3750
protected executeDebugCommand(args: string[]): ChildProcess {
3851
return this.cli.execute(["debug", this.platformName(), "--no-client"].concat(args), this._appRoot);
3952
}

0 commit comments

Comments
 (0)