diff --git a/.gitignore b/.gitignore index 59f24406e..6fefaa005 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ dist/ !css-value/**/*.* !fetch/**/*.* !apps/TelerikNEXT/lib/**/*.* +!build/*.* CrossPlatformModules.sln.ide/ *.suo CrossPlatformModules.suo diff --git a/build/run-testsapp.grunt.js b/build/run-testsapp.grunt.js new file mode 100644 index 000000000..678727570 --- /dev/null +++ b/build/run-testsapp.grunt.js @@ -0,0 +1,67 @@ +module.exports = { + run: function(grunt) { + + var localCfg = { + emulatorProcessIdentifier:".*emulator64-x86", + emuAvdName:"Api19", + androidRuntimePath:"/Users/erjan/tns-android.tgz", + outfile:"./TestRunResult.txt", + + workingDir=".testsapprun", + testsAppName:"TestsApp", + pathToApk:"./platforms/android/build/outputs/apk/TestsApp-debug.apk", + deployedAppName:"org.nativescript.$testsAppName", + mainActivityName:"com.tns.NativeScriptActivity" + } + + grunt.initConfig({ + clean: { + workingDir: { + src: localCfg.workingDir + } + }, + mkdir: { + workindDir: { + options: { + create [localCfg.workingDir], + mode: 0700 + } + } + } + exec: { + killEmulator: { + cmd: "pkill '" + localCfg.emulatorProcessIdentifier + "'", + exitCode: [0, 1] + }, + runTestsApp: { + cmd: "./runtestsapp.sh", + stdout: false, + cwd: "../" + } + } + }); + +// grunt.loadNpmTasks("grunt-contrib-copy"); +// grunt.loadNpmTasks("grunt-tslint"); +// grunt.loadNpmTasks("grunt-multi-dest"); +// grunt.loadNpmTasks("grunt-shell"); +// grunt.loadNpmTasks("grunt-env"); +// grunt.loadNpmTasks("grunt-simple-mocha"); + grunt.loadNpmTasks("grunt-exec"); + grunt.loadNpmTasks("grunt-mkdir"); + grunt.loadNpmTasks("grunt-contrib-clean"); + + grunt.registerTask("testsapp", [ + "clean:workingDir", + "mkdir:workingDir", + "exec:killEmulator", + "exec:runTestsApp", + + + + + "exec:killEmulator", + "clean:workingDir" + ]); + } +} diff --git a/gruntfile.js b/gruntfile.js index ccf174b34..67b0d8a1c 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -1,567 +1,570 @@ module.exports = function(grunt) { - var fs=require("fs"); - var pathModule=require("path"); - var filterTypeScriptFiles = function(content, srcPath) { - var matchRule = /^.*@private/ig; - if (matchRule.test(content)) - { - return false; - } - var processed = content; - processed = processed.replace(/\/\/[\/\s]*@private((.|\s)*?)\/\/[\/\s]*@endprivate/gm, ""); - return processed; - }; + if (grunt.cli.tasks.indexOf("testsapp") >= 0) { + var tsTester = require("./build/run-testsapp.grunt.js"); + tsTester.run(grunt); + } else { - var updatePackageDef = function(content, update) - { - var contentAsObject = JSON.parse(content); - update(contentAsObject); - return JSON.stringify(contentAsObject, null, "\t"); - } - var updateModulesPackageDef = function(content, srcPath) { - return updatePackageDef(content, function(contentAsObject) { - contentAsObject.version = localCfg.packageVersion; - if (localCfg.commitSHA) { - contentAsObject.repository.url += "/commit/" + localCfg.commitSHA; - } - }); - }; + var fs=require("fs"); + var pathModule=require("path"); - var updateAppPackageDef = function(content, srcPath) { - var currentAppName = grunt.task.current.data.appName; - return updatePackageDef(content, function(contentAsObject) { - contentAsObject.version = localCfg.packageVersion; - contentAsObject.author = "Telerik "; - var specificKeywords = ["telerik", "mobile", "nativescript", "{N}", "tns", "appbuilder"]; - if (currentAppName.indexOf("template-") == 0) { - var templateName = currentAppName.substring("template-".length); - contentAsObject.name = "tns-" + currentAppName; - contentAsObject.description = "Nativescript " + templateName + " project template"; - specificKeywords.push("template"); - } - else { - contentAsObject.name = "tns-samples-" + currentAppName; - contentAsObject.description = "Nativescript " + currentAppName + " sample application"; - specificKeywords.push("sample"); - } - contentAsObject.license = "BSD"; - addKeywords(contentAsObject, specificKeywords); - - if (!contentAsObject.repository) { - contentAsObject.repository = {}; - } - if (!contentAsObject.repository.url) { - contentAsObject.repository.url = localCfg.mainPackageContent.repository.url; - } - if (localCfg.commitSHA) { - contentAsObject.repository.url += "/commit/" + localCfg.commitSHA; - } - }); - }; - - var addKeywords = function(packageObject, newKeywords) { - if (!packageObject.keywords) { - packageObject.keywords = newKeywords; - return; - } - - if (typeof(packageObject.keywords) == "string") { - packageObject.keywords = packageObject.keywords.split(" "); - } - packageObject.keywords = packageObject.keywords.concat(newKeywords); - }; - - var updateDefinitionsPackageDef = function(content, srcPath) { - return updatePackageDef(content, function(contentAsObject) { - contentAsObject.version = localCfg.packageVersion; - contentAsObject.name = "tns-definitions"; - contentAsObject.description = "NativeScript Module definitions"; - contentAsObject.license = "Apache-2.0"; - if (localCfg.commitSHA) { - contentAsObject.repository.url += "/commit/" + localCfg.commitSHA; - } - }); - }; - - var getCommitSha = function() { - if (process.env.GIT_COMMIT) { - return process.env.GIT_COMMIT; - } - return ""; - }; - - var assignGitSHA = function(err, stdout, stderr, cb) { - if (!localCfg.commitSHA) { - localCfg.commitSHA = stdout.replace("\n", ""); - } - cb(); - }; - - var getPackageVersion = function() { - var buildVersion = process.env.PACKAGE_VERSION; - if (!buildVersion) { - return localCfg.mainPackageContent.version; - } - return localCfg.mainPackageContent.version + "-" + buildVersion; - }; - - var processAppFile = function(content, srcPath) { - return content; - }; - - var getSubDirs = function(dir) { - var allObjects = fs.readdirSync(dir); - var allDirs = []; - for (var i=0; i/", - cwd: localCfg.srcDir - }, - license: { - expand: true, - src: [ - "./LICENSE", - ], - dest: "<%= localCfg.outModulesDir %>/", - cwd: localCfg.srcDir - }, - appLicense: { - expand: true, - src: ["./LICENSE"], - cwd: localCfg.srcAppsDir, - dest: "__dummy__" - }, - definitionFiles: { - src: [ - localCfg.srcDir + "/**/*.d.ts", - pathModule.join(localCfg.srcDir, "LICENSE"), - //Exclude the d.ts files in the apps folder - these are part of the apps and are already packed there! - "!" + localCfg.srcDir + "/apps/**" - ].concat(localCfg.defaultExcludes).concat(localCfg.excludedModules), - dest: localCfg.outDefinitionsDir + "/", - expand: true, - options: { - process: filterTypeScriptFiles - } - }, - modulesPackageDef: { - expand: true, - src: localCfg.packageJsonFilePath, - dest: localCfg.outModulesDir + "/", - options: { - process: updateModulesPackageDef - } - }, - definitionsPackageDef: { - src: localCfg.packageJsonFilePath, - dest: localCfg.outDefinitionsDir + "/", - options: { - process: updateDefinitionsPackageDef - } - }, - appPackageDef: { - expand: true, - flatten: true, - src: "__app_package_json", - dest: "__dummy__", - options: { - process: updateAppPackageDef - } - }, - childPackageFiles: { - expand: true, - src: [ - localCfg.srcDir + "/**/package.json", - "!./package.json", - "!./Deploy/**/*.*", - "!./bin/**/*.*", - "!./Tests/**/*.*", - "!" + localCfg.outDir + "/**/*.*" - ].concat(localCfg.excludedModules), - dest: localCfg.outModulesDir + "/" - }, - rawAppsFiles: { - expand: true, - src: [ - "**/*.*", - "**/*", - "!**/*.map", - "!**/*.ts" - ], - dest: localCfg.outAppsDir, - cwd: localCfg.srcAppsDir, - dot: true - }, - readyAppFiles: { - expand: true, - src: ["./**/*.*"], - dest: localCfg.outAppsDir + "/", - cwd: localCfg.outModulesDir + "/apps/", - options: { - process: processAppFile - } - }, - readyTsAppFiles: { - expand: true, - src: ["./**/*.*", "!./**/*.map"], - dest: localCfg.outTsAppsDir + "/", - cwd: localCfg.srcAppsDir - }, - readyPackages: { - expand: true, - src: ["./**/*.tgz"], - dest: localCfg.outDir + "/", - cwd: localCfg.outDir, - flatten: true - } - }, - ts: { - build: { - src: localCfg.typeScriptSrc, - outDir: localCfg.outModulesDir, - options: { - fast: 'never', - module: "commonjs", - target: "es5", - sourceMap: false, - declaration: false, - removeComments: "<%= !grunt.option('leavecomments') || '' %>", - compiler: "node_modules/typescript/bin/tsc", - noEmitOnError: true, - experimentalDecorators: true, - noEmitHelpers: true - } - }, - buildNodeTests: { - src: [ - 'js-libs/easysax/**/*.ts', - 'xml/**/*.ts', - 'node-tests/**/*.ts', - ], - outDir: localCfg.outModulesDir, - options: { - fast: 'never', - module: "commonjs", - target: "es5", - sourceMap: false, - declaration: false, - removeComments: "<%= !grunt.option('leavecomments') || '' %>", - compiler: "node_modules/typescript/bin/tsc", - noEmitOnError: true - } - } - }, - tslint: { - build: { - files: { - src: localCfg.typeScriptSrcForTsLint + grunt.initConfig({ + localCfg : localCfg, + pkg: grunt.file.readJSON('package.json'), + clean: { + build: { + src: [localCfg.outDir] }, - options: { - configuration: grunt.file.readJSON("./build/tslint.json") - } - } - }, - exec: { - packModules: { - cmd: "npm pack", - cwd: localCfg.outModulesDir + "/" - }, - packDefinitions: { - cmd: "npm pack", - cwd: localCfg.outDefinitionsDir + "/" - }, - packApp: { - cmd: "npm pack", - cwd: "__dummy__" - }, - mochaNode: { - cmd: "grunt simplemocha:node" - }, - runTestsApp: { - cmd: "./runtestsapp.sh" - } - }, - multidest: { - copyLicenseFiles: { - tasks: ["copy:appLicense"], - dest: function() { - var apps = getSubDirs(localCfg.srcAppsDir); - var targetDirs = []; - apps.forEach(function(item){ - targetDirs.push(pathModule.join(localCfg.outAppsDir, item.name)); - targetDirs.push(pathModule.join(localCfg.outTsAppsDir, item.name)); - }); - return targetDirs; - }() - } - }, - shell: { - getGitSHA: { - command: "git rev-parse HEAD", - options: { - callback: assignGitSHA + typeScriptLeftovers: { + expand: true, + src: [ + "./.baseDir.*", + "./_references.js", + "./**/*.map" + ], + cwd: localCfg.outModulesDir + }, + nodeTests: { + src: localCfg.nodeTestsDir, + }, + readyAppFiles: { + src: [localCfg.outModulesDir + "/apps/**"] } }, - }, - simplemocha: { - node: { - src: localCfg.nodeTestsDir + '/**/*.js' - } - }, - env: { - nodeTests: { - NODE_PATH: localCfg.outModulesDir, - } - } - }); + copy: { + jsLibs: { + expand: true, + src: [ + "./js-libs/**/*.js", + "./fetch/**/*.js", + "./css/**/*.js", + "./css-value/**/*.js", + ], + dest: "<%= localCfg.outModulesDir %>/", + cwd: localCfg.srcDir + }, + license: { + expand: true, + src: [ + "./LICENSE", + ], + dest: "<%= localCfg.outModulesDir %>/", + cwd: localCfg.srcDir + }, + appLicense: { + expand: true, + src: ["./LICENSE"], + cwd: localCfg.srcAppsDir, + dest: "__dummy__" + }, + definitionFiles: { + src: [ + localCfg.srcDir + "/**/*.d.ts", + pathModule.join(localCfg.srcDir, "LICENSE"), + //Exclude the d.ts files in the apps folder - these are part of the apps and are already packed there! + "!" + localCfg.srcDir + "/apps/**" + ].concat(localCfg.defaultExcludes).concat(localCfg.excludedModules), + dest: localCfg.outDefinitionsDir + "/", + expand: true, + options: { + process: filterTypeScriptFiles + } + }, + modulesPackageDef: { + expand: true, + src: localCfg.packageJsonFilePath, + dest: localCfg.outModulesDir + "/", + options: { + process: updateModulesPackageDef + } + }, + definitionsPackageDef: { + src: localCfg.packageJsonFilePath, + dest: localCfg.outDefinitionsDir + "/", + options: { + process: updateDefinitionsPackageDef + } + }, + appPackageDef: { + expand: true, + flatten: true, + src: "__app_package_json", + dest: "__dummy__", + options: { + process: updateAppPackageDef + } + }, + childPackageFiles: { + expand: true, + src: [ + localCfg.srcDir + "/**/package.json", + "!./package.json", + "!./Deploy/**/*.*", + "!./bin/**/*.*", + "!./Tests/**/*.*", + "!" + localCfg.outDir + "/**/*.*" + ].concat(localCfg.excludedModules), + dest: localCfg.outModulesDir + "/" + }, + rawAppsFiles: { + expand: true, + src: [ + "**/*.*", + "**/*", + "!**/*.map", + "!**/*.ts" + ], + dest: localCfg.outAppsDir, + cwd: localCfg.srcAppsDir, + dot: true + }, + readyAppFiles: { + expand: true, + src: ["./**/*.*"], + dest: localCfg.outAppsDir + "/", + cwd: localCfg.outModulesDir + "/apps/", + options: { + process: processAppFile + } + }, + readyTsAppFiles: { + expand: true, + src: ["./**/*.*", "!./**/*.map"], + dest: localCfg.outTsAppsDir + "/", + cwd: localCfg.srcAppsDir + }, + readyPackages: { + expand: true, + src: ["./**/*.tgz"], + dest: localCfg.outDir + "/", + cwd: localCfg.outDir, + flatten: true + } + }, + ts: { + build: { + src: localCfg.typeScriptSrc, + outDir: localCfg.outModulesDir, + options: { + fast: 'never', + module: "commonjs", + target: "es5", + sourceMap: false, + declaration: false, + removeComments: "<%= !grunt.option('leavecomments') || '' %>", + compiler: "node_modules/typescript/bin/tsc", + noEmitOnError: true, + experimentalDecorators: true, + noEmitHelpers: true + } + }, + buildNodeTests: { + src: [ + 'js-libs/easysax/**/*.ts', + 'xml/**/*.ts', + 'node-tests/**/*.ts', + ], + outDir: localCfg.outModulesDir, + options: { + fast: 'never', + module: "commonjs", + target: "es5", + sourceMap: false, + declaration: false, + removeComments: "<%= !grunt.option('leavecomments') || '' %>", + compiler: "node_modules/typescript/bin/tsc", + noEmitOnError: true + } + } + }, + tslint: { + build: { + files: { + src: localCfg.typeScriptSrcForTsLint + }, + options: { + configuration: grunt.file.readJSON("./build/tslint.json") + } + } + }, + exec: { + packModules: { + cmd: "npm pack", + cwd: localCfg.outModulesDir + "/" + }, + packDefinitions: { + cmd: "npm pack", + cwd: localCfg.outDefinitionsDir + "/" + }, + packApp: { + cmd: "npm pack", + cwd: "__dummy__" + }, + mochaNode: { + cmd: "grunt simplemocha:node" + } + }, + multidest: { + copyLicenseFiles: { + tasks: ["copy:appLicense"], + dest: function() { + var apps = getSubDirs(localCfg.srcAppsDir); + var targetDirs = []; + apps.forEach(function(item){ + targetDirs.push(pathModule.join(localCfg.outAppsDir, item.name)); + targetDirs.push(pathModule.join(localCfg.outTsAppsDir, item.name)); + }); + return targetDirs; + }() + } + }, + shell: { + getGitSHA: { + command: "git rev-parse HEAD", + options: { + callback: assignGitSHA + } + }, + }, + simplemocha: { + node: { + src: localCfg.nodeTestsDir + '/**/*.js' + } + }, + env: { + nodeTests: { + NODE_PATH: localCfg.outModulesDir, + } + } + }); - grunt.loadNpmTasks("grunt-ts"); - grunt.loadNpmTasks("grunt-contrib-clean"); - grunt.loadNpmTasks("grunt-contrib-copy"); - grunt.loadNpmTasks("grunt-exec"); - grunt.loadNpmTasks("grunt-tslint"); - grunt.loadNpmTasks("grunt-multi-dest"); - grunt.loadNpmTasks("grunt-shell"); - grunt.loadNpmTasks("grunt-env"); - grunt.loadNpmTasks("grunt-simple-mocha"); + grunt.loadNpmTasks("grunt-ts"); + grunt.loadNpmTasks("grunt-contrib-clean"); + grunt.loadNpmTasks("grunt-contrib-copy"); + grunt.loadNpmTasks("grunt-exec"); + grunt.loadNpmTasks("grunt-tslint"); + grunt.loadNpmTasks("grunt-multi-dest"); + grunt.loadNpmTasks("grunt-shell"); + grunt.loadNpmTasks("grunt-env"); + grunt.loadNpmTasks("grunt-simple-mocha"); - var cloneTasks = function(originalTasks, taskNameSuffix) - { - var clonedTasks = []; - for(var i=0; i