markdown-magic 3.7.0 → 4.0.0

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/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  const mri = require('mri')
3
- const { runCli } = require('./src/cli')
3
+ const { runCli } = require('./src/cli-run')
4
4
  const argv = process.argv.slice(2)
5
5
  const cliArgs = mri(argv)
6
6
 
package/package.json CHANGED
@@ -1,41 +1,21 @@
1
1
  {
2
2
  "name": "markdown-magic",
3
- "version": "3.7.0",
3
+ "version": "4.0.0",
4
4
  "description": "Automatically update markdown files with content from external sources",
5
- "main": "src/index.js",
5
+ "main": "index.js",
6
6
  "bin": {
7
7
  "markdown": "./cli.js",
8
8
  "md-magic": "./cli.js",
9
9
  "mdm": "./cli.js"
10
10
  },
11
+ "types": "types/index.d.ts",
11
12
  "files": [
12
13
  "README.md",
13
14
  "package.json",
14
15
  "package-lock.json",
15
- "cli.js",
16
- "src"
16
+ "src",
17
+ "cli.js"
17
18
  ],
18
- "scripts": {
19
- "types": "tsc",
20
- "emit-types": "tsc --noEmit false --emitDeclarationOnly true",
21
- "docs": "node examples/generate-readme.js",
22
- "test": "npm run test:src && npm run test:test && echo 'tests done'",
23
- "test:src": "uvu src '.test.([mc]js|[jt]sx?)$'",
24
- "test:test": "uvu test '.test.([mc]js|[jt]sx?)$'",
25
- "test:block": "uvu src 'block-parser.test.([mc]js|[jt]sx?)$'",
26
- "test:cli": "uvu src 'cli.test.([mc]js|[jt]sx?)$'",
27
- "test:md": "uvu src 'md.test.([mc]js|[jt]sx?)$'",
28
- "test:fs": "uvu src 'fs.test.([mc]js|[jt]sx?)$'",
29
- "test:js": "uvu src 'block-parser-js.test.([mc]js|[jt]sx?)$'",
30
- "test:errors": "uvu test 'errors.test.([mc]js|[jt]sx?)$'",
31
- "test:transforms": "uvu test 'transforms.test.([mc]js|[jt]sx?)$'",
32
- "test:text": "uvu src 'text.test.([mc]js|[jt]sx?)$'",
33
- "cli": "node ./cli.js --path 'README.md' --config ./markdown.config.js",
34
- "publish": "git push origin && git push origin --tags",
35
- "release:patch": "npm version patch && npm publish",
36
- "release:minor": "npm version minor && npm publish",
37
- "release:major": "npm version major && npm publish"
38
- },
39
19
  "author": "David Wells",
40
20
  "license": "MIT",
41
21
  "homepage": "https://github.com/DavidWells/markdown-magic#readme",
@@ -44,7 +24,7 @@
44
24
  "url": "https://github.com/DavidWells/markdown-magic"
45
25
  },
46
26
  "dependencies": {
47
- "@davidwells/md-utils": "0.0.52",
27
+ "@davidwells/md-utils": "0.0.53",
48
28
  "globrex": "^0.1.2",
49
29
  "gray-matter": "^4.0.3",
50
30
  "is-glob": "^4.0.3",
@@ -58,7 +38,10 @@
58
38
  "punycode": "^2.3.1",
59
39
  "smart-glob": "^1.0.2",
60
40
  "string-width": "^4.2.3",
61
- "sync-request": "^6.1.0"
41
+ "sync-request": "^6.1.0",
42
+ "comment-block-transformer": "0.1.1",
43
+ "comment-block-replacer": "0.1.0",
44
+ "comment-block-parser": "1.0.7"
62
45
  },
63
46
  "devDependencies": {
64
47
  "ansi-styles": "^4.2.1",
@@ -68,5 +51,17 @@
68
51
  "safe-chalk": "^1.0.0",
69
52
  "typescript": "^5.0.2",
70
53
  "uvu": "^0.5.1"
54
+ },
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "scripts": {
59
+ "types": "tsc --emitDeclarationOnly --outDir types",
60
+ "docs": "node examples/generate-readme.js",
61
+ "test": "uvu . '.test.([mc]js|[jt]sx?)$'",
62
+ "cli": "node ./cli.js --path 'README.md' --config ./markdown.config.js",
63
+ "release:patch": "pnpm publish --version patch && git push origin && git push origin --tags",
64
+ "release:minor": "pnpm publish --version minor && git push origin && git push origin --tags",
65
+ "release:major": "pnpm publish --version major && git push origin && git push origin --tags"
71
66
  }
