Skip to content

Commit

Permalink
style: reformat code with prettier and eslint-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nknapp committed Jan 27, 2020
1 parent 55e9bff commit 29f566c
Show file tree
Hide file tree
Showing 40 changed files with 1,612 additions and 908 deletions.
8 changes: 4 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ module.exports = {
ecmaVersion: 2018
},
rules: {
"no-var": "error",
"prefer-const": "warn",
"no-console": "warn"
'no-var': 'error',
'prefer-const': 'warn',
'no-console': 'warn'
},
overrides: [
{
files: ['**/test/*-spec.js'],
env: {
mocha: true
// mocha: true
}
},
{
Expand Down
4 changes: 1 addition & 3 deletions .thought/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module.exports = {
plugins: [
require('thought-plugin-jsdoc')
],
plugins: [require('thought-plugin-jsdoc')],
badges: {
greenkeeper: true
}
Expand Down
19 changes: 10 additions & 9 deletions .thought/snippets/plugin-loading-plugins.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module.exports = function (customize) {

return customize
// jsdoc-support
.load(require('thought-plugin-jsdoc'))
// include open-open-source disclaimer in CONTRIBUTING.md
.load(require('thought-plugin-open-open-source'))
// include standardjs-disclaimer in CONTRIBUTING.md
.load(require('thought-plugin-standardjs'))
module.exports = function(customize) {
return (
customize
// jsdoc-support
.load(require('thought-plugin-jsdoc'))
// include open-open-source disclaimer in CONTRIBUTING.md
.load(require('thought-plugin-open-open-source'))
// include standardjs-disclaimer in CONTRIBUTING.md
.load(require('thought-plugin-standardjs'))
)
}
80 changes: 41 additions & 39 deletions customize.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,49 +33,51 @@ const defaultConfig = {
* @param {String} workingDir the working directory of thought
* @returns {Function} the Customize-Spec
*/
module.exports = function createSpec (workingDir) {
return function thoughtSpec (customize) {
module.exports = function createSpec(workingDir) {
return function thoughtSpec(customize) {
debug('creating customize config')
const configFile = path.resolve('.thought', 'config.js')
const config = fs.existsSync(configFile) ? require(configFile) : defaultConfig
debug('config loaded', config)
return customize
.registerEngine('handlebars', require('customize-engine-handlebars'))
.merge({ handlebars: { data: { config: defaultConfig } } })
.merge({
handlebars: {
partials: path.join(__dirname, 'handlebars', 'partials'),
templates: path.join(__dirname, 'handlebars', 'templates'),
helpers: require.resolve('./handlebars/helpers/index.js'),
data: {
'package': fs.readFile(path.resolve(workingDir, 'package.json'), 'utf-8').then(JSON.parse),
config: config,
workingDir: workingDir
},
preprocessor: require('./handlebars/preprocessor.js'),
hbsOptions: {
noEscape: true
return (
customize
.registerEngine('handlebars', require('customize-engine-handlebars'))
.merge({ handlebars: { data: { config: defaultConfig } } })
.merge({
handlebars: {
partials: path.join(__dirname, 'handlebars', 'partials'),
templates: path.join(__dirname, 'handlebars', 'templates'),
helpers: require.resolve('./handlebars/helpers/index.js'),
data: {
package: fs.readFile(path.resolve(workingDir, 'package.json'), 'utf-8').then(JSON.parse),
config: config,
workingDir: workingDir
},
preprocessor: require('./handlebars/preprocessor.js'),
hbsOptions: {
noEscape: true
}
}
}
})
// Apply any customization from the config-files (such as loading modules)
.load(function (customize) {
debug('Loading modules', config)
if (config && config.plugins) {
return config.plugins.reduce((prev, plugin) => {
return prev.load(plugin)
}, customize)
} else {
return customize
}
})
.merge({
handlebars: {
partials: path.join(workingDir, '.thought', 'partials'),
templates: path.join(workingDir, '.thought', 'templates'),
helpers: path.resolve(workingDir, '.thought', 'helpers.js'),
preprocessor: path.resolve(workingDir, '.thought', 'preprocessor.js')
}
})
})
// Apply any customization from the config-files (such as loading modules)
.load(function(customize) {
debug('Loading modules', config)
if (config && config.plugins) {
return config.plugins.reduce((prev, plugin) => {
return prev.load(plugin)
}, customize)
} else {
return customize
}
})
.merge({
handlebars: {
partials: path.join(workingDir, '.thought', 'partials'),
templates: path.join(workingDir, '.thought', 'templates'),
helpers: path.resolve(workingDir, '.thought', 'helpers.js'),
preprocessor: path.resolve(workingDir, '.thought', 'preprocessor.js')
}
})
)
}
}
10 changes: 0 additions & 10 deletions examples/.eslintrc.js

This file was deleted.

41 changes: 21 additions & 20 deletions examples/example-plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,31 @@ const path = require('path')
* Return a new instance of customize with merged configuration
* @param {Customize} customize
*/
module.exports = function examplePlugin (customize) {
return customize
// Include thought-plugin-jsdoc whenever this plugin is used
.load(require('thought-plugin-jsdoc'))
.merge({
handlebars: {
helpers: {
// Register a custom helper
shout: (text) => String(text).toUpperCase()
},
// Register partials from the 'partials/'-directory of the plugin-module
partials: path.resolve(__dirname, 'partials'),
// Register templates from the 'partials/'-directory of the plugin-module
templates: path.resolve(__dirname, 'templates'),
// Register a preprocessor that modifies the package-data
preprocessor: function (data) {
return this.parent(data)
.then(resolvedData => {
module.exports = function examplePlugin(customize) {
return (
customize
// Include thought-plugin-jsdoc whenever this plugin is used
.load(require('thought-plugin-jsdoc'))
.merge({
handlebars: {
helpers: {
// Register a custom helper
shout: text => String(text).toUpperCase()
},
// Register partials from the 'partials/'-directory of the plugin-module
partials: path.resolve(__dirname, 'partials'),
// Register templates from the 'partials/'-directory of the plugin-module
templates: path.resolve(__dirname, 'templates'),
// Register a preprocessor that modifies the package-data
preprocessor: function preprocessor(data) {
return this.parent(data).then(resolvedData => {
resolvedData.package.description += ' (modified by example-plugin)'
return resolvedData
})
}
}
}
})
})
)
}

module.exports.package = require('./package.json')
2 changes: 1 addition & 1 deletion examples/example-project-1-simple/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
* @module example-project
* @public
*/
module.exports = function multiply (a, b) {
module.exports = function multiply(a, b) {
return a * b
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module.exports = {
plugins: [
require('thought-plugin-jsdoc')
],
plugins: [require('thought-plugin-jsdoc')],
badges: {
greenkeeper: true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var multiply = require('../')
const multiply = require('../')

var x = 3
var y = 4
var xy = multiply(x, y)
const x = 3
const y = 4
const xy = multiply(x, y)

console.log(xy)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
* @module example-project
* @public
*/
module.exports = function multiply (a, b) {
module.exports = function multiply(a, b) {
return a * b
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
* @param {string} text a text to be shouted
* @returns {string} the text in uppercases
*/
shout: function (text) {
shout: function(text) {
return text && text.toUpperCase()
},

Expand All @@ -15,7 +15,7 @@ module.exports = {
* @param {string} text
* @returns {Promise<string>} a promise for the text
*/
delay: function (text) {
delay: function(text) {
return new Promise((resolve, reject) => setTimeout(() => resolve(text), 10))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
* A preprocessor can modify the incoming data.
* @param data
*/
module.exports = function (data) {
module.exports = function(data) {
// Call the original preprocessor first (attention: It returns a promise)
return this.parent(data)
.then(function (modifiedData) {
modifiedData.preprocessorText = 'You can probably use helpers to achieve most of the things ' +
'that a preprocessor is good for, but some day you may need one.'
console.log(modifiedData)
return modifiedData
})
return this.parent(data).then(function(modifiedData) {
modifiedData.preprocessorText =
'You can probably use helpers to achieve most of the things ' +
'that a preprocessor is good for, but some day you may need one.'
console.log(modifiedData)
return modifiedData
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
* @module example-project
* @public
*/
module.exports = function multiply (a, b) {
module.exports = function multiply(a, b) {
return a * b
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module.exports = {
plugins: [
require('../../example-plugin/index')
]
plugins: [require('../../example-plugin/index')]
}
2 changes: 1 addition & 1 deletion examples/example-project-4-writing-plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
* @module example-project
* @public
*/
module.exports = function multiply (a, b) {
module.exports = function multiply(a, b) {
return a * b
}
2 changes: 1 addition & 1 deletion examples/javascript-usage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var thought = require('../')
const thought = require('../')

thought({
addToGit: true
Expand Down
15 changes: 8 additions & 7 deletions examples/run-thought.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
* This script generates the documentation for all example-projects.
*/

var fs = require('fs-extra')
var exeq = require('../lib/utils/exeq')
var deep = require('deep-aplus')(Promise)
const fs = require('fs-extra')
const exeq = require('../lib/utils/exeq')
const deep = require('deep-aplus')(Promise)
process.chdir(__dirname)

// Run thought in all example projects
fs.readdir(__dirname)
.then(list => list.filter(dir => dir.match(/^example-project.*$/)))
.then(list => list.map(dir => {
return exeq('thought', ['run', '-a'], { cwd: dir })
.then((result) => {
.then(list =>
list.map(dir => {
return exeq('thought', ['run', '-a'], { cwd: dir }).then(result => {
console.log(`Done with '${dir}'`)
})
}))
})
)
.then(promises => deep(promises))
.then(() => console.log('finished...'))
14 changes: 7 additions & 7 deletions handlebars/helpers/dirTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = dirTree
* @access public
* @memberOf helpers
*/
async function dirTree (baseDir, globPattern, options) {
async function dirTree(baseDir, globPattern, options) {
// Is basedir is not a string, it is probably the handlebars "options" object
if (typeof globPattern !== 'string' && options == null) {
options = globPattern
Expand All @@ -47,7 +47,7 @@ async function dirTree (baseDir, globPattern, options) {
})
debug('dirTree glob result', files)
if (files.length === 0) {
throw new Error('Cannot find a single file for \'' + globPattern + '\' in \'' + baseDir + '\'')
throw new Error("Cannot find a single file for '" + globPattern + "' in '" + baseDir + "'")
}
files.sort()

Expand All @@ -56,7 +56,7 @@ async function dirTree (baseDir, globPattern, options) {
nodes: treeFromPaths(files, baseDir, ({ parent, file, explicit }) => {
if (explicit && hashOptions.links) {
// Compute relative path from current target-file to the listed file
var targetPath = path.relative(path.dirname(options.customize.targetFile), `${parent}/${file}`)
const targetPath = path.relative(path.dirname(options.customize.targetFile), `${parent}/${file}`)
return `<a href="${targetPath}">${file}</a>`
}
return file
Expand Down Expand Up @@ -92,9 +92,9 @@ async function dirTree (baseDir, globPattern, options) {
* @returns {object} a tree structure as needed by [archy](https://www.npmjs.com/package/archy)
* @access private
*/
function treeFromPaths (files, parent, renderLabelFn) {
var groups = _.groupBy(files, file => file.match(/^[^/]*\/?/))
return Object.keys(groups).map(function (groupKey) {
function treeFromPaths(files, parent, renderLabelFn) {
const groups = _.groupBy(files, file => file.match(/^[^/]*\/?/))
return Object.keys(groups).map(function(groupKey) {
const group = groups[groupKey]
// Is this group explicitly part of the result, or
// just implicit through its children
Expand All @@ -120,7 +120,7 @@ function treeFromPaths (files, parent, renderLabelFn) {
* Keep nodes with zero, two or more childs.
* @access private
*/
function condense (node) {
function condense(node) {
if (node.nodes.length === 1 && node.nodes[0].nodes.length > 0) {
return condense({
label: (node.label || '') + node.nodes[0].label,
Expand Down
Loading

0 comments on commit 29f566c

Please sign in to comment.