@all-contributors/cli 0.0.0-stage → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,62 @@
1
+ import { exec, execFile } from 'child_process';
2
+ import path from 'path';
3
+ import { promisify } from 'util';
4
+
5
+ import { conventions } from '../init/commit-conventions.js';
6
+ import * as util from '../util/index.js';
7
+
8
+ const commitTemplate =
9
+ '<%= prefix %> <%= (newContributor ? "Add" : "Update") %> @<%= username %> as a contributor';
10
+
11
+ const getRemoteOriginData = async () => {
12
+ const execAsync = promisify(exec);
13
+ const { stdout } = await execAsync('git config --get remote.origin.url');
14
+
15
+ return stdout;
16
+ };
17
+
18
+ function parse(originUrl) {
19
+ const result = /[:/]([A-Za-z0-9-_]+)\/([A-Za-z0-9-_]+)(?:\.git)?/.exec(originUrl);
20
+
21
+ if (!result) {
22
+ return null;
23
+ }
24
+
25
+ return {
26
+ projectOwner: result[1],
27
+ projectName: result[2],
28
+ };
29
+ }
30
+
31
+ export function getRepoInfo() {
32
+ return getRemoteOriginData().then(parse);
33
+ }
34
+
35
+ const spawnGitCommand = async (args) => {
36
+ try {
37
+ await promisify(execFile)('git', args);
38
+ } catch (error) {
39
+ const msg = error.stderr || `git ${args.join(' ')} - exit code: ${error.code}`;
40
+
41
+ throw new Error(msg, { cause: error });
42
+ }
43
+ };
44
+
45
+ export async function commit(options, data) {
46
+ const files = options.files.concat(options.config);
47
+ const absolutePathFiles = files.map((file) => path.resolve(process.cwd(), file));
48
+ const commitConvention = conventions[options.commitConvention];
49
+
50
+ return spawnGitCommand(['add'].concat(absolutePathFiles)).then(() => {
51
+ let commitMessage = util.template(options.commitTemplate || commitTemplate)({
52
+ ...data,
53
+ prefix: commitConvention.msg,
54
+ });
55
+
56
+ if (commitConvention.lowercase) {
57
+ commitMessage = commitConvention.transform(commitMessage);
58
+ }
59
+
60
+ return spawnGitCommand(['commit', '-m', commitMessage]);
61
+ });
62
+ }
@@ -0,0 +1,8 @@
1
+ import * as configFile from './config-file.js';
2
+ import { contributionTypes } from './contribution-types.js';
3
+ import * as git from './git.js';
4
+ import { template } from './template.js';
5
+ import * as url from './url.js';
6
+ import { UserError } from './user-error.js';
7
+
8
+ export { configFile, contributionTypes, git, template, url, UserError };
@@ -0,0 +1,8 @@
1
+ import { Eta } from 'eta';
2
+
3
+ const eta = new Eta({
4
+ useWith: true,
5
+ autoEscape: false,
6
+ });
7
+
8
+ export const template = (templateString) => (data) => eta.renderString(templateString, data);
@@ -0,0 +1,27 @@
1
+ export function isHttpProtocol(input) {
2
+ return new RegExp('^https?\\:?$').test(input);
3
+ }
4
+
5
+ export function isValidHttpUrl(input) {
6
+ try {
7
+ const url = new URL(input);
8
+
9
+ return isHttpProtocol(url.protocol);
10
+ } catch {
11
+ return false;
12
+ }
13
+ }
14
+
15
+ export function parseHttpUrl(input) {
16
+ if (typeof input !== 'string') {
17
+ throw new TypeError('input must be a string');
18
+ }
19
+
20
+ const url = new URL(new RegExp('^\\w+\\:\\/\\/').test(input) ? input : `http://${input}`);
21
+
22
+ if (!isHttpProtocol(url.protocol)) {
23
+ throw new TypeError('Provided URL has an invalid protocol');
24
+ }
25
+
26
+ return url.toString();
27
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * An error caused by the user's project setup rather than a bug in the CLI.
3
+ * The CLI prints only the message for these, without a stack trace.
4
+ */
5
+ export class UserError extends Error {
6
+ constructor(message, options) {
7
+ super(message, options);
8
+ this.name = 'UserError';
9
+ }
10
+ }
package/package.json CHANGED
@@ -1,6 +1,92 @@
1
1
  {
2
2
  "name": "@all-contributors/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "7.1.0",
4
+ "description": "Tool to easily add recognition for new contributors",
5
+ "keywords": [
6
+ "all-contributors",
7
+ "contributors"
8
+ ],
9
+ "homepage": "https://allcontributors.org/",
10
+ "bugs": {
11
+ "url": "https://github.com/all-contributors/cli/issues"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/all-contributors/cli.git"
16
+ },
17
+ "license": "MIT",
18
+ "author": {
19
+ "name": "All Contributors",
20
+ "url": "https://allcontributors.org"
21
+ },
22
+ "sideEffects": false,
23
+ "type": "module",
24
+ "main": "dist/api.js",
25
+ "bin": {
26
+ "all-contributors": "dist/cli.js"
27
+ },
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "allowScripts": {
32
+ "simple-git-hooks": false
33
+ },
34
+ "simple-git-hooks": {
35
+ "pre-commit": "npx lint-staged"
36
+ },
37
+ "lint-staged": {
38
+ "*": "oxfmt --no-error-on-unmatched-pattern"
39
+ },
40
+ "config": {
41
+ "commitizen": {
42
+ "path": "cz-conventional-changelog"
43
+ }
44
+ },
45
+ "dependencies": {
46
+ "eta": "^4.5.1",
47
+ "inquirer": "^14.0.2",
48
+ "json-fixer": "^1.6.8",
49
+ "yargs": "^18.0.0",
50
+ "yoctocolors": "^2.1.2"
51
+ },
52
+ "devDependencies": {
53
+ "@eslint/js": "10.0.1",
54
+ "@eslint/markdown": "9.0.0",
55
+ "@types/node": "26.6.6",
56
+ "@vitest/coverage-v8": "5.1.1",
57
+ "@vitest/eslint-plugin": "1.6.28",
58
+ "eslint": "10.15.0",
59
+ "eslint-plugin-import-x": "4.18.1",
60
+ "eslint-plugin-jsonc": "3.4.2",
61
+ "eslint-plugin-package-json": "1.14.0",
62
+ "eslint-plugin-perfectionist": "5.14.0",
63
+ "eslint-plugin-yml": "3.10.0",
64
+ "git-cz": "4.9.0",
65
+ "globals": "17.14.0",
66
+ "knip": "6.48.0",
67
+ "lint-staged": "17.6.2",
68
+ "nock": "15.0.6",
69
+ "oxfmt": "0.79.0",
70
+ "prettier": "3.10.1",
71
+ "simple-git-hooks": "2.14.0",
72
+ "vitest": "5.1.1"
73
+ },
74
+ "optionalDependencies": {
75
+ "prettier": "^3"
76
+ },
77
+ "engines": {
78
+ "node": ">=22.22.0"
79
+ },
80
+ "scripts": {
81
+ "add-contributor": "node src/cli.js add",
82
+ "build": "node scripts/build.ts",
83
+ "commit": "git-cz",
84
+ "dev": "./src/cli.js",
85
+ "format": "oxfmt",
86
+ "knip": "knip",
87
+ "lint": "eslint .",
88
+ "start": "./dist/cli.js",
89
+ "test": "vitest",
90
+ "test:e2e": "vitest run --config vitest.e2e.config.ts"
91
+ }
6
92
  }