Adding node to cache dir. Allow user to specify source dir. Clean up some code.
This commit is contained in:
Родитель
3f78df9a60
Коммит
6274945179
31
bin/compile
31
bin/compile
|
@ -15,7 +15,11 @@ CACHE_DIR=${2:-}
|
|||
ENV_DIR=${3:-}
|
||||
|
||||
BP_DIR=$(cd $(dirname ${0:-}); cd ..; pwd)
|
||||
SALESFORCE_DIR=$BUILD_DIR/.salesforce
|
||||
|
||||
### Configure salesforce directories
|
||||
SALESFORCE_DIR_NAME=".salesforce"
|
||||
SALESFORCE_DIR=$BUILD_DIR/$SALESFORCE_DIR_NAME
|
||||
SALESFORCE_CACHE_DIR=$CACHE_DIR/$SALESFORCE_DIR_NAME
|
||||
|
||||
### Load dependencies
|
||||
|
||||
|
@ -27,21 +31,30 @@ source $BP_DIR/lib/node.sh
|
|||
status "Exporting config vars to environment"
|
||||
export_env_dir
|
||||
|
||||
install_nodejs $SALESFORCE_DIR
|
||||
install_nodejs $SALESFORCE_CACHE_DIR
|
||||
|
||||
status "Coping deploy script to .salesforce/deploy"
|
||||
cp $BP_DIR/lib/deploy.js $SALESFORCE_DIR/deploy
|
||||
cp $BP_DIR/lib/deploy.js $SALESFORCE_DIR/deploy.js
|
||||
cp $BP_DIR/package.json $SALESFORCE_DIR/package.json
|
||||
|
||||
echo "node ./.salesforce/deploy.js" > $SALESFORCE_DIR/deploy
|
||||
chmod +x $SALESFORCE_DIR/deploy
|
||||
|
||||
status "Installing modules"
|
||||
cd $SALESFORCE_DIR
|
||||
npm install | indent
|
||||
|
||||
status "Building ZIP from salesforce/src to .salesforce/src.zip"
|
||||
mkdir -p metadata
|
||||
rm -rf metadata/*
|
||||
cp -r $BUILD_DIR/salesforce/src/ metadata
|
||||
zip -r $SALESFORCE_DIR/src.zip metadata | indent
|
||||
# Allow the user to specify the salesforce source. We only want to zip one
|
||||
# level above the source, and zip includes relative paths. So we first cd one
|
||||
# level above, the SRC_DIR, then zip the source folder, the SRC_FOLDER.
|
||||
SRC_PATH=${SALESFORCE_SRC_PATH:-"salesforce/src"}
|
||||
SRC_DIR=$(dirname $SRC_PATH)
|
||||
SRC_FOLDER=$(basename $SRC_PATH)
|
||||
|
||||
status "Building ZIP from $SRC_DIR to $SALESFORCE_DIR_NAME/src.zip"
|
||||
rm -f $SALESFORCE_DIR/src.zip
|
||||
cd $BUILD_DIR/$SRC_DIR
|
||||
zip -r $SALESFORCE_DIR/src.zip $SRC_FOLDER | indent
|
||||
|
||||
echo ""
|
||||
echo "Configure your application to invoke 'node .salesforce/deploy' in your release phase script or Procfile"
|
||||
echo "Configure your application to invoke '$SALESFORCE_DIR_NAME/deploy' in your release phase script or Procfile"
|
||||
|
|
|
@ -23,19 +23,18 @@ var fs = require('fs');
|
|||
var jsforce = require('jsforce');
|
||||
var Promise = require('bluebird');
|
||||
|
||||
var connection = new Promise(function (resolve, reject) {
|
||||
var oauth2 = new jsforce.OAuth2({
|
||||
var connection = new jsforce.OAuth2({
|
||||
clientId : clientId,
|
||||
clientSecret : clientSecret
|
||||
}).refreshToken(refreshToken, function(res, body) {
|
||||
}).refreshToken(refreshToken)
|
||||
.then(function(body) {
|
||||
// Logging too be able to log in through the UI. Set as an env var?
|
||||
console.log(body.access_token);
|
||||
resolve(new jsforce.Connection({
|
||||
return new jsforce.Connection({
|
||||
instanceUrl : `https://${instance}`,
|
||||
accessToken : body.access_token
|
||||
}));
|
||||
}).catch(reject);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
console.log('-----> Deploying metadata');
|
||||
connection.then(function(conn) {
|
||||
|
@ -46,7 +45,7 @@ connection.then(function(conn) {
|
|||
console.log(' polling...');
|
||||
});
|
||||
deployLocator.complete(true, function(err, result) {
|
||||
console.log(' ' + results.success);
|
||||
console.log(' ' + (result.success ? 'Success' : 'Failed'));
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
|
|
39
lib/node.sh
39
lib/node.sh
|
@ -1,3 +1,21 @@
|
|||
create_signature() {
|
||||
echo "$(node --version)"
|
||||
}
|
||||
|
||||
save_signature() {
|
||||
local sig_file="$1/signature"
|
||||
echo "$(create_signature)" > $sig_file
|
||||
}
|
||||
|
||||
load_signature() {
|
||||
local sig_file="$1/signature"
|
||||
if test -f $sig_file; then
|
||||
cat $sig_file
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
# Get the node binary from the heroku. Similar to how heroku does it but
|
||||
# without package.json resolution for the node version, since we only need
|
||||
# to install node to make this build pack work, not to support customer
|
||||
|
@ -9,12 +27,17 @@ install_nodejs() {
|
|||
local version=5.11.1
|
||||
local version_str="v$version-$(get_os)-$(get_cpu)"
|
||||
|
||||
status "Downloading and installing node $version..."
|
||||
mkdir -p "$dir"
|
||||
local download_url="https://s3pository.heroku.com/node/v$version/node-$version_str.tar.gz"
|
||||
curl "$download_url" --silent --fail --retry 5 --retry-max-time 15 -o /tmp/node.tar.gz || (echo "Unable to download node $version; does it exist?" && false)
|
||||
tar xzf /tmp/node.tar.gz -C /tmp
|
||||
rm -rf $dir/*
|
||||
mv /tmp/node-$version_str/* $dir
|
||||
chmod +x $dir/bin/*
|
||||
if [ "$(create_signature)" != "$(load_signature $dir)" ]; then
|
||||
status "Downloading and installing node $version..."
|
||||
mkdir -p "$dir"
|
||||
local download_url="https://s3pository.heroku.com/node/v$version/node-$version_str.tar.gz"
|
||||
curl "$download_url" --silent --fail --retry 5 --retry-max-time 15 -o /tmp/node.tar.gz || (echo "Unable to download node $version; does it exist?" && false)
|
||||
tar xzf /tmp/node.tar.gz -C /tmp
|
||||
rm -rf $dir/*
|
||||
mv /tmp/node-$version_str/* $dir
|
||||
chmod +x $dir/bin/*
|
||||
save_signature $dir
|
||||
else
|
||||
status "Using cached node version $version..."
|
||||
fi
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче