Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
[CB-3798] Provide support for optional localized node/npm/bb-tools
-Several script updates to provide support for optional localized binaries [node/npm/bbtools]
-Added support for overridable global CORDOVA_NODE env variable to point to node installation
-Added support for overridable global CORDOVA_BBTOOLS env variable to point to bbndk tools
-Run plugman via JS and not command-line
  • Loading branch information
jkeshavarzi authored and bryanhiggins committed Jul 30, 2013
1 parent db0aa17 commit 7b9334636790e1efa76071310b5086a80555397f
Show file tree
Hide file tree
Showing 33 changed files with 284 additions and 160 deletions.
@@ -18,33 +18,35 @@
#
#!/bin/sh

NODE=$(command -v node)
NPM=$(command -v npm)
source $(dirname "$0")/init

NODE="$CORDOVA_NODE/node"
NPM="$CORDOVA_NODE/npm"
JAVA=$(command -v java)
PACKAGER=$(command -v blackberry-nativepackager)
DEPLOYER=$(command -v blackberry-deploy)
SIGNER=$(command -v blackberry-signer)
PACKAGER="$CORDOVA_BBTOOLS/blackberry-nativepackager"
DEPLOYER="$CORDOVA_BBTOOLS/blackberry-deploy"
SIGNER="$CORDOVA_BBTOOLS/blackberry-signer"

if [ -z "$NODE" ]; then
if [ ! -x "$NODE" ]; then
echo node cannot be found on the path. Aborting.
EXIT_CODE=1
elif [ -z "$NPM" ]; then
elif [ ! -x "$NPM" ]; then
echo npm cannot be found on the path. Aborting.
EXIT_CODE=1
elif [ -z "$JAVA" ]; then
elif [ ! -x "$JAVA" ]; then
echo java cannot be found on the path. Aborting.
EXIT_CODE=1
elif [ -z "$PACKAGER" ]; then
elif [ ! -x "$PACKAGER" ]; then
echo blackberry-nativepackager cannot be found on the path. Aborting.
EXIT_CODE=1
elif [ -z "$DEPLOYER" ]; then
elif [ ! -x "$DEPLOYER" ]; then
echo blackberry-deploy cannot be found on the path. Aborting.
EXIT_CODE=1
elif [ -z "$SIGNER" ]; then
elif [ ! -x "$SIGNER" ]; then
echo blackberry-signer cannot be found on the path. Aborting.
EXIT_CODE=1
else
node "$( dirname "$0" )/check_reqs.js" "$@"
"$NODE" "$( dirname "$0" )/check_reqs.js" "$@"
EXIT_CODE=0
fi

@@ -17,43 +17,7 @@ goto comment
specific language governing permissions and limitations
under the License.
:comment

set FOUNDNODE=
for %%e in (%PATHEXT%) do (
for %%X in (node%%e) do (
if not defined FOUNDNODE (
set FOUNDNODE=%%~$PATH:X
)
)
)

set FOUNDNPM=
for %%X in (npm) do (
if not defined FOUNDNPM (
set FOUNDNPM=%%~$PATH:X
)
)

set FOUNDPACKAGER=
for %%X in (blackberry-nativepackager.bat) do (
if not defined FOUNDPACKAGER (
set FOUNDPACKAGER=%%~$PATH:X
)
)

set FOUNDDEPLOYER=
for %%X in (blackberry-deploy.bat) do (
if not defined FOUNDDEPLOYER (
set FOUNDDEPLOYER=%%~$PATH:X
)
)

set FOUNDSIGNER=
for %%X in (blackberry-signer.bat) do (
if not defined FOUNDSIGNER (
set FOUNDSIGNER=%%~$PATH:X
)
)
call "%~dp0init"

set FOUNDJAVA=
for %%e in (%PATHEXT%) do (
@@ -63,31 +27,29 @@ for %%e in (%PATHEXT%) do (
)
)
)


