From b5b9609a9a19a6ba3ef83d32da659f467881111e Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Tue, 12 Aug 2014 09:13:47 +0300 Subject: [PATCH 01/15] --- Gruntfile.js | 2 +- test/platform-service-tests.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/platform-service-tests.ts diff --git a/Gruntfile.js b/Gruntfile.js index 0f48d46272..3f1a40b18e 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -90,7 +90,6 @@ module.exports = function(grunt) { npm_test: { command: "npm test" } - }, copy: { @@ -114,6 +113,7 @@ module.exports = function(grunt) { grunt.loadNpmTasks("grunt-contrib-watch"); grunt.loadNpmTasks("grunt-shell"); grunt.loadNpmTasks("grunt-ts"); + grunt.loadNpmTasks("grunt-simple-mocha"); grunt.registerTask("set_package_version", function(version) { var fs = require("fs"); diff --git a/test/platform-service-tests.ts b/test/platform-service-tests.ts new file mode 100644 index 0000000000..4c12ac216f --- /dev/null +++ b/test/platform-service-tests.ts @@ -0,0 +1,29 @@ +/// + +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'); + +require('should'); + +var testInjector = new yok.Yok(); +testInjector.register('platformService', PlatformServiceLib.PlatformService); +testInjector.register('errors', stubs.ErrorsStub); +testInjector.register('fs', stubs.FileSystemStub); +testInjector.register('logger', stubs.LoggerStub); +testInjector.register('npm', stubs.NPMStub); +testInjector.register('projectData', stubs.ProjectDataStub); +testInjector.register('platformsData', stubs.PlatformsDataStub); + +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(); + + }) + }) +}); From 9cbf3f4b78eba4feb9e1210d2fbe883a21697b94 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Tue, 12 Aug 2014 01:23:00 -0700 Subject: [PATCH 02/15] Remove simplemocha reference. --- Gruntfile.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index 3f1a40b18e..3b621cca29 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -113,7 +113,6 @@ module.exports = function(grunt) { grunt.loadNpmTasks("grunt-contrib-watch"); grunt.loadNpmTasks("grunt-shell"); grunt.loadNpmTasks("grunt-ts"); - grunt.loadNpmTasks("grunt-simple-mocha"); grunt.registerTask("set_package_version", function(version) { var fs = require("fs"); From 5712f0d0a74de32d862dcb5bee43a1268f9a7499 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Tue, 12 Aug 2014 01:25:47 -0700 Subject: [PATCH 03/15] Changed tabs to spaces in Gruntfile.js --- Gruntfile.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 3b621cca29..a5d6da7ec1 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -3,11 +3,11 @@ var util = require("util"); var now = new Date().toISOString(); function shallowCopy(obj) { - var result = {}; - Object.keys(obj).forEach(function(key) { - result[key] = obj[key]; - }); - return result; + var result = {}; + Object.keys(obj).forEach(function(key) { + result[key] = obj[key]; + }); + return result; } var travis = process.env["TRAVIS"]; From 3a53051b02f0e1f4b580c998a893224103494cf5 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Tue, 12 Aug 2014 03:33:57 -0700 Subject: [PATCH 04/15] Convert Gruntfile.js spaces to tabs --- Gruntfile.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index a5d6da7ec1..3b621cca29 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -3,11 +3,11 @@ var util = require("util"); var now = new Date().toISOString(); function shallowCopy(obj) { - var result = {}; - Object.keys(obj).forEach(function(key) { - result[key] = obj[key]; - }); - return result; + var result = {}; + Object.keys(obj).forEach(function(key) { + result[key] = obj[key]; + }); + return result; } var travis = process.env["TRAVIS"]; From 803f8eee27f514ffafc611b3349bf9b522912a37 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Tue, 12 Aug 2014 03:35:30 -0700 Subject: [PATCH 05/15] Rename platform-service-tests to platform-service --- test/platform-service-tests.ts | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 test/platform-service-tests.ts diff --git a/test/platform-service-tests.ts b/test/platform-service-tests.ts deleted file mode 100644 index 4c12ac216f..0000000000 --- a/test/platform-service-tests.ts +++ /dev/null @@ -1,29 +0,0 @@ -/// - -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'); - -require('should'); - -var testInjector = new yok.Yok(); -testInjector.register('platformService', PlatformServiceLib.PlatformService); -testInjector.register('errors', stubs.ErrorsStub); -testInjector.register('fs', stubs.FileSystemStub); -testInjector.register('logger', stubs.LoggerStub); -testInjector.register('npm', stubs.NPMStub); -testInjector.register('projectData', stubs.ProjectDataStub); -testInjector.register('platformsData', stubs.PlatformsDataStub); - -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(); - - }) - }) -}); From 36271ec70c8048dad33bb03920dc141084a7525f Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Tue, 12 Aug 2014 05:30:41 -0700 Subject: [PATCH 06/15] test start now platform-agnostic --- Gruntfile.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Gruntfile.js b/Gruntfile.js index 3b621cca29..3e6ee1cdaf 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -22,6 +22,7 @@ module.exports = function(grunt) { dateString: now.substr(0, now.indexOf("T")), pkg: grunt.file.readJSON("package.json"), + shellCmdStart: process.platform === "win32" ? "" : "./", ts: { options: { From b3c90cc4993fe28aee70a1a86e2b16a93f46dec1 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Tue, 12 Aug 2014 06:21:08 -0700 Subject: [PATCH 07/15] Fix the test call; Call unit test run on pack --- Gruntfile.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index 3e6ee1cdaf..71651d19d5 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -129,10 +129,11 @@ module.exports = function(grunt) { grunt.file.write("package.json", JSON.stringify(packageJson, null, " ")); }); - grunt.registerTask("test", ["ts:devall", "shell:npm_test"]); + grunt.registerTask("test", ["ts:devall", "shell:dev_unit_tests"]); grunt.registerTask("pack", [ "clean", "ts:release_build", + "shell:ts_unit_tests", "set_package_version", "shell:build_package", From 4d09e46464dcd61f32691a50fb63b6e0034a8ea1 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Tue, 12 Aug 2014 06:33:12 -0700 Subject: [PATCH 08/15] Run tests on pack. --- Gruntfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index 71651d19d5..4d71a102f4 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -133,7 +133,7 @@ module.exports = function(grunt) { grunt.registerTask("pack", [ "clean", "ts:release_build", - "shell:ts_unit_tests", + "shell:ci_unit_tests", "set_package_version", "shell:build_package", From b25b775e0388958ef4d0c4f11d55b8ff24d89f72 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Tue, 12 Aug 2014 07:40:07 -0700 Subject: [PATCH 09/15] Transfer the test run from grunt to npm --- Gruntfile.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 4d71a102f4..b4838455e0 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -129,11 +129,11 @@ module.exports = function(grunt) { grunt.file.write("package.json", JSON.stringify(packageJson, null, " ")); }); - grunt.registerTask("test", ["ts:devall", "shell:dev_unit_tests"]); + grunt.registerTask("test", ["ts:devall", "shell:npm_test"]); grunt.registerTask("pack", [ "clean", "ts:release_build", - "shell:ci_unit_tests", + "shell:npm_test", "set_package_version", "shell:build_package", From 0c0e6270c1812832f48274577832f671a4b8e2fd Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Wed, 13 Aug 2014 17:12:19 +0300 Subject: [PATCH 10/15] Remove redundant grunt attribute --- Gruntfile.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index b4838455e0..154d2a2473 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -22,7 +22,6 @@ module.exports = function(grunt) { dateString: now.substr(0, now.indexOf("T")), pkg: grunt.file.readJSON("package.json"), - shellCmdStart: process.platform === "win32" ? "" : "./", ts: { options: { From c0f594775f8e077b874a605bcc84e3207181f007 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Tue, 12 Aug 2014 04:53:56 -0700 Subject: [PATCH 11/15] Added the base implementation of the update-platform command --- lib/bootstrap.ts | 1 + lib/commands/update-platform.ts | 12 ++++++++++++ lib/definitions/platform.d.ts | 2 ++ lib/services/platform-service.ts | 9 +++++++++ 4 files changed, 24 insertions(+) create mode 100644 lib/commands/update-platform.ts 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..d72e991715 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -229,6 +229,15 @@ export class PlatformService implements IPlatformService { }).future()(); } + public updatePlatforms(platforms: string[]): IFuture { + return (() => { + if(!platforms || platforms.length === 0) { + this.$errors.fail("No platform specified. Please specify a platform to update"); + } + + }).future()(); + } + private validatePlatform(platform: string): void { if(!platform) { this.$errors.fail("No platform specified.") From 0c4a854d6be6ecf9a38880b83b52c40cc67e0758 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Wed, 13 Aug 2014 17:05:54 +0300 Subject: [PATCH 12/15] Temporary commit; Working on adding a test, involving a call to a stubbed method --- lib/services/platform-service.ts | 55 ++++++++++++++++++++++++++++++++ test/platform-service.ts | 25 +++++++++++---- 2 files changed, 74 insertions(+), 6 deletions(-) diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index d72e991715..5025c89b93 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -235,6 +235,61 @@ export class PlatformService implements IPlatformService { this.$errors.fail("No platform 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(() => { +// 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()(); } diff --git a/test/platform-service.ts b/test/platform-service.ts index c2542ea29b..ae54d71183 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -20,11 +20,24 @@ 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.addPlatform = function(platform: string): IFuture { + return (() => { + addPlatformCalled = true; + }).future()(); + }; + + platformService.updatePlatforms(["aaa"]).wait(); + + addPlatformCalled.should.be.true; + }); + }) }); From ddb632acee922fcae4239769ffa1c74dbb1f5d86 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Wed, 13 Aug 2014 18:09:23 +0300 Subject: [PATCH 13/15] Fix the update-fallback-to-add test --- test/platform-service.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/platform-service.ts b/test/platform-service.ts index ae54d71183..53334a6b61 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -29,13 +29,22 @@ describe('PlatformService', function(){ 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()(); }; +console.log("Platform Service is: %o", platformService.addPlatform); - platformService.updatePlatforms(["aaa"]).wait(); + platformService.updatePlatforms(["ios"]).wait(); addPlatformCalled.should.be.true; }); From 66ccc07dad68e3906a1eeecde1ba0ea984dded0e Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Fri, 15 Aug 2014 16:02:05 +0300 Subject: [PATCH 14/15] Some short tests and an initial form of the updatePlatform method --- lib/services/platform-service.ts | 9 ++++- test/platform-service.ts | 61 ++++++++++++++++++++++++++------ 2 files changed, 59 insertions(+), 11 deletions(-) diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index 5025c89b93..65c7e54a86 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -232,7 +232,7 @@ export class PlatformService implements IPlatformService { public updatePlatforms(platforms: string[]): IFuture { return (() => { if(!platforms || platforms.length === 0) { - this.$errors.fail("No platform specified. Please specify a platform to update"); + this.$errors.fail("No platforms specified. Please specify a platform to update"); } _.each(platforms, platform => { @@ -251,6 +251,13 @@ export class PlatformService implements IPlatformService { 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]; diff --git a/test/platform-service.ts b/test/platform-service.ts index 53334a6b61..d6b1c2b96b 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); @@ -26,8 +26,8 @@ describe('PlatformService', function(){ (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'); + it("should fall back to adding platforms if specified platforms not installed", function(){ + var platformService = testInjector.resolve("platformService"); var addPlatformCalled = false; platformService.$projectData.platformsDir = ""; @@ -42,11 +42,52 @@ describe('PlatformService', function(){ addPlatformCalled = true; }).future()(); }; -console.log("Platform Service is: %o", platformService.addPlatform); 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; + }); + + }); }); From 286315414b5e1e8c8ea005e0280bfe78d7fe25d6 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Thu, 21 Aug 2014 11:48:54 +0300 Subject: [PATCH 15/15] Add a line to test the PR build --- test/platform-service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/platform-service.ts b/test/platform-service.ts index d6b1c2b96b..ef370c6d0b 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -27,6 +27,7 @@ describe('PlatformService', function(){ }); it("should fall back to adding platforms if specified platforms not installed", function(){ + var platformService = testInjector.resolve("platformService"); var addPlatformCalled = false; platformService.$projectData.platformsDir = "";