Skip to content

Instantly share code, notes, and snippets.

@evil-shrike
Created October 18, 2016 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evil-shrike/c7c625cf3ea4f2b54909a789a871f8d5 to your computer and use it in GitHub Desktop.
Save evil-shrike/c7c625cf3ea4f2b54909a789a871f8d5 to your computer and use it in GitHub Desktop.
artifactory-publisher example usage
var fs = require("fs");
var path = require("path");
var Q = require("Q");
var async = require("async");
var publisher = require("artifactory-publisher");
var artUrlBase = "http://artifacts.mydomain.com/my-repo/";
var options = {
credentials: {
username: "user1",
password: "pa$$w0rd"
}
//proxy: "http://localhost:8888"
}
var args = [].splice.call(process.argv, 2);
var folderPath; // path where files to publish are located
if (args.length === 0) {
console.log("USAGE: node deploy.js path/to/folder"); // assuming the current file is 'deploy.js'
return;
} else {
folderPath = args[0];
}
function extractProps (filePath) {
// XFW3.Core.1.16.0.nupkg => {product: "XFW3", version: "1.16"}
// XFW3.SmartClient.1.15.2.nupkg => {product: "XFW3.SmartClient", version: "1.15"}
// XFW3.WebClient.0.19.0.nupkg => {product: "WebClient", version: "0.19"}
if (!fs.statSync(filePath).isFile()) { return; }
var filename = path.parse(filePath).name;
if (!filename) { return; }
// looking for xxx.1.2.3yyy.nupkg
var parts = /(.*)\.([\d]+\.[\d]+)\.[\d]+.*\.nupkg/.exec(filename)
if (!parts) { return; }
return {
product: parts[1],
version: parts[2]
};
}
fs.readdir(folderPath, function (err,files) {
if (err != null) {
throw err;
}
async.eachSeries(files, function (fileName, cb) {
var filePath = path.resolve(folderPath + path.sep + fileName);
var props = extractProps(filePath);
if (!props) {
cb();
return;
}
var product = props.product.toLowerCase();
if (product.indexOf("xfw3.webclient") === 0) {
product = "WebClient";
} else if (product.indexOf("xfw3.smartclient") === 0) {
product = "XFW3.SmartClient";
} else if (product.indexOf("xfw3") === 0) {
product = "XFW3";
} else {
cb();
return;
}
var artUrl = artUrlBase + product + "/" + props.version + "/" + fileName;
console.log("Publishing " + filePath + " to " + artUrl);
// options.dryRun = true;
publisher.publish(filePath, artUrl, options).then(function () {
console.log("OK");
cb();
});
}, function () {
console.log("Done!\n");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment