Skip to content

Commit b63921f

Browse files
committed
Merge pull request #76 from NativeScript/fatme/fixes
Fixes and improvements
2 parents e0a8d4f + c514d1b commit b63921f

File tree

5 files changed

+22
-30
lines changed

5 files changed

+22
-30
lines changed

lib/services/android-project-service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class AndroidProjectService implements IPlatformProjectService {
4646
this.validateAndroidTarget(frameworkDir); // We need framework to be installed to validate android target so we can't call this method in validate()
4747

4848
var paths = "assets gen libs res".split(' ').map(p => path.join(frameworkDir, p));
49-
shell.cp("-r", paths, projectRoot);
49+
shell.cp("-R", paths, projectRoot);
5050

5151
paths = ".project AndroidManifest.xml project.properties".split(' ').map(p => path.join(frameworkDir, p));
5252
shell.cp("-f", paths, projectRoot);
@@ -91,11 +91,11 @@ class AndroidProjectService implements IPlatformProjectService {
9191
var assetsDirectory = path.join(platformData.projectRoot, "assets");
9292
var resDirectory = path.join(platformData.projectRoot, "res");
9393

94-
shell.cp("-r", path.join(appSourceDirectory, "*"), assetsDirectory);
94+
shell.cp("-Rf", path.join(appSourceDirectory, "*"), assetsDirectory);
9595

9696
var appResourcesDirectoryPath = path.join(assetsDirectory, constants.APP_RESOURCES_FOLDER_NAME);
9797
if (this.$fs.exists(appResourcesDirectoryPath).wait()) {
98-
shell.cp("-r", path.join(appResourcesDirectoryPath, platformData.normalizedPlatformName, "*"), resDirectory);
98+
shell.cp("-Rf", path.join(appResourcesDirectoryPath, platformData.normalizedPlatformName, "*"), resDirectory);
9999
this.$fs.deleteDirectory(appResourcesDirectoryPath).wait();
100100
}
101101

@@ -118,12 +118,12 @@ class AndroidProjectService implements IPlatformProjectService {
118118
command = 'cmd';
119119
}
120120

121-
var child = this.$childProcess.spawn(command, args, {stdio: "inherit"});
122-
return this.$fs.futureFromEvent(child, "close");
121+
return this.$childProcess.spawnFromEvent(command, args, "close", {stdio: "inherit"});
123122
}
124123

125124
private getAntArgs(configuration: string, projectRoot: string): string[] {
126125
var args = [configuration, "-f", path.join(projectRoot, "build.xml")];
126+
127127
return args;
128128
}
129129

lib/services/ios-project-service.ts

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class IOSProjectService implements IPlatformProjectService {
6161

6262
public createProject(projectRoot: string, frameworkDir: string): IFuture<void> {
6363
return (() => {
64-
shell.cp("-r", path.join(frameworkDir, "*"), projectRoot);
64+
shell.cp("-R", path.join(frameworkDir, "*"), projectRoot);
6565
}).future<void>()();
6666
}
6767

@@ -89,11 +89,11 @@ class IOSProjectService implements IPlatformProjectService {
8989
var appDestinationDirectory = path.join(platformData.projectRoot, this.$projectData.projectName);
9090
var resDirectory = path.join(platformData.projectRoot, this.$projectData.projectName, "Resources", "icons");
9191

92-
shell.cp("-r", path.join(appSourceDirectory, "*"), appDestinationDirectory);
92+
shell.cp("-Rf", path.join(appSourceDirectory, "*"), appDestinationDirectory);
9393

9494
var appResourcesDirectoryPath = path.join(appDestinationDirectory, constants.APP_RESOURCES_FOLDER_NAME);
9595
if (this.$fs.exists(appResourcesDirectoryPath).wait()) {
96-
shell.cp("-r", path.join(appResourcesDirectoryPath, platformData.normalizedPlatformName, "*"), resDirectory);
96+
shell.cp("-Rf", path.join(appResourcesDirectoryPath, platformData.normalizedPlatformName, "*"), resDirectory);
9797
this.$fs.deleteDirectory(appResourcesDirectoryPath).wait();
9898
}
9999

@@ -128,7 +128,7 @@ class IOSProjectService implements IPlatformProjectService {
128128
]);
129129
}
130130

131-
this.spawn("xcodebuild", args, "exit", {cwd: options, stdio: 'inherit'}).wait();
131+
this.$childProcess.spawnFromEvent("xcodebuild", args, "exit", {cwd: options, stdio: 'inherit'}).wait();
132132

133133
if(options.device) {
134134
var buildOutputPath = path.join(projectRoot, "build", options.device ? "device" : "emulator");
@@ -141,29 +141,11 @@ class IOSProjectService implements IPlatformProjectService {
141141
"-o", path.join(buildOutputPath, this.$projectData.projectName + ".ipa")
142142
];
143143

144-
this.spawn("xcrun", xcrunArgs, "exit", {cwd: options, stdio: 'inherit'}).wait();
144+
this.$childProcess.spawnFromEvent("xcrun", xcrunArgs, "exit", {cwd: options, stdio: 'inherit'}).wait();
145145
}
146146
}).future<void>()();
147147
}
148148