72
- }
67
+ }
File without changes
@@ -1,7 +1,7 @@
1
1
  const { test } = require('uvu')
2
2
  const assert = require('uvu/assert')
3
3
  const { deepLog } = require('./utils/logs')
4
- const { getGlobGroupsFromArgs, runCli } = require('./cli')
4
+ const { getGlobGroupsFromArgs, runCli } = require('./cli-run')
5
5
 
6
6
  const DEBUG = true
7
7
  const logger = (DEBUG) ? console.log : () => {}
package/src/defaults.js CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  const SYNTAX = 'md'
3
- const OPEN_WORD = 'doc-gen'
4
- const CLOSE_WORD = 'end-doc-gen'
3
+ const OPEN_WORD = 'docs'
4
+ const CLOSE_WORD = '/docs'
5
5
  const DEFAULT_GLOB_PATTERN = '**/**.md'
6
6
 
7
7
  module.exports = {
package/src/index.js CHANGED
@@ -15,15 +15,15 @@ const { getSyntaxInfo } = require('./utils/syntax')
15
15
  const { onlyUnique, getCodeLocation, pluralize } = require('./utils')
16
16
  const { readFile, resolveOutputPath, resolveFlatPath } = require('./utils/fs')
17
17
  const stringBreak = require('./utils/string-break')
18
- const { processFile } = require('./process-file')
19
- const { processContents } = require('./process-contents')
18
+ const { processFile } = require('comment-block-replacer')
19
+ const { blockTransformer } = require('comment-block-transformer')
20
20
  const { parseMarkdown } = require('@davidwells/md-utils')
21
21
  const { success, error, info, convertHrtime, deepLog } = require('./utils/logs')
22
22
  const { OPEN_WORD, CLOSE_WORD, DEFAULT_GLOB_PATTERN } = require('./defaults')
23
- const { getBlockRegex, parseBlocks } = require('./block-parser')
23
+ const { getBlockRegex, parseBlocks } = require('comment-block-parser')
24
24
  const toposort = require('./utils/toposort')
25
25
  // const { hashFile } = require('./utils/hash-file')
26
- // const { getBlockRegex } = require('./block-parser')
26
+ // const { getBlockRegex } = require('comment-block-parser')
27
27
  // const diff = require('../misc/old-test/utils/diff')
28
28
 
29
29
  // old https://raw.githubusercontent.com/DavidWells/markdown-magic/add-package-scripts-plugin/index.js
@@ -46,16 +46,20 @@ const defaultOptions = {
46
46
  failOnMissingRemote: true,
47
47
  }
48
48
 
49
- /**!
49
+ /**
50
50
  * Allowed file syntaxes
51
51
  * @typedef {'md' | 'js' | 'yml' | 'yaml'} SyntaxType
52
52
  */
53
53
 
54
- /**!
54
+ /**
55
55
  * Path to file, files or Glob string or Glob Array
56
56
  * @typedef {string|Array<string>} FilePathsOrGlobs
57
57
  */
58
58
 
59
+ /**
60
+ * @typedef {import('comment-block-replacer').ProcessFileOptions} ProcessFileOptions
61
+ */
62
+
59
63
  /**
60
64
  * Configuration for markdown magic
61
65
  *
@@ -63,20 +67,21 @@ const defaultOptions = {
63
67
  *
64
68
  * @typedef {object} MarkdownMagicOptions
65
69
  * @property {FilePathsOrGlobs} [files] - Files to process.
66
- * @property {Array} [transforms = defaultTransforms] - Custom commands to transform block contents, see transforms & custom transforms sections below.
67
- * @property {OutputConfig} [output] - Output configuration
70
+ * @property {Object} [transforms = defaultTransforms] - Custom commands to transform block contents, see transforms & custom transforms sections below.
71
+ * @property {OutputConfig|string} [output] - Output configuration object or directory path
68
72
  * @property {SyntaxType} [syntax = 'md'] - Syntax to parse
69
- * @property {string} [open = 'doc-gen'] - Opening match word
70
- * @property {string} [close = 'end-doc-gen'] - Closing match word. If not defined will be same as opening word.
71
- * @property {string} [cwd = process.cwd() ] - Current working directory. Default process.cwd()
73
+ * @property {string} [open = 'docs'] - Opening match word. Default is 'docs'.
74
+ * @property {string} [close = '/docs'] - Closing match word. Default is '/docs'. If not defined will be same as opening word with closing slash added.
75
+ * @property {string} [cwd = process.cwd() ] - Current working directory. Default process.cwd()
72
76
  * @property {boolean} [outputFlatten] - Flatten files that are output
73
77
  * @property {boolean} [useGitGlob] - Use git glob for LARGE file directories
74
- * @property {boolean} [dryRun = false] - See planned execution of matched blocks
78
+ * @property {boolean} [dry = false] - See planned execution of matched blocks
75
79
  * @property {boolean} [debug = false] - See debug details
76
80
  * @property {boolean} [silent = false] - Silence all console output
77
81
  * @property {boolean} [applyTransformsToSource = true] - Apply transforms to source file. Default is true.
78
82
  * @property {boolean} [failOnMissingTransforms = false] - Fail if transform functions are missing. Default skip blocks.
79
83
  * @property {boolean} [failOnMissingRemote = true] - Fail if remote file is missing.
84
+ * @property {string} [outputDir] - Deprecated: Use `output` instead. Output directory path.
80
85
  */
81
86
 
82
87
  /**
@@ -130,7 +135,7 @@ async function markdownMagic(globOrOpts = {}, options = {}) {
130
135
  const {
131
136
  transforms,
132
137
  // open,
133
- /** lol @type {OutputConfig} */
138
+ /** @type {OutputConfig} */
134
139
  output = {},
135
140
  outputFlatten = false,
136
141
  useGitGlob = false,
@@ -140,8 +145,9 @@ async function markdownMagic(globOrOpts = {}, options = {}) {
140
145
  syntax = 'md',
141
146
  silent = false,
142
147
  } = opts
143
-
144
- let dryRun = opts.dryRun || opts.dry || opts.plan || false
148
+
149
+ // @ts-ignore
150
+ let dryRun = opts.dry || opts.dryRun || opts.plan || false
145
151
 
146
152
  // @ts-ignore
147
153
  const outputDir = output.directory || opts.outputDir
@@ -497,8 +503,8 @@ async function markdownMagic(globOrOpts = {}, options = {}) {
497
503
  const issues = item.missingTransforms.map((trn) => {
498
504
  // logger('trn', trn)
499
505
  // const rowData = getRowAndColumnFromCharPos(item.updatedContents, trn.open.start)
500
- const location = `${item.srcPath}:${trn.block.lines[0]}:0`
501
- const message = `Transform "${trn.transform}" at line ${trn.block.lines[0]} does not exist. → ${location}`
506
+ const location = `${item.srcPath}:${trn.lines[0]}:0`
507
+ const message = `Transform "${trn.transform}" at line ${trn.lines[0]} does not exist. → ${location}`
502
508
  return {
503
509
  message,
504
510
  location
@@ -535,11 +541,11 @@ async function markdownMagic(globOrOpts = {}, options = {}) {
535
541
  planTotal = planTotal + transformsToRun.length
536
542
  // logger(`Found ${transformsToRun.length} transforms in ${item.srcPath}`)
537
543
  transformsToRun.forEach((trn) => {
538
- const line = trn.block.lines[0]
544
+ const line = trn.lines[0]
539
545
  const location = getCodeLocation(item.srcPath, line)
540
546
  const planData = ` - "${trn.transform}" at line ${line} → ${location}`
541
547
  planMsg += `\n${planData}`
542
- // logger(` - "${trn.transform}" at line ${trn.block.lines[0]}`)
548
+ // logger(` - "${trn.transform}" at line ${trn.lines[0]}`)
543
549
  })
544
550
  const newLine = plan.length !== i + 1 ? '\n' : ''
545
551
  return `${planMsg}${newLine}`
@@ -763,7 +769,7 @@ const stringUtils = {
763
769
  module.exports = {
764
770
  markdownMagic,
765
771
  parseMarkdown,
766
- processContents,
772
+ blockTransformer,
767
773
  processFile,
768
774
  stringUtils
769
775
  }
package/src/index.test.js CHANGED
@@ -1,10 +1,10 @@
1
1
  const { test } = require('uvu')
2
2
  const assert = require('uvu/assert')
3
- const { markdownMagic, processContents, processFile } = require('./')
3
+ const { markdownMagic, blockTransformer, processFile } = require('./')
4
4
 
5
5
  test('Main API', () => {
6
6
  assert.equal(typeof markdownMagic, 'function')
7
- assert.equal(typeof processContents, 'function')
7
+ assert.equal(typeof blockTransformer, 'function')
8
8
  assert.equal(typeof processFile, 'function')
9
9
  })
10
10