Skip to content

Instantly share code, notes, and snippets.

@elycruz
Created December 13, 2017 03:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elycruz/3d6397ac531411ed710326f330c5c58c to your computer and use it in GitHub Desktop.
Save elycruz/3d6397ac531411ed710326f330c5c58c to your computer and use it in GitHub Desktop.
Outputs the version number of an npm package through a readstream.
const
util = require('util'),
stream = require('stream'),
Readable = stream.Readable,
packageJson = require('../package');
function VersionNumberReadStream (options) {
Readable.call(this, Object.assign({
encoding: 'utf8',
objectMode: false,
}, options));
}
util.inherits(VersionNumberReadStream, Readable);
VersionNumberReadStream.prototype._read = function () {
`/**
* Content generated by '{project-root}/build-scripts/VersionNumberReadStream.js'.
* Generated ${new Date()}
*/
export const version = '${packageJson.version}';
export default version;
`
.split('').forEach(this.push, this);
this.push('\n');
this.push(null);
};
module.exports = VersionNumberReadStream;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment