Skip to content

Commit

Permalink
Merge pull request #1123 from maizzle/revert-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
cossssmin authored Dec 29, 2023
2 parents 9ecd26e + 9ac0e80 commit 0681f56
Show file tree
Hide file tree
Showing 26 changed files with 40 additions and 93 deletions.
4 changes: 2 additions & 2 deletions src/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const Config = require('../generators/config')
const buildToFile = require('../commands/build')
const renderToString = require('../functions/render')

const {get, isObject} = require('lodash')
const {clearConsole, merge} = require('../utils/helpers')
const {get, merge, isObject} = require('lodash')
const {clearConsole} = require('../utils/helpers')

/**
* Initialize Browsersync on-demand
Expand Down
3 changes: 2 additions & 1 deletion src/generators/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path')
const {merge, requireUncached} = require('../utils/helpers')
const {merge} = require('lodash')
const {requireUncached} = require('../utils/helpers')

const baseConfigFileNames = [
'./maizzle.config.js',
Expand Down
5 changes: 2 additions & 3 deletions src/generators/output/to-disk.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const path = require('path')
const fs = require('fs-extra')
const glob = require('glob-promise')
const {get, isEmpty} = require('lodash')
const {merge} = require('../../utils/helpers')
const {get, merge, isEmpty} = require('lodash')

const Config = require('../config')
const Tailwind = require('../tailwindcss')
const Plaintext = require('../plaintext')
const Tailwind = require('../tailwindcss')

const render = require('./to-string')

Expand Down
7 changes: 3 additions & 4 deletions src/generators/output/to-string.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const fm = require('front-matter')
const {get} = require('lodash')
const Config = require('../config')
const {get, merge} = require('lodash')
const posthtml = require('../posthtml')
const {merge} = require('../../utils/helpers')
const Transformers = require('../../transformers')
const Tailwind = require('../tailwindcss')
const Config = require('../config')
const Transformers = require('../../transformers')

module.exports = async (html, options) => {
process.env.NODE_ENV = get(options, 'maizzle.env', 'local')
Expand Down
3 changes: 1 addition & 2 deletions src/generators/plaintext.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const path = require('path')
const {get} = require('lodash')
const posthtml = require('posthtml')
const {merge} = require('../utils/helpers')
const {get, merge} = require('lodash')
const {stripHtml} = require('string-strip-html')
const defaultConfig = require('./posthtml/defaultConfig')

Expand Down
3 changes: 1 addition & 2 deletions src/generators/posthtml/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const fm = require('front-matter')
const posthtml = require('posthtml')
const {get, omit} = require('lodash')
const fetch = require('posthtml-fetch')
const layouts = require('posthtml-extend')
const {merge} = require('../../utils/helpers')
const {get, merge, omit} = require('lodash')
const components = require('posthtml-component')
const defaultPosthtmlConfig = require('./defaultConfig')
const defaultComponentsConfig = require('./defaultComponentsConfig')
Expand Down
4 changes: 2 additions & 2 deletions src/generators/tailwindcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ const fs = require('fs-extra')
const postcss = require('postcss')
const tailwindcss = require('tailwindcss')
const postcssImport = require('postcss-import')
const {get, isObject, isEmpty} = require('lodash')
const {get, merge, isObject, isEmpty} = require('lodash')
const postcssNested = require('tailwindcss/nesting')
const {merge, requireUncached} = require('../utils/helpers')
const {requireUncached} = require('../utils/helpers')
const mergeLonghand = require('postcss-merge-longhand')
const defaultComponentsConfig = require('./posthtml/defaultComponentsConfig')

Expand Down
10 changes: 8 additions & 2 deletions src/transformers/attributeToStyle.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
const {
get,
merge,
forEach,
intersection,
keys,
isEmpty
} = require('lodash')
const posthtml = require('posthtml')
const {merge} = require('../utils/helpers')
const parseAttrs = require('posthtml-attrs-parser')
const defaultConfig = require('../generators/posthtml/defaultConfig')
const {get, forEach, intersection, keys, isEmpty} = require('lodash')

module.exports = async (html, config = {}, direct = false) => {
const posthtmlOptions = merge(defaultConfig, get(config, 'build.posthtml.options', {}))
Expand Down
3 changes: 1 addition & 2 deletions src/transformers/baseUrl.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const posthtml = require('posthtml')
const isUrl = require('is-url-superb')
const {merge} = require('../utils/helpers')
const baseUrl = require('posthtml-base-url')
const {get, isObject, isEmpty} = require('lodash')
const {get, merge, isObject, isEmpty} = require('lodash')
const defaultConfig = require('../generators/posthtml/defaultConfig')

module.exports = async (html, config = {}, direct = false) => {
Expand Down
3 changes: 1 addition & 2 deletions src/transformers/extraAttributes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const posthtml = require('posthtml')
const {get, isObject} = require('lodash')
const {merge} = require('../utils/helpers')
const {get, merge, isObject} = require('lodash')
const addAttributes = require('posthtml-extra-attributes')
const defaultConfig = require('../generators/posthtml/defaultConfig')

Expand Down
3 changes: 1 addition & 2 deletions src/transformers/filters/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const posthtml = require('posthtml')
const {get, omit, has} = require('lodash')
const {merge} = require('../../utils/helpers')
const {get, merge, omit, has} = require('lodash')
const defaultFilters = require('./defaultFilters')
const PostCSS = require('../../generators/postcss')
const posthtmlContent = require('posthtml-content')
Expand Down
3 changes: 1 addition & 2 deletions src/transformers/markdown.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const {get} = require('lodash')
const posthtml = require('posthtml')
const {merge} = require('../utils/helpers')
const {get, merge} = require('lodash')
const markdown = require('posthtml-markdownit')
const defaultConfig = require('../generators/posthtml/defaultConfig')

Expand Down
3 changes: 1 addition & 2 deletions src/transformers/posthtmlMso.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const {get} = require('lodash')
const posthtml = require('posthtml')
const {get, merge} = require('lodash')
const outlook = require('posthtml-mso')
const {merge} = require('../utils/helpers')
const defaultConfig = require('../generators/posthtml/defaultConfig')

module.exports = async (html, config) => {
Expand Down
3 changes: 1 addition & 2 deletions src/transformers/prettify.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable camelcase */
const pretty = require('pretty')
const {merge} = require('../utils/helpers')
const {get, isEmpty, isObject} = require('lodash')
const {get, merge, isEmpty, isObject} = require('lodash')

