commit-and-tag-version 11.3.0 → 12.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.
- package/.eslintrc +46 -3
- package/.gitattributes +2 -0
- package/.github/dependabot.yml +19 -0
- package/.github/workflows/ci.yaml +12 -5
- package/.github/workflows/release-please.yml +3 -3
- package/.prettierrc +3 -0
- package/CHANGELOG.md +19 -0
- package/README.md +7 -1
- package/bin/cli.js +6 -6
- package/command.js +43 -37
- package/defaults.js +12 -11
- package/index.js +44 -42
- package/jest.config.js +28 -0
- package/lib/checkpoint.js +19 -8
- package/lib/configuration.js +17 -17
- package/lib/detect-package-manager.js +20 -20
- package/lib/format-commit-message.js +3 -3
- package/lib/latest-semver-tag.js +13 -11
- package/lib/lifecycles/bump.js +136 -105
- package/lib/lifecycles/changelog.js +88 -48
- package/lib/lifecycles/commit.js +41 -42
- package/lib/lifecycles/tag.js +41 -31
- package/lib/preset-loader.js +12 -10
- package/lib/print-error.js +10 -7
- package/lib/run-exec.js +10 -10
- package/lib/run-execFile.js +10 -10
- package/lib/run-lifecycle-script.js +16 -11
- package/lib/stringify-package.js +10 -10
- package/lib/updaters/index.js +40 -33
- package/lib/updaters/types/csproj.js +9 -7
- package/lib/updaters/types/gradle.js +10 -8
- package/lib/updaters/types/json.js +14 -14
- package/lib/updaters/types/plain-text.js +4 -4
- package/lib/write-file.js +4 -4
- package/package.json +20 -25
- package/test/commit-message-config.integration-test.js +106 -0
- package/test/config-files.integration-test.js +114 -0
- package/test/config-keys.integration-test.js +83 -0
- package/test/core.spec.js +1594 -874
- package/test/git.integration-test.js +363 -0
- package/test/invalid-config.integration-test.js +73 -0
- package/test/mocks/jest-mocks.js +48 -0
- package/test/mocks/updater/customer-updater.js +5 -8
- package/test/mocks/updater/increment-updater.js +5 -5
- package/test/pre-commit-hook.integration-test.js +192 -0
- package/test/preset.integration-test.js +56 -0
- package/test/stringify-package.spec.js +18 -22
- package/test/utils.spec.js +26 -42
- package/renovate.json +0 -9
- package/test/config-files.spec.js +0 -176
- package/test/git.spec.js +0 -480
- package/test/preset.spec.js +0 -52
package/lib/lifecycles/commit.js
CHANGED
|
@@ -1,69 +1,68 @@
|
|
|
1
|
-
const bump = require('../lifecycles/bump')
|
|
2
|
-
const checkpoint = require('../checkpoint')
|
|
3
|
-
const formatCommitMessage = require('../format-commit-message')
|
|
4
|
-
const path = require('path')
|
|
5
|
-
const runExecFile = require('../run-execFile')
|
|
6
|
-
const runLifecycleScript = require('../run-lifecycle-script')
|
|
1
|
+
const bump = require('../lifecycles/bump');
|
|
2
|
+
const checkpoint = require('../checkpoint');
|
|
3
|
+
const formatCommitMessage = require('../format-commit-message');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const runExecFile = require('../run-execFile');
|
|
6
|
+
const runLifecycleScript = require('../run-lifecycle-script');
|
|
7
7
|
|
|
8
8
|
module.exports = async function (args, newVersion) {
|
|
9
|
-
if (args.skip.commit) return
|
|
10
|
-
const message = await runLifecycleScript(args, 'precommit')
|
|
11
|
-
if (message && message.length) args.releaseCommitMessageFormat = message
|
|
12
|
-
await execCommit(args, newVersion)
|
|
13
|
-
await runLifecycleScript(args, 'postcommit')
|
|
14
|
-
}
|
|
9
|
+
if (args.skip.commit) return;
|
|
10
|
+
const message = await runLifecycleScript(args, 'precommit');
|
|
11
|
+
if (message && message.length) args.releaseCommitMessageFormat = message;
|
|
12
|
+
await execCommit(args, newVersion);
|
|
13
|
+
await runLifecycleScript(args, 'postcommit');
|
|
14
|
+
};
|
|
15
15
|
|
|
16
|
-
async function execCommit
|
|
17
|
-
let msg = 'committing %s'
|
|
18
|
-
let paths = []
|
|
19
|
-
const verify = args.verify === false || args.n ? ['--no-verify'] : []
|
|
20
|
-
const sign = args.sign ? ['-S'] : []
|
|
21
|
-
const
|
|
16
|
+
async function execCommit(args, newVersion) {
|
|
17
|
+
let msg = 'committing %s';
|
|
18
|
+
let paths = [];
|
|
19
|
+
const verify = args.verify === false || args.n ? ['--no-verify'] : [];
|
|
20
|
+
const sign = args.sign ? ['-S'] : [];
|
|
21
|
+
const signoff = args.signoff ? ['--signoff'] : [];
|
|
22
|
+
const toAdd = [];
|
|
22
23
|
|
|
23
24
|
// only start with a pre-populated paths list when CHANGELOG processing is not skipped
|
|
24
25
|
if (!args.skip.changelog) {
|
|
25
|
-
paths = [args.infile]
|
|
26
|
-
toAdd.push(args.infile)
|
|
26
|
+
paths = [args.infile];
|
|
27
|
+
toAdd.push(args.infile);
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
// commit any of the config files that we've updated
|
|
30
31
|
// the version # for.
|
|
31
32
|
Object.keys(bump.getUpdatedConfigs()).forEach(function (p) {
|
|
32
|
-
paths.unshift(p)
|
|
33
|
-
toAdd.push(path.relative(process.cwd(), p))
|
|
33
|
+
paths.unshift(p);
|
|
34
|
+
toAdd.push(path.relative(process.cwd(), p));
|
|
34
35
|
|
|
35
36
|
// account for multiple files in the output message
|
|
36
37
|
if (paths.length > 1) {
|
|
37
|
-
msg += ' and %s'
|
|
38
|
+
msg += ' and %s';
|
|
38
39
|
}
|
|
39
|
-
})
|
|
40
|
+
});
|
|
40
41
|
|
|
41
42
|
if (args.commitAll) {
|
|
42
|
-
msg += ' and %s'
|
|
43
|
-
paths.push('all staged files')
|
|
43
|
+
msg += ' and %s';
|
|
44
|
+
paths.push('all staged files');
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
checkpoint(args, msg, paths)
|
|
47
|
+
checkpoint(args, msg, paths);
|
|
47
48
|
|
|
48
49
|
// nothing to do, exit without commit anything
|
|
49
|
-
if (
|
|
50
|
-
|
|
50
|
+
if (
|
|
51
|
+
!args.commitAll &&
|
|
52
|
+
args.skip.changelog &&
|
|
53
|
+
args.skip.bump &&
|
|
54
|
+
toAdd.length === 0
|
|
55
|
+
) {
|
|
56
|
+
return;
|
|
51
57
|
}
|
|
52
58
|
|
|
53
|
-
await runExecFile(args, 'git', ['add'].concat(toAdd))
|
|
59
|
+
await runExecFile(args, 'git', ['add'].concat(toAdd));
|
|
54
60
|
await runExecFile(
|
|
55
61
|
args,
|
|
56
62
|
'git',
|
|
57
|
-
[
|
|
58
|
-
'
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
args.commitAll ? [] : toAdd,
|
|
63
|
-
[
|
|
64
|
-
'-m',
|
|
65
|
-
`${formatCommitMessage(args.releaseCommitMessageFormat, newVersion)}`
|
|
66
|
-
]
|
|
67
|
-
)
|
|
68
|
-
)
|
|
63
|
+
['commit'].concat(verify, sign, signoff, args.commitAll ? [] : toAdd, [
|
|
64
|
+
'-m',
|
|
65
|
+
`${formatCommitMessage(args.releaseCommitMessageFormat, newVersion)}`,
|
|
66
|
+
]),
|
|
67
|
+
);
|
|
69
68
|
}
|
package/lib/lifecycles/tag.js
CHANGED
|
@@ -1,50 +1,60 @@
|
|
|
1
|
-
const bump = require('../lifecycles/bump')
|
|
2
|
-
const chalk = require('chalk')
|
|
3
|
-
const checkpoint = require('../checkpoint')
|
|
4
|
-
const figures = require('figures')
|
|
5
|
-
const formatCommitMessage = require('../format-commit-message')
|
|
6
|
-
const runExecFile = require('../run-execFile')
|
|
7
|
-
const runLifecycleScript = require('../run-lifecycle-script')
|
|
8
|
-
const { detectPMByLockFile } = require('../detect-package-manager')
|
|
1
|
+
const bump = require('../lifecycles/bump');
|
|
2
|
+
const chalk = require('chalk');
|
|
3
|
+
const checkpoint = require('../checkpoint');
|
|
4
|
+
const figures = require('figures');
|
|
5
|
+
const formatCommitMessage = require('../format-commit-message');
|
|
6
|
+
const runExecFile = require('../run-execFile');
|
|
7
|
+
const runLifecycleScript = require('../run-lifecycle-script');
|
|
8
|
+
const { detectPMByLockFile } = require('../detect-package-manager');
|
|
9
9
|
|
|
10
10
|
module.exports = async function (newVersion, pkgPrivate, args) {
|
|
11
|
-
if (args.skip.tag) return
|
|
12
|
-
await runLifecycleScript(args, 'pretag')
|
|
13
|
-
await execTag(newVersion, pkgPrivate, args)
|
|
14
|
-
await runLifecycleScript(args, 'posttag')
|
|
15
|
-
}
|
|
11
|
+
if (args.skip.tag) return;
|
|
12
|
+
await runLifecycleScript(args, 'pretag');
|
|
13
|
+
await execTag(newVersion, pkgPrivate, args);
|
|
14
|
+
await runLifecycleScript(args, 'posttag');
|
|
15
|
+
};
|
|
16
16
|
|
|
17
|
-
async function detectPublishHint
|
|
18
|
-
const npmClientName = await detectPMByLockFile()
|
|
19
|
-
const publishCommand = 'publish'
|
|
20
|
-
return `${npmClientName} ${publishCommand}
|
|
17
|
+
async function detectPublishHint() {
|
|
18
|
+
const npmClientName = await detectPMByLockFile();
|
|
19
|
+
const publishCommand = 'publish';
|
|
20
|
+
return `${npmClientName} ${publishCommand}`;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
async function execTag
|
|
24
|
-
const tagOption = []
|
|
23
|
+
async function execTag(newVersion, pkgPrivate, args) {
|
|
24
|
+
const tagOption = [];
|
|
25
25
|
if (args.sign) {
|
|
26
|
-
tagOption.push('-s')
|
|
26
|
+
tagOption.push('-s');
|
|
27
27
|
} else {
|
|
28
|
-
tagOption.push('-a')
|
|
28
|
+
tagOption.push('-a');
|
|
29
29
|
}
|
|
30
30
|
if (args.tagForce) {
|
|
31
|
-
tagOption.push('-f')
|
|
31
|
+
tagOption.push('-f');
|
|
32
32
|
}
|
|
33
|
-
checkpoint(args, 'tagging release %s%s', [args.tagPrefix, newVersion])
|
|
34
|
-
await runExecFile(args, 'git', [
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
checkpoint(args, 'tagging release %s%s', [args.tagPrefix, newVersion]);
|
|
34
|
+
await runExecFile(args, 'git', [
|
|
35
|
+
'tag',
|
|
36
|
+
...tagOption,
|
|
37
|
+
args.tagPrefix + newVersion,
|
|
38
|
+
'-m',
|
|
39
|
+
`${formatCommitMessage(args.releaseCommitMessageFormat, newVersion)}`,
|
|
40
|
+
]);
|
|
41
|
+
const currentBranch = await runExecFile('', 'git', [
|
|
42
|
+
'rev-parse',
|
|
43
|
+
'--abbrev-ref',
|
|
44
|
+
'HEAD',
|
|
45
|
+
]);
|
|
46
|
+
let message = 'git push --follow-tags origin ' + currentBranch.trim();
|
|
37
47
|
if (pkgPrivate !== true && bump.getUpdatedConfigs()['package.json']) {
|
|
38
|
-
const npmPublishHint = args.npmPublishHint || await detectPublishHint()
|
|
39
|
-
message += ` && ${npmPublishHint}
|
|
48
|
+
const npmPublishHint = args.npmPublishHint || (await detectPublishHint());
|
|
49
|
+
message += ` && ${npmPublishHint}`;
|
|
40
50
|
if (args.prerelease !== undefined) {
|
|
41
51
|
if (args.prerelease === '') {
|
|
42
|
-
message += ' --tag prerelease'
|
|
52
|
+
message += ' --tag prerelease';
|
|
43
53
|
} else {
|
|
44
|
-
message += ' --tag ' + args.prerelease
|
|
54
|
+
message += ' --tag ' + args.prerelease;
|
|
45
55
|
}
|
|
46
56
|
}
|
|
47
57
|
}
|
|
48
58
|
|
|
49
|
-
checkpoint(args, 'Run `%s` to publish', [message], chalk.blue(figures.info))
|
|
59
|
+
checkpoint(args, 'Run `%s` to publish', [message], chalk.blue(figures.info));
|
|
50
60
|
}
|
package/lib/preset-loader.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
// TODO: this should be replaced with an object we maintain and
|
|
2
2
|
// describe in: https://github.com/conventional-changelog/conventional-changelog-config-spec
|
|
3
|
-
const spec = require('conventional-changelog-config-spec')
|
|
3
|
+
const spec = require('conventional-changelog-config-spec');
|
|
4
4
|
|
|
5
5
|
module.exports = (args) => {
|
|
6
|
-
const defaultPreset = require.resolve(
|
|
7
|
-
|
|
6
|
+
const defaultPreset = require.resolve(
|
|
7
|
+
'conventional-changelog-conventionalcommits',
|
|
8
|
+
);
|
|
9
|
+
let preset = args.preset || defaultPreset;
|
|
8
10
|
if (preset === defaultPreset) {
|
|
9
11
|
preset = {
|
|
10
|
-
name: defaultPreset
|
|
11
|
-
}
|
|
12
|
-
Object.keys(spec.properties).forEach(key => {
|
|
13
|
-
if (args[key] !== undefined) preset[key] = args[key]
|
|
14
|
-
})
|
|
12
|
+
name: defaultPreset,
|
|
13
|
+
};
|
|
14
|
+
Object.keys(spec.properties).forEach((key) => {
|
|
15
|
+
if (args[key] !== undefined) preset[key] = args[key];
|
|
16
|
+
});
|
|
15
17
|
}
|
|
16
|
-
return preset
|
|
17
|
-
}
|
|
18
|
+
return preset;
|
|
19
|
+
};
|
package/lib/print-error.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
const chalk = require('chalk')
|
|
1
|
+
const chalk = require('chalk');
|
|
2
2
|
|
|
3
3
|
module.exports = function (args, msg, opts) {
|
|
4
4
|
if (!args.silent) {
|
|
5
|
-
opts = Object.assign(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
opts = Object.assign(
|
|
6
|
+
{
|
|
7
|
+
level: 'error',
|
|
8
|
+
color: 'red',
|
|
9
|
+
},
|
|
10
|
+
opts,
|
|
11
|
+
);
|
|
9
12
|
|
|
10
|
-
console[opts.level](chalk[opts.color](msg))
|
|
13
|
+
console[opts.level](chalk[opts.color](msg));
|
|
11
14
|
}
|
|
12
|
-
}
|
|
15
|
+
};
|
package/lib/run-exec.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
const { promisify } = require('util')
|
|
2
|
-
const printError = require('./print-error')
|
|
1
|
+
const { promisify } = require('util');
|
|
2
|
+
const printError = require('./print-error');
|
|
3
3
|
|
|
4
|
-
const exec = promisify(require('child_process').exec)
|
|
4
|
+
const exec = promisify(require('child_process').exec);
|
|
5
5
|
|
|
6
6
|
module.exports = async function (args, cmd) {
|
|
7
|
-
if (args.dryRun) return
|
|
7
|
+
if (args.dryRun) return;
|
|
8
8
|
try {
|
|
9
|
-
const { stderr, stdout } = await exec(cmd)
|
|
9
|
+
const { stderr, stdout } = await exec(cmd);
|
|
10
10
|
// If exec returns content in stderr, but no error, print it as a warning
|
|
11
|
-
if (stderr) printError(args, stderr, { level: 'warn', color: 'yellow' })
|
|
12
|
-
return stdout
|
|
11
|
+
if (stderr) printError(args, stderr, { level: 'warn', color: 'yellow' });
|
|
12
|
+
return stdout;
|
|
13
13
|
} catch (error) {
|
|
14
14
|
// If exec returns an error, print it and exit with return code 1
|
|
15
|
-
printError(args, error.stderr || error.message)
|
|
16
|
-
throw error
|
|
15
|
+
printError(args, error.stderr || error.message);
|
|
16
|
+
throw error;
|
|
17
17
|
}
|
|
18
|
-
}
|
|
18
|
+
};
|
package/lib/run-execFile.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
const { promisify } = require('util')
|
|
2
|
-
const printError = require('./print-error')
|
|
1
|
+
const { promisify } = require('util');
|
|
2
|
+
const printError = require('./print-error');
|
|
3
3
|
|
|
4
|
-
const execFile = promisify(require('child_process').execFile)
|
|
4
|
+
const execFile = promisify(require('child_process').execFile);
|
|
5
5
|
|
|
6
6
|
module.exports = async function (args, cmd, cmdArgs) {
|
|
7
|
-
if (args.dryRun) return
|
|
7
|
+
if (args.dryRun) return;
|
|
8
8
|
try {
|
|
9
|
-
const { stderr, stdout } = await execFile(cmd, cmdArgs)
|
|
9
|
+
const { stderr, stdout } = await execFile(cmd, cmdArgs);
|
|
10
10
|
// If execFile returns content in stderr, but no error, print it as a warning
|
|
11
|
-
if (stderr) printError(args, stderr, { level: 'warn', color: 'yellow' })
|
|
12
|
-
return stdout
|
|
11
|
+
if (stderr) printError(args, stderr, { level: 'warn', color: 'yellow' });
|
|
12
|
+
return stdout;
|
|
13
13
|
} catch (error) {
|
|
14
14
|
// If execFile returns an error, print it and exit with return code 1
|
|
15
|
-
printError(args, error.stderr || error.message)
|
|
16
|
-
throw error
|
|
15
|
+
printError(args, error.stderr || error.message);
|
|
16
|
+
throw error;
|
|
17
17
|
}
|
|
18
|
-
}
|
|
18
|
+
};
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
const chalk = require('chalk')
|
|
2
|
-
const checkpoint = require('./checkpoint')
|
|
3
|
-
const figures = require('figures')
|
|
4
|
-
const runExec = require('./run-exec')
|
|
1
|
+
const chalk = require('chalk');
|
|
2
|
+
const checkpoint = require('./checkpoint');
|
|
3
|
+
const figures = require('figures');
|
|
4
|
+
const runExec = require('./run-exec');
|
|
5
5
|
|
|
6
6
|
module.exports = function (args, hookName) {
|
|
7
|
-
const scripts = args.scripts
|
|
8
|
-
if (!scripts || !scripts[hookName]) return Promise.resolve()
|
|
9
|
-
const command = scripts[hookName]
|
|
10
|
-
checkpoint(args, 'Running lifecycle script "%s"', [hookName])
|
|
11
|
-
checkpoint(
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
const scripts = args.scripts;
|
|
8
|
+
if (!scripts || !scripts[hookName]) return Promise.resolve();
|
|
9
|
+
const command = scripts[hookName];
|
|
10
|
+
checkpoint(args, 'Running lifecycle script "%s"', [hookName]);
|
|
11
|
+
checkpoint(
|
|
12
|
+
args,
|
|
13
|
+
'- execute command: "%s"',
|
|
14
|
+
[command],
|
|
15
|
+
chalk.blue(figures.info),
|
|
16
|
+
);
|
|
17
|
+
return runExec(args, command);
|
|
18
|
+
};
|
package/lib/stringify-package.js
CHANGED
|
@@ -16,21 +16,21 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
16
16
|
https://github.com/npm/stringify-package/blob/main/LICENSE
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
'use strict'
|
|
19
|
+
'use strict';
|
|
20
20
|
|
|
21
|
-
module.exports = stringifyPackage
|
|
21
|
+
module.exports = stringifyPackage;
|
|
22
22
|
|
|
23
|
-
const DEFAULT_INDENT = 2
|
|
24
|
-
const CRLF = '\r\n'
|
|
25
|
-
const LF = '\n'
|
|
23
|
+
const DEFAULT_INDENT = 2;
|
|
24
|
+
const CRLF = '\r\n';
|
|
25
|
+
const LF = '\n';
|
|
26
26
|
|
|
27
|
-
function stringifyPackage
|
|
28
|
-
indent = indent || (indent === 0 ? 0 : DEFAULT_INDENT)
|
|
29
|
-
const json = JSON.stringify(data, null, indent)
|
|
27
|
+
function stringifyPackage(data, indent, newline) {
|
|
28
|
+
indent = indent || (indent === 0 ? 0 : DEFAULT_INDENT);
|
|
29
|
+
const json = JSON.stringify(data, null, indent);
|
|
30
30
|
|
|
31
31
|
if (newline === CRLF) {
|
|
32
|
-
return json.replace(/\n/g, CRLF) + CRLF
|
|
32
|
+
return json.replace(/\n/g, CRLF) + CRLF;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
return json + LF
|
|
35
|
+
return json + LF;
|
|
36
36
|
}
|
package/lib/updaters/index.js
CHANGED
|
@@ -1,61 +1,63 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
const JSON_BUMP_FILES = require('../../defaults').bumpFiles
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const JSON_BUMP_FILES = require('../../defaults').bumpFiles;
|
|
3
3
|
const updatersByType = {
|
|
4
4
|
json: require('./types/json'),
|
|
5
5
|
'plain-text': require('./types/plain-text'),
|
|
6
6
|
gradle: require('./types/gradle'),
|
|
7
|
-
csproj: require('./types/csproj')
|
|
8
|
-
}
|
|
9
|
-
const PLAIN_TEXT_BUMP_FILES = ['VERSION.txt', 'version.txt']
|
|
7
|
+
csproj: require('./types/csproj'),
|
|
8
|
+
};
|
|
9
|
+
const PLAIN_TEXT_BUMP_FILES = ['VERSION.txt', 'version.txt'];
|
|
10
10
|
|
|
11
|
-
function getUpdaterByType
|
|
12
|
-
const updater = updatersByType[type]
|
|
11
|
+
function getUpdaterByType(type) {
|
|
12
|
+
const updater = updatersByType[type];
|
|
13
13
|
if (!updater) {
|
|
14
|
-
throw Error(`Unable to locate updater for provided type (${type}).`)
|
|
14
|
+
throw Error(`Unable to locate updater for provided type (${type}).`);
|
|
15
15
|
}
|
|
16
|
-
return updater
|
|
16
|
+
return updater;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
function getUpdaterByFilename
|
|
19
|
+
function getUpdaterByFilename(filename) {
|
|
20
20
|
if (JSON_BUMP_FILES.includes(path.basename(filename))) {
|
|
21
|
-
return getUpdaterByType('json')
|
|
21
|
+
return getUpdaterByType('json');
|
|
22
22
|
}
|
|
23
23
|
if (PLAIN_TEXT_BUMP_FILES.includes(filename)) {
|
|
24
|
-
return getUpdaterByType('plain-text')
|
|
24
|
+
return getUpdaterByType('plain-text');
|
|
25
25
|
}
|
|
26
26
|
if (/build.gradle/.test(filename)) {
|
|
27
|
-
return getUpdaterByType('gradle')
|
|
27
|
+
return getUpdaterByType('gradle');
|
|
28
28
|
}
|
|
29
29
|
if (filename.endsWith('.csproj')) {
|
|
30
|
-
return getUpdaterByType('csproj')
|
|
30
|
+
return getUpdaterByType('csproj');
|
|
31
31
|
}
|
|
32
32
|
throw Error(
|
|
33
|
-
`Unsupported file (${filename}) provided for bumping.\n Please specify the updater \`type\` or use a custom \`updater
|
|
34
|
-
)
|
|
33
|
+
`Unsupported file (${filename}) provided for bumping.\n Please specify the updater \`type\` or use a custom \`updater\`.`,
|
|
34
|
+
);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
function getCustomUpdaterFromPath
|
|
37
|
+
function getCustomUpdaterFromPath(updater) {
|
|
38
38
|
if (typeof updater === 'string') {
|
|
39
|
-
return require(path.resolve(process.cwd(), updater))
|
|
39
|
+
return require(path.resolve(process.cwd(), updater));
|
|
40
40
|
}
|
|
41
41
|
if (
|
|
42
42
|
typeof updater.readVersion === 'function' &&
|
|
43
43
|
typeof updater.writeVersion === 'function'
|
|
44
44
|
) {
|
|
45
|
-
return updater
|
|
45
|
+
return updater;
|
|
46
46
|
}
|
|
47
|
-
throw new Error(
|
|
47
|
+
throw new Error(
|
|
48
|
+
'Updater must be a string path or an object with readVersion and writeVersion methods',
|
|
49
|
+
);
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
/**
|
|
51
53
|
* Simple check to determine if the object provided is a compatible updater.
|
|
52
54
|
*/
|
|
53
|
-
function isValidUpdater
|
|
55
|
+
function isValidUpdater(obj) {
|
|
54
56
|
return (
|
|
55
57
|
obj &&
|
|
56
58
|
typeof obj.readVersion === 'function' &&
|
|
57
59
|
typeof obj.writeVersion === 'function'
|
|
58
|
-
)
|
|
60
|
+
);
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
module.exports.resolveUpdaterObjectFromArgument = function (arg) {
|
|
@@ -63,35 +65,40 @@ module.exports.resolveUpdaterObjectFromArgument = function (arg) {
|
|
|
63
65
|
* If an Object was not provided, we assume it's the path/filename
|
|
64
66
|
* of the updater.
|
|
65
67
|
*/
|
|
66
|
-
let updater = arg
|
|
68
|
+
let updater = arg;
|
|
67
69
|
if (isValidUpdater(updater)) {
|
|
68
|
-
return updater
|
|
70
|
+
return updater;
|
|
69
71
|
}
|
|
70
72
|
if (typeof updater !== 'object') {
|
|
71
73
|
updater = {
|
|
72
|
-
filename: arg
|
|
73
|
-
}
|
|
74
|
+
filename: arg,
|
|
75
|
+
};
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
if (!isValidUpdater(updater.updater)) {
|
|
77
79
|
try {
|
|
78
80
|
if (typeof updater.updater === 'string') {
|
|
79
|
-
updater.updater = getCustomUpdaterFromPath(updater.updater)
|
|
81
|
+
updater.updater = getCustomUpdaterFromPath(updater.updater);
|
|
80
82
|
} else if (updater.type) {
|
|
81
|
-
updater.updater = getUpdaterByType(updater.type)
|
|
83
|
+
updater.updater = getUpdaterByType(updater.type);
|
|
82
84
|
} else {
|
|
83
|
-
updater.updater = getUpdaterByFilename(updater.filename)
|
|
85
|
+
updater.updater = getUpdaterByFilename(updater.filename);
|
|
84
86
|
}
|
|
85
87
|
} catch (err) {
|
|
86
|
-
if (err.code !== 'ENOENT')
|
|
88
|
+
if (err.code !== 'ENOENT')
|
|
89
|
+
console.warn(
|
|
90
|
+
`Unable to obtain updater for: ${JSON.stringify(arg)}\n - Error: ${
|
|
91
|
+
err.message
|
|
92
|
+
}\n - Skipping...`,
|
|
93
|
+
);
|
|
87
94
|
}
|
|
88
95
|
}
|
|
89
96
|
/**
|
|
90
97
|
* We weren't able to resolve an updater for the argument.
|
|
91
98
|
*/
|
|
92
99
|
if (!isValidUpdater(updater.updater)) {
|
|
93
|
-
return false
|
|
100
|
+
return false;
|
|
94
101
|
}
|
|
95
102
|
|
|
96
|
-
return updater
|
|
97
|
-
}
|
|
103
|
+
return updater;
|
|
104
|
+
};
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
const versionRegex = /<Version>(.*)<\/Version
|
|
1
|
+
const versionRegex = /<Version>(.*)<\/Version>/;
|
|
2
2
|
|
|
3
3
|
module.exports.readVersion = function (contents) {
|
|
4
|
-
const matches = versionRegex.exec(contents)
|
|
4
|
+
const matches = versionRegex.exec(contents);
|
|
5
5
|
if (matches === null || matches.length !== 2) {
|
|
6
|
-
throw new Error(
|
|
6
|
+
throw new Error(
|
|
7
|
+
'Failed to read the Version field in your csproj file - is it present?',
|
|
8
|
+
);
|
|
7
9
|
}
|
|
8
|
-
return matches[1]
|
|
9
|
-
}
|
|
10
|
+
return matches[1];
|
|
11
|
+
};
|
|
10
12
|
|
|
11
13
|
module.exports.writeVersion = function (contents, version) {
|
|
12
|
-
return contents.replace(versionRegex, `<Version>${version}</Version>`)
|
|
13
|
-
}
|
|
14
|
+
return contents.replace(versionRegex, `<Version>${version}</Version>`);
|
|
15
|
+
};
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
const versionRegex = /^version\s+=\s+['"]([\d.]+)['"]/m
|
|
1
|
+
const versionRegex = /^version\s+=\s+['"]([\d.]+)['"]/m;
|
|
2
2
|
|
|
3
3
|
module.exports.readVersion = function (contents) {
|
|
4
|
-
const matches = versionRegex.exec(contents)
|
|
4
|
+
const matches = versionRegex.exec(contents);
|
|
5
5
|
if (matches === null) {
|
|
6
|
-
throw new Error(
|
|
6
|
+
throw new Error(
|
|
7
|
+
'Failed to read the version field in your gradle file - is it present?',
|
|
8
|
+
);
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
return matches[1]
|
|
10
|
-
}
|
|
11
|
+
return matches[1];
|
|
12
|
+
};
|
|
11
13
|
|
|
12
14
|
module.exports.writeVersion = function (contents, version) {
|
|
13
15
|
return contents.replace(versionRegex, () => {
|
|
14
|
-
return `version = "${version}"
|
|
15
|
-
})
|
|
16
|
-
}
|
|
16
|
+
return `version = "${version}"`;
|
|
17
|
+
});
|
|
18
|
+
};
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
const stringifyPackage = require('../../stringify-package')
|
|
2
|
-
const detectIndent = require('detect-indent')
|
|
3
|
-
const detectNewline = require('detect-newline')
|
|
1
|
+
const stringifyPackage = require('../../stringify-package');
|
|
2
|
+
const detectIndent = require('detect-indent');
|
|
3
|
+
const detectNewline = require('detect-newline');
|
|
4
4
|
|
|
5
5
|
module.exports.readVersion = function (contents) {
|
|
6
|
-
return JSON.parse(contents).version
|
|
7
|
-
}
|
|
6
|
+
return JSON.parse(contents).version;
|
|
7
|
+
};
|
|
8
8
|
|
|
9
9
|
module.exports.writeVersion = function (contents, version) {
|
|
10
|
-
const json = JSON.parse(contents)
|
|
11
|
-
const indent = detectIndent(contents).indent
|
|
12
|
-
const newline = detectNewline(contents)
|
|
13
|
-
json.version = version
|
|
10
|
+
const json = JSON.parse(contents);
|
|
11
|
+
const indent = detectIndent(contents).indent;
|
|
12
|
+
const newline = detectNewline(contents);
|
|
13
|
+
json.version = version;
|
|
14
14
|
|
|
15
15
|
if (json.packages && json.packages['']) {
|
|
16
16
|
// package-lock v2 stores version there too
|
|
17
|
-
json.packages[''].version = version
|
|
17
|
+
json.packages[''].version = version;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
return stringifyPackage(json, indent, newline)
|
|
21
|
-
}
|
|
20
|
+
return stringifyPackage(json, indent, newline);
|
|
21
|
+
};
|
|
22
22
|
|
|
23
23
|
module.exports.isPrivate = function (contents) {
|
|
24
|
-
return JSON.parse(contents).private
|
|
25
|
-
}
|
|
24
|
+
return JSON.parse(contents).private;
|
|
25
|
+
};
|
package/lib/write-file.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const fs = require('fs')
|
|
1
|
+
const fs = require('fs');
|
|
2
2
|
|
|
3
3
|
module.exports = function (args, filePath, content) {
|
|
4
|
-
if (args.dryRun) return
|
|
5
|
-
fs.writeFileSync(filePath, content, 'utf8')
|
|
6
|
-
}
|
|
4
|
+
if (args.dryRun) return;
|
|
5
|
+
fs.writeFileSync(filePath, content, 'utf8');
|
|
6
|
+
};
|