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 +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 +26 -20
- 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 +3 -3
- package/src/transforms/index.js +21 -21
- package/src/transforms/install.js +3 -3
- package/src/transforms/sectionToc.js +4 -4
- package/src/transforms/toc.js +5 -5
- package/src/transforms/wordCount.js +3 -2
- package/src/utils/fs.js +22 -0
- package/src/utils/fs.test.js +2 -2
- package/src/utils/index.js +21 -0
- package/src/utils/regex-timeout.js +1 -1
- package/src/utils/text.js +103 -11
- package/README.md +0 -700
- 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
|
@@ -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('
|
|
19
|
-
const {
|
|
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('
|
|
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('
|
|
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 {
|
|
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}
|
|
70
|
-
* @property {string}
|
|
71
|
-
* @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()
|
|
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} [
|
|
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
|
-
/**
|
|
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
|
-
|
|
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.
|
|
501
|
-
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}`
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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,
|
|
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
|
|