1 | const globby = require('globby')
|
2 | const processFile = require('./lib/processFile')
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | module.exports = async function markdownMagic(filePaths, config, callback) {
|
17 | const files = globby.sync(filePaths)
|
18 | const configuration = config || {}
|
19 | if (!callback && typeof configuration === 'function') {
|
20 | callback = configuration
|
21 | } else if (typeof config === 'object' && config.callback) {
|
22 |
|
23 | callback = config.callback
|
24 | }
|
25 | if (!files.length) {
|
26 | callback && callback('No files matched')
|
27 | console.log('No files matched pattern', filePaths)
|
28 | return false
|
29 | }
|
30 | configuration.originalFilePaths = files
|
31 |
|
32 | const data = files.map(async (file) => {
|
33 | const x = await processFile(file, configuration)
|
34 | return x
|
35 | })
|
36 |
|
37 | const values = await Promise.all(data)
|
38 |
|
39 | if (callback) {
|
40 | callback(null, values)
|
41 | }
|
42 | return values
|
43 | }
|
44 |
|
45 |
|
46 | module.exports.globby = globby
|