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

opencollective-postinstall

Package Overview
Dependencies
Maintainers
2
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

opencollective-postinstall - npm Package Compare versions

Comparing version 1.0.18 to 1.1.0

appveyor.yml

101

bin/setup.js
#!/usr/bin/env node
const utils = require('../lib/utils');
const utils = require("../lib/utils");
const debug = utils.debug;
if (!utils.isDevEnvironment()) {
debug("Not in dev environment");
process.exit(0);
}
const debug = utils.debug;
// In some CI environment, NODE_ENV might not be defined.

@@ -19,4 +19,4 @@ // We exit if `inquirer` module is not installed

const inquirer = require('inquirer');
if (typeof inquirer.prompt([]).then !== 'function') {
const inquirer = require("inquirer");
if (typeof inquirer.prompt([]).then !== "function") {
debug("Wrong version of inquirer, exiting");

@@ -26,6 +26,6 @@ process.exit(0);

const fs = require('fs');
const path = require('path');
const fetchData = require('../lib/fetchData');
const print = require('../lib/print');
const fs = require("fs");
const path = require("path");
const fetchData = require("../lib/fetchData");
const print = require("../lib/print");

@@ -36,6 +36,6 @@ const fetchLogo = fetchData.fetchLogo;

const parentDir = process.cwd().split('/').slice(-2, -1)[0];
if (parentDir !== 'node_modules') {
const parentDir = process.cwd().split(process.platform === 'win32' ? "\\" : "/").slice(-2, -1)[0];
if (parentDir !== "node_modules") {
// No need to run the setup in standalone mode
debug(`Parent dir (${parentDir}) is not "node_modules", exiting`);
debug("Parent dir (" + parentDir + ") is not \"node_modules\", exiting");
debug("Current dir (cwd):", process.cwd());

@@ -45,11 +45,11 @@ process.exit(0);

const projectPackageJSON = path.normalize('../../package.json');
const projectREADME = path.normalize('../../README.md');
const projectPackageJSON = path.normalize("../../package.json");
const projectREADME = path.normalize("../../README.md");
var package;
try {
package = JSON.parse(fs.readFileSync(projectPackageJSON, 'utf8'));
debug(`package.json successfully loaded for ${package.name}`);
package = JSON.parse(fs.readFileSync(projectPackageJSON, "utf8"));
debug("package.json successfully loaded for " + package.name);
} catch(e) {
debug(`Unable to load ${process.cwd()}/${projectPackageJSON}`, e);
debug("Unable to load " + process.cwd() + "/" + projectPackageJSON, e);
}

@@ -68,34 +68,41 @@ if (!package) {

if (process.env.OC_POSTINSTALL_TEST) {
return {
collectiveSlug: package.name,
logo: "https://opencollective.com/opencollective/logo.txt"
};
}
const questions = [
{
type: 'input',
name: 'collectiveSlug',
message: 'Enter the slug of your collective (https://opencollective.com/:slug)',
type: "input",
name: "collectiveSlug",
message: "Enter the slug of your collective (https://opencollective.com/:slug)",
default: package.name,
validate: (str) => {
if(str.match(/^[a-zA-Z\-0-9]+$/)) return true;
else return 'Please enter a valid slug (e.g. https://opencollective.com/webpack)';
else return "Please enter a valid slug (e.g. https://opencollective.com/webpack)";
}
},
{
type: 'list',
name: 'showLogo',
message: 'What logo should we use?',
type: "list",
name: "showLogo",
message: "What logo should we use?",
choices: (answers) => [
{ name: 'Open Collective logo (see above)', value: `https://opencollective.com/opencollective/logo.txt` },
{ name: `The logo of your Collective (https://opencollective.com/${answers.collectiveSlug}/logo.txt)`, value: `https://opencollective.com/${answers.collectiveSlug}/logo.txt` },
{ name: 'Custom URL', value: 'custom'},
{ name: 'No logo', value: null }
{ name: "Open Collective logo (see above)", value: "https://opencollective.com/opencollective/logo.txt" },
{ name: "The logo of your Collective (https://opencollective.com/" + answers.collectiveSlug + "/logo.txt)", value: "https://opencollective.com/" + answers.collectiveSlug + "/logo.txt" },
{ name: "Custom URL", value: "custom"},
{ name: "No logo", value: null }
]
},
{
type: 'input',
name: 'logo',
message: 'URL of your logo in ASCII art',
default: (answers) => `https://opencollective.com/${answers.collectiveSlug}/logo.txt`,
type: "input",
name: "logo",
message: "URL of your logo in ASCII art",
default: (answers) => "https://opencollective.com/" + answers.collectiveSlug + "/logo.txt",
validate: (str) => {
if(str.match(/^https?:\/\/[^\/]+\/.+$/)) return true;
else return 'Please enter a valid url (e.g. https://opencollective.com/webpack/logo.txt)';
else return "Please enter a valid url (e.g. https://opencollective.com/webpack/logo.txt)";
},
when: (answers) => answers.showLogo === 'custom'
when: (answers) => answers.showLogo === "custom"
}

@@ -115,6 +122,6 @@ ];

const ProcessAnswers = function(answers) {
console.log(`> Updating your package.json`);
console.log("> Updating your package.json");
package.collective = {
type: "opencollective",
url: `https://opencollective.com/${answers.collectiveSlug}`
url: "https://opencollective.com/" + answers.collectiveSlug
}

@@ -127,10 +134,10 @@ const logo = answers.logo || answers.showLogo;

}
var postinstall = "node node_modules/.bin/opencollective-postinstall || exit";
var postinstall = "opencollective-postinstall || exit 0";
package.scripts = package.scripts || {};
if (package.scripts.postinstall && package.scripts.postinstall.indexOf(postinstall) === -1) {
package.scripts.postinstall = `${package.scripts.postinstall} && ${postinstall}`;
package.scripts.postinstall = package.scripts.postinstall + " && " + postinstall;
} else {
package.scripts.postinstall = postinstall;
}
fs.writeFileSync(projectPackageJSON, JSON.stringify(package, null, 2), 'utf8');
fs.writeFileSync(projectPackageJSON, JSON.stringify(package, null, 2), "utf8");
return updateREADME(answers.collectiveSlug);

@@ -140,12 +147,10 @@ }

const updateREADME = function(collectiveSlug) {
const badgesmd = `[![Backers on Open Collective](https://opencollective.com/${collectiveSlug}/backers/badge.svg)](#backers)
[![Sponsors on Open Collective](https://opencollective.com/${collectiveSlug}/sponsors/badge.svg)](#sponsors)`;
const badgeshtml = `<a href="#backers" alt="sponsors on Open Collective"><img src="https://opencollective.com/${collectiveSlug}/backers/badge.svg" /></a>
<a href="#sponsors" alt="Sponsors on Open Collective"><img src="https://opencollective.com/${collectiveSlug}/sponsors/badge.svg" /></a>`;
const badgesmd = "[![Backers on Open Collective](https://opencollective.com/" + collectiveSlug + "/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/" + collectiveSlug + "/sponsors/badge.svg)](#sponsors)";
const badgeshtml = "<a href=\"#backers\" alt=\"sponsors on Open Collective\"><img src=\"https://opencollective.com/" + collectiveSlug + "/backers/badge.svg\" /></a> <a href=\"#sponsors\" alt=\"Sponsors on Open Collective\"><img src=\"https://opencollective.com/" + collectiveSlug + "/sponsors/badge.svg\" /></a>";
var readme;
try {
readme = fs.readFileSync(projectREADME, 'utf8');
readme = fs.readFileSync(projectREADME, "utf8");
if (readme.indexOf(`https://opencollective.com/${collectiveSlug}/backers/badge.svg`) !== -1) {
if (readme.indexOf("https://opencollective.com/" + collectiveSlug + "/backers/badge.svg") !== -1) {
console.log("Looks like you already have Open Collective added to your README.md, skipping this step.")

@@ -155,3 +160,3 @@ return;

const lines = readme.split('\n');
const lines = readme.split("\n");
const newLines = [];

@@ -171,3 +176,3 @@

console.log("> Adding badges and placeholders for backers and sponsors on your README.md");
return fs.writeFileSync(projectREADME, newLines.join('\n'), 'utf8');
return fs.writeFileSync(projectREADME, newLines.join("\n"), "utf8");
});

@@ -174,0 +179,0 @@ } catch(e) {

@@ -31,3 +31,3 @@ const execSync = require('child_process').execSync;

opts.align = opts.align || 'center';
const terminalCols = parseInt(execSync(`tput cols`).toString());
const terminalCols = process.platform === 'win32' ? 80 : parseInt(execSync(`tput cols`).toString());
const strLength = str.replace(/\u001b\[[0-9]{2}m/g,'').length;

@@ -34,0 +34,0 @@ const leftPaddingLength = (opts.align === 'center') ? Math.floor((terminalCols - strLength) / 2) : 2;

{
"name": "opencollective-postinstall",
"version": "1.0.18",
"version": "1.1.0",
"description": "Prompt users to donate after they install your node module with npm install",

@@ -11,7 +11,7 @@ "main": "index.js",

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "mocha test",
"postinstall": "node bin/setup.js"
},
"bin": {
"opencollective-postinstall": "./bin/opencollective-postinstall.js"
"opencollective-postinstall": "./bin/opencollective-postinstall"
},

@@ -35,3 +35,8 @@ "keywords": [

"inquirer": "^3.0.6"
},
"devDependencies": {
"chai": "3.5.0",
"cross-env": "^4.0.0",
"mocha": "3.2.0"
}
}

Sorry, the diff of this file is not supported yet

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