-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from axelpale/release-3.2
Release candidate 3.2.0
- Loading branch information
Showing
29 changed files
with
1,242 additions
and
436 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
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 |
---|---|---|
@@ -1,7 +1,3 @@ | ||
|
||
const gv = require('./lib/genversion') | ||
const v = require('./lib/version') | ||
|
||
exports.check = gv.check | ||
exports.generate = gv.generate | ||
exports.version = v | ||
exports.check = require('./lib/check') | ||
exports.generate = require('./lib/generate') | ||
exports.version = require('./lib/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
const dryRun = require('./dryRun') | ||
const fs = require('fs') | ||
|
||
module.exports = (targetPath, opts, callback) => { | ||
// Check if a version file can be generated. | ||
// | ||
// Parameters | ||
// targetPath | ||
// relative or absolute filepath to version file. | ||
// opts | ||
// optional options object. See dryRun docs for details. | ||
// callback | ||
// function (err, doesExist, isByGenversion, isUpToDate) | ||
// err | ||
// non-null on file system error | ||
// doesExist | ||
// boolean, if the version file exists | ||
// isByGenversion | ||
// boolean, true if file exists and is generated by genversion. | ||
// The check is done by comparing the SIGNATURE on the first line. | ||
// isUpToDate | ||
// boolean, true if contents of the file are exactly as | ||
// freshly generated. | ||
// | ||
if (typeof callback !== 'function') { | ||
if (typeof opts !== 'function') { | ||
throw new Error('Unexpected callback argument') | ||
} else { | ||
callback = opts | ||
opts = {} | ||
} | ||
} | ||
|
||
dryRun(targetPath, opts, (err, result) => { | ||
if (err) { | ||
return callback(err) | ||
} | ||
|
||
const absTarget = result.absoluteTargetPath | ||
const referenceContent = result.generatedContent | ||
|
||
fs.readFile(absTarget, 'utf8', (errf, fileContent) => { | ||
if (errf) { | ||
if (errf.code === 'ENOENT') { | ||
// OK, file does not exist. | ||
return callback(null, false, false, false) | ||
} | ||
// Real error. | ||
return callback(errf, false, false, false) | ||
} | ||
|
||
// Issue axelpale/genversion#15 | ||
// Remove all the CR characters inserted by git on clone/checkout | ||
// when git configuration has core.autocrlf=true | ||
while (fileContent.indexOf('\r') >= 0) { | ||
fileContent = fileContent.replace(/\r/, '') | ||
} | ||
|
||
// Get first line to test if we can touch the file. | ||
// We should not touch the file if it does not resemble | ||
// the content with which we are about to rewrite it. | ||
const fingerprint = fileContent.trim().substring(0, 5).toLowerCase() | ||
const refprint = referenceContent.trim().substring(0, 5).toLowerCase() | ||
// Find the file begins like the generated content. | ||
if (fingerprint !== refprint) { | ||
// The file exists but is not created by genversion | ||
return callback(null, true, false, false) | ||
} | ||
|
||
if (fileContent !== referenceContent) { | ||
// The file is created by genversion but has outdated content | ||
return callback(null, true, true, false) | ||
} | ||
|
||
// OK, the existing file was generated by genversion and is up to date. | ||
return callback(null, true, true, true) | ||
}) | ||
}) | ||
} |
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,2 @@ | ||
// The signature is the first line of the generated file. | ||
exports.SIGNATURE = '// Generated by genversion.' |
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,20 @@ | ||
module.exports = (csv) => { | ||
if (!csv) { | ||
return [] | ||
} | ||
|
||
if (Array.isArray(csv)) { | ||
// Spread comma-separated values and flatten | ||
const flat = csv.reduce((acc, str) => { | ||
return acc.concat(str.split(',')) | ||
}, []).map(str => str.trim()) | ||
|
||
return flat | ||
} | ||
|
||
if (typeof csv === 'string') { | ||
return csv.split(',').map(str => str.trim()) | ||
} | ||
|
||
return [] | ||
} |
Oops, something went wrong.