Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-pre-gyp-github

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-pre-gyp-github - npm Package Compare versions

Comparing version 1.2.2 to 1.3.0

2

bin/node-pre-gyp-github.js

@@ -10,2 +10,3 @@ #!/usr/bin/env node

.option("-r, --release", "publish immediately, do not create draft")
.option("-s, --silent", "turns verbose messages off")
.action(function(cmd, options){

@@ -15,2 +16,3 @@ var opts = {},

opts.draft = options.release ? false : true;
opts.verbose = options.silent ? false : true;
x.publish(opts);

@@ -17,0 +19,0 @@ });

29

index.js
"use strict";
var path = require("path");
var fs = require('fs');
var GitHubApi = require("github");
var cwd = process.cwd();
var path = require("path");
var fs = require('fs');
var GitHubApi = require("github");
var cwd = process.cwd();
var verbose;
var consoleLog = function(x){
return (verbose) ? consoleLog(x) : false;
};
function NodePreGypGithub() {}

@@ -80,7 +85,7 @@

Object.keys(args).forEach(function(key) {
if(args.hasOwnProperty(key)) {
if(args.hasOwnProperty(key) && options.hasOwnProperty(key)) {
options[key] = args[key];
}
});
this.github.authenticate(this.authenticate_settings());

@@ -100,3 +105,3 @@ this.github.releases.createRelease(options, callback);

if(err) throw err;
console.log('Staged file ' + cfg.fileName + ' saved to ' + this.owner + '/' + this.repo + ' release ' + this.release.tag_name + ' successfully.');
consoleLog('Staged file ' + cfg.fileName + ' saved to ' + this.owner + '/' + this.repo + ' release ' + this.release.tag_name + ' successfully.');
}.bind(this));

@@ -107,3 +112,3 @@ };

var asset;
console.log("Stage directory path: " + path.join(this.stage_dir));
consoleLog("Stage directory path: " + path.join(this.stage_dir));
fs.readdir(path.join(this.stage_dir), function(err, files){

@@ -122,3 +127,3 @@ if(err) throw err;

else {
console.log("Staged file " + file + " found. Proceeding to upload it.");
consoleLog("Staged file " + file + " found. Proceeding to upload it.");
this.uploadAsset({

@@ -134,2 +139,4 @@ fileName: file,

NodePreGypGithub.prototype.publish = function(options) {
options = (typeof options === 'undefined') ? {} : options;
verbose = (typeof options.verbose === 'undefined' || options.verbose) ? true : false;
this.init();

@@ -172,6 +179,6 @@ this.github.authenticate(this.authenticate_settings());

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.");
consoleLog('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 {
console.log('Release ' + release.tag_name + " not found, so a new release was created and published.");
consoleLog('Release ' + release.tag_name + " not found, so a new release was created and published.");
}

@@ -178,0 +185,0 @@ this.uploadAssets();

{
"name": "node-pre-gyp-github",
"version": "1.2.2",
"version": "1.3.0",
"description": "A node-pre-gyp module which provides the ability to publish to GitHub releases.",

@@ -9,3 +9,3 @@ "bin": "./bin/node-pre-gyp-github.js",

"test": "mocha test",
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec"
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha --report text-lcov -- -R spec | node ./node_modules/coveralls/bin/coveralls.js"
},

@@ -34,2 +34,3 @@ "repository": {

"chai": "^3.5.0",
"coveralls": "^2.11.9",
"istanbul": "^0.4.3",

@@ -36,0 +37,0 @@ "mocha": "^2.5.3"

# node-pre-gyp-github
##### A node-pre-gyp module which provides the ability to publish to GitHub releases.
[![Coverage Status](https://coveralls.io/repos/github/bchr02/node-pre-gyp-github/badge.svg?branch=master)](https://coveralls.io/github/bchr02/node-pre-gyp-github?branch=master)
[![Join the chat at https://gitter.im/bchr02/node-pre-gyp-github](https://badges.gitter.im/bchr02/node-pre-gyp-github.svg)](https://gitter.im/bchr02/node-pre-gyp-github?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

@@ -9,6 +10,7 @@

## Options
## Options for publish command
* --silent : Turns verbose messages off.
* --release : Publish the GitHub Release immediately instead of creating a Draft.
ex. ```node-pre-gyp-github publish --release```
For Ex. ```node-pre-gyp-github publish --release```

@@ -15,0 +17,0 @@ ## Install

@@ -13,3 +13,3 @@ "use strict";

var reset_mocks = function() {
process.env['NODE_PRE_GYP_GITHUB_TOKEN'] = "secret";
process.env.NODE_PRE_GYP_GITHUB_TOKEN = "secret";
fs = reset_index('fs');

@@ -23,3 +23,3 @@ fs.readFileSync = function(){return '{"name":"test","version":"0.0.1","repository": {"url":"git+https://github.com/test/test.git"},"binary":{"host":"https://github.com/test/test/releases/download/","remote_path":"{version}"}}';};

index.github.releases.createRelease = function(options, cb){
cb(null,{"tag_name":"0.0.1","assets":[{}]});
cb(null,{"tag_name":"0.0.1","draft":true,"assets":[{}]});
};

@@ -29,36 +29,71 @@ index.github.releases.uploadAsset = function(cfg,cb){cb();};

if(!process.env.COVERALLS_SERVICE_NAME) console.log('To post to coveralls.io, be sure to set COVERALLS_SERVICE_NAME environment variable');
if(!process.env.COVERALLS_REPO_TOKEN) console.log('To post to coveralls.io, be sure to set COVERALLS_REPO_TOKEN environment variable');
describe("Publishes packages to GitHub Releases", function() {
describe("Throws an Error when node-pre-gyp-github is not configured properly", function() {
describe("Publishes without an error under all options", function() {
it("should publish a non-draft release without an error", function() {
var options = {'draft': false, 'verbose': false};
reset_mocks();
fs.readdir = function(filename, cb) {
cb(null,["filename"]);
};
index.github.releases.createRelease = function(options, cb){
cb(null,{"tag_name":"0.0.1","draft":false,"assets":[{}]});
};
expect(function(){ index.publish(options); }).to.not.throw();
});
it("should publish a draft release without an error", function() {
var options = {'draft': true, 'verbose': false};
reset_mocks();
fs.readdir = function(filename, cb) {
cb(null,["filename"]);
};
expect(function(){ index.publish(options); }).to.not.throw();
});
});
describe("Throws an error when node-pre-gyp-github is not configured properly", function() {
it("should throw an error when missing repository.url in package.json", function() {
var options = {'draft': true, 'verbose': false};
reset_mocks();
fs.readFileSync = function(){return '{}';};
expect(function(){ index.publish(); }).to.throw("Missing repository.url in package.json");
expect(function(){ index.publish(options); }).to.throw("Missing repository.url in package.json");
});
it("should throw an error when a correctly formatted GitHub repository.url is not found in package.json", function() {
var options = {'draft': true, 'verbose': false};
reset_mocks();
fs.readFileSync = function(){return '{"repository": {"url":"bad_format_url"}}';};
expect(function(){ index.publish(); }).to.throw("A correctly formatted GitHub repository.url was not found within package.json");
expect(function(){ index.publish(options); }).to.throw("A correctly formatted GitHub repository.url was not found within package.json");
});
it("should throw an error when missing binary.host in package.json", function() {
var options = {'draft': true, 'verbose': false};
reset_mocks();
fs.readFileSync = function(){return '{"repository": {"url":"git+https://github.com/test/test.git"}}';};
expect(function(){ index.publish(); }).to.throw("Missing binary.host in package.json");
expect(function(){ index.publish(options); }).to.throw("Missing binary.host in package.json");
});
it("should throw an error when binary.host does not begin with the correct url", function() {
var options = {'draft': true, 'verbose': false};
reset_mocks();
fs.readFileSync = function(){return '{"repository": {"url":"git+https://github.com/test/test.git"},"binary":{"host":"bad_format_binary"}}';};
expect(function(){ index.publish(); }).to.throw(/^binary.host in package.json should begin with:/i);
expect(function(){ index.publish(options); }).to.throw(/^binary.host in package.json should begin with:/i);
});
it("should throw an error when the NODE_PRE_GYP_GITHUB_TOKEN environment variable is not found", function() {
var options = {'draft': true, 'verbose': false};
reset_mocks();
process.env['NODE_PRE_GYP_GITHUB_TOKEN'] = "";
expect(function(){ index.publish(); }).to.throw("NODE_PRE_GYP_GITHUB_TOKEN environment variable not found");
process.env.NODE_PRE_GYP_GITHUB_TOKEN = "";
expect(function(){ index.publish(options); }).to.throw("NODE_PRE_GYP_GITHUB_TOKEN environment variable not found");
});
it("should throw an error when github.releases.listReleases returns an error", function() {
var options = {'draft': true, 'verbose': false};
reset_mocks();

@@ -68,7 +103,7 @@ index.github.releases.listReleases = function(options, cb){

};
expect(function(){ index.publish(); }).to.throw('listReleases error');
expect(function(){ index.publish(options); }).to.throw('listReleases error');
});
it("should throw an error when github.releases.createRelease returns an error", function() {
var options = {'draft': true};
var options = {'draft': true, 'verbose': false};
reset_mocks();

@@ -85,3 +120,3 @@ index.github.releases.listReleases = function(options, cb){

it("should throw an error when the stage directory structure is missing", function() {
var options = {'draft': true};
var options = {'draft': true, 'verbose': false};
reset_mocks();

@@ -95,3 +130,3 @@ fs.readdir = function(filename, cb) {

it("should throw an error when there are no files found within the stage directory", function() {
var options = {'draft': true};
var options = {'draft': true, 'verbose': false};
reset_mocks();

@@ -105,3 +140,3 @@ fs.readdir = function(filename, cb) {

it("should throw an error when a staged file already exists in the current release", function() {
var options = {'draft': true};
var options = {'draft': true, 'verbose': false};
reset_mocks();

@@ -118,3 +153,3 @@ fs.readdir = function(filename, cb) {

it("should throw an error when github.releases.uploadAsset returns an error", function() {
var options = {'draft': true};
var options = {'draft': true, 'verbose': false};
reset_mocks();

@@ -130,8 +165,16 @@ fs.readdir = function(filename, cb) {

it("should publish without an error", function() {
var options = {'draft': true};
});
describe("Verify backwords compatible with any breaking changes made within the same MINOR version.", function() {
it("should publish even when package.json's binary.remote_path property is not provided and instead the version is hard coded within binary.host", function() {
var options = {'draft': false, 'verbose': false};
reset_mocks();
fs.readFileSync = function(){return '{"name":"test","version":"0.0.1","repository": {"url":"git+https://github.com/test/test.git"},"binary":{"host":"https://github.com/test/test/releases/download/0.0.1"}}';};
fs.readdir = function(filename, cb) {
cb(null,["filename"]);
};
index.github.releases.createRelease = function(options, cb){
cb(null,{"tag_name":"0.0.1","draft":false,"assets":[{}]});
};
expect(function(){ index.publish(options); }).to.not.throw();

@@ -138,0 +181,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc