Skip to content

Commit

Permalink
Merge caa80c9 into 9d6ac8b
Browse files Browse the repository at this point in the history
  • Loading branch information
Zearin committed Jun 7, 2018
2 parents 9d6ac8b + caa80c9 commit d89f379
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ test/fixtures/*/build
coverage
.vscode/
.idea/
.DS_Store
34 changes: 33 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,39 @@ This project adheres to [Semantic Versioning](http://semver.org).
This document follows the guidelines of [Keep A Changelog](http://keepachangelog.com).

## [Unreleased]
- Nothing here yet...


### Added
* ESLint (...finally!) (#305) (@Zearin)


### Removed
* Dependency `absolute` (save ≈21k!) (c05f9e2) (@Zearin)


### Updated
Thanks to ESLint, we’ve tidied up Metalsmith’s source code a bit.

* **Dependencies:**
- `graymatter`: 2.0.0 ▶︎ 2.1.0 (030cd8c, 5446866) (@moozzyk)

* Update `CHANGELOG.md` format to follow “[Keep A Changelog](http://keepachangelog.com)” (#266) (@Zearin)


### Fixed
* Fix test error on Windows (#158) (@moozzyk)


### Security
**The new `npm audit` command is awesome.** You should use it in your own projects!

#### `npm audit` vulnerability fixes
* **Development Dependencies:**
- `coveralls`: 2.11.6 ▶︎ 3.0.1 (#308) (@Zearin)
Fix 5 “Moderate” vulnerabilities
- `metalsmith-markdown`: 0.2.1 ▶︎ 0.2.2 (#312) (@Zearin)
Fix 1 “Low” vulnerability



## [2.3.0] - 2016-10-28
Expand Down
39 changes: 27 additions & 12 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

var absolute = require('absolute')
var assert = require('assert')
var clone = require('clone')
var fs = require('co-fs-extra')
var is = require('is')
var matter = require('gray-matter')
var Mode = require('stat-mode')
var path = require('path')
Expand All @@ -21,6 +19,17 @@ var Ware = require('ware')
readdir = thunkify(readdir)
rm = thunkify(rm)


/**
* Helpers
*/

var isBoolean = function(b) {return typeof b === 'boolean'}
var isNumber = function(n) {return typeof n === 'number' && !Number.isNaN(n)}
var isObject = function(o) {return o !== null && typeof o === 'object'}
var isString = function(s) {return typeof s === 'string'}


/**
* Export `Metalsmith`.
*/
Expand Down Expand Up @@ -68,7 +77,7 @@ Metalsmith.prototype.use = function(plugin){

Metalsmith.prototype.directory = function(directory){
if (!arguments.length) return path.resolve(this._directory)
assert(is.string(directory), 'You must pass a directory path string.')
if (!isString(directory)) throw new TypeError('You must pass a directory path string.')
this._directory = directory
return this
}
Expand All @@ -82,7 +91,7 @@ Metalsmith.prototype.directory = function(directory){

Metalsmith.prototype.metadata = function(metadata){
if (!arguments.length) return this._metadata
assert(is.object(metadata), 'You must pass a metadata object.')
if (!isObject(metadata)) throw new TypeError('You must pass a metadata object.')
this._metadata = clone(metadata)
return this
}
Expand All @@ -96,7 +105,7 @@ Metalsmith.prototype.metadata = function(metadata){

Metalsmith.prototype.source = function(path){
if (!arguments.length) return this.path(this._source)
assert(is.string(path), 'You must pass a source path string.')
if (!isString(path)) throw new TypeError('You must pass a source path string.')
this._source = path
return this
}
Expand All @@ -110,7 +119,7 @@ Metalsmith.prototype.source = function(path){

Metalsmith.prototype.destination = function(path){
if (!arguments.length) return this.path(this._destination)
assert(is.string(path), 'You must pass a destination path string.')
if (!isString(path)) throw new TypeError('You must pass a destination path string.')
this._destination = path
return this
}
Expand All @@ -124,7 +133,7 @@ Metalsmith.prototype.destination = function(path){

Metalsmith.prototype.concurrency = function(max){
if (!arguments.length) return this._concurrency
assert(is.number(max), 'You must pass a number for concurrency.')
if (!isNumber(max)) throw new TypeError('You must pass a number for concurrency.')
this._concurrency = max
return this
}
Expand All @@ -137,7 +146,7 @@ Metalsmith.prototype.concurrency = function(max){
*/
Metalsmith.prototype.clean = function(clean){
if (!arguments.length) return this._clean
assert(is.boolean(clean), 'You must pass a boolean.')
if (!isBoolean(clean)) throw new TypeError('You must pass a boolean.')
this._clean = clean
return this
}
Expand All @@ -151,7 +160,7 @@ Metalsmith.prototype.clean = function(clean){

Metalsmith.prototype.frontmatter = function(frontmatter){
if (!arguments.length) return this._frontmatter
assert(is.boolean(frontmatter), 'You must pass a boolean.')
if (!isBoolean(frontmatter)) throw new TypeError('You must pass a boolean.')
this._frontmatter = frontmatter
return this
}
Expand Down Expand Up @@ -270,7 +279,7 @@ Metalsmith.prototype.readFile = unyield(function*(file){
var src = this.source()
var ret = {}

if (!absolute(file)) file = path.resolve(src, file)
if (!path.isAbsolute(file)) file = path.resolve(src, file)

try {
var frontmatter = this.frontmatter()
Expand All @@ -288,7 +297,13 @@ Metalsmith.prototype.readFile = unyield(function*(file){
}

ret = parsed.data
ret.contents = new Buffer(parsed.content)
// Use `Buffer.from` whenever possible
// See:
// - https://nodejs.org/api/buffer.html#buffer_new_buffer_string_encoding
// - https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_string_encoding
ret.contents = (Buffer.hasOwnProperty('from'))
? Buffer.from(parsed.content)
: new Buffer(parsed.content)
} else {
ret.contents = buffer
}
Expand Down Expand Up @@ -343,7 +358,7 @@ Metalsmith.prototype.write = unyield(function*(files, dir){

Metalsmith.prototype.writeFile = unyield(function*(file, data){
var dest = this.destination()
if (!absolute(file)) file = path.resolve(dest, file)
if (!path.isAbsolute(file)) file = path.resolve(dest, file)

try {
yield fs.outputFile(file, data.contents)
Expand Down
22 changes: 6 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
"lint": "./node_modules/.bin/eslint index.js lib/* bin/* test/*.js"
},
"dependencies": {
"absolute": "0.0.1",
"chalk": "^1.1.3",
"clone": "^1.0.2",
"clone": "^2.1.1",
"co-fs-extra": "^1.2.1",
"commander": "^2.6.0",
"gray-matter": "^2.1.0",
"gray-matter": "^2.1.1",
"has-generators": "^1.0.1",
"is": "^3.1.0",
"is-utf8": "~0.2.0",
"recursive-readdir": "^2.1.0",
"rimraf": "^2.2.8",
Expand All @@ -38,7 +36,7 @@
"win-fork": "^1.1.1"
},
"devDependencies": {
"assert-dir-equal": "~1.0.1",
"assert-dir-equal": "^1.1.0",
"co-mocha": "^1.0.1",
"coveralls": "^3.0.1",
"eslint": "^4.19.1",
Expand Down

0 comments on commit d89f379

Please sign in to comment.