Skip to content

Test-PR-INCOMPLETE #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ module.exports = function(grunt) {
npm_test: {
command: "npm test"
}

},

copy: {
Expand Down Expand Up @@ -133,6 +132,7 @@ module.exports = function(grunt) {
grunt.registerTask("pack", [
"clean",
"ts:release_build",
"shell:npm_test",

"set_package_version",
"shell:build_package",
Expand Down
1 change: 1 addition & 0 deletions lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ $injector.requireCommand("create", "./commands/create-project");
$injector.requireCommand("platform|*list", "./commands/list-platforms");
$injector.requireCommand("platform|add", "./commands/add-platform");
$injector.requireCommand("platform|remove", "./commands/remove-platform");
$injector.requireCommand("platform|update", "./commands/update-platform");
$injector.requireCommand("run", "./commands/run");
$injector.requireCommand("prepare", "./commands/prepare");
$injector.requireCommand("build", "./commands/build");
Expand Down
12 changes: 12 additions & 0 deletions lib/commands/update-platform.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
///<reference path="../.d.ts"/>

export class UpdatePlatformCommand implements ICommand {
constructor(private $platformService: IPlatformService) { }

execute(args: string[]): IFuture<void> {
return (() => {
this.$platformService.updatePlatforms(args).wait();
}).future<void>()();
}
}
$injector.registerCommand("platform|update", UpdatePlatformCommand);
2 changes: 2 additions & 0 deletions lib/definitions/platform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ interface IPlatformService {
preparePlatform(platform: string): IFuture<void>;
buildPlatform(platform: string): IFuture<void>;
deploy(platform: string): IFuture<void>;
removePlatforms(platforms: string[]): IFuture<void>;
updatePlatforms(platforms: string[]): IFuture<void>;
}

interface IPlatformData {
Expand Down
71 changes: 71 additions & 0 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,77 @@ export class PlatformService implements IPlatformService {
}).future<void>()();
}

public updatePlatforms(platforms: string[]): IFuture<void> {
return (() => {
if(!platforms || platforms.length === 0) {
this.$errors.fail("No platforms specified. Please specify a platform to update");
}

_.each(platforms, platform => {
if (!this.isPlatformInstalled(platform).wait())
{
this.addPlatform(platform.toLowerCase()).wait();
}
else
{
this.updatePlatform(platform.toLowerCase()).wait();
}
});

}).future<void>()();
}

private updatePlatform(platform: string): IFuture<void> {
return(() => {

this.validatePlatform(platform);

var platformPath = path.join(this.$projectData.platformsDir, platform);
if (!this.$fs.exists(platformPath).wait()) {
this.addPlatform(platform).wait();
}
// var parts = platform.split("@");
// platform = parts[0];
// var version = parts[1];
//
// this.validatePlatform(platform);
//
// var platformPath = path.join(this.$projectData.platformsDir, platform);
// if (this.$fs.exists(platformPath).wait()) {
// this.$errors.fail("Platform %s already added", platform);
// }
//
// var platformData = this.$platformsData.getPlatformData(platform);
//
// // Copy platform specific files in platforms dir
// var platformProjectService = platformData.platformProjectService;
// platformProjectService.validate().wait();
//
// // Log the values for project
// this.$logger.trace("Creating NativeScript project for the %s platform", platform);
// this.$logger.trace("Path: %s", platformData.projectRoot);
// this.$logger.trace("Package: %s", this.$projectData.projectId);
// this.$logger.trace("Name: %s", this.$projectData.projectName);
//
// this.$logger.out("Copying template files...");
//
// // get path to downloaded framework package
// var frameworkDir = this.$npm.install(platformData.frameworkPackageName,
// path.join(this.$projectData.platformsDir, platform), version).wait();
// frameworkDir = path.join(frameworkDir, constants.PROJECT_FRAMEWORK_FOLDER_NAME);
//
// try {
// this.addPlatformCore(platformData, frameworkDir).wait();
// } catch(err) {
// this.$fs.deleteDirectory(platformPath).wait();
// throw err;
// }
//
// this.$logger.out("Project successfully created.");

}).future<void>()();
}

private validatePlatform(platform: string): void {
if(!platform) {
this.$errors.fail("No platform specified.")
Expand Down
88 changes: 76 additions & 12 deletions test/platform-service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/// <reference path=".d.ts" />

import PlatformServiceLib = require('../lib/services/platform-service');
import NodePackageManagerLib = require('../lib/node-package-manager');
import ProjectLib = require('../lib/services/project-service');
import stubs = require('./stubs');
import PlatformServiceLib = require("../lib/services/platform-service");
import NodePackageManagerLib = require("../lib/node-package-manager");
import ProjectLib = require("../lib/services/project-service");
import stubs = require("./stubs");

import yok = require('../lib/common/yok');
import yok = require("../lib/common/yok");

require('should');
require("should");

var testInjector = new yok.Yok();
testInjector.register('platformService', PlatformServiceLib.PlatformService);
Expand All @@ -20,11 +20,75 @@ testInjector.register('platformsData', stubs.PlatformsDataStub);
testInjector.register('devicesServices', {});

describe('PlatformService', function(){
describe('#updatePlatforms()', function(){
it('should fail when no services provided', function(){
var platformService = testInjector.resolve('platformService');
(function(){return platformService.updatePlatforms().wait(); }).should.throw();
describe('#updatePlatforms()', function(){
it('should fail if no services provided and no services exist', function(){
var platformService = testInjector.resolve('platformService');
(function(){return platformService.updatePlatforms().wait(); }).should.throw();
});

})
})
it("should fall back to adding platforms if specified platforms not installed", function(){

var platformService = testInjector.resolve("platformService");
var addPlatformCalled = false;
platformService.$projectData.platformsDir = "";

platformService.isPlatformInstalled = function(platform: string): IFuture<boolean> {
return (() => {
return false;
}).future<boolean>()();
}

platformService.addPlatform = function(platform: string): IFuture<void> {
return (() => {
addPlatformCalled = true;
}).future<void>()();
};

platformService.updatePlatforms(["ios"]).wait();

addPlatformCalled.should.be.true;
});
});

describe("#updatePlatform(platform)", function() {
it ("should fail if platform null or undefined", function(){
var platformService = testInjector.resolve("platformService");
(() => { return platformService.updatePlatform(null).wait(); }).should.throw();
(() => { return platformService.updatePlatform().wait(); }).should.throw();
});

it ("should fail if platform not supported", function(){
var platformService = testInjector.resolve("platformService");
(() => { return platformService.updatePlatform("unsupported").wait(); }).should.throw();
});

it("should fall back to adding the platform if not installed", function(){
var platformService = testInjector.resolve("platformService");
var addPlatformCalled = false;
platformService.$projectData.platformsDir = "";
platformService.$platformsData.getPlatformData = function(platform: string) {return {};};
platformService.$fs.exists = function(platformPath: string): IFuture<boolean> {
return (() => {
return false;
}).future<boolean>()();
};

platformService.isPlatformInstalled = function(platform: string): IFuture<boolean> {
return (() => {
return false;
}).future<boolean>()();
}

platformService.addPlatform = function(platform: string): IFuture<void> {
return (() => {
addPlatformCalled = true;
}).future<void>()();
};

platformService.updatePlatform("android").wait();

addPlatformCalled.should.be.true;
});

});
});