Skip to content

Commit 9b83cda

Browse files
nadyaADimitar Kerezov
authored andcommitted
WIP
1 parent 2f3745a commit 9b83cda

File tree

7 files changed

+115
-67
lines changed

7 files changed

+115
-67
lines changed

lib/providers/livesync-provider.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import * as path from "path";
22
import * as temp from "temp";
3+
import { TNS_MODULES_FOLDER_NAME } from "../constants";
34

45
export class LiveSyncProvider implements ILiveSyncProvider {
56
constructor(private $androidLiveSyncServiceLocator: { factory: Function },
67
private $iosLiveSyncServiceLocator: { factory: Function },
78
private $platformService: IPlatformService,
89
private $platformsData: IPlatformsData,
910
private $logger: ILogger,
10-
private $childProcess: IChildProcess,
11-
private $options: IOptions) { }
11+
private $options: IOptions,
12+
private $mobileHelper: Mobile.IMobileHelper,
13+
private $fs: IFileSystem) { }
1214

1315
private static FAST_SYNC_FILE_EXTENSIONS = [".css", ".xml", ".html"];
1416

@@ -63,21 +65,25 @@ export class LiveSyncProvider implements ILiveSyncProvider {
6365
}
6466

6567
public async transferFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string, isFullSync: boolean): Promise<void> {
66-
if (deviceAppData.platform.toLowerCase() === "android" || !deviceAppData.deviceSyncZipPath || !isFullSync) {
68+
if (this.$mobileHelper.isAndroidPlatform(deviceAppData.platform) || !deviceAppData.deviceSyncZipPath || !isFullSync) {
6769
await deviceAppData.device.fileSystem.transferFiles(deviceAppData, localToDevicePaths);
6870
} else {
6971
temp.track();
7072
let tempZip = temp.path({ prefix: "sync", suffix: ".zip" });
73+
let tempApp = temp.mkdirSync("app");
7174
this.$logger.trace("Creating zip file: " + tempZip);
75+
this.$fs.copyFile(path.join(path.dirname(projectFilesPath), "app/*"), tempApp);
7276

73-
if (this.$options.syncAllFiles) {
74-
await this.$childProcess.spawnFromEvent("zip", ["-r", "-0", tempZip, "app"], "close", { cwd: path.dirname(projectFilesPath) });
75-
} else {
77+
if (!this.$options.syncAllFiles) {
7678
this.$logger.info("Skipping node_modules folder! Use the syncAllFiles option to sync files from this folder.");
77-
await this.$childProcess.spawnFromEvent("zip", ["-r", "-0", tempZip, "app", "-x", "app/tns_modules/*"], "close", { cwd: path.dirname(projectFilesPath) });
79+
this.$fs.deleteDirectory(path.join(tempApp, TNS_MODULES_FOLDER_NAME));
7880
}
7981

80-
deviceAppData.device.fileSystem.transferFiles(deviceAppData, [{
82+
await this.$fs.zipFiles(tempZip, this.$fs.enumerateFilesInDirectorySync(tempApp), (res) => {
83+
return path.join("app", path.relative(tempApp, res));
84+
});
85+
86+
await deviceAppData.device.fileSystem.transferFiles(deviceAppData, [{
8187
getLocalPath: () => tempZip,
8288
getDevicePath: () => deviceAppData.deviceSyncZipPath,
8389
getRelativeToProjectBasePath: () => "../sync.zip",

lib/services/ios-project-service.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as plist from "plist";
1313
import { IOSProvisionService } from "./ios-provision-service";
1414
import { IOSEntitlementsService } from "./ios-entitlements-service";
1515
import { XCConfigService } from "./xcconfig-service";
16+
const simplePlist = require("simple-plist");
1617

1718
export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServiceBase implements IPlatformProjectService {
1819
private static XCODE_PROJECT_EXT_NAME = ".xcodeproj";
@@ -39,6 +40,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
3940
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
4041
private $devicesService: Mobile.IDevicesService,
4142
private $mobileHelper: Mobile.IMobileHelper,
43+
private $hostInfo: IHostInfo,
4244
private $pluginVariablesService: IPluginVariablesService,
4345
private $xcprojService: IXcprojService,
4446
private $iOSProvisionService: IOSProvisionService,
@@ -111,6 +113,10 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
111113
}
112114

113115
public async validate(): Promise<void> {
116+
if (!this.$hostInfo.isDarwin) {
117+
return;
118+
}
119+
114120
try {
115121
await this.$childProcess.exec("which xcodebuild");
116122
} catch (error) {
@@ -492,12 +498,12 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
492498
}
493499

494500
private async addFramework(frameworkPath: string, projectData: IProjectData): Promise<void> {
495-
await this.validateFramework(frameworkPath);
501+
this.validateFramework(frameworkPath);
496502

497503
let project = this.createPbxProj(projectData);
498504
let frameworkName = path.basename(frameworkPath, path.extname(frameworkPath));
499505
let frameworkBinaryPath = path.join(frameworkPath, frameworkName);
500-
let isDynamic = _.includes((await this.$childProcess.spawnFromEvent("otool", ["-Vh", frameworkBinaryPath], "close")).stdout, " DYLIB ");
506+
let isDynamic = _.includes((await this.$childProcess.spawnFromEvent(path.join(__dirname, "..", "..", "vendor", "file", "file.exe"), [frameworkBinaryPath], "close")).stdout, "dynamically linked");
501507

502508
let frameworkAddOptions: IXcode.Options = { customFramework: true };
503509

@@ -918,17 +924,18 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
918924
return path.join(newModulesDir, constants.PROJECT_FRAMEWORK_FOLDER_NAME, `${IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER}.xcodeproj`, "project.pbxproj");
919925
}
920926

921-
private async validateFramework(libraryPath: string): Promise<void> {
922-
let infoPlistPath = path.join(libraryPath, "Info.plist");
927+
private validateFramework(libraryPath: string): void {
928+
const infoPlistPath = path.join(libraryPath, "Info.plist");
923929
if (!this.$fs.exists(infoPlistPath)) {
924930
this.$errors.failWithoutHelp("The bundle at %s does not contain an Info.plist file.", libraryPath);
925931
}
926932

927-
let packageType = (await this.$childProcess.spawnFromEvent("/usr/libexec/PlistBuddy", ["-c", "Print :CFBundlePackageType", infoPlistPath], "close")).stdout.trim();
933+
const plistJson = simplePlist.readFileSync(infoPlistPath);
934+
const packageType = plistJson["CFBundlePackageType"];
935+
928936
if (packageType !== "FMWK") {
929937
this.$errors.failWithoutHelp("The bundle at %s does not appear to be a dynamic framework.", libraryPath);
930938
}
931-
932939
}
933940

934941
private async validateStaticLibrary(libraryPath: string): Promise<void> {
@@ -997,9 +1004,9 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
9971004
}
9981005

9991006
private async prepareFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData, projectData: IProjectData): Promise<void> {
1000-
for (let fileName of this.getAllLibsForPluginWithFileExtension(pluginData, ".framework")) {
1001-
await this.addFramework(path.join(pluginPlatformsFolderPath, fileName), projectData);
1002-
}
1007+
await _.each(this.getAllLibsForPluginWithFileExtension(pluginData, ".framework"), (fileName) => {
1008+
this.addFramework(path.join(pluginPlatformsFolderPath, fileName), projectData);
1009+
});
10031010
}
10041011

10051012
private async prepareStaticLibs(pluginPlatformsFolderPath: string, pluginData: IPluginData, projectData: IProjectData): Promise<void> {
@@ -1107,11 +1114,13 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
11071114
this.$fs.writeFile(projectFile, "");
11081115
}
11091116

1110-
await this.checkIfXcodeprojIsRequired();
1111-
let escapedProjectFile = projectFile.replace(/'/g, "\\'"),
1112-
escapedPluginFile = pluginFile.replace(/'/g, "\\'"),
1113-
mergeScript = `require 'xcodeproj'; Xcodeproj::Config.new('${escapedProjectFile}').merge(Xcodeproj::Config.new('${escapedPluginFile}')).save_as(Pathname.new('${escapedProjectFile}'))`;
1114-
await this.$childProcess.exec(`ruby -e "${mergeScript}"`);
1117+
if (this.$hostInfo.isDarwin) {
1118+
await this.checkIfXcodeprojIsRequired();
1119+
let escapedProjectFile = projectFile.replace(/'/g, "\\'"),
1120+
escapedPluginFile = pluginFile.replace(/'/g, "\\'"),
1121+
mergeScript = `require 'xcodeproj'; Xcodeproj::Config.new('${escapedProjectFile}').merge(Xcodeproj::Config.new('${escapedPluginFile}')).save_as(Pathname.new('${escapedProjectFile}'))`;
1122+
await this.$childProcess.exec(`ruby -e "${mergeScript}"`);
1123+
}
11151124
}
11161125

11171126
private async mergeProjectXcconfigFiles(release: boolean, projectData: IProjectData): Promise<void> {

lib/services/platform-service.ts

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -370,32 +370,34 @@ export class PlatformService extends EventEmitter implements IPlatformService {
370370
}
371371

372372
public async shouldBuild(platform: string, projectData: IProjectData, buildConfig: IBuildConfig): Promise<boolean> {
373-
if (this.$projectChangesService.currentChanges.changesRequireBuild) {
374-
return true;
375-
}
376-
let platformData = this.$platformsData.getPlatformData(platform, projectData);
377-
let forDevice = !buildConfig || buildConfig.buildForDevice;
378-
let outputPath = forDevice ? platformData.deviceBuildOutputPath : platformData.emulatorBuildOutputPath;
379-
if (!this.$fs.exists(outputPath)) {
380-
return true;
381-
}
382-
let packageNames = platformData.getValidPackageNames({ isForDevice: forDevice });
383-
let packages = this.getApplicationPackages(outputPath, packageNames);
384-
if (packages.length === 0) {
385-
return true;
386-
}
387-
let prepareInfo = this.$projectChangesService.getPrepareInfo(platform, projectData);
388-
let buildInfo = this.getBuildInfo(platform, platformData, buildConfig);
389-
if (!prepareInfo || !buildInfo) {
390-
return true;
391-
}
392-
if (buildConfig.clean) {
393-
return true;
394-
}
395-
if (prepareInfo.time === buildInfo.prepareTime) {
396-
return false;
397-
}
398-
return prepareInfo.changesRequireBuildTime !== buildInfo.prepareTime;
373+
//TODO: shouldBuild - issue with outputPath - we do not have always the built dir locally
374+
return false;
375+
// if (this.$projectChangesService.currentChanges.changesRequireBuild) {
376+
// return true;
377+
// }
378+
// let platformData = this.$platformsData.getPlatformData(platform, projectData);
379+
// let forDevice = !buildConfig || buildConfig.buildForDevice;
380+
// let outputPath = forDevice ? platformData.deviceBuildOutputPath : platformData.emulatorBuildOutputPath;
381+
// if (!this.$fs.exists(outputPath)) {
382+
// return true;
383+
// }
384+
// let packageNames = platformData.getValidPackageNames({ isForDevice: forDevice });
385+
// let packages = this.getApplicationPackages(outputPath, packageNames);
386+
// if (packages.length === 0) {
387+
// return true;
388+
// }
389+
// let prepareInfo = this.$projectChangesService.getPrepareInfo(platform, projectData);
390+
// let buildInfo = this.getBuildInfo(platform, platformData, buildConfig);
391+
// if (!prepareInfo || !buildInfo) {
392+
// return true;
393+
// }
394+
// if (buildConfig.clean) {
395+
// return true;
396+
// }
397+
// if (prepareInfo.time === buildInfo.prepareTime) {
398+
// return false;
399+
// }
400+
// return prepareInfo.changesRequireBuildTime !== buildInfo.prepareTime;
399401
}
400402

401403
public async trackProjectType(projectData: IProjectData): Promise<void> {
@@ -462,25 +464,25 @@ export class PlatformService extends EventEmitter implements IPlatformService {
462464

463465
public async installApplication(device: Mobile.IDevice, buildConfig: IBuildConfig, projectData: IProjectData): Promise<void> {
464466
this.$logger.out("Installing...");
465-
let platformData = this.$platformsData.getPlatformData(device.deviceInfo.platform, projectData);
466-
let packageFile = "";
467-
if (this.$devicesService.isiOSSimulator(device)) {
468-
packageFile = this.getLatestApplicationPackageForEmulator(platformData, buildConfig).packageName;
469-
} else {
470-
packageFile = this.getLatestApplicationPackageForDevice(platformData, buildConfig).packageName;
471-
}
467+
// let platformData = this.$platformsData.getPlatformData(device.deviceInfo.platform, projectData);
468+
// let packageFile = "";
469+
// if (this.$devicesService.isiOSSimulator(device)) {
470+
// packageFile = this.getLatestApplicationPackageForEmulator(platformData, buildConfig).packageName;
471+
// } else {
472+
// packageFile = this.getLatestApplicationPackageForDevice(platformData, buildConfig).packageName;
473+
// }
472474

473-
await platformData.platformProjectService.cleanDeviceTempFolder(device.deviceInfo.identifier, projectData);
475+
// await platformData.platformProjectService.cleanDeviceTempFolder(device.deviceInfo.identifier, projectData);
474476

475-
await device.applicationManager.reinstallApplication(projectData.projectId, packageFile);
477+
// await device.applicationManager.reinstallApplication(projectData.projectId, packageFile);
476478

477-
if (!buildConfig.release) {
478-
let deviceFilePath = await this.getDeviceBuildInfoFilePath(device, projectData);
479-
let buildInfoFilePath = this.getBuildOutputPath(device.deviceInfo.platform, platformData, { buildForDevice: !device.isEmulator });
480-
let appIdentifier = projectData.projectId;
479+
// if (!buildConfig.release) {
480+
// let deviceFilePath = await this.getDeviceBuildInfoFilePath(device, projectData);
481+
// let buildInfoFilePath = this.getBuildOutputPath(device.deviceInfo.platform, platformData, { buildForDevice: !device.isEmulator });
482+
// let appIdentifier = projectData.projectId;
481483

482-
await device.fileSystem.putFile(path.join(buildInfoFilePath, buildInfoFileName), deviceFilePath, appIdentifier);
483-
}
484+
// await device.fileSystem.putFile(path.join(buildInfoFilePath, buildInfoFileName), deviceFilePath, appIdentifier);
485+
// }
484486

485487
this.$logger.out(`Successfully installed on device with identifier '${device.deviceInfo.identifier}'.`);
486488
}
@@ -678,9 +680,10 @@ export class PlatformService extends EventEmitter implements IPlatformService {
678680
this.$errors.fail("Invalid platform %s. Valid platforms are %s.", platform, helpers.formatListOfNames(this.$platformsData.platformsNames));
679681
}
680682

681-
if (!this.isPlatformSupportedForOS(platform, projectData)) {
682-
this.$errors.fail("Applications for platform %s can not be built on this OS - %s", platform, process.platform);
683-
}
683+
//TODO: move to commands.
684+
// if (!this.isPlatformSupportedForOS(platform, projectData)) {
685+
// this.$errors.fail("Applications for platform %s can not be built on this OS - %s", platform, process.platform);
686+
// }
684687
}
685688

686689
public validatePlatformInstalled(platform: string, projectData: IProjectData): void {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"request": "2.81.0",
6767
"semver": "5.3.0",
6868
"shelljs": "0.7.6",
69+
"simple-plist": "0.2.1",
6970
"source-map": "0.5.6",
7071
"tabtab": "https://github.com/Icenium/node-tabtab/tarball/master",
7172
"temp": "0.8.3",

vendor/file/COPYING

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
$File: COPYING,v 1.1 2008/02/05 19:08:11 christos Exp $
2+
Copyright (c) Ian F. Darwin 1986, 1987, 1989, 1990, 1991, 1992, 1994, 1995.
3+
Software written by Ian F. Darwin and others;
4+
maintained 1994- Christos Zoulas.
5+
6+
This software is not subject to any export provision of the United States
7+
Department of Commerce, and may be exported to any country or planet.
8+
9+
Redistribution and use in source and binary forms, with or without
10+
modification, are permitted provided that the following conditions
11+
are met:
12+
1. Redistributions of source code must retain the above copyright
13+
notice immediately at the beginning of the file, without modification,
14+
this list of conditions, and the following disclaimer.
15+
2. Redistributions in binary form must reproduce the above copyright
16+
notice, this list of conditions and the following disclaimer in the
17+
documentation and/or other materials provided with the distribution.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29+
SUCH DAMAGE.

vendor/file/file.exe

21.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)