Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
CB-8412 Fix all jshint issues for WP8 platform
  • Loading branch information
Murat Sutunc committed Feb 3, 2015
1 parent 10db8df commit 656bf2fc60cea42931dbfc05da395709cf5c553c
Showing 16 changed files with 181 additions and 214 deletions.
@@ -17,9 +17,11 @@
under the License.
*/

/* jshint wsh:true, node:false, bitwise:false */

var fso = WScript.CreateObject('Scripting.FileSystemObject'),
shell = WScript.CreateObject("shell.application"),
wscript_shell = WScript.CreateObject("WScript.Shell");
shell = WScript.CreateObject('shell.application'),
wscript_shell = WScript.CreateObject('WScript.Shell');

//Set up directory structure of current release
//arguments passed in
@@ -41,9 +43,9 @@ var addToVS = false;

// help function
function Usage() {
Log("\nUsage: createTemplates [-install]");
Log("Build/zips up templates from the local repo")
Log(" -install : also installs templates to user directory on success\n");
Log('\nUsage: createTemplates [-install]');
Log('Build/zips up templates from the local repo');
Log(' -install : also installs templates to user directory on success\n');
}

// logs messaged to stdout and stderr
@@ -69,9 +71,6 @@ function deleteFolderIfExists(path) {
}
}

var ForReading = 1, ForWriting = 2, ForAppending = 8;
var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0;

// returns the contents of a file
function read(filename) {
if(fso.FileExists(filename))
@@ -89,19 +88,6 @@ function read(filename) {
return null;
}

// writes the contents to the specified file
function write(filename, contents) {
var f=fso.OpenTextFile(filename, ForWriting, TristateTrue);
f.Write(contents);
f.Close();
}

// replaces the matches of regexp with replacement
function replaceInFile(filename, regexp, replacement) {
var text = read(filename).replace(regexp,replacement);
write(filename,text);
}

// executes a commmand in the shell
function exec(command) {
var oShell=wscript_shell.Exec(command);
@@ -112,55 +98,34 @@ function exec(command) {
WScript.sleep(100);
}
else {
Log("Exec timed out with command :: " + command);
}
}
}

// executes a commmand in the shell
function exec_verbose(command) {
//Log("Command: " + command);
var oShell=wscript_shell.Exec(command);
while (oShell.Status === 0) {
//Wait a little bit so we're not super looping
WScript.sleep(100);
//Print any stdout output from the script
if(!oShell.StdOut.AtEndOfStream) {
Log(oShell.StdOut.ReadLine());
Log('Exec timed out with command :: ' + command);
}
}
//Check to make sure our scripts did not encounter an error
if(!oShell.StdErr.AtEndOfStream)
{
var err_line = oShell.StdErr.ReadAll();
WScript.StdErr.WriteLine(err_line);
WScript.Quit(1);
}
}

function copyFile(src,dest) {
exec('%comspec% /c copy /Y ' + src + ' ' + dest);
}

function copyCommonScripts() {
var srcPath = platformRoot + "\\bin";
var destPath = platformRoot + templatePath + "\\cordova";
var srcPath = platformRoot + '\\bin';
var destPath = platformRoot + templatePath + '\\cordova';

copyFile(srcPath + "\\check_reqs.bat", destPath + "\\check_reqs.bat");
copyFile(srcPath + "\\check_reqs.js", destPath + "\\check_reqs.js");
copyFile(srcPath + '\\check_reqs.bat', destPath + '\\check_reqs.bat');
copyFile(srcPath + '\\check_reqs.js', destPath + '\\check_reqs.js');
}

function removeCommonScripts() {
var destPath = platformRoot + templatePath + "\\cordova";
var destPath = platformRoot + templatePath + '\\cordova';

deleteFileIfExists(destPath + "\\check_reqs.bat");
deleteFileIfExists(destPath + "\\check_reqs.js");
deleteFileIfExists(destPath + '\\check_reqs.bat');
deleteFileIfExists(destPath + '\\check_reqs.js');
}

