|
3 | 3 | const chalk = require('chalk')
|
4 | 4 | const checkpoint = require('../checkpoint')
|
5 | 5 | const conventionalRecommendedBump = require('conventional-recommended-bump')
|
6 |
| -const detectIndent = require('detect-indent') |
7 |
| -const detectNewline = require('detect-newline') |
8 | 6 | const figures = require('figures')
|
9 | 7 | const fs = require('fs')
|
10 | 8 | const DotGitignore = require('dotgitignore')
|
11 | 9 | const path = require('path')
|
12 | 10 | const presetLoader = require('../preset-loader')
|
13 | 11 | const runLifecycleScript = require('../run-lifecycle-script')
|
14 | 12 | const semver = require('semver')
|
15 |
| -const stringifyPackage = require('stringify-package') |
16 | 13 | const writeFile = require('../write-file')
|
17 |
| - |
| 14 | +const { resolveUpdaterObjectFromArgument } = require('../updaters') |
18 | 15 | let configsToUpdate = {}
|
19 | 16 |
|
20 | 17 | function Bump (args, version) {
|
@@ -51,19 +48,6 @@ Bump.getUpdatedConfigs = function () {
|
51 | 48 | return configsToUpdate
|
52 | 49 | }
|
53 | 50 |
|
54 |
| -Bump.pkgFiles = [ |
55 |
| - 'package.json', |
56 |
| - 'bower.json', |
57 |
| - 'manifest.json', |
58 |
| - 'composer.json' |
59 |
| -] |
60 |
| - |
61 |
| -Bump.lockFiles = [ |
62 |
| - 'package-lock.json', |
63 |
| - 'npm-shrinkwrap.json', |
64 |
| - 'composer.lock' |
65 |
| -] |
66 |
| - |
67 | 51 | function getReleaseType (prerelease, expectedReleaseType, currentVersion) {
|
68 | 52 | if (isString(prerelease)) {
|
69 | 53 | if (isInPrerelease(currentVersion)) {
|
@@ -154,32 +138,38 @@ function bumpVersion (releaseAs, currentVersion, args) {
|
154 | 138 | }
|
155 | 139 |
|
156 | 140 | /**
|
157 |
| - * attempt to update the version # in a collection of common config |
158 |
| - * files, e.g., package.json, bower.json. |
159 |
| - * |
| 141 | + * attempt to update the version number in provided `bumpFiles` |
160 | 142 | * @param args config object
|
161 |
| - * @param newVersion version # to update to. |
162 |
| - * @return {string} |
| 143 | + * @param newVersion version number to update to. |
| 144 | + * @return void |
163 | 145 | */
|
164 | 146 | function updateConfigs (args, newVersion) {
|
165 | 147 | const dotgit = DotGitignore()
|
166 |
| - Bump.pkgFiles.concat(Bump.lockFiles).forEach(function (filename) { |
167 |
| - const configPath = path.resolve(process.cwd(), filename) |
| 148 | + args.bumpFiles.forEach(function (bumpFile) { |
| 149 | + const updater = resolveUpdaterObjectFromArgument(bumpFile) |
| 150 | + if (!updater) { |
| 151 | + return |
| 152 | + } |
| 153 | + const configPath = path.resolve(process.cwd(), updater.filename) |
168 | 154 | try {
|
169 | 155 | if (dotgit.ignore(configPath)) return
|
170 | 156 | const stat = fs.lstatSync(configPath)
|
171 |
| - if (stat.isFile()) { |
172 |
| - const data = fs.readFileSync(configPath, 'utf8') |
173 |
| - const indent = detectIndent(data).indent |
174 |
| - const newline = detectNewline(data) |
175 |
| - const config = JSON.parse(data) |
176 |
| - checkpoint(args, 'bumping version in ' + filename + ' from %s to %s', [config.version, newVersion]) |
177 |
| - config.version = newVersion |
178 |
| - writeFile(args, configPath, stringifyPackage(config, indent, newline)) |
179 |
| - // flag any config files that we modify the version # for |
180 |
| - // as having been updated. |
181 |
| - configsToUpdate[filename] = true |
182 |
| - } |
| 157 | + |
| 158 | + if (!stat.isFile()) return |
| 159 | + const contents = fs.readFileSync(configPath, 'utf8') |
| 160 | + checkpoint( |
| 161 | + args, |
| 162 | + 'bumping version in ' + updater.filename + ' from %s to %s', |
| 163 | + [updater.updater.readVersion(contents), newVersion] |
| 164 | + ) |
| 165 | + writeFile( |
| 166 | + args, |
| 167 | + configPath, |
| 168 | + updater.updater.writeVersion(contents, newVersion) |
| 169 | + ) |
| 170 | + // flag any config files that we modify the version # for |
| 171 | + // as having been updated. |
| 172 | + configsToUpdate[updater.filename] = true |
183 | 173 | } catch (err) {
|
184 | 174 | if (err.code !== 'ENOENT') console.warn(err.message)
|
185 | 175 | }
|
|
0 commit comments