markdown-magic 3.6.4 → 3.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +20 -9
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -113,7 +113,7 @@ const defaultOptions = {
|
|
|
113
113
|
})
|
|
114
114
|
*/
|
|
115
115
|
async function markdownMagic(globOrOpts = {}, options = {}) {
|
|
116
|
-
const
|
|
116
|
+
const hrStart = process.hrtime.bigint()
|
|
117
117
|
let opts = options || {}
|
|
118
118
|
let globPat
|
|
119
119
|
if (typeof globOrOpts === 'string' || Array.isArray(globOrOpts)) {
|
|
@@ -134,12 +134,13 @@ async function markdownMagic(globOrOpts = {}, options = {}) {
|
|
|
134
134
|
useGitGlob = false,
|
|
135
135
|
failOnMissingTransforms = false,
|
|
136
136
|
failOnMissingRemote = true,
|
|
137
|
-
dryRun = false,
|
|
138
137
|
debug = false,
|
|
139
138
|
syntax = 'md',
|
|
140
139
|
silent = false,
|
|
141
140
|
} = opts
|
|
142
141
|
|
|
142
|
+
let dryRun = opts.dryRun || opts.dry || opts.plan || false
|
|
143
|
+
|
|
143
144
|
// @ts-ignore
|
|
144
145
|
const outputDir = output.directory || opts.outputDir
|
|
145
146
|
const removeComments = output.removeComments || false
|
|
@@ -203,7 +204,8 @@ async function markdownMagic(globOrOpts = {}, options = {}) {
|
|
|
203
204
|
opts.globPattern = globs
|
|
204
205
|
|
|
205
206
|
logger(LINE)
|
|
206
|
-
|
|
207
|
+
const dryRunPostFix = (dryRun) ? ' - Dry run' : ''
|
|
208
|
+
success(` Markdown Magic Starting...${dryRunPostFix}`, silent, '✨ ')
|
|
207
209
|
logger(`${LINE}\n`)
|
|
208
210
|
|
|
209
211
|
info(` Searching for comment blocks...`, silent, '🔎 ')
|
|
@@ -213,9 +215,9 @@ async function markdownMagic(globOrOpts = {}, options = {}) {
|
|
|
213
215
|
logger(`Searching: `, globs)
|
|
214
216
|
|
|
215
217
|
if (dryRun || debug) {
|
|
218
|
+
logger()
|
|
216
219
|
info(`Glob patterns:`, silent)
|
|
217
220
|
logger(globs)
|
|
218
|
-
logger()
|
|
219
221
|
/*
|
|
220
222
|
process.exit(1)
|
|
221
223
|
/** */
|
|
@@ -360,7 +362,7 @@ async function markdownMagic(globOrOpts = {}, options = {}) {
|
|
|
360
362
|
const sortedItems = sortedIds.map(id => blocks.find(item => item.id === id)).filter(Boolean);
|
|
361
363
|
|
|
362
364
|
// topoSort(blocks)
|
|
363
|
-
const orderedFiles = sortedItems.map((
|
|
365
|
+
const orderedFiles = sortedItems.map((block) => block.id)
|
|
364
366
|
// console.log('sortedItems', sortedItems)
|
|
365
367
|
// console.log('orderedFiles', orderedFiles)
|
|
366
368
|
|
|
@@ -674,8 +676,17 @@ async function markdownMagic(globOrOpts = {}, options = {}) {
|
|
|
674
676
|
process.exit(1)
|
|
675
677
|
/** */
|
|
676
678
|
logger()
|
|
677
|
-
info(` Results:`, silent, "💫 ")
|
|
678
679
|
|
|
680
|
+
if (dryRun) {
|
|
681
|
+
logger('Dry run complete. Exiting markdown magic early.')
|
|
682
|
+
return {
|
|
683
|
+
errors,
|
|
684
|
+
filesChanged: [],
|
|
685
|
+
results: plan
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
info(` Results:`, silent, "💫 ")
|
|
679
690
|
/*
|
|
680
691
|
TODO:
|
|
681
692
|
- Output to new file
|
|
@@ -686,14 +697,14 @@ async function markdownMagic(globOrOpts = {}, options = {}) {
|
|
|
686
697
|
logErrors(errors)
|
|
687
698
|
}
|
|
688
699
|
|
|
689
|
-
const
|
|
700
|
+
const elapsed = convertHrtime(process.hrtime.bigint() - hrStart)
|
|
690
701
|
|
|
691
702
|
logger()
|
|
692
703
|
logger(`${LINE}`)
|
|
693
|
-
success(`Markdown Magic Done. ${
|
|
704
|
+
success(`Markdown Magic Done. ${elapsed.seconds} seconds`, silent)
|
|
694
705
|
logger(`${LINE}`)
|
|
695
706
|
return {
|
|
696
|
-
// @TODO maybe
|
|
707
|
+
// @TODO maybe separate changed and output files
|
|
697
708
|
filesChanged: plan.filter(({ isChanged, isNewPath }) => isChanged || isNewPath).map(({ outputPath }) => outputPath),
|
|
698
709
|
results: plan,
|
|
699
710
|
errors,
|