Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
CB-4780 update script with windows support
  • Loading branch information
lorinbeer committed Oct 23, 2013
1 parent 6b2ae1d commit 5a96c23c036a339f838ccd9c36254acaf641e806
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 94 deletions.
@@ -0,0 +1,94 @@
#!/usr/bin/env node

/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/

var shell = require('shelljs'),
path = require('path'),
fs = require('fs'),
ROOT = path.join(__dirname, '..', '..');

function setShellFatal(value, func) {
var oldVal = shell.config.fatal;
shell.config.fatal = value;
func();
shell.config.fatal = oldVal;
}


function updateNativeDir(projectpath) {
shell.cp('-rf', path.join(ROOT,'bin','templates','project','native'), path.join(projectpath,'native'));
}

function updateProjectJson(projectpath) {
var projectJson = require(path.resolve(path.join(projectpath, "project.json")));
projectJson.globalFetchDir = path.join(ROOT,'plugins');
fs.writeFileSync(path.join(projectpath, "project.json"), JSON.stringify(projectJson, null, 4) + "\n", "utf-8");
}

function updateCordovaJS(projectpath,version) {
var jspath = path.join(projectpath,'lib','cordova'+version,'javascript');
shell.rm('-rf', path.join(projectpath, 'lib')); //remove old lib tree
shell.mkdir('-p', jspath); // remake lib dir tree with updated version
shell.cp('-f', path.join(ROOT,'javascript','cordova.blackberry10.js'), path.join(jspath,'cordova.js')); // copy new js
shell.cp('-f', path.join(ROOT,'javascript','cordova.blackberry10.js'), path.join('www','cordova.js'));
}

function updateCordovaTools(projectpath) {
// update cordova scripts from template
shell.cp('-rf', path.join(ROOT,'bin','templates','project','cordova'), path.join(projectpath,'cordova'));
// update repo level scripts
updateTargetTool(projectpath);
updateInitTool(projectpath);
}

function updateTargetTool(projectpath) {
shell.cp('-f', path.join(ROOT,'bin','target'), path.join(projectpath,'cordova'));
shell.cp('-f', path.join(ROOT,'bin','target.bat'), path.join(projectpath,'cordova'));
shell.cp('-f', path.join(ROOT,'bin','lib','target.js'), path.join(projectpath,'cordova','lib'));
shell.cp('-f', path.join(ROOT,'bin','lib','utils.js'), path.join(projectpath,'cordova','lib'));
}

function updateInitTool(projectpath) {
shell.cp('-f', path.join(ROOT,'bin','init.bat'), path.join(projectpath, 'cordova'));
shell.cp('-f', path.join(ROOT,'bin','init'), path.join(projectpath, 'cordova'));
}

exports.updateProject = function(projectpath) {
var version = fs.readFileSync(path.join(ROOT, 'VERSION'), 'utf-8').trim();
setShellFatal(true, function() {
updateCordovaJS(projectpath,version);
updateCordovaTools(projectpath);
updateNativeDir(projectpath);
updateProjectJson(projectpath);
//console.log('BlackBerry10 project is now at version ' + version);
});
};

if (require.main === module) {
(function() {
var args = process.argv;
if (args.length < 3 || (args[2] == '--help' || args[2] == '-h')) {
console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'update')) + ' <path_to_project>');
process.exit(1);
} else {
exports.updateProject(args[2]);
}
})();
}
@@ -1,94 +1,28 @@
#!/usr/bin/env node

/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/

var shell = require('shelljs'),
path = require('path'),
fs = require('fs'),
ROOT = path.join(__dirname, '..');

function setShellFatal(value, func) {
var oldVal = shell.config.fatal;
shell.config.fatal = value;
func();
shell.config.fatal = oldVal;
}


function updateNativeDir(projectpath) {
shell.cp('-rf', path.join(ROOT,'bin','templates','project','native'), path.join(projectpath,'native'));
}

function updateProjectJson(projectpath) {
var projectJson = require(path.resolve(path.join(projectpath, "project.json")));
projectJson.globalFetchDir = path.join(ROOT,'plugins');
fs.writeFileSync(path.join(projectpath, "project.json"), JSON.stringify(projectJson, null, 4) + "\n", "utf-8");
}

function updateCordovaJS(projectpath,version) {
var jspath = path.join(projectpath,'lib','cordova'+version,'javascript');
shell.rm('-rf', path.join(projectpath, 'lib')); //remove old lib tree
shell.mkdir('-p', jspath); // remake lib dir tree with updated version
shell.cp('-f', path.join(ROOT,'javascript','cordova.blackberry10.js'), path.join(jspath,'cordova.js')); // copy new js
shell.cp('-f', path.join(ROOT,'javascript','cordova.blackberry10.js'), path.join('www','cordova.js'));
}

function updateCordovaTools(projectpath) {
// update cordova scripts from template
shell.cp('-rf', path.join(ROOT,'bin','templates','project','cordova'), path.join(projectpath,'cordova'));
// update repo level scripts
updateTargetTool(projectpath);
updateInitTool(projectpath);
}

function updateTargetTool(projectpath) {
shell.cp('-f', path.join(ROOT,'bin','target'), path.join(projectpath,'cordova'));
shell.cp('-f', path.join(ROOT,'bin','target.bat'), path.join(projectpath,'cordova'));
shell.cp('-f', path.join(ROOT,'bin','lib','target.js'), path.join(projectpath,'cordova','lib'));
shell.cp('-f', path.join(ROOT,'bin','lib','utils.js'), path.join(projectpath,'cordova','lib'));
}

function updateInitTool(projectpath) {
shell.cp('-f', path.join(ROOT,'bin','init.bat'), path.join(projectpath, 'cordova'));
shell.cp('-f', path.join(ROOT,'bin','init'), path.join(projectpath, 'cordova'));
}

exports.updateProject = function(projectpath) {
var version = fs.readFileSync(path.join(ROOT, 'VERSION'), 'utf-8').trim();
setShellFatal(true, function() {
updateCordovaJS(projectpath,version);
updateCordovaTools(projectpath);
updateNativeDir(projectpath);
updateProjectJson(projectpath);
//console.log('BlackBerry10 project is now at version ' + version);
});
};

if (require.main === module) {
(function() {
var args = process.argv;
if (args.length < 3 || (args[2] == '--help' || args[2] == '-h')) {
console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'update')) + ' <path_to_project>');
process.exit(1);
} else {
exports.updateProject(args[2]);
}
})();
}
#! /bin/sh
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# create a cordova/blackberry project
#
# USAGE
# ./update [projectpath]
#
#!/bin/sh

BIN_DIR=$(dirname "$0")
source "$BIN_DIR/init"
"$CORDOVA_NODE/node" "$BIN_DIR/lib/update.js" "$@"
@@ -0,0 +1,21 @@
@ECHO OFF
goto comment
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
:comment
call "%~dps0init"
"%CORDOVA_NODE%\node.exe" "%~dps0\lib\update.js" %*

0 comments on commit 5a96c23

Please sign in to comment.