Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.

Commit 9dae4ea

Browse files
chore: bump dependencies
1 parent 8562461 commit 9dae4ea

File tree

6 files changed

+2665
-2521
lines changed

6 files changed

+2665
-2521
lines changed

example/build.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#!/usr/bin/env node
22

3-
const metalsmith = require('metalsmith')
4-
const metalsmithConcat = require('..')
3+
const metalsmith = require('metalsmith');
4+
const metalsmithConcat = require('..');
55

66
metalsmith(__dirname)
7-
.use(
8-
metalsmithConcat({
9-
files: '**/*.css',
10-
output: 'main.css',
11-
})
12-
)
13-
.build(error => {
14-
if (error) {
15-
throw error
16-
}
17-
})
7+
.use(
8+
metalsmithConcat({
9+
files: '**/*.css',
10+
output: 'main.css'
11+
})
12+
)
13+
.build(error => {
14+
if (error) {
15+
throw error;
16+
}
17+
});

example/build.test.js

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
const fs = require('fs')
2-
const path = require('path')
3-
const { execFile } = require('child_process')
4-
const rimraf = require('rimraf')
5-
const test = require('ava')
1+
const fs = require('fs');
2+
const path = require('path');
3+
const {execFile} = require('child_process');
4+
const rimraf = require('rimraf');
5+
const test = require('ava');
66

7-
const build = path.join(__dirname, 'build')
7+
const build = path.join(__dirname, 'build');
88
// Make sure the build is cleaned before/after each test
9-
test.beforeEach.cb(t => rimraf(build, t.end))
10-
test.afterEach.always.cb(t => rimraf(build, t.end))
9+
test.beforeEach.cb(t => {
10+
rimraf(build, t.end);
11+
});
12+
test.afterEach.always.cb(t => {
13+
rimraf(build, t.end);
14+
});
1115

1216
test.serial.cb('the example should build successfully', t => {
13-
t.plan(3)
14-
execFile(
15-
'node',
16-
[path.join(__dirname, 'build.js')],
17-
{ cwd: path.join(__dirname, '..') },
18-
error => {
19-
t.falsy(error)
20-
fs.lstat(build, (error, stats) => {
21-
t.falsy(error)
22-
t.true(stats.isDirectory())
23-
t.end()
24-
})
25-
}
26-
)
27-
})
17+
t.plan(3);
18+
execFile(
19+
'node',
20+
[path.join(__dirname, 'build.js')],
21+
{cwd: path.join(__dirname, '..')},
22+
error => {
23+
t.falsy(error);
24+
fs.lstat(build, (error, stats) => {
25+
t.falsy(error);
26+
t.true(stats.isDirectory());
27+
t.end();
28+
});
29+
}
30+
);
31+
});

index.js