module.exports = async (html, config = {}, direct = false) => {
const defaultConfig = {
Expand Down
3 changes: 1 addition & 2 deletions src/transformers/preventWidows.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const posthtml = require('posthtml')
const {get, isEmpty} = require('lodash')
const {merge} = require('../utils/helpers')
const {get, merge, isEmpty} = require('lodash')
const {removeWidows} = require('string-remove-widows')
const defaultConfig = require('../generators/posthtml/defaultConfig')

Expand Down
3 changes: 1 addition & 2 deletions src/transformers/removeAttributes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const {get} = require('lodash')
const posthtml = require('posthtml')
const {merge} = require('../utils/helpers')
const {get, merge} = require('lodash')
const defaultConfig = require('../generators/posthtml/defaultConfig')

module.exports = async (html, config = {}, direct = false) => {
Expand Down
4 changes: 2 additions & 2 deletions src/transformers/removeInlineBackgroundColor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const posthtml = require('posthtml')
const {get, isEmpty} = require('lodash')
const {get, merge, isEmpty} = require('lodash')
const parseAttrs = require('posthtml-attrs-parser')
const {merge, toStyleString} = require('../utils/helpers')
const {toStyleString} = require('../utils/helpers')
const defaultConfig = require('../generators/posthtml/defaultConfig')

module.exports = async (html, config = {}, direct = false) => {
Expand Down
4 changes: 2 additions & 2 deletions src/transformers/removeInlineSizes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const posthtml = require('posthtml')
const {get, isEmpty} = require('lodash')
const {get, merge, isEmpty} = require('lodash')
const parseAttrs = require('posthtml-attrs-parser')
const {merge, toStyleString} = require('../utils/helpers')
const {toStyleString} = require('../utils/helpers')
const defaultConfig = require('../generators/posthtml/defaultConfig')

module.exports = async (html, config = {}, direct = false) => {
Expand Down
3 changes: 1 addition & 2 deletions src/transformers/removeInlinedSelectors.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const postcss = require('postcss')
const posthtml = require('posthtml')
const {merge} = require('../utils/helpers')
const {get, has, remove} = require('lodash')
const {get, merge, has, remove} = require('lodash')
const parseAttrs = require('posthtml-attrs-parser')
const matchHelper = require('posthtml-match-helper')
const defaultConfig = require('../generators/posthtml/defaultConfig')
Expand Down
3 changes: 1 addition & 2 deletions src/transformers/removeUnusedCss.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const {comb} = require('email-comb')
const {merge} = require('../utils/helpers')
const {get, isEmpty, isObject} = require('lodash')
const {get, merge, isEmpty, isObject} = require('lodash')
const removeInlinedClasses = require('./removeInlinedSelectors')

module.exports = async (html, config = {}, direct = false) => {
Expand Down
3 changes: 1 addition & 2 deletions src/transformers/safeClassNames.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const posthtml = require('posthtml')
const {get, isEmpty} = require('lodash')
const {merge} = require('../utils/helpers')
const {get, merge, isEmpty} = require('lodash')
const safeClassNames = require('posthtml-safe-class-names')
const defaultConfig = require('../generators/posthtml/defaultConfig')

Expand Down
3 changes: 1 addition & 2 deletions src/transformers/shorthandInlineCSS.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const posthtml = require('posthtml')
const {merge} = require('../utils/helpers')
const {get, isObject, isEmpty} = require('lodash')
const {get, merge, isObject, isEmpty} = require('lodash')
const mergeInlineLonghand = require('posthtml-postcss-merge-longhand')
const defaultConfig = require('../generators/posthtml/defaultConfig')

Expand Down
3 changes: 1 addition & 2 deletions src/transformers/sixHex.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const {get} = require('lodash')
const posthtml = require('posthtml')
const {merge} = require('../utils/helpers')
const {get, merge} = require('lodash')
const {conv} = require('color-shorthand-hex-to-six-digit')
const defaultConfig = require('../generators/posthtml/defaultConfig')

Expand Down
3 changes: 1 addition & 2 deletions src/transformers/urlParameters.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const posthtml = require('posthtml')
const {get, isEmpty} = require('lodash')
const {merge} = require('../utils/helpers')
const {get, merge, isEmpty} = require('lodash')
const urlParams = require('posthtml-url-parameters')
const defaultConfig = require('../generators/posthtml/defaultConfig')

Expand Down
23 changes: 1 addition & 22 deletions src/utils/helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const {mergeWith} = require('lodash')

module.exports = {
requireUncached: module => {
try {
Expand All @@ -11,24 +9,5 @@ module.exports = {
},
// https://github.com/lukeed/console-clear
clearConsole: () => process.stdout.write('\x1B[H\x1B[2J'),
toStyleString: (object = {}) => Object.entries(object).map(([k, v]) => `${k}: ${v}`).join('; '),
merge: (...objects) => {
if (objects.length < 2) {
return objects[0]
}

let merged = {}

for (const object of objects) {
merged = mergeWith(merged, object, (existingValue, newValue) => {
if (Array.isArray(existingValue) && Array.isArray(newValue)) {
return [...existingValue, ...newValue]
}

return undefined
})
}

return merged
}
toStyleString: (object = {}) => Object.entries(object).map(([k, v]) => `${k}: ${v}`).join('; ')
}
21 changes: 0 additions & 21 deletions test/test-misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,3 @@ test('requires an uncached module', t => {
const helpers = h.requireUncached(path.resolve(process.cwd(), 'src/utils/helpers'))
t.is(typeof helpers.requireUncached, 'function')
})

test('merges multiple objects containing arrays', t => {
const object1 = {foo: 'bar', arr: [1, 2]}
const object2 = {arr: [3, 4], baz: 'qux'}
const object3 = {what: 'ever', arr: [5, 6]}
const merged = h.merge(object1, object2, object3)

t.deepEqual(merged, {
arr: [1, 2, 3, 4, 5, 6],
baz: 'qux',
foo: 'bar',
what: 'ever'
})
})

test('returns object when less than two objects are provided', t => {
const object = {arr: [1, 2]}
const merged = h.merge(object)

t.deepEqual(merged, object)
})

0 comments on commit 0681f56

Please sign in to comment.