149-
private spawn(command: string, args: string[], event: string, options?: any): IFuture<void> { // event should be exit or close
150-
var future = new Future<void>();
151-
var childProcess = this.$childProcess.spawn(command, args, options);
152-
childProcess.once(event, () => {
153-
var args = _.toArray(arguments);
154-
var statusCode = args[0];
155-
var signal = args[1];
156-
157-
if(statusCode !== 0) {
158-
future.throw(util.format("Command %s exited with code %s", command, statusCode));
159-
} else {
160-
future.return();
161-
}
162-
});
163-
164-
return future;
165-
}
166-
167149
private replaceFileContent(file: string): IFuture<void> {
168150
return (() => {
169151
var fileContent = this.$fs.readText(file).wait();

lib/services/platform-service.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,19 @@ export class PlatformService implements IPlatformService {
143143

144144
var appDirectoryPath = path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME);
145145
var contents = this.$fs.readDirectory(appDirectoryPath).wait();
146+
var files: string[] = [];
146147

147148
_.each(contents, d => {
148149
var fsStat = this.$fs.getFsStats(path.join(appDirectoryPath, d)).wait();
149150
if(fsStat.isDirectory() && d !== constants.APP_RESOURCES_FOLDER_NAME) {
150151
this.processPlatformSpecificFiles(platform, helpers.enumerateFilesInDirectorySync(path.join(appFilesLocation, d))).wait();
152+
} else if(fsStat.isFile()) {
153+
files.push(path.join(appFilesLocation,d));
151154
}
152155
});
153156

157+
this.processPlatformSpecificFiles(platform, files).wait();
158+
154159
this.$logger.out("Project successfully prepared");
155160

156161
}).future<void>()();
@@ -236,7 +241,9 @@ export class PlatformService implements IPlatformService {
236241
var packageFile = this.getLatestApplicationPackageForEmulator(platformData).wait().packageName;
237242
this.$logger.out("Using ", packageFile);
238243

239-
emulatorServices.startEmulator(packageFile, options.emulator).wait();
244+
var logFilePath = path.join(platformData.projectRoot, this.$projectData.projectName, "emulator.log");
245+
246+
emulatorServices.startEmulator(packageFile, {image: options.emulator, stderrFilePath: logFilePath, stdoutFilePath: logFilePath }).wait();
240247
}).future<void>()();
241248
}
242249

resources/help.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ General commands:
1515
This lets you build the project with the SDK for the selected platform and deploy it on device.
1616
build Builds the project for the selected target platform and produces an application package.
1717
deploy Deploys the project to a connected device.
18+
emulate Deploys the project on emulator.
1819
run Runs your project on a connected device. This is shorthand for prepare, build, and deploy.
1920
list-devices Lists all recognized connected devices.
2021
feature-usage-tracking Configures anonymous feature usage tracking.
@@ -177,6 +178,8 @@ Runs your project on a connected device. This is shorthand for prepare, build, a
177178
Usage:
178179
$ tns emulate [<platform>]
179180

181+
Deploys the project on emulator.
182+
180183
--[/]--
181184

182185
--[list-devices]--

0 commit comments

Comments
 (0)