-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat-header-support
- Loading branch information
Showing
16 changed files
with
425 additions
and
135 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
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
Oops, something went wrong.