mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
Prepare and build just the test app.
Useful for test runs when you don't need everything below the apps folder.
This commit is contained in:
58
gruntfile.js
58
gruntfile.js
@ -1,4 +1,5 @@
|
|||||||
var tsconfig = require('./tsconfig.json');
|
var tsconfig = require('./tsconfig.json');
|
||||||
|
var shelljs = require("shelljs");
|
||||||
|
|
||||||
module.exports = function(grunt) {
|
module.exports = function(grunt) {
|
||||||
|
|
||||||
@ -11,6 +12,12 @@ module.exports = function(grunt) {
|
|||||||
var fs=require("fs");
|
var fs=require("fs");
|
||||||
var pathModule=require("path");
|
var pathModule=require("path");
|
||||||
|
|
||||||
|
var tsLintOption = grunt.option('runtslint');
|
||||||
|
var skipTsLint = tsLintOption == 'false' || tsLintOption == false;
|
||||||
|
if (tsLintOption == null) {
|
||||||
|
skipTsLint = false;
|
||||||
|
}
|
||||||
|
|
||||||
var filterTypeScriptFiles = function(content, srcPath) {
|
var filterTypeScriptFiles = function(content, srcPath) {
|
||||||
var matchRule = /^.*@private/ig;
|
var matchRule = /^.*@private/ig;
|
||||||
if (matchRule.test(content))
|
if (matchRule.test(content))
|
||||||
@ -109,19 +116,19 @@ module.exports = function(grunt) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var getSubDirs = function(dir) {
|
var getSubDirs = function(dir) {
|
||||||
var allObjects = fs.readdirSync(dir);
|
return shelljs.ls(dir).filter(function (subDir) {
|
||||||
var allDirs = [];
|
return shelljs.test('-d', pathModule.join(dir, subDir));
|
||||||
for (var i=0; i<allObjects.length; i++)
|
});
|
||||||
{
|
};
|
||||||
var currentObjName = allObjects[i];
|
|
||||||
var currentObjPath = pathModule.join(dir, currentObjName);
|
var getApps = function() {
|
||||||
var stats = fs.statSync(currentObjPath);
|
var allApps = getSubDirs(localCfg.srcAppsDir);
|
||||||
if (stats.isDirectory())
|
if (grunt.option('test-app-only')) {
|
||||||
{
|
allApps = allApps.filter(function(appName) {
|
||||||
allDirs.push({name: currentObjName, path: currentObjPath});
|
return appName === 'tests';
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
return allApps;
|
||||||
return allDirs;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var localCfg = {
|
var localCfg = {
|
||||||
@ -387,11 +394,11 @@ module.exports = function(grunt) {
|
|||||||
copyLicenseFiles: {
|
copyLicenseFiles: {
|
||||||
tasks: ["copy:appLicense"],
|
tasks: ["copy:appLicense"],
|
||||||
dest: function() {
|
dest: function() {
|
||||||
var apps = getSubDirs(localCfg.srcAppsDir);
|
var apps = getApps();
|
||||||
var targetDirs = [];
|
var targetDirs = [];
|
||||||
apps.forEach(function(item){
|
apps.forEach(function(item){
|
||||||
targetDirs.push(pathModule.join(localCfg.outAppsDir, item.name));
|
targetDirs.push(pathModule.join(localCfg.outAppsDir, item));
|
||||||
targetDirs.push(pathModule.join(localCfg.outTsAppsDir, item.name));
|
targetDirs.push(pathModule.join(localCfg.outTsAppsDir, item));
|
||||||
});
|
});
|
||||||
return targetDirs;
|
return targetDirs;
|
||||||
}()
|
}()
|
||||||
@ -484,7 +491,12 @@ module.exports = function(grunt) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
grunt.registerTask("processEachApp", function(outAppsDir, pkgAppNameSuffix){
|
grunt.registerTask("processEachApp", function(outAppsDir, pkgAppNameSuffix){
|
||||||
var allapps = getSubDirs(localCfg.srcAppsDir);
|
var allApps = getApps();
|
||||||
|
if (grunt.option('test-app-only')) {
|
||||||
|
allApps = allApps.filter(function(appName) {
|
||||||
|
return appName === 'tests';
|
||||||
|
});
|
||||||
|
}
|
||||||
var tasks = [
|
var tasks = [
|
||||||
{
|
{
|
||||||
name: ["copy", "appPackageDef"],
|
name: ["copy", "appPackageDef"],
|
||||||
@ -493,7 +505,7 @@ module.exports = function(grunt) {
|
|||||||
var pkgFilePath = pathModule.join(outAppDir, "package.json");
|
var pkgFilePath = pathModule.join(outAppDir, "package.json");
|
||||||
cfg.src = pkgFilePath;
|
cfg.src = pkgFilePath;
|
||||||
cfg.dest = outAppDir;
|
cfg.dest = outAppDir;
|
||||||
cfg.appName = currentApp.name + (pkgAppNameSuffix || "");
|
cfg.appName = currentAppName + (pkgAppNameSuffix || "");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -504,12 +516,10 @@ module.exports = function(grunt) {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
for (var j=0; j<allapps.length; j++) {
|
allApps.forEach(function (currentApp) {
|
||||||
var currentApp = allapps[j];
|
var clonedTasks = cloneTasks(tasks, currentApp);
|
||||||
var clonedTasks = cloneTasks(tasks, currentApp.name);
|
|
||||||
|
|
||||||
enqueueTasks(clonedTasks);
|
enqueueTasks(clonedTasks);
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
grunt.registerTask("tests", [
|
grunt.registerTask("tests", [
|
||||||
@ -585,7 +595,7 @@ module.exports = function(grunt) {
|
|||||||
"copy:readyPackages"
|
"copy:readyPackages"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
grunt.registerTask("default", ((typeof(grunt.option('runtslint')) != "undefined" && !grunt.option('runtslint')) ? [] : ["tslint:build"]).concat([
|
grunt.registerTask("default", (skipTsLint ? [] : ["tslint:build"]).concat([
|
||||||
"build-all",
|
"build-all",
|
||||||
|
|
||||||
"pack-apps",
|
"pack-apps",
|
||||||
@ -609,7 +619,7 @@ module.exports = function(grunt) {
|
|||||||
//alias just-build for backwards compatibility
|
//alias just-build for backwards compatibility
|
||||||
grunt.registerTask("just-build", ["build-all"]);
|
grunt.registerTask("just-build", ["build-all"]);
|
||||||
|
|
||||||
grunt.registerTask("build-all", ((typeof(grunt.option('runtslint')) != "undefined" && !grunt.option('runtslint')) ? [] : ["tslint:build"]).concat([
|
grunt.registerTask("build-all", (skipTsLint ? [] : ["tslint:build"]).concat([
|
||||||
"pack-modules",
|
"pack-modules",
|
||||||
|
|
||||||
"collect-apps-raw-files",
|
"collect-apps-raw-files",
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
],
|
],
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"shelljs": "0.5.3",
|
||||||
"chai": "3.2.0",
|
"chai": "3.2.0",
|
||||||
"grunt": "0.4.5",
|
"grunt": "0.4.5",
|
||||||
"grunt-bom-removal": "0.2.0",
|
"grunt-bom-removal": "0.2.0",
|
||||||
|
Reference in New Issue
Block a user