Lines changed: 125 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,134 @@
1-
const fs = require('fs')
2-
const path = require('path')
3-
const async = require('async')
4-
const glob = require('glob')
5-
const minimatch = require('minimatch')
6-
7-
function gathererFromSourceDirectory(source, pattern, { keepConcatenated }) {
8-
return done => {
9-
// We loop over all the files Metalsmith knows of and return an array of all
10-
// the files contents matching the given pattern
11-
return done(
12-
null,
13-
Object.keys(source).reduce((acc, filepath) => {
14-
if (minimatch(filepath, pattern)) {
15-
acc.push(source[filepath].contents)
16-
if (!keepConcatenated) {
17-
delete source[filepath]
18-
}
19-
}
20-
21-
return acc
22-
}, [])
23-
)
24-
}
1+
const fs = require('fs');
2+
const path = require('path');
3+
const async = require('async');
4+
const glob = require('glob');
5+
const minimatch = require('minimatch');
6+
7+
function gathererFromSourceDirectory(source, pattern, {keepConcatenated}) {
8+
return done => {
9+
// We loop over all the files Metalsmith knows of and return an array of all
10+
// the files contents matching the given pattern
11+
return done(
12+
null,
13+
Object.keys(source).reduce((acc, filepath) => {
14+
if (minimatch(filepath, pattern)) {
15+
acc.push(source[filepath].contents);
16+
if (!keepConcatenated) {
17+
delete source[filepath];
18+
}
19+
}
20+
21+
return acc;
22+
}, [])
23+
);
24+
};
2525
}
2626

2727
function gathererFromSearchPaths(rootPath, searchPaths, pattern) {
28-
return done => {
29-
// We loop over the search paths and return an array of all the files
30-
// contents matching the given pattern
31-
async.map(
32-
searchPaths,
33-
(searchPath, callback) => {
34-
const globPattern = path.resolve(rootPath, searchPath, pattern)
35-
glob.glob(
36-
globPattern,
37-
{
38-
ignore: path.resolve(rootPath, 'src/**/*'),
39-
minimatch,
40-
nodir: true,
41-
},
42-
(error, filepaths) => {
43-
if (error) {
44-
return callback(error)
45-
}
46-
47-
async.map(
48-
filepaths.map(filepath => path.resolve(rootPath, filepath)),
49-
fs.readFile,
50-
callback
51-
)
52-
}
53-
)
54-
},
55-
(error, filesContents) => {
56-
if (error) {
57-
return done(error)
58-
}
59-
60-
return done(null, [].concat(...filesContents)) // Shallow flatten
61-
}
62-
)
63-
}
28+
return done => {
29+
// We loop over the search paths and return an array of all the files
30+
// contents matching the given pattern
31+
async.map(
32+
searchPaths,
33+
(searchPath, callback) => {
34+
const globPattern = path.resolve(rootPath, searchPath, pattern);
35+
glob.glob(
36+
globPattern,
37+
{
38+
ignore: path.resolve(rootPath, 'src/**/*'),
39+
minimatch,
40+
nodir: true
41+
},
42+
(error, filepaths) => {
43+
if (error) {
44+
return callback(error);
45+
}
46+
47+
async.map(
48+
filepaths.map(filepath => path.resolve(rootPath, filepath)),
49+
fs.readFile,
50+
callback
51+
);
52+
}
53+
);
54+
},
55+
(error, filesContents) => {
56+
if (error) {
57+
return done(error);
58+
}
59+
60+
return done(null, [].concat(...filesContents)); // Shallow flatten
61+
}
62+
);
63+
};
6464
}
6565

6666
function metalsmithifyPath(path) {
67-
return path.replace(/[/\\]+/g, '/')
67+
return path.replace(/[/\\]+/g, '/');
6868
}
6969

7070
module.exports = (options = {}) => {
71-
if (!(typeof options.output === 'string' && options.output.length > 0)) {
72-
throw new Error(
73-
'`options.output` is mandatory and has to be a non-empty string'
74-
)
75-
}
76-
77-
const output = metalsmithifyPath(options.output)
78-
79-
const patterns = (Array.isArray(options.files)
80-
? options.files
81-
: typeof options.files === 'string'
82-
? [options.files]
83-
: ['**/*']
84-
).map(metalsmithifyPath)
85-
86-
const EOL =
87-
typeof options.insertNewline === 'string'
88-
? options.insertNewline
89-
: options.insertNewline === false
90-
? ''
91-
: '\n'
92-
93-
const searchPaths = Array.isArray(options.searchPaths)
94-
? options.searchPaths
95-
: typeof options.searchPaths === 'string'
96-
? [options.searchPaths]
97-
: []
98-
99-
const { forceOutput = false, keepConcatenated = false } = options
100-
101-
return (files, metalsmith, done) => {
102-
if (output in files && !forceOutput) {
103-
return done(
104-
new Error(
105-
`The file "${output}" already exists, see the documentation for 'options.forceOutput'`
106-
)
107-
)
108-
}
109-
110-
// We reduce the array of patterns into an array of gatherers
111-
const gatherers = patterns.reduce(
112-
(acc, pattern) => [
113-
...acc,
114-
gathererFromSourceDirectory(files, pattern, { keepConcatenated }),
115-
gathererFromSearchPaths(metalsmith._directory, searchPaths, pattern),
116-
],
117-
[]
118-
)
119-
120-
// Gather all the files contents and generate the final concatenated file
121-
async.parallel(gatherers, (error, gatherersResults) => {
122-
if (error) {
123-
return done(error)
124-
}
125-
126-
const filesContents = [
127-
...[].concat(...gatherersResults), // Shallow flatten the results from each gatherers [[a], [b]] -> [a, b]
128-
'', // Append an empty string so that the final join result includes a trailing new line
129-
]
130-
131-
files[output] = { contents: Buffer.from(filesContents.join(EOL)) }
132-
return done()
133-
})
134-
}
135-
}
71+
if (!(typeof options.output === 'string' && options.output.length > 0)) {
72+
throw new Error(
73+
'`options.output` is mandatory and has to be a non-empty string'
74+
);
75+
}
76+
77+
const output = metalsmithifyPath(options.output);
78+
79+
const patterns = (Array.isArray(options.files) ?
80+
options.files :
81+
(typeof options.files === 'string' ?
82+
[options.files] :
83+
['**/*'])
84+
).map(p => metalsmithifyPath(p));
85+
86+
const EOL = typeof options.insertNewline === 'string' ?
87+
options.insertNewline :
88+
(options.insertNewline === false ?
89+
'' :
90+
'\n');
91+
92+
const searchPaths = Array.isArray(options.searchPaths) ?
93+
options.searchPaths :
94+
(typeof options.searchPaths === 'string' ?
95+
[options.searchPaths] :
96+
[]);
97+
98+
const {forceOutput = false, keepConcatenated = false} = options;
99+
100+
return (files, metalsmith, done) => {
101+
if (output in files && !forceOutput) {
102+
return done(
103+
new Error(
104+
`The file "${output}" already exists, see the documentation for 'options.forceOutput'`
105+
)
106+
);
107+
}
108+
109+
// We reduce the array of patterns into an array of gatherers
110+
const gatherers = patterns.reduce(
111+
(acc, pattern) => [
112+
...acc,
113+
gathererFromSourceDirectory(files, pattern, {keepConcatenated}),
114+
gathererFromSearchPaths(metalsmith._directory, searchPaths, pattern)
115+
],
116+
[]
117+
);
118+
119+
// Gather all the files contents and generate the final concatenated file
120+
async.parallel(gatherers, (error, gatherersResults) => {
121+
if (error) {
122+
return done(error);
123+
}
124+
125+
const filesContents = [
126+
...[].concat(...gatherersResults), // Shallow flatten the results from each gatherers [[a], [b]] -> [a, b]
127+
'' // Append an empty string so that the final join result includes a trailing new line
128+
];
129+
130+
files[output] = {contents: Buffer.from(filesContents.join(EOL))};
131+
return done();
132+
});
133+
};
134+
};