// packages templates into .zip
function package_templates()
{
Log("Creating template .zip files for wp8");
Log('Creating template .zip files for wp8');
var templateOutFilename = repoRoot + '\\CordovaWP8_' + versionNum.replace(/\./g, '_') + '.zip';

// clear the destination
@@ -171,7 +136,7 @@ function package_templates()
deleteFolderIfExists(platformRoot + templatePath + '\\obj');
deleteFolderIfExists(platformRoot + templatePath + '\\Service\ References');

deleteFileIfExists(platformRoot + templatePath + "\\CordovaWP8Solution.v11.suo");
deleteFileIfExists(platformRoot + templatePath + '\\CordovaWP8Solution.v11.suo');

copyCommonScripts();

@@ -181,56 +146,57 @@ function package_templates()

// update .vstemplate files for the template zips.

var cleanVersionName = "CordovaWP8_" + versionNum.replace(/\./g, '_');
var cleanVersionName = 'CordovaWP8_' + versionNum.replace(/\./g, '_');

var projXml = WScript.CreateObject("Microsoft.XMLDOM");
var projXml = WScript.CreateObject('Microsoft.XMLDOM');
var xNode = null;
projXml.async = false;
var fullTemplatePath = platformRoot + templatePath + '\\MyTemplate.vstemplate';
if (projXml.load(fullTemplatePath)) {

// <Name>CordovaWP8_ + versionNum.replace(/\./g, '_')</Name>
var xNode = projXml.selectSingleNode("VSTemplate/TemplateData/Name");
if(xNode != null)
xNode = projXml.selectSingleNode('VSTemplate/TemplateData/Name');
if(xNode !== null)
{
// Log("replacing version in Name");
xNode.text = cleanVersionName;
}

// <DefaultName>CordovaWP8_ + versionNum</DefaultName>
xNode = projXml.selectSingleNode("VSTemplate/TemplateData/DefaultName");
if(xNode != null)
xNode = projXml.selectSingleNode('VSTemplate/TemplateData/DefaultName');
if(xNode !== null)
{
// Log("replacing version in DefaultName");
xNode.text = cleanVersionName + '_';
}

xNode = projXml.selectSingleNode("VSTemplate/TemplateData/Description");
if(xNode != null)
xNode = projXml.selectSingleNode('VSTemplate/TemplateData/Description');
if(xNode !== null)
{
xNode.text = xNode.text.replace("0.0.0", versionNum);
xNode.text = xNode.text.replace('0.0.0', versionNum);
}
projXml.save(fullTemplatePath);

}


// Use proper XML-DOM named nodes and replace them with cordova current version
var projXml = WScript.CreateObject("Microsoft.XMLDOM");
projXml = WScript.CreateObject('Microsoft.XMLDOM');
projXml.async = false;
if (projXml.load(platformRoot + templatePath + '\\MyTemplate.vstemplate')) {

// <Name>CordovaWP7_ + versionNum.replace(/\./g, '_')</Name>
var xNode = projXml.selectSingleNode("VSTemplate/TemplateData/Name");
if(xNode != null)
xNode = projXml.selectSingleNode('VSTemplate/TemplateData/Name');
if(xNode !== null)
{
xNode.text = "CordovaWP8_" + versionNum.replace(/\./g, '_');
xNode.text = 'CordovaWP8_' + versionNum.replace(/\./g, '_');
}

// <DefaultName>CordovaWP7_ + versionNum</DefaultName>
xNode = projXml.selectSingleNode("VSTemplate/TemplateData/DefaultName");
if(xNode != null)
xNode = projXml.selectSingleNode('VSTemplate/TemplateData/DefaultName');
if(xNode !== null)
{
xNode.text = "CordovaWP8_" + versionNum;
xNode.text = 'CordovaWP8_' + versionNum;
}

projXml.save(platformRoot + templatePath + '\\MyTemplate.vstemplate');
@@ -241,18 +207,19 @@ function package_templates()

if(addToVS)
{
var template_dir = wscript_shell.ExpandEnvironmentStrings("%USERPROFILE%") + '\\Documents\\Visual Studio 2012\\Templates\\ProjectTemplates';
var dest = null;
var template_dir = wscript_shell.ExpandEnvironmentStrings('%USERPROFILE%') + '\\Documents\\Visual Studio 2012\\Templates\\ProjectTemplates';
if(fso.FolderExists(template_dir ))
{
dest = shell.NameSpace(template_dir);
dest.CopyHere(templateOutFilename, 4|20);
}
else
{
Log("WARNING: Could not find template directory in Visual Studio,\n you can manually copy over the template .zip files.");
Log('WARNING: Could not find template directory in Visual Studio,\n you can manually copy over the template .zip files.');
}
// add to VS-2013 as well
template_dir = wscript_shell.ExpandEnvironmentStrings("%USERPROFILE%") + '\\Documents\\Visual Studio 2013\\Templates\\ProjectTemplates';
template_dir = wscript_shell.ExpandEnvironmentStrings('%USERPROFILE%') + '\\Documents\\Visual Studio 2013\\Templates\\ProjectTemplates';
if(fso.FolderExists(template_dir ))
{
dest = shell.NameSpace(template_dir);
@@ -262,15 +229,15 @@ function package_templates()

removeCommonScripts();
deleteFileIfExists(platformRoot + templatePath + '\\config.xml');
deleteFileIfExists(platformRoot + templatePath + "\\VERSION");
deleteFileIfExists(platformRoot + templatePath + '\\VERSION');
}

function zip_project(zip_path, project_path) {
// create empty ZIP file and open for adding
var file = fso.CreateTextFile(zip_path, true);

// create twenty-two byte "fingerprint" for .zip
file.write("PK");
file.write('PK');
file.write(String.fromCharCode(5));
file.write(String.fromCharCode(6));
file.write('\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0');
@@ -306,12 +273,12 @@ function parseArgs() {
if(args.Count() > 0) {

//Support help flags -help, --help, /?
if(args(0).indexOf("-help") > -1 ||
args(0).indexOf("/?") > -1 ) {
if(args(0).indexOf('-help') > -1 ||
args(0).indexOf('/?') > -1 ) {
Usage();
WScript.Quit(1);
}
else if(args(0).indexOf("-install") > -1) {
else if(args(0).indexOf('-install') > -1) {
addToVS = true;
}
}
@@ -320,5 +287,5 @@ function parseArgs() {
// MAIN
parseArgs();
// build/package the templates
versionNum = read(platformRoot + "\\VERSION");
versionNum = read(platformRoot + '\\VERSION');
package_templates(repoRoot);
@@ -24,12 +24,12 @@ var Q = require('Q'),
module.exports.run = function () {
if (os.platform() != 'win32'){
// Build Universal windows apps available for windows platform only, so we reject on others platforms
return Q.reject("ERROR: Cordova tooling for Windows requires Windows OS");
return Q.reject('ERROR: Cordova tooling for Windows requires Windows OS');
}
// Check whther MSBuild Tools are available
return MSBuildTools.findAvailableVersion();
};

module.exports.help = function () {
console.log("Usage: check_reqs or node check_reqs");
console.log('Usage: check_reqs or node check_reqs');
};

0 comments on commit 656bf2f

Please sign in to comment.