diff --git a/Gruntfile.js b/Gruntfile.js
index 0f48d46272..154d2a2473 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -90,7 +90,6 @@ module.exports = function(grunt) {
npm_test: {
command: "npm test"
}
-
},
copy: {
@@ -133,6 +132,7 @@ module.exports = function(grunt) {
grunt.registerTask("pack", [
"clean",
"ts:release_build",
+ "shell:npm_test",
"set_package_version",
"shell:build_package",
diff --git a/lib/bootstrap.ts b/lib/bootstrap.ts
index 7472b9916f..d8eab23984 100644
--- a/lib/bootstrap.ts
+++ b/lib/bootstrap.ts
@@ -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");
diff --git a/lib/commands/update-platform.ts b/lib/commands/update-platform.ts
new file mode 100644
index 0000000000..4e4804657c
--- /dev/null
+++ b/lib/commands/update-platform.ts
@@ -0,0 +1,12 @@
+///
+
+export class UpdatePlatformCommand implements ICommand {
+ constructor(private $platformService: IPlatformService) { }
+
+ execute(args: string[]): IFuture {
+ return (() => {
+ this.$platformService.updatePlatforms(args).wait();
+ }).future()();
+ }
+}
+$injector.registerCommand("platform|update", UpdatePlatformCommand);
diff --git a/lib/definitions/platform.d.ts b/lib/definitions/platform.d.ts
index 77a45ebc6e..e36e99f04b 100644
--- a/lib/definitions/platform.d.ts
+++ b/lib/definitions/platform.d.ts
@@ -7,6 +7,8 @@ interface IPlatformService {
preparePlatform(platform: string): IFuture;
buildPlatform(platform: string): IFuture;
deploy(platform: string): IFuture;
+ removePlatforms(platforms: string[]): IFuture;
+ updatePlatforms(platforms: string[]): IFuture;
}
interface IPlatformData {
diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts
index e2d66a13d7..65c7e54a86 100644
--- a/lib/services/platform-service.ts
+++ b/lib/services/platform-service.ts
@@ -229,6 +229,77 @@ export class PlatformService implements IPlatformService {
}).future()();
}
+ public updatePlatforms(platforms: string[]): IFuture {
+ 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()();
+ }
+
+ private updatePlatform(platform: string): IFuture {
+ 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()();
+ }
+
private validatePlatform(platform: string): void {
if(!platform) {
this.$errors.fail("No platform specified.")
diff --git a/test/platform-service.ts b/test/platform-service.ts
index c2542ea29b..ef370c6d0b 100644
--- a/test/platform-service.ts
+++ b/test/platform-service.ts
@@ -1,13 +1,13 @@
///
-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);
@@ -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 {
+ return (() => {
+ return false;
+ }).future()();
+ }
+
+ platformService.addPlatform = function(platform: string): IFuture {
+ return (() => {
+ addPlatformCalled = true;
+ }).future()();
+ };
+
+ 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 {
+ return (() => {
+ return false;
+ }).future()();
+ };
+
+ platformService.isPlatformInstalled = function(platform: string): IFuture {
+ return (() => {
+ return false;
+ }).future()();
+ }
+
+ platformService.addPlatform = function(platform: string): IFuture {
+ return (() => {
+ addPlatformCalled = true;
+ }).future()();
+ };
+
+ platformService.updatePlatform("android").wait();
+
+ addPlatformCalled.should.be.true;
+ });
+
+ });
});