version-from-git 1.1.3-main.98ff1b7 → 1.2.1-main.202512240318.67492b7
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.
- package/dist/version-from-git.d.ts +1 -0
- package/dist/version-from-git.js +80 -0
- package/dist/version-from-git.js.map +1 -0
- package/package.json +31 -21
- package/src/index.js +0 -108
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
import { program } from "commander";
|
|
6
|
+
import spawn from "cross-spawn";
|
|
7
|
+
import { branch as gitBranch, long as gitLong, short as gitShort } from "git-rev-sync";
|
|
8
|
+
import { join, resolve } from "path";
|
|
9
|
+
import { fileURLToPath } from "url";
|
|
10
|
+
import { onErrorResumeNext } from "on-error-resume-next/async";
|
|
11
|
+
import { readPackage } from "read-pkg";
|
|
12
|
+
import { major, minor, patch } from "semver";
|
|
13
|
+
var { green, magenta, red, yellow } = chalk;
|
|
14
|
+
var { log } = console;
|
|
15
|
+
var ourPackageJSON = await readPackage({ cwd: join(fileURLToPath(import.meta.url), "../../") });
|
|
16
|
+
var DEFAULT_TEMPLATE = "branch.short";
|
|
17
|
+
program.version(ourPackageJSON.version).description(ourPackageJSON.description || "").option("-p, --path <path>", "path to package.json, default to current directory", process.cwd()).option("--template <template>", "pre-release version template", DEFAULT_TEMPLATE).option("-t, --travis", "run in Travis CI: skip when TRAVIS_TAG present").option("-f, --force", 'run "npm version" with --force').option("-m, --message <message>", 'run "npm version" with --message').option("--allow-same-version", 'run "npm version" with --allow-same-version').option("--sign-git-tag", 'run "npm version" with --sign-git-tag').option("--no-commit-hooks", 'run "npm version" with --commit-hooks').option("--no-git-tag-version", 'run "npm version" with --no-git-tag-version').parse(process.argv);
|
|
18
|
+
var options = program.opts();
|
|
19
|
+
log(`Running ${green(`${ourPackageJSON.name}@${ourPackageJSON.version}`)}`);
|
|
20
|
+
var branch;
|
|
21
|
+
var long;
|
|
22
|
+
var short;
|
|
23
|
+
if (options["travis"]) {
|
|
24
|
+
log(`Travis mode ${magenta("enabled")}`);
|
|
25
|
+
if (process.env["TRAVIS_TAG"]) {
|
|
26
|
+
log(yellow("Environment variable TRAVIS_TAG is present, we will not generate a new version, exiting"));
|
|
27
|
+
process.exit(0);
|
|
28
|
+
}
|
|
29
|
+
branch = process.env["TRAVIS_BRANCH"];
|
|
30
|
+
}
|
|
31
|
+
if (options["path"]) {
|
|
32
|
+
process.chdir(resolve(options["path"]));
|
|
33
|
+
}
|
|
34
|
+
var cwd = process.cwd();
|
|
35
|
+
try {
|
|
36
|
+
branch = branch || gitBranch(cwd);
|
|
37
|
+
long = gitLong(cwd);
|
|
38
|
+
short = gitShort(cwd);
|
|
39
|
+
} catch {
|
|
40
|
+
log(red("Failed to read from .git directory, is this a Git branch with at least one commit?"));
|
|
41
|
+
process.exit(-1);
|
|
42
|
+
}
|
|
43
|
+
var packageJSONPath = resolve(".");
|
|
44
|
+
log(`Reading from ${magenta(packageJSONPath)}`);
|
|
45
|
+
var packageJSON = await onErrorResumeNext(
|
|
46
|
+
() => readPackage({ cwd: packageJSONPath })
|
|
47
|
+
);
|
|
48
|
+
if (!packageJSON) {
|
|
49
|
+
log(red("Failed to read package.json, is it missing or malformed?"));
|
|
50
|
+
process.exit(-1);
|
|
51
|
+
}
|
|
52
|
+
var { version } = packageJSON;
|
|
53
|
+
var preRelease = (options["template"] || DEFAULT_TEMPLATE).replace(/\w+/giu, (name) => {
|
|
54
|
+
switch (name) {
|
|
55
|
+
case "branch":
|
|
56
|
+
return branch;
|
|
57
|
+
case "short":
|
|
58
|
+
return short;
|
|
59
|
+
case "long":
|
|
60
|
+
return long;
|
|
61
|
+
default:
|
|
62
|
+
return name;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
var nextVersion = `${major(version)}.${minor(version)}.${patch(version)}-${preRelease}`;
|
|
66
|
+
log(`Bumping from ${green(version)} to ${green(nextVersion)}`);
|
|
67
|
+
var args = [
|
|
68
|
+
"version",
|
|
69
|
+
...options["allowSameVersion"] ? ["--allow-same-version"] : [],
|
|
70
|
+
...options["commitHooks"] ? [] : ["--no-commit-hooks"],
|
|
71
|
+
...options["force"] ? ["--force"] : [],
|
|
72
|
+
...options["gitTagVersion"] ? [] : ["--no-git-tag-version"],
|
|
73
|
+
...options["message"] ? ["--message", options["message"]] : [],
|
|
74
|
+
...options["signGitTag"] ? ["--sign-git-tag"] : [],
|
|
75
|
+
nextVersion
|
|
76
|
+
];
|
|
77
|
+
log(`Running ${magenta(`npm ${args.join(" ")}`)}`);
|
|
78
|
+
var result = spawn.sync("npm", args, { cwd, stdio: "inherit" });
|
|
79
|
+
process.exit(result.status);
|
|
80
|
+
//# sourceMappingURL=version-from-git.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport chalk from 'chalk';\nimport { program } from 'commander';\nimport spawn from 'cross-spawn';\nimport { branch as gitBranch, long as gitLong, short as gitShort } from 'git-rev-sync';\nimport { join, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { onErrorResumeNext } from 'on-error-resume-next/async';\nimport { readPackage } from 'read-pkg';\nimport { major, minor, patch } from 'semver';\n\nconst { green, magenta, red, yellow } = chalk;\nconst { log } = console;\n\nconst ourPackageJSON = await readPackage({ cwd: join(fileURLToPath(import.meta.url), '../../') });\n\nconst DEFAULT_TEMPLATE = 'branch.short';\n\nprogram\n .version(ourPackageJSON.version)\n .description(ourPackageJSON.description || '')\n .option('-p, --path <path>', 'path to package.json, default to current directory', process.cwd())\n .option('--template <template>', 'pre-release version template', DEFAULT_TEMPLATE)\n .option('-t, --travis', 'run in Travis CI: skip when TRAVIS_TAG present')\n .option('-f, --force', 'run \"npm version\" with --force')\n .option('-m, --message <message>', 'run \"npm version\" with --message')\n .option('--allow-same-version', 'run \"npm version\" with --allow-same-version')\n .option('--sign-git-tag', 'run \"npm version\" with --sign-git-tag')\n .option('--no-commit-hooks', 'run \"npm version\" with --commit-hooks')\n .option('--no-git-tag-version', 'run \"npm version\" with --no-git-tag-version')\n .parse(process.argv);\n\nconst options = program.opts();\n\nlog(`Running ${green(`${ourPackageJSON.name}@${ourPackageJSON.version}`)}`);\n\nlet branch, long, short;\n\nif (options['travis']) {\n log(`Travis mode ${magenta('enabled')}`);\n\n if (process.env['TRAVIS_TAG']) {\n log(yellow('Environment variable TRAVIS_TAG is present, we will not generate a new version, exiting'));\n\n process.exit(0);\n }\n\n branch = process.env['TRAVIS_BRANCH'];\n}\n\nif (options['path']) {\n process.chdir(resolve(options['path']));\n}\n\nconst cwd = process.cwd();\n\ntry {\n branch = branch || gitBranch(cwd);\n long = gitLong(cwd);\n short = gitShort(cwd);\n} catch {\n log(red('Failed to read from .git directory, is this a Git branch with at least one commit?'));\n process.exit(-1);\n}\n\nconst packageJSONPath = resolve('.');\n\nlog(`Reading from ${magenta(packageJSONPath)}`);\n\nconst packageJSON: { version: string } | undefined = await onErrorResumeNext(() =>\n readPackage({ cwd: packageJSONPath })\n);\n\nif (!packageJSON) {\n log(red('Failed to read package.json, is it missing or malformed?'));\n process.exit(-1);\n}\n\nconst { version } = packageJSON;\nconst preRelease = (options['template'] || DEFAULT_TEMPLATE).replace(/\\w+/giu, (name: string) => {\n switch (name) {\n case 'branch':\n return branch;\n case 'short':\n return short;\n case 'long':\n return long;\n\n default:\n return name;\n }\n});\n\nconst nextVersion = `${major(version)}.${minor(version)}.${patch(version)}-${preRelease}`;\n\nlog(`Bumping from ${green(version)} to ${green(nextVersion)}`);\n\nconst args = [\n 'version',\n ...(options['allowSameVersion'] ? ['--allow-same-version'] : []),\n ...(options['commitHooks'] ? [] : ['--no-commit-hooks']),\n ...(options['force'] ? ['--force'] : []),\n ...(options['gitTagVersion'] ? [] : ['--no-git-tag-version']),\n ...(options['message'] ? ['--message', options['message']] : []),\n ...(options['signGitTag'] ? ['--sign-git-tag'] : []),\n nextVersion\n];\n\nlog(`Running ${magenta(`npm ${args.join(' ')}`)}`);\n\nconst result = spawn.sync('npm', args, { cwd, stdio: 'inherit' });\n\nprocess.exit(result.status);\n"],"mappings":"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","names":[]}
|
package/package.json
CHANGED
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "version-from-git",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1-main.202512240318.67492b7",
|
|
4
4
|
"description": "Bump package.json version to pre-release tagged with Git branch and short commit hash, 1.0.0-main.1a2b3c4",
|
|
5
5
|
"files": [
|
|
6
|
-
"
|
|
7
|
-
"./
|
|
8
|
-
"./src/**/*.mjs"
|
|
6
|
+
"./*.js",
|
|
7
|
+
"./dist/"
|
|
9
8
|
],
|
|
10
|
-
"
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "./dist/version-from-git.js",
|
|
11
|
+
"typings": "./dist/version-from-git.d.ts",
|
|
11
12
|
"bin": {
|
|
12
|
-
"version-from-git": "./
|
|
13
|
+
"version-from-git": "./dist/version-from-git.js"
|
|
13
14
|
},
|
|
14
15
|
"scripts": {
|
|
15
|
-
"
|
|
16
|
-
"bump
|
|
17
|
-
"bump:dev": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '(.localPeerDependencies // {}) as $L | (.devDependencies // {}) | to_entries | map(select(.key as $K | $L | has($K) | not)) | map(.key + \"
|
|
18
|
-
"bump:prod": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '(.localPeerDependencies // {}) as $L | (.dependencies // {}) | to_entries | map(select(.key as $K | $L | has($K) | not)) | map(.key + \"
|
|
19
|
-
"
|
|
20
|
-
"precommit:eslint": "eslint ./src/",
|
|
16
|
+
"build": "tsup-node",
|
|
17
|
+
"bump": "npm run bump:prod && npm run bump:dev",
|
|
18
|
+
"bump:dev": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '(.pinDependencies // {}) as $P | (.localPeerDependencies // {}) as $L | (.devDependencies // {}) | to_entries | map(select(.key as $K | $L | has($K) | not)) | map(.key + \"@\" + ($P[.key] // [\"latest\"])[0]) | join(\" \")') && [ ! -z \"$PACKAGES_TO_BUMP\" ] && npm install $PACKAGES_TO_BUMP || true",
|
|
19
|
+
"bump:prod": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '(.pinDependencies // {}) as $P | (.localPeerDependencies // {}) as $L | (.dependencies // {}) | to_entries | map(select(.key as $K | $L | has($K) | not)) | map(.key + \"@\" + ($P[.key] // [\"latest\"])[0]) | join(\" \")') && [ ! -z \"$PACKAGES_TO_BUMP\" ] && npm install $PACKAGES_TO_BUMP || true",
|
|
20
|
+
"precommit": "npm run precommit:eslint && npm run precommit:publint && npm run precommit:typescript:production && npm run precommit:typescript:test",
|
|
21
|
+
"precommit:eslint": "ESLINT_USE_FLAT_CONFIG=false eslint ./src/",
|
|
22
|
+
"precommit:publint": "publint",
|
|
21
23
|
"precommit:typescript:production": "tsc --noEmit --project ./src/tsconfig.precommit.production.json",
|
|
22
24
|
"precommit:typescript:test": "tsc --noEmit --project ./src/tsconfig.precommit.test.json",
|
|
23
25
|
"prepack": "cp ../../CHANGELOG.md . && cp ../../LICENSE . && cp ../../README.md .",
|
|
26
|
+
"start": "npm run build -- --onSuccess \"touch ../pages/package.json\" --watch",
|
|
24
27
|
"switch": "cat package.json | jq --arg SWITCH_NAME $SWITCH_NAME -r '(.[\"switch:\" + $SWITCH_NAME] // {}) as $TEMPLATE | .devDependencies += ($TEMPLATE.devDependencies // {}) | .dependencies += ($TEMPLATE.dependencies // {})' | tee ./package.json.tmp && mv ./package.json.tmp ./package.json",
|
|
25
|
-
"test": "
|
|
28
|
+
"test": "node --test ${CI:---watch} **/*.{spec,test}.{[jt]s,[jt]sx,c[jt]s,m[jt]s}"
|
|
26
29
|
},
|
|
27
30
|
"repository": {
|
|
28
31
|
"type": "git",
|
|
29
|
-
"url": "
|
|
32
|
+
"url": "https://github.com/compulim/version-from-git.git"
|
|
30
33
|
},
|
|
31
34
|
"keywords": [
|
|
32
35
|
"branch",
|
|
@@ -44,15 +47,22 @@
|
|
|
44
47
|
},
|
|
45
48
|
"homepage": "https://github.com/compulim/version-from-git#readme",
|
|
46
49
|
"dependencies": {
|
|
47
|
-
"chalk": "^
|
|
48
|
-
"commander": "^
|
|
49
|
-
"cross-spawn": "^
|
|
50
|
+
"chalk": "^5.6.2",
|
|
51
|
+
"commander": "^14.0.2",
|
|
52
|
+
"cross-spawn": "^7.0.6",
|
|
50
53
|
"git-rev-sync": "^3.0.2",
|
|
51
|
-
"on-error-resume-next": "^
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
+
"on-error-resume-next": "^2.0.3",
|
|
55
|
+
"read-pkg": "^10.0.0",
|
|
56
|
+
"semver": "^7.7.3",
|
|
57
|
+
"version-from-git": "^1.2.1-main.202512240318.67492b7"
|
|
54
58
|
},
|
|
55
59
|
"devDependencies": {
|
|
56
|
-
"@tsconfig/
|
|
60
|
+
"@tsconfig/recommended": "^1.0.13",
|
|
61
|
+
"@tsconfig/strictest": "^2.0.8",
|
|
62
|
+
"@types/cross-spawn": "^6.0.6",
|
|
63
|
+
"@types/git-rev-sync": "^2.0.2",
|
|
64
|
+
"@types/semver": "^7.7.1",
|
|
65
|
+
"publint": "^0.3.16",
|
|
66
|
+
"tsup": "^8.5.1"
|
|
57
67
|
}
|
|
58
68
|
}
|
package/src/index.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const { branch: gitBranch, short: gitShort, long: gitLong } = require('git-rev-sync');
|
|
4
|
-
const { join, resolve } = require('path');
|
|
5
|
-
const { major, minor, patch } = require('semver');
|
|
6
|
-
const { green, magenta, red, yellow } = require('chalk');
|
|
7
|
-
const { default: onErrorResumeNext } = require('on-error-resume-next');
|
|
8
|
-
const program = require('commander');
|
|
9
|
-
const spawn = require('cross-spawn');
|
|
10
|
-
|
|
11
|
-
const { log } = console;
|
|
12
|
-
const ourPackageJSON = require(join(__dirname, '../package.json'));
|
|
13
|
-
|
|
14
|
-
const DEFAULT_TEMPLATE = 'branch.short';
|
|
15
|
-
|
|
16
|
-
program
|
|
17
|
-
.version(ourPackageJSON.version)
|
|
18
|
-
.description(ourPackageJSON.description)
|
|
19
|
-
.option('-p, --path <path>', 'path to package.json, default to current directory', process.cwd())
|
|
20
|
-
.option('--template <template>', 'pre-release version template', DEFAULT_TEMPLATE)
|
|
21
|
-
.option('-t, --travis', 'run in Travis CI: skip when TRAVIS_TAG present')
|
|
22
|
-
.option('-f, --force', 'run "npm version" with --force')
|
|
23
|
-
.option('-m, --message <message>', 'run "npm version" with --message')
|
|
24
|
-
.option('--allow-same-version', 'run "npm version" with --allow-same-version')
|
|
25
|
-
.option('--sign-git-tag', 'run "npm version" with --sign-git-tag')
|
|
26
|
-
.option('--no-commit-hooks', 'run "npm version" with --commit-hooks')
|
|
27
|
-
.option('--no-git-tag-version', 'run "npm version" with --no-git-tag-version')
|
|
28
|
-
.parse(process.argv);
|
|
29
|
-
|
|
30
|
-
function main() {
|
|
31
|
-
log(`Running ${green(`${ourPackageJSON.name}@${ourPackageJSON.version}`)}`);
|
|
32
|
-
|
|
33
|
-
let branch, long, short;
|
|
34
|
-
|
|
35
|
-
if (program.travis) {
|
|
36
|
-
log(`Travis mode ${magenta('enabled')}`);
|
|
37
|
-
|
|
38
|
-
if (process.env.TRAVIS_TAG) {
|
|
39
|
-
return log(yellow('Environment variable TRAVIS_TAG is present, we will not generate a new version, exiting'));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
branch = process.env.TRAVIS_BRANCH;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (program.path) {
|
|
46
|
-
process.chdir(resolve(program.path));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const cwd = process.cwd();
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
branch = branch || gitBranch(cwd);
|
|
53
|
-
long = gitLong(cwd);
|
|
54
|
-
short = gitShort(cwd);
|
|
55
|
-
} catch (err) {
|
|
56
|
-
log(red('Failed to read from .git directory, is this a Git branch with at least one commit?'));
|
|
57
|
-
process.exit(-1);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const packageJSONPath = resolve('package.json');
|
|
61
|
-
|
|
62
|
-
log(`Reading from ${magenta(packageJSONPath)}`);
|
|
63
|
-
|
|
64
|
-
const packageJSON = onErrorResumeNext(() => require(packageJSONPath));
|
|
65
|
-
|
|
66
|
-
if (!packageJSON) {
|
|
67
|
-
log(red('Failed to read package.json, is it missing or malformed?'));
|
|
68
|
-
process.exit(-1);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const { version } = packageJSON;
|
|
72
|
-
const preRelease = (program.template || DEFAULT_TEMPLATE).replace(/\w+/giu, name => {
|
|
73
|
-
switch (name) {
|
|
74
|
-
case 'branch':
|
|
75
|
-
return branch;
|
|
76
|
-
case 'short':
|
|
77
|
-
return short;
|
|
78
|
-
case 'long':
|
|
79
|
-
return long;
|
|
80
|
-
|
|
81
|
-
default:
|
|
82
|
-
return name;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
const nextVersion = `${major(version)}.${minor(version)}.${patch(version)}-${preRelease}`;
|
|
87
|
-
|
|
88
|
-
log(`Bumping from ${green(version)} to ${green(nextVersion)}`);
|
|
89
|
-
|
|
90
|
-
const args = [
|
|
91
|
-
'version',
|
|
92
|
-
...(program.allowSameVersion ? ['--allow-same-version'] : []),
|
|
93
|
-
...(program.commitHooks ? [] : ['--no-commit-hooks']),
|
|
94
|
-
...(program.force ? ['--force'] : []),
|
|
95
|
-
...(program.gitTagVersion ? [] : ['--no-git-tag-version']),
|
|
96
|
-
...(program.message ? ['--message', program.message] : []),
|
|
97
|
-
...(program.signGitTag ? ['--sign-git-tag'] : []),
|
|
98
|
-
nextVersion
|
|
99
|
-
];
|
|
100
|
-
|
|
101
|
-
log(`Running ${magenta(`npm ${args.join(' ')}`)}`);
|
|
102
|
-
|
|
103
|
-
const result = spawn.sync('npm', args, { cwd, stdio: 'inherit' });
|
|
104
|
-
|
|
105
|
-
process.exit(result.status);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
main();
|