Skip to content

Commit

Permalink
docs: updates README, slight change to the API
Browse files Browse the repository at this point in the history
  • Loading branch information
jbottigliero committed Aug 7, 2019
1 parent ea90faa commit 3c3d80a
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 110 deletions.
229 changes: 143 additions & 86 deletions README.md

Large diffs are not rendered by default.

27 changes: 7 additions & 20 deletions lib/lifecycles/bump.js
Expand Up @@ -11,8 +11,7 @@ const presetLoader = require('../preset-loader')
const runLifecycleScript = require('../run-lifecycle-script')
const semver = require('semver')
const writeFile = require('../write-file')
const JSON_BUMP_FILES = require('../../defaults').bumpFiles

const { getUpdaterByFilename, getUpdaterByType, getCustomUpdater } = require('../updaters')
let configsToUpdate = {}

function Bump (args, version) {
Expand Down Expand Up @@ -138,19 +137,6 @@ function bumpVersion (releaseAs, currentVersion, args) {
})
}

function getUpdaterByFileName (filename) {
if (JSON_BUMP_FILES.includes(filename)) {
return require('../package-files/json')
}
try {
return require(`../package-files/${filename}.js`)
} catch (err) {
throw Error(
`Unsupported file (${filename}) provided for updating – please provide a custom updater.`
)
}
}

/**
* attempt to update the version number in provided `bumpFiles`
* @param args config object
Expand All @@ -172,13 +158,14 @@ function updateConfigs (args, newVersion) {

if (!stat.isFile()) return

if (!bumpFile.updater) {
bumpFile.updater = getUpdaterByFileName(bumpFile.filename)
if (bumpFile.updater) {
bumpFile.updater = getCustomUpdater(bumpFile.updater)
} else if (bumpFile.type) {
bumpFile.updater = getUpdaterByType(bumpFile.type)
} else {
bumpFile.updater = require(
path.resolve(process.cwd(), bumpFile.updater)
)
bumpFile.updater = getUpdaterByFilename(bumpFile.filename)
}

let contents = fs.readFileSync(configPath, 'utf8')
checkpoint(
args,
Expand Down
29 changes: 29 additions & 0 deletions lib/updaters/index.js
@@ -0,0 +1,29 @@
const path = require('path')
const JSON_BUMP_FILES = require('../../defaults').bumpFiles
const PLAIN_TEXT_BUMP_FILES = ['VERSION.txt', 'version.txt']

function getUpdaterByType (type) {
try {
return require(`./types/${type}`)
} catch (e) {
throw Error(`Unable to locate updated for provided type (${type}).`)
}
}

module.exports.getUpdaterByType = getUpdaterByType

module.exports.getUpdaterByFilename = function (filename) {
if (JSON_BUMP_FILES.includes(filename)) {
return getUpdaterByType('json')
}
if (PLAIN_TEXT_BUMP_FILES.includes(filename)) {
return getUpdaterByType('plain-text')
}
throw Error(
`Unsupported file (${filename}) provided for bumping.\n Please specifcy the updater \`type\` or use a custom \`updater\`.`
)
}

module.exports.getCustomUpdater = function (updater) {
return require(path.resolve(process.cwd(), updater))
}
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions test.js
Expand Up @@ -946,6 +946,23 @@ describe('standard-version', function () {
fs.readFileSync('version.txt', 'utf-8').should.equal('1.1.0')
})
})

it('bumps a custom `plain-text` file', function () {
fs.copyFileSync('../test/mocks/VERSION-1.0.0.txt', 'VERSION_TRACKER.txt')
commit('feat: first commit')
return require('./index')({
silent: true,
bumpFiles: [
{
filename: 'VERSION_TRACKER.txt',
type: 'plain-text'
}
]
})
.then(() => {
fs.readFileSync('VERSION_TRACKER.txt', 'utf-8').should.equal('1.1.0')
})
})
})

describe('npm-shrinkwrap.json support', function () {
Expand Down
1 change: 1 addition & 0 deletions test/mocks/VERSION-1.0.0.txt
@@ -0,0 +1 @@
1.0.0
24 changes: 20 additions & 4 deletions test/mocks/mix.exs
@@ -1,12 +1,28 @@
defmodule StandardVersion.MixProject do
use Mix.Project

def project do
[
app: :standard_version
version: "0.0.1",
elixir: "~> 1.8",
app: :standard_version,
version: "0.1.0",
elixir: "~> 1.9",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
end

# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end

# Run "mix help deps" to learn about dependencies.
defp deps do
[
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
]
end
end

0 comments on commit 3c3d80a

Please sign in to comment.