Skip to content

Commit

Permalink
fix-marketplace-install
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoffrey Goh committed Jul 6, 2016
1 parent fc249eb commit de51e41
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 429 deletions.
85 changes: 12 additions & 73 deletions Tasks/codepush-patch/codepush-patch.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,5 @@
var path = require("path");
var tl = require("vsts-task-lib");
require("shelljs/global");

// Global variables.
var codePushCommandPrefix = "node " + path.join(__dirname, "node_modules", "code-push-cli", "script", "cli");

// Export for unit testing.
function log(message) {
console.log(message);
}

// Helper functions.
function buildCommand(cmd, positionArgs, optionFlags) {
var command = codePushCommandPrefix + " " + cmd;

positionArgs && positionArgs.forEach(function (positionArg) {
command = command + " \"" + positionArg + "\"";
});

for (var flag in optionFlags) {
// If the value is falsey, the option flag doesn't have to be specified.
if (optionFlags[flag] || optionFlags[flag] === "") {
var flagValue = "" + optionFlags[flag];

command = command + " --" + flag;
command = command + " \"" + flagValue + "\"";
}
}

return command;
}

function executeCommandAndHandleResult(cmd, positionArgs, optionFlags) {
var command = buildCommand(cmd, positionArgs, optionFlags);

var result = exec(command, { silent: true });

if (result.code == 0) {
module.exports.log(result.output);
} else {
tl.setResult(1, result.output);
ensureLoggedOut();
throw new Error(result.output);
}

return result;
}

function ensureLoggedOut() {
exec(buildCommand("logout"), { silent: true });
}
var CodePushSdk = require("code-push");

// The main function to be executed.
function performPatchTask(accessKey, appName, deploymentName, label, description, isDisabled, isMandatory, rollout, appStoreVersion) {
Expand All @@ -75,37 +25,26 @@ function performPatchTask(accessKey, appName, deploymentName, label, description
console.error("Access key required");
tl.setResult(1, "Access key required");
}

// Ensure all other users are logged out.
ensureLoggedOut();

// Log in to the CodePush CLI.
executeCommandAndHandleResult("login", /*positionArgs*/ null, { accessKey: accessKey });

// Run release command.
executeCommandAndHandleResult(
"patch",
[appName, deploymentName],

var codePushSdk = new CodePushSdk(accessKey);
codePushSdk.patchRelease(
appName, deploymentName, label,
{
label: (label === "latest" ? false : label),
description: (description === "noChange" ? false : description),
disabled: (isDisabled === "noChange" ? false : isDisabled),
mandatory: (isMandatory === "noChange" ? false : isMandatory),
rollout: (rollout === "noChange" ? false : rollout),
rollout: (rollout === "noChange" ? null : parseInt(rollout.replace("%", ""))),
targetBinaryVersion: (appStoreVersion === "noChange" ? false : appStoreVersion)
}
);

// Log out.
ensureLoggedOut();
})
.done(function() {
tl.setResult(1, "Successfully patched " + appName + " - " + deploymentName + " (" + label + ")");
}, function(error) {
throw error;
});
}

module.exports = {
buildCommand: buildCommand,
commandPrefix: codePushCommandPrefix,
ensureLoggedOut: ensureLoggedOut,
executeCommandAndHandleResult: executeCommandAndHandleResult,
log: log,
performPatchTask: performPatchTask
}