if not defined FOUNDNODE (
echo npm cannot be found on the path. Aborting.
if not exist "%CORDOVA_NODE%\node.exe" (
echo node cannot be found on the path. Aborting.
exit /b 1
)
if not defined FOUNDNPM (
echo node cannot be found on the path. Aborting.
if not exist "%CORDOVA_NODE%\npm" (
echo npm cannot be found on the path. Aborting.
exit /b 1
)
if not defined FOUNDJAVA (
echo java cannot be found on the path. Aborting.
exit /b 1
)
if not defined FOUNDPACKAGER (
if not exist "%CORDOVA_BBTOOLS%\blackberry-nativepackager" (
echo blackberry-nativepackager cannot be found on the path. Aborting.
exit /b 1
)
if not defined FOUNDDEPLOYER (
if not exist "%CORDOVA_BBTOOLS%\blackberry-deploy" (
echo blackberry-deploy cannot be found on the path. Aborting.
exit /b 1
)
if not defined FOUNDSIGNER (
if not exist "%CORDOVA_BBTOOLS%\blackberry-signer" (
echo blackberry-signer cannot be found on the path. Aborting.
exit /b 1
)

@node.exe "%~dp0\check_reqs.js" %*
"%CORDOVA_NODE%\node" "%~dp0\check_reqs.js" %*
@@ -23,8 +23,11 @@
#
#!/bin/sh

source $(dirname "$0")/init

CURRENT_DIR=$(pwd)
BIN_DIR=$(dirname "$0")
BIN_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
NPM_PACKAGE_JSON="$BIN_DIR"/../package.json

#Run check_reqs before doing anything and exit if there's an error
"$BIN_DIR"/check_reqs
@@ -33,13 +36,16 @@ if [ ${?} -ne 0 ]; then
fi

#Run npm install every time (even if node_modules folder is present) to cover platform upgrade
cd "$BIN_DIR"/..
#Removed sudo usage so that node modules are not ownder by root
npm install
cd "$CURRENT_DIR"
if [ -e $NPM_PACKAGE_JSON ]; then
cd "$BIN_DIR"/..
#Removed sudo usage so that node modules are not ownder by root
"$CORDOVA_NODE/npm" install
cd "$CURRENT_DIR"

if ! [ $? -eq 0 ]; then
echo "NPM install failed. Aborting."
else
node "$BIN_DIR"/create.js "$@"
if ! [ $? -eq 0 ]; then
echo "NPM install failed. Aborting."
exit 1
fi
fi

"$CORDOVA_NODE/node" "$BIN_DIR"/create.js "$@"
@@ -17,15 +17,17 @@ goto comment
specific language governing permissions and limitations
under the License.
:comment

set BIN_DIR=%~dp0

call "%BIN_DIR%init"
call "%BIN_DIR%check_reqs"

if "%ERRORLEVEL%" == "1" exit /B 1

pushd %BIN_DIR%..
call npm install
popd
if exist "%BIN_DIR%..\package.json" (
pushd %BIN_DIR%..
call "%CORDOVA_NODE%\npm" install
popd
)

node.exe "%BIN_DIR%create.js" %*
"%CORDOVA_NODE%\node" "%BIN_DIR%create.js" %*
@@ -112,18 +112,54 @@ function copyJavascript() {
}

function copyFilesToProject() {
var nodeModulesDest = path.join(project_path, "cordova", "node_modules");
var nodeModulesDest = path.join(project_path, "cordova", "node_modules"),
bbtoolsBinDest = path.join(project_path, "cordova", "dependencies", "bb-tools", "bin"),
bbtoolsLibDest = path.join(project_path, "cordova", "dependencies", "bb-tools", "lib"),
bbNativePackager = "blackberry-nativepackager",
bbSigner = "blackberry-signer",
bbDeploy = "blackberry-deploy";

// create project using template directory
wrench.mkdirSyncRecursive(project_path, 0777);
wrench.copyDirSyncRecursive(TEMPLATE_PROJECT_DIR, project_path);

//copy dependencies folder if exists
if (fs.existsSync(path.join(BIN_DIR, "dependencies"))) {
//Copy node binaries
wrench.mkdirSyncRecursive(path.join(project_path, "cordova", "dependencies", "node"), 0755);
wrench.copyDirSyncRecursive(path.join(BIN_DIR, "dependencies", "node"), path.join(project_path, "cordova", "dependencies", "node"));

//Copy bb-tools bin files
wrench.mkdirSyncRecursive(bbtoolsBinDest, 0755);

if (utils.isWindows()) {
bbNativePackager += ".bat";
bbSigner += ".bat";
bbDeploy += ".bat";
}

utils.copyFile(path.join(BIN_DIR, "dependencies", "bb-tools", "bin", bbNativePackager), bbtoolsBinDest);
utils.copyFile(path.join(BIN_DIR, "dependencies", "bb-tools", "bin", bbSigner), bbtoolsBinDest);
utils.copyFile(path.join(BIN_DIR, "dependencies", "bb-tools", "bin", bbDeploy), bbtoolsBinDest);

//copy bb-tools lib folder
wrench.mkdirSyncRecursive(bbtoolsLibDest, 0755);
wrench.copyDirSyncRecursive(path.join(BIN_DIR, "dependencies", "bb-tools", "lib"), bbtoolsLibDest);
}

// copy repo level target tool to project
utils.copyFile(path.join(BIN_DIR, "target"), path.join(project_path, "cordova"));
utils.copyFile(path.join(BIN_DIR, "target.bat"), path.join(project_path, "cordova"));
utils.copyFile(path.join(BIN_DIR, "lib", "target.js"), path.join(project_path, "cordova", "lib"));
utils.copyFile(path.join(BIN_DIR, "lib", "utils.js"), path.join(project_path, "cordova", "lib"));

// copy repo level init script to project
if (utils.isWindows()) {
utils.copyFile(path.join(BIN_DIR, "init.bat"), path.join(project_path, "cordova"));
} else {
utils.copyFile(path.join(BIN_DIR, "init"), path.join(project_path, "cordova"));
}

// change file permission for cordova scripts because ant copy doesn't preserve file permissions
wrench.chmodSyncRecursive(path.join(project_path,"cordova"), 0700);

@@ -133,6 +169,7 @@ function copyFilesToProject() {
//copy node modules to cordova build directory
wrench.mkdirSyncRecursive(nodeModulesDest, 0777);
wrench.copyDirSyncRecursive(MODULES_PROJECT_DIR, nodeModulesDest);

//change permissions of plugman
fs.chmodSync(path.join(nodeModulesDest, "plugman", "main.js"), 0755);

@@ -0,0 +1,53 @@
#! /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.
#
#!/bin/sh
CURRENT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
LOCAL_NODE_BIN=$CURRENT_DIR/dependencies/node/bin
LOCAL_BBTOOLS=$CURRENT_DIR/dependencies/bb-tools/bin

if [ -z "$CORDOVA_NODE" ]; then
if [ -x "$LOCAL_NODE_BIN" ]; then
#set CORDOVA_NODE to local node version, if exists
CORDOVA_NODE=$LOCAL_NODE_BIN
else
#set CORDOVA_NODE to whichever node is on path, if exists
NODE_PATH=$(command -v node)
if [ ! -z "$NODE_PATH" ]; then
CORDOVA_NODE=$(dirname $NODE_PATH)
fi
fi

export CORDOVA_NODE=$CORDOVA_NODE
fi

if [ -z "$CORDOVA_BBTOOLS" ]; then
if [ -x "$LOCAL_BBTOOLS" ]; then
#set CORDOVA_BBTOOLS to local bbtools, if exists
CORDOVA_BBTOOLS=$LOCAL_BBTOOLS
else
#set CORDOVA_BBTOOLS to whichever bbtools is on path, if exists
BBTOOLS_PATH=$(command -v blackberry-nativepackager)
if [ ! -z "$BBTOOLS_PATH" ]; then
CORDOVA_BBTOOLS=$(dirname $BBTOOLS_PATH)
fi
fi

export CORDOVA_BBTOOLS=$CORDOVA_BBTOOLS
fi

@@ -0,0 +1,62 @@
@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

set LOCAL_NODE_BINARY=%~dp0dependencies\node\bin
set LOCAL_BBTOOLS_BINARY=%~dp0dependencies\bb-tools\bin



if defined %CORDOVA_NODE% { goto bbtools }

if exist "%LOCAL_NODE_BINARY%" (
set CORDOVA_NODE=%LOCAL_NODE_BINARY%
) else (
for %%e in (%PATHEXT%) do (
for %%X in (node%%e) do (
if not defined FOUNDNODE (
set FOUNDNODE=%%~$PATH:X
)
)
)

if defined FOUNDNODE (
for %%F in ("%FOUNDNODE%") do set CORDOVA_NODE=%%~dpF
)
)

:bbtools

if defined %CORDOVA_BBTOOLS% { exit /B }

if exist "%LOCAL_BBTOOLS_BINARY%" (
set CORDOVA_BBTOOLS=%LOCAL_BBTOOLS_BINARY%
) else (
for %%e in (%PATHEXT%) do (
for %%X in (blackberry-nativepackager%%e) do (
if not defined FOUNDBBTOOLS (
set FOUNDBBTOOLS=%%~$PATH:X
)
)
)

if defined FOUNDBBTOOLS (
for %%F in ("%FOUNDBBTOOLS%") do set CORDOVA_BBTOOLS=%%~dpF
)
)
@@ -1,3 +1,3 @@
#!/bin/sh

node "$( dirname "$0")/lib/target" "$@"
source $(dirname "$0")/init
"$CORDOVA_NODE/node" "$( dirname "$0")/lib/target" "$@"
@@ -17,5 +17,5 @@ goto comment
specific language governing permissions and limitations
under the License.
:comment

@node.exe %~dps0\lib\target %*
call "%~dp0init"
"%CORDOVA_NODE%\node.exe" "%~dps0\lib\target" %*
@@ -1,5 +1,6 @@
#!/bin/sh
source $(dirname "$0")/init

#package app
node "$(dirname "$0")/lib/build" "$@"
"$CORDOVA_NODE/node" "$(dirname "$0")/lib/build" "$@"

0 comments on commit 7b93346

Please sign in to comment.