markdown-magic 3.6.5 → 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 +1 -1
- package/package.json +23 -28
- package/src/{cli.js → cli-run.js} +0 -0
- package/src/{cli.test.js → cli-run.test.js} +1 -1
- package/src/defaults.js +2 -2
- package/src/index.js +30 -22
- package/src/index.test.js +2 -2
- package/src/process-contents.js +2 -458
- package/src/transforms/code/index.js +6 -6
- package/src/transforms/fileTree.js +213 -0
- package/src/transforms/index.js +87 -19
- package/src/transforms/install.js +3 -3
- package/src/transforms/sectionToc.js +4 -4
- package/src/transforms/toc.js +7 -7
- package/src/transforms/wordCount.js +3 -2
- package/src/types.js +1 -1
- package/src/utils/fs.js +22 -0
- package/src/utils/fs.test.js +5 -2
- package/src/utils/index.js +21 -0
- package/src/utils/regex-timeout.js +1 -1
- package/src/utils/syntax.js +29 -1
- package/src/utils/text.js +115 -16
- package/src/utils/text.test.js +76 -3
- package/README.md +0 -605
- package/src/block-parser-js.test.js +0 -171
- package/src/block-parser.js +0 -405
- package/src/block-parser.test.js +0 -481
- package/src/process-file.js +0 -66
package/cli.js
CHANGED
package/package.json
CHANGED
|
@@ -1,41 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markdown-magic",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Automatically update markdown files with content from external sources",
|
|
5
|
-
"main": "
|
|
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
|
-
"
|
|
16
|
-
"
|
|
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.
|
|
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
package/src/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
const path = require('path')
|
|
2
2
|
// @TODO remove this once we have swapped out node-fetch@2.7
|
|
3
|
-
const moduleAlias = require('module-alias') // "Fix" for
|
|
4
|
-
moduleAlias.addAlias('punycode', 'punycode/') // "Fix" for
|
|
3
|
+
const moduleAlias = require('module-alias') // "Fix" for punycode dep warning in node 22+
|
|
4
|
+
moduleAlias.addAlias('punycode', 'punycode/') // "Fix" for punycode dep warning in node 22+
|
|
5
5
|
const { glob, globWithGit } = require('smart-glob')
|
|
6
6
|
const codeTransform = require('./transforms/code')
|
|
7
7
|
const fileTransform = require('./transforms/file')
|
|
8
|
+
const fileTreeTransform = require('./transforms/fileTree')
|
|
8
9
|
const tocTransform = require('./transforms/toc')
|
|
9
10
|
const sectionTocTransform = require('./transforms/sectionToc')
|
|
10
11
|
const wordCountTransform = require('./transforms/wordCount')
|
|
@@ -14,15 +15,15 @@ const { getSyntaxInfo } = require('./utils/syntax')
|
|
|
14
15
|
const { onlyUnique, getCodeLocation, pluralize } = require('./utils')
|
|
15
16
|
const { readFile, resolveOutputPath, resolveFlatPath } = require('./utils/fs')
|
|
16
17
|
const stringBreak = require('./utils/string-break')
|
|
17
|
-
const { processFile } = require('
|
|
18
|
-
const {
|
|
18
|
+
const { processFile } = require('comment-block-replacer')
|
|
19
|
+
const { blockTransformer } = require('comment-block-transformer')
|
|
19
20
|
const { parseMarkdown } = require('@davidwells/md-utils')
|
|
20
21
|
const { success, error, info, convertHrtime, deepLog } = require('./utils/logs')
|
|
21
22
|
const { OPEN_WORD, CLOSE_WORD, DEFAULT_GLOB_PATTERN } = require('./defaults')
|
|
22
|
-
const { getBlockRegex, parseBlocks } = require('
|
|
23
|
+
const { getBlockRegex, parseBlocks } = require('comment-block-parser')
|
|
23
24
|
const toposort = require('./utils/toposort')
|
|
24
25
|
// const { hashFile } = require('./utils/hash-file')
|
|
25
|
-
// const { getBlockRegex } = require('
|
|
26
|
+
// const { getBlockRegex } = require('comment-block-parser')
|
|
26
27
|
// const diff = require('../misc/old-test/utils/diff')
|
|
27
28
|
|
|
28
29
|
// old https://raw.githubusercontent.com/DavidWells/markdown-magic/add-package-scripts-plugin/index.js
|
|
@@ -32,6 +33,7 @@ const LINE = '──────────────────────
|
|
|
32
33
|
const defaultTransforms = {
|
|
33
34
|
CODE: codeTransform,
|
|
34
35
|
FILE: fileTransform,
|
|
36
|
+
fileTree: fileTreeTransform,
|
|
35
37
|
TOC: tocTransform,
|
|
36
38
|
sectionToc: sectionTocTransform,
|
|
37
39
|
wordCount: wordCountTransform,
|
|
@@ -44,16 +46,20 @@ const defaultOptions = {
|
|
|
44
46
|
failOnMissingRemote: true,
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
/**
|
|
48
50
|
* Allowed file syntaxes
|
|
49
51
|
* @typedef {'md' | 'js' | 'yml' | 'yaml'} SyntaxType
|
|
50
52
|
*/
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
/**
|
|
53
55
|
* Path to file, files or Glob string or Glob Array
|
|
54
56
|
* @typedef {string|Array<string>} FilePathsOrGlobs
|
|
55
57
|
*/
|
|
56
58
|
|
|
59
|
+
/**
|
|
60
|
+
* @typedef {import('comment-block-replacer').ProcessFileOptions} ProcessFileOptions
|
|
61
|
+
*/
|
|
62
|
+
|
|
57
63
|
/**
|
|
58
64
|
* Configuration for markdown magic
|
|
59
65
|
*
|
|
@@ -61,20 +67,21 @@ const defaultOptions = {
|
|
|
61
67
|
*
|
|
62
68
|
* @typedef {object} MarkdownMagicOptions
|
|
63
69
|
* @property {FilePathsOrGlobs} [files] - Files to process.
|
|
64
|
-
* @property {
|
|
65
|
-
* @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
|
|
66
72
|
* @property {SyntaxType} [syntax = 'md'] - Syntax to parse
|
|
67
|
-
* @property {string}
|
|
68
|
-
* @property {string}
|
|
69
|
-
* @property {string}
|
|
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()
|
|
70
76
|
* @property {boolean} [outputFlatten] - Flatten files that are output
|
|
71
77
|
* @property {boolean} [useGitGlob] - Use git glob for LARGE file directories
|
|
72
|
-
* @property {boolean} [
|
|
78
|
+
* @property {boolean} [dry = false] - See planned execution of matched blocks
|
|
73
79
|
* @property {boolean} [debug = false] - See debug details
|
|
74
80
|
* @property {boolean} [silent = false] - Silence all console output
|
|
75
81
|
* @property {boolean} [applyTransformsToSource = true] - Apply transforms to source file. Default is true.
|
|
76
82
|
* @property {boolean} [failOnMissingTransforms = false] - Fail if transform functions are missing. Default skip blocks.
|
|
77
83
|
* @property {boolean} [failOnMissingRemote = true] - Fail if remote file is missing.
|
|
84
|
+
* @property {string} [outputDir] - Deprecated: Use `output` instead. Output directory path.
|
|
78
85
|
*/
|
|
79
86
|
|
|
80
87
|
/**
|
|
@@ -128,7 +135,7 @@ async function markdownMagic(globOrOpts = {}, options = {}) {
|
|
|
128
135
|
const {
|
|
129
136
|
transforms,
|
|
130
137
|
// open,
|
|
131
|
-
/**
|
|
138
|
+
/** @type {OutputConfig} */
|
|
132
139
|
output = {},
|
|
133
140
|
outputFlatten = false,
|
|
134
141
|
useGitGlob = false,
|
|
@@ -138,8 +145,9 @@ async function markdownMagic(globOrOpts = {}, options = {}) {
|
|
|
138
145
|
syntax = 'md',
|
|
139
146
|
silent = false,
|
|
140
147
|
} = opts
|
|
141
|
-
|
|
142
|
-
|
|
148
|
+
|
|
149
|
+
// @ts-ignore
|
|
150
|
+
let dryRun = opts.dry || opts.dryRun || opts.plan || false
|
|
143
151
|
|
|
144
152
|
// @ts-ignore
|
|
145
153
|
const outputDir = output.directory || opts.outputDir
|
|
@@ -495,8 +503,8 @@ async function markdownMagic(globOrOpts = {}, options = {}) {
|
|
|
495
503
|
const issues = item.missingTransforms.map((trn) => {
|
|
496
504
|
// logger('trn', trn)
|
|
497
505
|
// const rowData = getRowAndColumnFromCharPos(item.updatedContents, trn.open.start)
|
|
498
|
-
const location = `${item.srcPath}:${trn.
|
|
499
|
-
const message = `Transform "${trn.transform}" at line ${trn.
|
|
506
|
+
const location = `${item.srcPath}:${trn.lines[0]}:0`
|
|
507
|
+
const message = `Transform "${trn.transform}" at line ${trn.lines[0]} does not exist. → ${location}`
|
|
500
508
|
return {
|
|
501
509
|
message,
|
|
502
510
|
location
|
|
@@ -533,11 +541,11 @@ async function markdownMagic(globOrOpts = {}, options = {}) {
|
|
|
533
541
|
planTotal = planTotal + transformsToRun.length
|
|
534
542
|
// logger(`Found ${transformsToRun.length} transforms in ${item.srcPath}`)
|
|
535
543
|
transformsToRun.forEach((trn) => {
|
|
536
|
-
const line = trn.
|
|
544
|
+
const line = trn.lines[0]
|
|
537
545
|
const location = getCodeLocation(item.srcPath, line)
|
|
538
546
|
const planData = ` - "${trn.transform}" at line ${line} → ${location}`
|
|
539
547
|
planMsg += `\n${planData}`
|
|
540
|
-
// logger(` - "${trn.transform}" at line ${trn.
|
|
548
|
+
// logger(` - "${trn.transform}" at line ${trn.lines[0]}`)
|
|
541
549
|
})
|
|
542
550
|
const newLine = plan.length !== i + 1 ? '\n' : ''
|
|
543
551
|
return `${planMsg}${newLine}`
|
|
@@ -761,7 +769,7 @@ const stringUtils = {
|
|
|
761
769
|
module.exports = {
|
|
762
770
|
markdownMagic,
|
|
763
771
|
parseMarkdown,
|
|
764
|
-
|
|
772
|
+
blockTransformer,
|
|
765
773
|
processFile,
|
|
766
774
|
stringUtils
|
|
767
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,
|
|
3
|
+
const { markdownMagic, blockTransformer, processFile } = require('./')
|
|
4
4
|
|
|
5
5
|
test('Main API', () => {
|
|
6
6
|
assert.equal(typeof markdownMagic, 'function')
|
|
7
|
-
assert.equal(typeof
|
|
7
|
+
assert.equal(typeof blockTransformer, 'function')
|
|
8
8
|
assert.equal(typeof processFile, 'function')
|
|
9
9
|
})
|
|
10
10
|
|