diff --git a/package-lock.json b/package-lock.json index da8b8cf..65e3d9b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,13 +10,13 @@ "license": "MIT", "dependencies": { "@babel/runtime": "^7.7.6", - "chalk": "^5.6.2", "inquirer": "^7.3.3", "json-fixer": "^1.6.8", "lodash": "^4.11.2", "node-fetch": "^2.6.0", "pify": "^5.0.0", - "yargs": "^18.0.0" + "yargs": "^18.0.0", + "yoctocolors": "^2.1.2" }, "bin": { "all-contributors": "dist/cli.js" @@ -122,6 +122,7 @@ "integrity": "sha512-CGOfOJqWjg2qW/Mb6zNsDm+u5vFQ8DxXfbM09z69p5Z6+mE1ikP2jUXw+j42Pf1XTYED2Rni5f95npYeuwMDQA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@babel/code-frame": "^7.29.0", "@babel/generator": "^7.29.0", @@ -4809,6 +4810,7 @@ "integrity": "sha512-qoQprZvz5wQFJwMDqeseRXWv3rqMvhgpbXFfVyWhbx9X47POIA6i/+dXefEmZKoAgOaTdaIgNSMqMIU61yRyzA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@babel/parser": "^7.20.7", "@babel/types": "^7.20.7", @@ -4945,6 +4947,7 @@ "integrity": "sha512-BkmoP5/FhRYek5izySdkOneRyXYN35I860MFAGupTdebyE66uZaR+bXLHq8k4DirE5DwQi3NuhvRU1jqTVwUrQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "undici-types": "~7.16.0" } @@ -5463,6 +5466,7 @@ "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", "dev": true, "license": "MIT", + "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -6315,6 +6319,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "caniuse-lite": "^1.0.30001370", "electron-to-chromium": "^1.4.202", @@ -6491,6 +6496,7 @@ "version": "5.6.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.6.2.tgz", "integrity": "sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==", + "dev": true, "license": "MIT", "engines": { "node": "^12.17.0 || ^14.13 || >=16.0.0" @@ -7968,6 +7974,7 @@ "integrity": "sha512-LEyamqS7W5HB3ujJyvi0HQK/dtVINZvd5mAAp9eT5S/ujByGjiZLCzPcHVzuXbpJDJF/cxwHlfceVUDZ2lnSTw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.1", @@ -10460,6 +10467,7 @@ "integrity": "sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@jest/core": "^29.7.0", "@jest/types": "^29.6.3", @@ -11959,6 +11967,7 @@ "integrity": "sha512-ekilCSN1jwRvIbgeg/57YFh8qQDNbwDb9xT/qu2DAHbFFZUicIl4ygVaAvzveMhMVr3LnpSKTNnwt8PoOfmKhQ==", "dev": true, "license": "MIT", + "peer": true, "bin": { "jiti": "lib/jiti-cli.mjs" } @@ -12278,6 +12287,7 @@ "integrity": "sha512-TiZzBSJja/LbhNPvk6yc0JrX9XqhQ0hdh6M2svYfsHGejaKFIAGd9MQ+ERIMzLGlN/kZoYIgdxFV0PuljTKXag==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@eslint-community/regexpp": "^4.4.0", "@typescript-eslint/scope-manager": "5.62.0", @@ -12313,6 +12323,7 @@ "integrity": "sha512-VlJEV0fOQ7BExOsHYAGrgbEiZoi8D+Bl2+f6V2RrXerRSylnp+ZBHmPvaIa8cz0Ajx7WO7Z5RqfgYg7ED1nRhA==", "dev": true, "license": "BSD-2-Clause", + "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "5.62.0", "@typescript-eslint/types": "5.62.0", @@ -12602,6 +12613,7 @@ "deprecated": "This version is no longer supported. Please see https://eslint.org/version-support for other options.", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", @@ -13342,22 +13354,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/kcd-scripts/node_modules/typescript": { - "version": "4.9.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", - "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", - "dev": true, - "license": "Apache-2.0", - "optional": true, - "peer": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=4.2.0" - } - }, "node_modules/kcd-scripts/node_modules/wrap-ansi": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", @@ -16035,6 +16031,7 @@ "integrity": "sha512-oQL6lgK3e2QZeQ7gcgIkS2YZPg5slw37hYufJ3edKlfQSGGm8ICoxswK15ntSzF/a8+h7ekRy7k7oWc3BQ7y8A==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@types/estree": "1.0.8" }, @@ -17634,6 +17631,7 @@ "integrity": "sha512-o5a9xKjbtuhY6Bi5S3+HvbRERmouabWbyUcpXXUA1u+GNUKoROi9byOJ8M0nHbHYHkYICiMlqxkg1KkYmm25Sw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "esbuild": "^0.21.3", "postcss": "^8.4.43", @@ -17717,6 +17715,7 @@ "integrity": "sha512-MSmPM9REYqDGBI8439mA4mWhV5sKmDlBKWIYbA3lRb2PTHACE0mgKwA8yQ2xq9vxDTuk4iPrECBAEW2aoFXY0Q==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@vitest/expect": "2.1.9", "@vitest/mocker": "2.1.9", @@ -18294,6 +18293,18 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/yoctocolors": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/yoctocolors/-/yoctocolors-2.1.2.tgz", + "integrity": "sha512-CzhO+pFNo8ajLM2d2IW/R93ipy99LWjtwblvC1RsoSUMZgyLbYFr221TnSNT7GjGdYui6P459mw9JH/g/zW2ug==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/zod": { "version": "4.3.6", "resolved": "https://registry.npmjs.org/zod/-/zod-4.3.6.tgz", diff --git a/package.json b/package.json index 242c6cc..9a07d67 100644 --- a/package.json +++ b/package.json @@ -48,13 +48,13 @@ "homepage": "https://github.com/all-contributors/all-contributors-cli#readme", "dependencies": { "@babel/runtime": "^7.7.6", - "chalk": "^5.6.2", "inquirer": "^7.3.3", "json-fixer": "^1.6.8", "lodash": "^4.11.2", "node-fetch": "^2.6.0", "pify": "^5.0.0", - "yargs": "^18.0.0" + "yargs": "^18.0.0", + "yoctocolors": "^2.1.2" }, "devDependencies": { "@babel/cli": "^7.26.0", diff --git a/src/api.js b/src/api.js index 95e5461..f0f4204 100644 --- a/src/api.js +++ b/src/api.js @@ -3,15 +3,15 @@ // This is to support adding contributors using the AllContributors GitHub Bot (see github.com/all-contributors/all-contributors-bot // These Node API's are intended to be network and side effect free, everything should be in memory with no io to network/disk -const chalk = require('chalk') +const YoctoColors = require('yoctocolors') const addContributorWithDetails = require('./contributors/addWithDetails') const generate = require('./generate') const {addContributorsList, addBadge} = require('./init/init-content') process.stdout.write( - chalk.yellow( - `${chalk.bold( + YoctoColors.yellow( + `${YoctoColors.bold( 'WARNING', )} :: Using the all-contributors node-api comes with zero guarantees of stability and may contain breaking changes without warning\n`, ), diff --git a/src/cli.js b/src/cli.js index 359226a..4e9f481 100755 --- a/src/cli.js +++ b/src/cli.js @@ -2,8 +2,8 @@ const path = require('path') const yargs = require('yargs/yargs') +const YoctoColors = require('yoctocolors') const {hideBin} = require('yargs/helpers') -const chalk = require('chalk') const inquirer = require('inquirer') const init = require('./init') @@ -70,14 +70,11 @@ function startGeneration(argv) { } async function addContribution(argv) { - // ensure the config file exists - await util.configFile.readConfig(argv.config) - const username = argv._[1] === undefined ? undefined : String(argv._[1]) const contributions = argv._[2] // Add or update contributor in the config file - const data = updateContributors(argv, username, contributions) + const data = await updateContributors(argv, username, contributions) argv.contributors = data.contributors @@ -90,22 +87,20 @@ async function addContribution(argv) { } async function checkContributors(argv) { - const configData = await util.configFile.readConfig(argv.config) - return repo .getContributors( - configData.projectOwner, - configData.projectName, - configData.repoType, - configData.repoHost, + argv.projectOwner, + argv.projectName, + argv.repoType, + argv.repoHost, ) .then(repoContributors => { - const checkKey = repo.getCheckKey(configData.repoType) - const knownContributions = configData.contributors.reduce((obj, item) => { + const checkKey = repo.getCheckKey(argv.repoType) + const knownContributions = argv.contributors.reduce((obj, item) => { obj[item[checkKey]] = item.contributions return obj }, {}) - const knownContributors = configData.contributors.map( + const knownContributors = argv.contributors.map( contributor => contributor[checkKey], ) @@ -122,14 +117,17 @@ async function checkContributors(argv) { if (missingInConfig.length) { process.stdout.write( - chalk.bold('Missing contributors in .all-contributorsrc:\n'), + YoctoColors.bold('Missing contributors in .all-contributorsrc:\n'), ) - process.stdout.write(` ${missingInConfig.join(', ')}\n`) + process.stdout.write(`${missingInConfig.join(', ')}\n`) } if (missingFromRepo.length) { + process.stdout.write('\n') process.stdout.write( - chalk.bold('Unknown contributors found in .all-contributorsrc:\n'), + YoctoColors.bold( + 'Unknown contributors found in .all-contributorsrc:\n', + ), ) process.stdout.write(`${missingFromRepo.join(', ')}\n`) } @@ -169,6 +167,18 @@ function promptForCommand(argv) { async function run() { try { const argv = getArgs() + + // Load and merge config file data into argv + try { + const configData = await util.configFile.readConfig(argv.config) + Object.assign(argv, configData) + } catch (error) { + if (error instanceof SyntaxError || argv.config !== defaultRCFile) { + throw error + } + // If default config file doesn't exist, that's okay + } + const command = await promptForCommand(argv) switch (command) { diff --git a/src/util/git.js b/src/util/git.js index e3f78c8..3f0d125 100644 --- a/src/util/git.js +++ b/src/util/git.js @@ -3,7 +3,6 @@ const spawn = require('child_process').spawn const _ = require('lodash/fp') const pify = require('pify') const conventions = require('../init/commit-conventions') -const {readConfig} = require('./config-file') const commitTemplate = '<%= prefix %> <%= (newContributor ? "Add" : "Update") %> @<%= username %> as a contributor' @@ -58,8 +57,7 @@ async function commit(options, data) { const absolutePathFiles = files.map(file => { return path.resolve(process.cwd(), file) }) - const config = await readConfig(options.config) - const commitConvention = conventions[config.commitConvention] + const commitConvention = conventions[options.commitConvention] return spawnGitCommand(['add'].concat(absolutePathFiles)).then(() => { let commitMessage = _.template(options.commitTemplate || commitTemplate)({