├── .github └── dependabot.yml ├── .gitignore ├── README.md ├── index.js ├── package.json ├── LICENSE └── index.test.js /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: npm 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | timezone: Europe/Berlin 8 | open-pull-requests-limit: 10 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | yarn.lock 3 | # Logs 4 | logs 5 | *.log 6 | npm-debug.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | 13 | # Directory for instrumented libs generated by jscoverage/JSCover 14 | lib-cov 15 | 16 | # Coverage directory used by tools like istanbul 17 | coverage 18 | 19 | # nyc test coverage 20 | .nyc_output 21 | 22 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 23 | .grunt 24 | 25 | # node-waf configuration 26 | .lock-wscript 27 | 28 | # Compiled binary addons (http://nodejs.org/api/addons.html) 29 | build/Release 30 | 31 | # Dependency directories 32 | node_modules 33 | jspm_packages 34 | 35 | # Optional npm cache directory 36 | .npm 37 | 38 | # Optional REPL history 39 | .node_repl_history 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Open Collective postinstall 2 | 3 | Lightweight npm postinstall message to invite people to donate to your collective 4 | 5 | ## Installation 6 | 7 | ``` 8 | npm install --save opencollective-postinstall 9 | ``` 10 | 11 | And in your `package.json` add: 12 | 13 | ```json 14 | { 15 | ... 16 | "scripts": { 17 | "postinstall": "opencollective-postinstall" 18 | }, 19 | "collective": { 20 | "url": "https://opencollective.com/webpack" 21 | } 22 | ... 23 | } 24 | ``` 25 | 26 | ## Disabling this message 27 | 28 | In some places (e.g. CI) you may want to disable this output. You can do this by setting the environment variable `DISABLE_OPENCOLLECTIVE=true`. 29 | 30 | It will not be shown if npm's log level is set to silent (`--silent`), warn (`--quiet`), or error (`--loglevel error`). 31 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | function isTrue(value) { 4 | return !!value && value !== "0" && value !== "false" 5 | } 6 | 7 | var envDisable = isTrue(process.env.DISABLE_OPENCOLLECTIVE) || isTrue(process.env.OPEN_SOURCE_CONTRIBUTOR) || isTrue(process.env.CI); 8 | var logLevel = process.env.npm_config_loglevel; 9 | var logLevelDisplay = ['silent', 'error', 'warn'].indexOf(logLevel) > -1; 10 | 11 | if (!envDisable && !logLevelDisplay) { 12 | var pkg = require(require('path').resolve('./package.json')); 13 | if (pkg.collective) { 14 | console.log(`\u001b[96m\u001b[1mThank you for using ${pkg.name}!\u001b[96m\u001b[1m`); 15 | console.log(`\u001b[0m\u001b[96mIf you rely on this package, please consider supporting our open collective:\u001b[22m\u001b[39m`); 16 | console.log(`> \u001b[94m${pkg.collective.url}/donate\u001b[0m\n`); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "opencollective-postinstall", 3 | "version": "2.0.3", 4 | "description": "Lightweight npm postinstall message to invite people to donate to your collective", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/opencollective/opencollective-postinstall.git" 12 | }, 13 | "files": [ 14 | "index.js" 15 | ], 16 | "bin": "index.js", 17 | "keywords": [ 18 | "opencollective", 19 | "donation", 20 | "funding", 21 | "sustain" 22 | ], 23 | "author": "Xavier Damman (@xdamman)", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/opencollective/opencollective-postinstall/issues" 27 | }, 28 | "homepage": "https://github.com/opencollective/opencollective-postinstall#readme", 29 | "devDependencies": { 30 | "jest": "^27.0.6" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Open Collective 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /index.test.js: -------------------------------------------------------------------------------- 1 | jest.mock('./package.json', () => ({ 2 | name: 'testpkg2', 3 | collective: {url: 'testurl'} 4 | }), {virtual: true}); 5 | 6 | describe('test all the things', () => { 7 | const env = global.process.env; 8 | const console = global.console; 9 | beforeEach(() => { 10 | global.console = {log: jest.fn(), warn: global.console.warn}; 11 | }); 12 | afterEach(() => { 13 | global.process.env = env; 14 | global.console.log.mockReset(); 15 | global.console = console; 16 | jest.resetModules(); 17 | }); 18 | 19 | describe('outputs the correct values', () => { 20 | it('when called without args', () =>{ 21 | expect(global.console.log).not.toHaveBeenCalled(); 22 | require('./index'); 23 | expect(global.console.log).toHaveBeenCalledTimes(3); 24 | expect(global.console.log).toHaveBeenNthCalledWith(1, 25 | `\u001b[96m\u001b[1mThank you for using testpkg2!\u001b[96m\u001b[1m` 26 | ); 27 | expect(global.console.log).toHaveBeenNthCalledWith(3, 28 | `> \u001b[94mtesturl/donate\u001b[0m\n` 29 | ); 30 | }); 31 | 32 | [0, false].forEach(falsy => { 33 | it(`when Disable is set to ${falsy}`, () => { 34 | global.process.env = {DISABLE_OPENCOLLECTIVE: falsy}; 35 | expect(global.console.log).not.toHaveBeenCalled(); 36 | require('./index'); 37 | expect(global.console.log).toHaveBeenCalledTimes(3); 38 | }); 39 | }); 40 | 41 | ['notice', 'http', 'timing', 'info', 'verbose', 'silly'].forEach(log => { 42 | it(`when config_loglevel is set to ${log}`, () => { 43 | global.process.env = {npm_config_loglevel: log} 44 | expect(global.console.log).not.toHaveBeenCalled(); 45 | require('./index'); 46 | expect(global.console.log).toHaveBeenCalledTimes(3); 47 | }); 48 | }); 49 | }); 50 | 51 | describe('does not show output', () => { 52 | [1, true].forEach(truthy => { 53 | it(`when Disable is set to ${truthy}`, () => { 54 | global.process.env = {DISABLE_OPENCOLLECTIVE: truthy}; 55 | expect(global.console.log).not.toHaveBeenCalled(); 56 | require('./index'); 57 | expect(global.console.log).not.toHaveBeenCalled(); 58 | }); 59 | }); 60 | 61 | ['warn', 'error', 'silent'].forEach(log => { 62 | it(`when npm_config_loglevel is set to ${log}`, () => { 63 | global.process.env = {npm_config_loglevel: log} 64 | require('./index'); 65 | expect(global.console.log).not.toHaveBeenCalled(); 66 | }); 67 | }); 68 | }); 69 | }); --------------------------------------------------------------------------------