package.json

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,19 @@
2424
"lib/*"
2525
],
2626
"scripts": {
27-
"format": "prettier --write \"{,.}**.{js,md,yml}\" && xo --fix",
28-
"test": "prettier --check \"{,.}**.{js,md,yml}\" && xo && ava"
29-
},
30-
"xo": {
31-
"prettier": true
32-
},
33-
"prettier": {
34-
"bracketSpacing": true,
35-
"jsxBracketSameLine": false,
36-
"semi": false,
37-
"singleQuote": true,
38-
"tabWidth": 2,
39-
"trailingComma": "es5",
40-
"useTabs": false
27+
"format": "xo --fix",
28+
"test": "xo && ava"
4129
},
4230
"dependencies": {
43-
"async": "^3.1.0",
44-
"glob": "^7.1.4",
45-
"minimatch": "^3.0.4"
31+
"async": "3.2.0",
32+
"glob": "7.1.6",
33+
"minimatch": "3.0.4"
4634
},
4735
"devDependencies": {
48-
"ava": "2.3.0",
36+
"ava": "3.8.2",
4937
"metalsmith": "2.3.0",
50-
"prettier": "1.18.2",
51-
"rimraf": "3.0.0",
52-
"sinon": "7.4.2",
53-
"xo": "0.24.0"
38+
"rimraf": "3.0.2",
39+
"sinon": "9.0.2",
40+
"xo": "0.30.0"
5441
}
5542
}

0 commit comments

Comments
 (0)