Reconfigure android-specific tasks and arguments to be cross-platform. Update documentation

This commit is contained in:
Erjan Gavalji
2015-10-26 18:01:28 +02:00
parent cfb6c41542
commit 8355634274
2 changed files with 47 additions and 17 deletions

View File

@ -13,7 +13,7 @@ module.exports = {
emulatorProcessIdentifier: grunt.option("emuPId"), emulatorProcessIdentifier: grunt.option("emuPId"),
emuAvdName: grunt.option("avd"), emuAvdName: grunt.option("avd"),
outFile: grunt.option("logFilePath"), outFile: grunt.option("logFilePath"),
androidRuntimePath: grunt.option("androidRuntimePath"), runtimePath: grunt.option("runtimePath"),
showEmu: grunt.option("showEmu") showEmu: grunt.option("showEmu")
}; };
@ -38,7 +38,7 @@ module.exports = {
modulesPath: args.modulesPath || "./bin/dist/tns-core-modules-" + modulesPackageConfig.version + ".tgz", modulesPath: args.modulesPath || "./bin/dist/tns-core-modules-" + modulesPackageConfig.version + ".tgz",
emuAvdName: args.emuAvdName, emuAvdName: args.emuAvdName,
outfile: args.outFile || "./TestRunResult.txt", outfile: args.outFile || "./TestRunResult.txt",
androidFrameworkArgument: args.androidRuntimePath ? " --frameworkPath=" + args.androidRuntimePath : "", frameworkArgument: args.runtimePath ? " --frameworkPath=" + args.runtimePath : "",
showEmu: args.showEmu || false, showEmu: args.showEmu || false,
workingDir:".testsapprun", workingDir:".testsapprun",
@ -112,6 +112,27 @@ module.exports = {
return newContent; return newContent;
} }
} }
},
addiOSPermissions: {
src: localCfg.testsAppName + "-Info.plist",
dest: pathModule.join(localCfg.applicationDir,"/platforms/ios/", localCfg.testsAppName) + "/",
cwd: pathModule.join(localCfg.applicationDir,"/platforms/ios/", localCfg.testsAppName),
expand: true,
options: {
process: function(content, srcPath) {
var newContent = content;
var lastDictLocator = /(<\/dict>\s*<\/plist>)$/gm;
if (!/NSAppTransportSecurity/.test(content)) {
newContent = newContent.replace(lastDictLocator, "<key>NSAppTransportSecurity</key>\n$1");
}
if (!/NSAllowsArbitraryLoads/.test(content)) {
newContent = newContent.replace(lastDictLocator, "<dict>\n<key>NSAllowsArbitraryLoads</key>\n<true/>\n</dict>\n$1");
}
return newContent;
}
}
} }
}, },
exec: { exec: {
@ -127,12 +148,8 @@ module.exports = {
cmd: localCfg.tnsPath + " create " + localCfg.testsAppName, cmd: localCfg.tnsPath + " create " + localCfg.testsAppName,
cwd: localCfg.workingDir cwd: localCfg.workingDir
}, },
addAndroidPlatform: { addPlatform: {
cmd: "tns platform add android " + localCfg.androidFrameworkArgument, cmd: "tns platform add " + localCfg.platform.toLowerCase() + " " + localCfg.frameworkArgument,
cwd: localCfg.applicationDir
},
buildAndroidApp: {
cmd: "tns build android",
cwd: localCfg.applicationDir cwd: localCfg.applicationDir
}, },
restartAdb: { restartAdb: {
@ -163,7 +180,16 @@ module.exports = {
maxBuffer: Infinity maxBuffer: Infinity
} }
} }
} },
buildApp: {
command: "tns build " + localCfg.platform.toLowerCase(),
options: {
execOptions: {
maxBuffer: Infinity,
cwd: localCfg.applicationDir
}
}
},
} }
}); });
@ -178,15 +204,17 @@ module.exports = {
return templatedTaskName.replace(/\{platform\}/, localCfg.platform); return templatedTaskName.replace(/\{platform\}/, localCfg.platform);
} }
grunt.registerTask("doPostPlatformAdd", [ grunt.registerTask("doPostPlatformAddAndroid", [
"exec:restartAdb" "exec:restartAdb"
]); ]);
grunt.registerTask("doPostPlatformAddiOS", [
]);
grunt.registerTask("testsapp", [ grunt.registerTask("testsapp", [
"clean:workingDir", "clean:workingDir",
"mkdir:workingDir", "mkdir:workingDir",
getPlatformSpecificTask("exec:kill{platform}Emulator"), // getPlatformSpecificTask("exec:kill{platform}Emulator"),
getPlatformSpecificTask("exec:start{platform}Emulator"), // getPlatformSpecificTask("exec:start{platform}Emulator"),
"exec:createApp", "exec:createApp",
"clean:originalAppDir", "clean:originalAppDir",
@ -196,10 +224,10 @@ module.exports = {
"copy:modulesToDir", "copy:modulesToDir",
"clean:tempExtractedModules", "clean:tempExtractedModules",
getPlatformSpecificTask("exec:add{platform}Platform"), "exec:addPlatform",
getPlatformSpecificTask("copy:add{platform}Permissions"), getPlatformSpecificTask("copy:add{platform}Permissions"),
getPlatformSpecificTask("exec:build{platform}App"), "shell:buildApp",
"doPostPlatformAdd", getPlatformSpecificTask("doPostPlatformAdd{platform}"),
getPlatformSpecificTask("exec:uninstallExisting{platform}App"), getPlatformSpecificTask("exec:uninstallExisting{platform}App"),
getPlatformSpecificTask("exec:installNew{platform}App"), getPlatformSpecificTask("exec:installNew{platform}App"),

View File

@ -46,9 +46,11 @@ emulator process, as the emulator sometimes hangs.
tests. tests.
- `logFilePath`: [Optional] The path to the file, which the test app run - `logFilePath`: [Optional] The path to the file, which the test app run
log will get saved to. Defaults to "./TestRunResult.txt". log will get saved to. Defaults to "./TestRunResult.txt".
- `androidRuntimePath`: [Optional] The path to a custom Android Runtime - `runtimePath`: [Optional] The path to a custom iOS or Android Runtime
package to have the tests run onto. If not specified, the newest available package to have the tests run onto. If not specified, the newest available
build on [npmjs.com](http://npmjs.com). build on [npmjs.com](http://npmjs.com) -
[tns-ios](https://www.npmjs.com/package/tns-ios) or
[tns-android](https://www.npmjs.com/package/tns-android).
# Sample run: # Sample run:
``` ```