-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: custom 'bumpFiles' and 'packageFiles' support (#372)
Co-Authored-By: Sébastien Règne <[email protected]>
- Loading branch information
Showing
14 changed files
with
397 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
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}).`) | ||
} | ||
} | ||
|
||
function getUpdaterByFilename (filename) { | ||
if (JSON_BUMP_FILES.includes(path.basename(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\`.` | ||
) | ||
} | ||
|
||
function getCustomUpdater (updater) { | ||
return require(path.resolve(process.cwd(), updater)) | ||
} | ||
|
||
module.exports.resolveUpdaterObjectFromArgument = function (arg) { | ||
/** | ||
* If an Object was not provided, we assume it's the path/filename | ||
* of the updater. | ||
*/ | ||
let updater = arg | ||
if (typeof updater !== 'object') { | ||
updater = { | ||
filename: arg | ||
} | ||
} | ||
try { | ||
if (updater.updater) { | ||
updater.updater = getCustomUpdater(updater.updater) | ||
} else if (updater.type) { | ||
updater.updater = getUpdaterByType(updater.type) | ||
} else { | ||
updater.updater = getUpdaterByFilename(updater.filename) | ||
} | ||
} catch (err) { | ||
if (err.code !== 'ENOENT') console.warn(err.message) | ||
} | ||
/** | ||
* We weren't able to resolve an updater for the argument. | ||
*/ | ||
if (!updater.updater) { | ||
return false | ||
} | ||
|
||
return updater | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const stringifyPackage = require('stringify-package') | ||
const detectIndent = require('detect-indent') | ||
const detectNewline = require('detect-newline') | ||
|
||
module.exports.readVersion = function (contents) { | ||
return JSON.parse(contents).version | ||
} | ||
|
||
module.exports.writeVersion = function (contents, version) { | ||
const json = JSON.parse(contents) | ||
const indent = detectIndent(contents).indent | ||
const newline = detectNewline(contents) | ||
json.version = version | ||
return stringifyPackage(json, indent, newline) | ||
} | ||
|
||
module.exports.isPrivate = function (contents) { | ||
return JSON.parse(contents).private | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports.readVersion = function (contents) { | ||
return contents | ||
} | ||
|
||
module.exports.writeVersion = function (_contents, version) { | ||
return version | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
6.3.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
defmodule StandardVersion.MixProject do | ||
use Mix.Project | ||
|
||
def project do | ||
[ | ||
app: :standard_version, | ||
version: "0.1.0", | ||
elixir: "~> 1.9", | ||
start_permanent: Mix.env() == :prod, | ||
deps: deps() | ||
] | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const REPLACER = /version: "(.*)"/ | ||
|
||
module.exports.readVersion = function (contents) { | ||
return REPLACER.exec(contents)[1] | ||
} | ||
|
||
module.exports.writeVersion = function (contents, version) { | ||
return contents.replace( | ||
REPLACER.exec(contents)[0], | ||
`version: "${version}"` | ||
) | ||
} |
Empty file.