Expand Down
4 changes: 2 additions & 2 deletions Tasks/codepush-patch/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vsts-task-code-push-patch",
"version": "1.0.0",
"version": "1.0.1",
"description": "Update the metadata for an existing release",
"main": "codepush-patch.js",
"scripts": {
Expand All @@ -10,7 +10,7 @@
"author": "Microsoft Corporation",
"license": "ISC",
"dependencies": {
"code-push-cli": "^1.10.0-beta",
"code-push": "github:Microsoft/code-push#code-push-sdk-lite",
"vsts-task-lib": "^0.5.7"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion Tasks/codepush-patch/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": "1",
"Minor": "0",
"Patch": "0"
"Patch": "1"
},
"minimumAgentVersion": "1.83.0",
"instanceNameFormat": "Patch the $(releaseLabel) release for $(deploymentName) ($(appName))",
Expand Down
135 changes: 0 additions & 135 deletions Tasks/codepush-patch/test.js

This file was deleted.

83 changes: 9 additions & 74 deletions Tasks/codepush-promote/codepush-promote.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,5 @@
var path = require("path");
var tl = require("vsts-task-lib");
require("shelljs/global");

// Global variables.
var codePushCommandPrefix = "node " + path.join(__dirname, "node_modules", "code-push-cli", "script", "cli");

// Export for unit testing.
function log(message) {
console.log(message);
}

// Helper functions.
function buildCommand(cmd, positionArgs, optionFlags) {
var command = codePushCommandPrefix + " " + cmd;

positionArgs && positionArgs.forEach(function (positionArg) {
command = command + " \"" + positionArg + "\"";
});

for (var flag in optionFlags) {
// If the value is falsey, the option flag doesn't have to be specified.
if (optionFlags[flag] || optionFlags[flag] === "") {
var flagValue = "" + optionFlags[flag];

command = command + " --" + flag;
// For boolean flags, the presence of the flag is enough to indicate its value.
if (flagValue != "true") {
command = command + " \"" + flagValue + "\"";
}
}
}

return command;
}

function executeCommandAndHandleResult(cmd, positionArgs, optionFlags) {
var command = buildCommand(cmd, positionArgs, optionFlags);

var result = exec(command, { silent: true });

if (result.code == 0) {
module.exports.log(result.output);
} else {
tl.setResult(1, result.output);
ensureLoggedOut();
throw new Error(result.output);
}

return result;
}

function ensureLoggedOut() {
exec(buildCommand("logout"), { silent: true });
}
var CodePushSdk = require("code-push");

// The main function to be executed.
function performPromoteTask(accessKey, appName, sourceDeploymentName, targetDeploymentName, appStoreVersion, description, rollout, isMandatory, isDisabled) {
Expand Down Expand Up @@ -84,31 +31,19 @@ function performPromoteTask(accessKey, appName, sourceDeploymentName, targetDepl
description: description === "Inherit" ? null : description,
disabled: isDisabled === "Inherit" ? null : isDisabled,
mandatory: isMandatory === "Inherit" ? null : isMandatory,
rollout: rollout
rollout: parseInt(rollout.replace("%", ""))
};

// Ensure all other users are logged out.
ensureLoggedOut();

// Log in to the CodePush CLI.
executeCommandAndHandleResult("login", /*positionArgs*/ null, { accessKey: accessKey });

// Run promote command.
executeCommandAndHandleResult(
"promote",
[appName, sourceDeploymentName, targetDeploymentName],
updateMetadata);

// Log out.
ensureLoggedOut();
var codePushSdk = new CodePushSdk(accessKey);
return codePushSdk.promote(appName, sourceDeploymentName, targetDeploymentName, updateMetadata)
.done(function() {
tl.setResult(1, "Successfully promoted " + sourceDeploymentName + " to " + targetDeploymentName);
}, function(error) {
throw error;
});
}

module.exports = {
buildCommand: buildCommand,
commandPrefix: codePushCommandPrefix,
ensureLoggedOut: ensureLoggedOut,
executeCommandAndHandleResult: executeCommandAndHandleResult,
log: log,
performPromoteTask: performPromoteTask
}

Expand Down
4 changes: 2 additions & 2 deletions Tasks/codepush-promote/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vsts-task-code-push-promote",
"version": "1.2.1",
"version": "1.2.2",
"description": "Promote a CodePush release from one deployment to another",
"main": "codepush-promote.js",
"scripts": {
Expand All @@ -10,7 +10,7 @@
"author": "Microsoft Corporation",
"license": "ISC",
"dependencies": {
"code-push-cli": "^1.10.0-beta",
"code-push": "github:Microsoft/code-push#code-push-sdk-lite",
"vsts-task-lib": "^0.5.7"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion Tasks/codepush-promote/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": "1",
"Minor": "2",
"Patch": "1"
"Patch": "2"
},
"minimumAgentVersion": "1.83.0",
"instanceNameFormat": "Promote $(sourceDeploymentName) to $(targetDeploymentName) ($(appName))",
Expand Down
Loading

0 comments on commit de51e41

Please sign in to comment.