markdown-magic 3.6.3 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown-magic",
3
- "version": "3.6.3",
3
+ "version": "3.6.5",
4
4
  "description": "Automatically update markdown files with content from external sources",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/index.js CHANGED
@@ -113,7 +113,7 @@ const defaultOptions = {
113
113
  })
114
114
  */
115
115
  async function markdownMagic(globOrOpts = {}, options = {}) {
116
- const hrstart = process.hrtime.bigint()
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,19 +204,20 @@ async function markdownMagic(globOrOpts = {}, options = {}) {
203
204
  opts.globPattern = globs
204
205
 
205
206
  logger(LINE)
206
- success(` Markdown Magic Starting...`, silent, ' ')
207
+ const dryRunPostFix = (dryRun) ? ' - Dry run' : ''
208
+ success(` Markdown Magic Starting...${dryRunPostFix}`, silent, '✨ ')
207
209
  logger(`${LINE}\n`)
208
210
 
209
- info(`Searching for comment blocks...`, silent, '🔎 ')
211
+ info(` Searching for comment blocks...`, silent, '🔎 ')
210
212
  logger(`\nSyntax: ${syntax}`)
211
213
  logger(`Block Open: ${open}`)
212
214
  logger(`Block Close: ${close}`)
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((item) => item.id)
365
+ const orderedFiles = sortedItems.map((block) => block.id)
364
366
  // console.log('sortedItems', sortedItems)
365
367
  // console.log('orderedFiles', orderedFiles)
366
368
 
@@ -465,9 +467,9 @@ async function markdownMagic(globOrOpts = {}, options = {}) {
465
467
  }
466
468
 
467
469
  logger()
468
- info(`Available Transforms:`, silent, '🔁 ')
470
+ info(` Available Transforms:`, silent, '🔁 ')
469
471
  logger(`\n${Object.keys(useTransforms).join(', ')}\n`)
470
- info(`Syntax example:`, silent, '🧱 ')
472
+ info(` Syntax example:`, silent, '🧱 ')
471
473
  logger()
472
474
  logCommentBlockSyntax({
473
475
  syntax: syntax,
@@ -551,7 +553,7 @@ async function markdownMagic(globOrOpts = {}, options = {}) {
551
553
  results: plan
552
554
  }
553
555
  } else {
554
- info(`Parse results:`, silent, "🟢 ")
556
+ info(` Parse results:`, silent, "🟢 ")
555
557
  const total = planTotal + missingTotal
556
558
  logger()
557
559
  logger(`Total transforms: ${total}`)
@@ -576,11 +578,11 @@ async function markdownMagic(globOrOpts = {}, options = {}) {
576
578
  // logger('\nStats:')
577
579
 
578
580
  if (planOutput.length) {
579
- info(`Execution plan:`, silent, "📑 ")
581
+ info(` Execution plan:`, silent, "📑 ")
580
582
  logger()
581
583
  logger(planOutput.join('\n'))
582
584
  } else {
583
- info(`Execution plan:`, silent, "📑 ")
585
+ info(` Execution plan:`, silent, "📑 ")
584
586
  logger('\nNo transforms to run. Exiting markdown magic early.')
585
587
  logger('If you think this is incorrect, verify your comment blocks in your src and the settings in your config.')
586
588
  }
@@ -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 elasped = convertHrtime(process.hrtime.bigint() - hrstart)
700
+ const elapsed = convertHrtime(process.hrtime.bigint() - hrStart)
690
701
 
691
702
  logger()
692
703
  logger(`${LINE}`)
693
- success(`Markdown Magic Done. ${elasped.seconds} seconds`, silent)
704
+ success(`Markdown Magic Done. ${elapsed.seconds} seconds`, silent)
694
705
  logger(`${LINE}`)
695
706
  return {
696
- // @TODO maybe seperate changed and output files
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,
@@ -24,7 +24,6 @@ const path = require('path')
24
24
  * @return {string} Updated content to place in the content block
25
25
  */
26
26
  function install(api) {
27
- console.log('INSTALL API', api)
28
27
  const { options } = api
29
28
  const { isDev = false } = options
30
29
  let packageName = options.packageName