diff --git a/bin/node-pre-gyp-github.js b/bin/node-pre-gyp-github.js index aa3640a..6f85549 100644 --- a/bin/node-pre-gyp-github.js +++ b/bin/node-pre-gyp-github.js @@ -5,7 +5,7 @@ var program = require('commander'); program .command('publish [options]') - .description('publish the contents of .\\bin\\stage to the current version\'s GitHub release') + .description('publishes the contents of .\\build\\stage\\{version} to the current version\'s GitHub release') .option("-r, --release", "publish immediately, do not create draft") .action(function(cmd, options){ var opts = {}, @@ -20,7 +20,7 @@ program console.log(); console.log('Usage: node-pre-gyp-github publish'); console.log(); - console.log('publish the contents of .\\bin\\stage to the current version\'s GitHub release'); + console.log('publishes the contents of .\\build\\stage\\{version} to the current version\'s GitHub release'); }); program.parse(process.argv); diff --git a/index.js b/index.js index f069449..aee3862 100644 --- a/index.js +++ b/index.js @@ -22,7 +22,7 @@ NodePreGypGithub.prototype.init = function() { this.package_json = JSON.parse(fs.readFileSync(path.join(cwd,'package.json'))); if(!this.package_json.repository || !this.package_json.repository.url){ - throw new Error('Error: Missing repository.url in package.json'); + throw new Error('Missing repository.url in package.json'); } else { ownerRepo = this.package_json.repository.url.match(/github\.com\/(.*)(?=\.git)/i); @@ -31,15 +31,15 @@ NodePreGypGithub.prototype.init = function() { this.owner = ownerRepo[0]; this.repo = ownerRepo[1]; } - else throw new Error('Error: A correctly formatted GitHub repository.url was not found within package.json'); + else throw new Error('A correctly formatted GitHub repository.url was not found within package.json'); } hostPrefix = 'https://github.com/' + this.owner + '/' + this.repo + '/releases/download/'; if(!this.package_json.binary || 'object' !== typeof this.package_json.binary || 'string' !== typeof this.package_json.binary.host){ - throw new Error('Error: Missing binary.host in package.json, configure node-pre-gyp first'); + throw new Error('Missing binary.host in package.json'); } else if (this.package_json.binary.host.substr(0, hostPrefix.length) !== hostPrefix){ - throw new Error('Error: binary.host in package.json should begin with: "' + hostPrefix + '"'); + throw new Error('binary.host in package.json should begin with: "' + hostPrefix + '"'); } this.github = new GitHubApi({ // set defaults @@ -58,9 +58,11 @@ NodePreGypGithub.prototype.init = function() { }; NodePreGypGithub.prototype.authenticate_settings = function(){ + var token = process.env.NODE_PRE_GYP_GITHUB_TOKEN; + if(!token) throw new Error('NODE_PRE_GYP_GITHUB_TOKEN environment variable not found'); return { - type: "oauth", - token: process.env.NODE_PRE_GYP_GITHUB_TOKEN + "type": "oauth", + "token": token }; }; @@ -106,14 +108,14 @@ NodePreGypGithub.prototype.uploadAssets = function(){ fs.readdir(path.join(this.stage_dir), function(err, files){ if(err) throw err; - if(typeof files === 'undefined') throw new Error('No file found to upload'); + if(!files.length) throw new Error('No files found within the stage directory: ' + this.stage_dir); files.forEach(function(file){ asset = this.release.assets.filter(function(element, index, array){ return element.name === file; }); if(asset.length) { - console.log("Staged file " + file + " found but it already exists in release " + this.release.tag_name + ". If you would like to replace it, you must first manually delete it within GitHub."); + throw new Error("Staged file " + file + " found but it already exists in release " + this.release.tag_name + ". If you would like to replace it, you must first manually delete it within GitHub."); } else { console.log("Staged file " + file + " found. Proceeding to upload it."); @@ -158,11 +160,12 @@ NodePreGypGithub.prototype.publish = function(options) { if(!release.length) { this.createRelease(options, function(err, release) { if(err) throw err; - + this.release = release; if (release.draft) { console.log('Release ' + release.tag_name + " not found, so a draft release was created. YOU MUST MANUALLY PUBLISH THIS DRAFT WITHIN GITHUB FOR IT TO BE ACCESSIBLE."); - } else { + } + else { console.log('Release ' + release.tag_name + " not found, so a new release was created and published."); } this.uploadAssets();