var tsconfig = require('./tsconfig.json'); module.exports = function(grunt) { if (grunt.cli.tasks.indexOf("testsapp") >= 0 || grunt.cli.tasks.indexOf("buildTestsApp")>= 0) { var tsTester = require("./build/run-testsapp.grunt.js"); tsTester.run(grunt); return; } 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; }; 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 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 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/node_modules/tns-core-modules/**/*', options: { force: true }, }, readyAppFiles: { src: [localCfg.outModulesDir + "/apps/**"] } }, 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: [ "**/*.d.ts", //Exclude the d.ts files in the apps folder - these are part of the apps and are already packed there! "!apps/**", "!ts-apps/**", "!node-tests/**", "!org.nativescript.widgets.d.ts", "!android17.d.ts", "!**/*.android.d.ts", "!ios.d.ts", "!**/*.ios.d.ts", ].concat(localCfg.defaultExcludes), dest: localCfg.outModulesDir + "/", expand: true, options: { process: filterTypeScriptFiles } }, modulesPackageDef: { expand: true, src: localCfg.packageJsonFilePath, dest: localCfg.outModulesDir + "/", options: { process: updateModulesPackageDef } }, appPackageDef: { expand: true, flatten: true, src: "__app_package_json", dest: "__dummy__", options: { process: updateAppPackageDef } }, childPackageFiles: { expand: true, src: [ "**/package.json", "!package.json", "!Deploy/**/*.*", "!bin/**/*.*", "!Tests/**/*.*", "!node_modules/**/*.*", "!" + localCfg.outDir + "/**/*.*" ], 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 }, builtModules: { expand: true, src: [ '**/*', '!*.md', '!apps/**/*', '!node_modules/**/*', '!node-tests/**/*', ], cwd: localCfg.outModulesDir, dest: "<%= grunt.option('path') %>/node_modules/tns-core-modules/", } }, ts: { build: { tsconfig: 'tsconfig.json', outDir: localCfg.outModulesDir, options: tsOptions }, buildNodeTests: { src: [ 'js-libs/easysax/**/*.ts', 'xml/**/*.ts', 'node-tests/**/*.ts', 'es-collections.d.ts', ], outDir: localCfg.outModulesDir, options: tsOptions }, buildDts: { src: [ '**/*.d.ts', '!org.nativescript.widgets.d.ts', '!**/*.android.d.ts', '!node_modules/**/*', '!bin/**/*', '!apps/**/*', '!android17.d.ts', '!ios.d.ts', ], outDir: localCfg.outModulesDir, options: tsOptions }, testCombinedDts: { src: [ pathModule.join(localCfg.outModulesDir, 'tns-core-modules.d.ts'), ], outDir: localCfg.outModulesDir, options: tsOptions } }, tslint: { build: { files: { src: localCfg.typeScriptSrcForTsLint }, options: { configuration: grunt.file.readJSON("./build/tslint.json") } } }, exec: { packModules: { cmd: "npm pack", cwd: localCfg.outModulesDir + "/" }, 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, } }, bom: { allTargetFiles: { src: [ pathModule.join(localCfg.outDir, "**/*.ts"), pathModule.join(localCfg.outDir, "**/*.js"), pathModule.join(localCfg.outDir, "**/*.css"), pathModule.join(localCfg.outDir, "**/*.xml") ] } }, typedoc: { build: { options: { // 'flag:undefined' will set flags without options. "module": 'commonjs', "target": 'es5', "out": localCfg.outApiRefDir, //"json": './dist/doc.json', "name": 'NativeScript', "includeDeclarations": undefined, //"excludeExternals": undefined, //"externalPattern": './declarations.d.ts', "mode": "file", //"readme": "source/README.md", //"entryPoint": '"a-module"' // verbose: undefined }, src: localCfg.srcTsdFiles } } }); 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-bom-removal'); grunt.loadNpmTasks('grunt-typedoc'); var cloneTasks = function(originalTasks, taskNameSuffix) { var clonedTasks = []; for(var i=0; i'; }); var combinedDtsPath = pathModule.join(localCfg.outModulesDir, 'tns-core-modules.d.ts'); grunt.file.write(combinedDtsPath, dtsLines.join('\n')); }); //aliasing pack-modules for backwards compatibility grunt.registerTask("pack-modules", [ "compile-modules", "exec:packModules" ]); grunt.registerTask("pack-apps", [ "processEachApp:" + localCfg.outAppsDir ]); grunt.registerTask("pack-ts-apps", [ "processEachApp:" + localCfg.outTsAppsDir + ":-ts" ]); grunt.registerTask("get-ready-packages", [ "copy:readyPackages" ]); grunt.registerTask("default", ((typeof(grunt.option('runtslint')) != "undefined" && !grunt.option('runtslint')) ? [] : ["tslint:build"]).concat([ "build-all", "pack-apps", "pack-ts-apps", "get-ready-packages" ])); grunt.registerTask("compile-modules", [ "clean:build", "shell:getGitSHA", "compile-ts", "bom:allTargetFiles", "collect-modules-raw-files", "copy:modulesPackageDef", "copy:definitionFiles", "copy:jsLibs", "generate-tns-core-modules-dts", "ts:testCombinedDts", ]); //alias just-build for backwards compatibility grunt.registerTask("just-build", ["build-all"]); grunt.registerTask("build-all", ((typeof(grunt.option('runtslint')) != "undefined" && !grunt.option('runtslint')) ? [] : ["tslint:build"]).concat([ "pack-modules", "collect-apps-raw-files", "distribute-apps-files", "distribute-ts-apps-files", ])); grunt.registerTask("node-tests", [ "clean:nodeTests", "ts:buildNodeTests", "copy:childPackageFiles", "copy:jsLibs", "env:nodeTests", "exec:mochaNode", //spawn a new process to use the new NODE_PATH ]); };