Skip to content

Commit

Permalink
chore: lint bin/_metalsmith
Browse files Browse the repository at this point in the history
  • Loading branch information
webketje committed Jan 4, 2022
1 parent 5e290e1 commit cce1558
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions bin/_metalsmith
Expand Up @@ -6,11 +6,11 @@
* Dependencies.
*/

var chalk = require('chalk')
var exists = require('fs').existsSync
var Metalsmith = require('..')
var program = require('commander')
var resolve = require('path').resolve
const chalk = require('chalk')
const exists = require('fs').existsSync
const Metalsmith = require('..')
const program = require('commander')
const resolve = require('path').resolve

/**
* Usage.
Expand Down Expand Up @@ -45,13 +45,14 @@ program.parse(process.argv)
* Config.
*/

var dir = process.cwd()
var config = program.config
var path = resolve(dir, config)
const dir = process.cwd()
const config = program.config
const path = resolve(dir, config)
if (!exists(path)) fatal('could not find a ' + config + ' configuration file.')

let json
try {
var json = require(path)
json = require(path)
} catch (e) {
fatal('it seems like ' + config + ' is malformed.')
}
Expand All @@ -60,7 +61,7 @@ try {
* Metalsmith.
*/

var metalsmith = new Metalsmith(dir)
const metalsmith = new Metalsmith(dir)
if (json.source) metalsmith.source(json.source)
if (json.destination) metalsmith.destination(json.destination)
if (json.concurrency) metalsmith.concurrency(json.concurrency)
Expand All @@ -74,13 +75,13 @@ if (json.ignore != null) metalsmith.ignore(json.ignore)
*/

normalize(json.plugins).forEach(function(plugin){
for (var name in plugin) {
var opts = plugin[name]
var mod
for (const name in plugin) {
const opts = plugin[name]
let mod

try {
var local = resolve(dir, name)
var npm = resolve(dir, 'node_modules', name)
const local = resolve(dir, name)
const npm = resolve(dir, 'node_modules', name)

if (exists(local) || exists(local + '.js')) {
mod = require(local)
Expand Down Expand Up @@ -149,10 +150,10 @@ function log(message){

function normalize(obj){
if (obj instanceof Array) return obj
var ret = []
const ret = []

for (var key in obj) {
var plugin = {}
for (const key in obj) {
const plugin = {}
plugin[key] = obj[key]
ret.push(plugin)
}
Expand Down

0 comments on commit cce1558

Please sign in to comment.