markdown-magic 2.6.0 → 3.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.
Files changed (61) hide show
  1. package/README.md +6 -10
  2. package/cli.js +5 -82
  3. package/lib/block-parser-js.test.js +179 -0
  4. package/lib/block-parser.js +389 -0
  5. package/lib/{utils/new-parser.test.js → block-parser.test.js} +168 -50
  6. package/lib/cli.js +234 -0
  7. package/lib/cli.test.js +409 -0
  8. package/lib/defaults.js +12 -0
  9. package/lib/index.js +319 -184
  10. package/lib/index.test.js +11 -0
  11. package/lib/options-parser.js +498 -0
  12. package/lib/options-parser.test.js +1237 -0
  13. package/lib/process-contents.js +330 -0
  14. package/lib/process-file.js +34 -0
  15. package/lib/transforms/code.js +67 -22
  16. package/lib/transforms/file.js +13 -10
  17. package/lib/transforms/remote.js +9 -6
  18. package/lib/transforms/toc.js +136 -64
  19. package/lib/transforms/wordCount.js +5 -0
  20. package/lib/utils/fs.js +340 -0
  21. package/lib/utils/fs.test.js +268 -0
  22. package/lib/utils/html-to-json/compat.js +42 -0
  23. package/lib/utils/html-to-json/format.js +64 -0
  24. package/lib/utils/html-to-json/index.js +37 -0
  25. package/lib/utils/html-to-json/lexer.js +345 -0
  26. package/lib/utils/html-to-json/parser.js +146 -0
  27. package/lib/utils/html-to-json/stringify.js +37 -0
  28. package/lib/utils/html-to-json/tags.js +171 -0
  29. package/lib/utils/index.js +19 -0
  30. package/{cli-utils.js → lib/utils/load-config.js} +2 -6
  31. package/lib/utils/logs.js +89 -0
  32. package/lib/utils/md/filters.js +20 -0
  33. package/lib/utils/md/find-code-blocks.js +80 -0
  34. package/lib/utils/md/find-date.js +32 -0
  35. package/lib/utils/md/find-frontmatter.js +94 -0
  36. package/lib/utils/md/find-frontmatter.test.js +17 -0
  37. package/lib/utils/md/find-html-tags.js +105 -0
  38. package/lib/utils/md/find-images.js +102 -0
  39. package/lib/utils/md/find-links.js +202 -0
  40. package/lib/utils/md/find-unmatched-html-tags.js +33 -0
  41. package/lib/utils/md/fixtures/2022-01-22-date-in-filename.md +14 -0
  42. package/lib/utils/md/fixtures/file-with-frontmatter.md +32 -0
  43. package/lib/utils/md/fixtures/file-with-links.md +143 -0
  44. package/lib/utils/md/md.test.js +37 -0
  45. package/lib/utils/md/parse.js +122 -0
  46. package/lib/utils/md/utils.js +19 -0
  47. package/lib/utils/regex-timeout.js +83 -0
  48. package/lib/utils/regex.js +38 -5
  49. package/lib/utils/remoteRequest.js +54 -0
  50. package/lib/utils/syntax.js +79 -0
  51. package/lib/utils/text.js +260 -0
  52. package/lib/utils/text.test.js +311 -0
  53. package/package.json +26 -26
  54. package/index.js +0 -46
  55. package/lib/processFile.js +0 -154
  56. package/lib/transforms/index.js +0 -114
  57. package/lib/updateContents.js +0 -125
  58. package/lib/utils/_md.test.js +0 -63
  59. package/lib/utils/new-parser.js +0 -412
  60. package/lib/utils/weird-parse.js +0 -230
  61. package/lib/utils/weird-parse.test.js +0 -217
package/lib/cli.js ADDED
@@ -0,0 +1,234 @@
1
+
2
+ const path = require('path')
3
+ const isGlob = require('is-glob')
4
+ const isValidFilePath = require('is-valid-path')
5
+ const { loadConfig } = require('./utils/load-config')
6
+ const { findUp } = require('./utils/fs')
7
+ const { markdownMagic } = require('./')
8
+ const { optionsParse, isArrayLike } = require('./options-parser')
9
+ const { deepLog } = require('./utils/logs')
10
+ const { REGEX_REGEX, escapeRegexString } = require('./utils/regex')
11
+ const { getFirstCharacter, isUpperCase } = require('./utils/text')
12
+ const argv = process.argv.slice(2)
13
+ const cwd = process.cwd()
14
+ const defaultConfigPath = 'md.config.js'
15
+
16
+ async function getBaseDir(currentDir = cwd) {
17
+ const gitDir = await findUp(currentDir, '.git')
18
+ return (gitDir) ? path.dirname(gitDir) : currentDir
19
+ }
20
+
21
+ function stringLooksLikeFile(value) {
22
+ return !value.match(/^-+/) // isn't option looking
23
+ && isValidFilePath(value)
24
+ && (
25
+ path.basename(value).indexOf('.') > -1 // has period
26
+ || getFirstCharacter(value) === '_' // starts with _
27
+ // || isUpperCase(value) // is all caps
28
+ )
29
+ }
30
+
31
+ function getValue(val) {
32
+ return (val[1] !== '=') ? val[1] : val[0]
33
+ }
34
+
35
+ function trimLeadingDashes(value) {
36
+ return value.replace(/^-+/, '')
37
+ }
38
+
39
+ function removeNodeModules(value = '') {
40
+ if (typeof value !== 'string') {
41
+ return true
42
+ }
43
+ return !value.match(/node_modules\//)
44
+ }
45
+
46
+ function coerceStringToRegex(str) {
47
+ const isRegex = str.match(REGEX_REGEX)
48
+ if (isRegex) {
49
+ const [ match, pattern, flags ] = isRegex
50
+ return new RegExp(escapeRegexString(pattern, flags))
51
+ }
52
+ return str
53
+ }
54
+
55
+ function convertToArray(str = '') {
56
+ const { fixedArray } = optionsParse(`fixedArray=${str}`)
57
+ return (fixedArray || [])
58
+ }
59
+
60
+ function addValue(value, currentCollection) {
61
+ if (isArrayLike(value)) {
62
+ const array = convertToArray(value)
63
+ // uniquify returned array
64
+ return Array.from(new Set(currentCollection.concat(array)))
65
+ }
66
+ if (currentCollection.indexOf(value) > -1) {
67
+ return currentCollection
68
+ }
69
+ return currentCollection.concat(value)
70
+ }
71
+
72
+ /*
73
+ node ./cli.js test/fixtures/md/**.md debug --transform test/fixtures/md/transform-**.md 1233535235 = hahah funky=hi --ignore test/fixtures/output/**.md --lol --whatever test/fixtures/md/syntax-**.md --foo=bar --fun lol.md what=no.md x 'xno.md' what
74
+ */
75
+ function getGlobGroupsFromArgs(args, opts = {}) {
76
+ const globKeys = opts.globKeys || []
77
+ let proceding = ['', '']
78
+ let collection = []
79
+ let globGroups = []
80
+ let reserved = []
81
+ let otherOpts = []
82
+ let cacheKey = ''
83
+ for (let i = 0; i < args.length; i++) {
84
+ const isLastArg = (args.length - 1) === i
85
+ const arg = args[i]
86
+ const prevArg = args[i - 1]
87
+ const looksLikeFile = stringLooksLikeFile(arg) // @TODO verify file exists?
88
+ // console.log('looksLikeFile', looksLikeFile)
89
+ // console.log('cacheKey', cacheKey)
90
+ // console.log('arg', arg)
91
+
92
+ if (looksLikeFile && typeof cacheKey !== 'undefined') {
93
+ // @TODO verify file exists?
94
+ collection.push(arg)
95
+ } else if (arg.match(/^-+/)) {
96
+ cacheKey = arg
97
+ if (collection.length) {
98
+ const val = getValue(proceding)
99
+ reserved.push(val)
100
+ globGroups.push({
101
+ key: trimLeadingDashes(val),
102
+ raw: val,
103
+ values: collection.filter(removeNodeModules).map((x) => coerceStringToRegex(x))
104
+ })
105
+ collection = []
106
+ }
107
+ proceding = [ prevArg, arg ]
108
+ } else if (cacheKey && arg.match(/=/)) {
109
+ // console.log('FOOO', arg)
110
+ cacheKey = undefined
111
+ }
112
+
113
+ const cleanKey = trimLeadingDashes(cacheKey || '')
114
+ const isDefinedGlobKey = globKeys.includes(cleanKey) || globKeys.includes(cacheKey)
115
+ // console.log(`isDefinedGlobKey: ${cleanKey}`, isDefinedGlobKey)
116
+ if (isDefinedGlobKey && (isGlob(arg) || looksLikeFile)) {
117
+ /*
118
+ console.log('ADD collection.push', arg)
119
+ /** */
120
+ collection = addValue(arg, collection)
121
+ } else {
122
+ if (!cacheKey && isGlob(arg)) {
123
+ collection = addValue(arg, collection)
124
+ } else if (!looksLikeFile) {
125
+ /* Pass through non matching args */
126
+ /*
127
+ console.log('ADD otherOpts', arg)
128
+ /** */
129
+ otherOpts.push(arg)
130
+ }
131
+ }
132
+
133
+ if (isLastArg && collection.length) {
134
+ const val = getValue(proceding)
135
+ reserved.push(val)
136
+ globGroups.push({
137
+ key: trimLeadingDashes(val),
138
+ raw: val,
139
+ values: collection.filter(removeNodeModules).map((x) => coerceStringToRegex(x))
140
+ })
141
+ collection = []
142
+ }
143
+ }
144
+
145
+ return {
146
+ globGroups,
147
+ otherOpts: otherOpts.filter((opt) => !reserved.includes(opt))
148
+ }
149
+ }
150
+
151
+ // const unique = Array.from(new Set(dismiss.concat(nodeSlug)))
152
+
153
+
154
+ async function runCli(options = {}) {
155
+ let configFile
156
+ let opts = {}
157
+ /*
158
+ console.log('argv', argv)
159
+ console.log('options', options)
160
+ /** */
161
+ /* If raw args found, process them further */
162
+ if (argv.length && (options._ && options._.length || (options.file || options.files))) {
163
+ // if (isGlob(argv[0])) {
164
+ // console.log('glob', argv[0])
165
+ // options.glob = argv[0]
166
+ // }
167
+ const globParse = getGlobGroupsFromArgs(argv, {
168
+ // CLI args that should be glob keys
169
+ globKeys: ['files', 'file']
170
+ })
171
+ const { globGroups, otherOpts } = globParse
172
+ // deepLog(globParse)
173
+ // console.log('globParse', globParse)
174
+ if (globGroups.length) {
175
+ const globGroupByKey = globGroups.reduce((acc, curr, i) => {
176
+ acc[curr.key] = globGroups[i]
177
+ return acc
178
+ }, {})
179
+ // console.log('globGroupByKey', globGroupByKey)
180
+
181
+ if (globGroupByKey.file) {
182
+ options.glob = globGroupByKey.file.values
183
+ } else if (globGroupByKey['']) {
184
+ options.glob = globGroupByKey[''].values
185
+ }
186
+
187
+ if (globGroupByKey.ignore) {
188
+ options.ignore = globGroupByKey.ignore.values
189
+ }
190
+
191
+ /*
192
+ deepLog(options)
193
+ /** */
194
+ }
195
+
196
+ /* Parse for weird CLI inputs */
197
+ const extraParse = optionsParse(otherOpts.join(' '))
198
+
199
+ /*
200
+ console.log('otherOpts', otherOpts)
201
+ console.log('extraParse', extraParse)
202
+ /** */
203
+
204
+ delete options._
205
+ opts = {
206
+ ...options,
207
+ ...extraParse
208
+ }
209
+ // console.log('opts', opts)
210
+ }
211
+ if (opts.config) {
212
+ configFile = opts.config
213
+ } else {
214
+ const baseDir = await getBaseDir()
215
+ configFile = await findUp(baseDir, defaultConfigPath)
216
+ }
217
+ const config = (configFile) ? loadConfig(configFile) : {}
218
+ const mergedConfig = {
219
+ ...config,
220
+ ...opts,
221
+ }
222
+
223
+ mergedConfig.outputDir = mergedConfig.output || mergedConfig.outputDir
224
+ /*
225
+ console.log('mergedConfig', mergedConfig)
226
+ // return
227
+ /** */
228
+ await markdownMagic(mergedConfig)
229
+ }
230
+
231
+ module.exports = {
232
+ getGlobGroupsFromArgs,
233
+ runCli
234
+ }
@@ -0,0 +1,409 @@
1
+ const { test } = require('uvu')
2
+ const assert = require('uvu/assert')
3
+ const { deepLog } = require('./utils/logs')
4
+ const { getGlobGroupsFromArgs, runCli } = require('./cli')
5
+
6
+ const DEBUG = true
7
+ const logger = (DEBUG) ? console.log : () => {}
8
+ const deepLogger = (DEBUG) ? deepLog : () => {}
9
+
10
+ function logInput(rawArgs) {
11
+ logger('\n───────────────────────')
12
+ logger('Input:')
13
+ logger(rawArgs.join(" "))
14
+ logger('───────────────────────\n')
15
+ }
16
+
17
+ test('Exports API', () => {
18
+ assert.equal(typeof runCli, 'function', 'undefined val')
19
+ assert.equal(typeof getGlobGroupsFromArgs, 'function', 'undefined val')
20
+ })
21
+
22
+ test('Returns globs', () => {
23
+ /* CLI command with list of files already passed in
24
+ node ./cli.js test/fixtures/md/**.md debug --transform test/fixtures/md/transform-**.md 1233535235 = hahah funky=hi --ignore test/fixtures/output/**.md --lol --whatever test/fixtures/md/syntax-**.md --foo=bar --fun lol.md what=no.md x 'xno.md' what
25
+ */
26
+ const rawArgv = [
27
+ 'test/fixtures/md/basic.md',
28
+ 'test/fixtures/md/error-missing-transforms-two.md',
29
+ 'test/fixtures/md/error-missing-transforms.md',
30
+ 'test/fixtures/md/error-no-block-transform-defined.md',
31
+ 'test/fixtures/md/error-unbalanced.md',
32
+ 'test/fixtures/md/format-inline.md',
33
+ 'test/fixtures/md/format-with-wacky-indentation.md',
34
+ 'test/fixtures/md/inline-two.md',
35
+ 'test/fixtures/md/inline.md',
36
+ 'test/fixtures/md/missing-transform.md',
37
+ 'test/fixtures/md/mixed.md',
38
+ 'test/fixtures/md/no-transforms.md',
39
+ 'test/fixtures/md/string.md',
40
+ 'test/fixtures/md/syntax-legacy-colon.md',
41
+ 'test/fixtures/md/syntax-legacy-query.md',
42
+ 'test/fixtures/md/transform-code.md',
43
+ 'test/fixtures/md/transform-custom.md',
44
+ 'test/fixtures/md/transform-file.md',
45
+ 'test/fixtures/md/transform-remote.md',
46
+ 'test/fixtures/md/transform-toc.md',
47
+ 'test/fixtures/md/transform-wordCount.md',
48
+ 'debug',
49
+ '--transform',
50
+ 'test/fixtures/md/transform-code.md',
51
+ 'test/fixtures/md/transform-custom.md',
52
+ 'test/fixtures/md/transform-file.md',
53
+ 'test/fixtures/md/transform-remote.md',
54
+ 'test/fixtures/md/transform-toc.md',
55
+ 'test/fixtures/md/transform-wordCount.md',
56
+ '1233535235',
57
+ '=',
58
+ 'hahah',
59
+ 'funky=hi',
60
+ '--ignore',
61
+ 'test/fixtures/output/basic.md',
62
+ 'test/fixtures/output/block-no-transform.md',
63
+ 'test/fixtures/output/error-missing-transforms-two.md',
64
+ 'test/fixtures/output/error-missing-transforms.md',
65
+ 'test/fixtures/output/fixture-code.md',
66
+ 'test/fixtures/output/format-inline.md',
67
+ 'test/fixtures/output/format-with-wacky-indentation.md',
68
+ 'test/fixtures/output/go-simple.md',
69
+ 'test/fixtures/output/inline-two.md',
70
+ 'test/fixtures/output/inline.md',
71
+ 'test/fixtures/output/missing-transform.md',
72
+ 'test/fixtures/output/mixed.md',
73
+ 'test/fixtures/output/params.md',
74
+ 'test/fixtures/output/remote.md',
75
+ 'test/fixtures/output/toc.md',
76
+ 'test/fixtures/output/transform-code.md',
77
+ 'test/fixtures/output/transform-custom.md',
78
+ 'test/fixtures/output/transform-file.md',
79
+ 'test/fixtures/output/transform-remote.md',
80
+ 'test/fixtures/output/transform-toc.md',
81
+ 'test/fixtures/output/transform-wordCount.md',
82
+ 'test/fixtures/output/with-wacky-indentation.md',
83
+ '--lol',
84
+ '--whatever',
85
+ 'test/fixtures/md/syntax-legacy-colon.md',
86
+ 'test/fixtures/md/syntax-legacy-query.md',
87
+ '--foo=bar',
88
+ '--fun',
89
+ 'lol.md',
90
+ 'what=no.md',
91
+ 'x',
92
+ 'xno.md',
93
+ 'what'
94
+ ]
95
+
96
+ const globData = getGlobGroupsFromArgs(rawArgv)
97
+ //*
98
+ logInput(rawArgv)
99
+ deepLogger(globData)
100
+ /** */
101
+ assert.equal(globData.globGroups, [
102
+ {
103
+ key: '',
104
+ raw: '',
105
+ values: [
106
+ 'test/fixtures/md/basic.md',
107
+ 'test/fixtures/md/error-missing-transforms-two.md',
108
+ 'test/fixtures/md/error-missing-transforms.md',
109
+ 'test/fixtures/md/error-no-block-transform-defined.md',
110
+ 'test/fixtures/md/error-unbalanced.md',
111
+ 'test/fixtures/md/format-inline.md',
112
+ 'test/fixtures/md/format-with-wacky-indentation.md',
113
+ 'test/fixtures/md/inline-two.md',
114
+ 'test/fixtures/md/inline.md',
115
+ 'test/fixtures/md/missing-transform.md',
116
+ 'test/fixtures/md/mixed.md',
117
+ 'test/fixtures/md/no-transforms.md',
118
+ 'test/fixtures/md/string.md',
119
+ 'test/fixtures/md/syntax-legacy-colon.md',
120
+ 'test/fixtures/md/syntax-legacy-query.md',
121
+ 'test/fixtures/md/transform-code.md',
122
+ 'test/fixtures/md/transform-custom.md',
123
+ 'test/fixtures/md/transform-file.md',
124
+ 'test/fixtures/md/transform-remote.md',
125
+ 'test/fixtures/md/transform-toc.md',
126
+ 'test/fixtures/md/transform-wordCount.md'
127
+ ]
128
+ },
129
+ {
130
+ key: 'transform',
131
+ raw: '--transform',
132
+ values: [
133
+ 'test/fixtures/md/transform-code.md',
134
+ 'test/fixtures/md/transform-custom.md',
135
+ 'test/fixtures/md/transform-file.md',
136
+ 'test/fixtures/md/transform-remote.md',
137
+ 'test/fixtures/md/transform-toc.md',
138
+ 'test/fixtures/md/transform-wordCount.md'
139
+ ]
140
+ },
141
+ {
142
+ key: 'ignore',
143
+ raw: '--ignore',
144
+ values: [
145
+ 'test/fixtures/output/basic.md',
146
+ 'test/fixtures/output/block-no-transform.md',
147
+ 'test/fixtures/output/error-missing-transforms-two.md',
148
+ 'test/fixtures/output/error-missing-transforms.md',
149
+ 'test/fixtures/output/fixture-code.md',
150
+ 'test/fixtures/output/format-inline.md',
151
+ 'test/fixtures/output/format-with-wacky-indentation.md',
152
+ 'test/fixtures/output/go-simple.md',
153
+ 'test/fixtures/output/inline-two.md',
154
+ 'test/fixtures/output/inline.md',
155
+ 'test/fixtures/output/missing-transform.md',
156
+ 'test/fixtures/output/mixed.md',
157
+ 'test/fixtures/output/params.md',
158
+ 'test/fixtures/output/remote.md',
159
+ 'test/fixtures/output/toc.md',
160
+ 'test/fixtures/output/transform-code.md',
161
+ 'test/fixtures/output/transform-custom.md',
162
+ 'test/fixtures/output/transform-file.md',
163
+ 'test/fixtures/output/transform-remote.md',
164
+ 'test/fixtures/output/transform-toc.md',
165
+ 'test/fixtures/output/transform-wordCount.md',
166
+ 'test/fixtures/output/with-wacky-indentation.md'
167
+ ]
168
+ },
169
+ {
170
+ key: 'whatever',
171
+ raw: '--whatever',
172
+ values: [
173
+ 'test/fixtures/md/syntax-legacy-colon.md',
174
+ 'test/fixtures/md/syntax-legacy-query.md'
175
+ ]
176
+ },
177
+ { key: 'fun', raw: '--fun', values: [ 'lol.md' ] }
178
+ ])
179
+ })
180
+
181
+ test('test 2', () => {
182
+ /* CLI command with list of files already passed in
183
+ node ./cli.js --file '**.md' 'funky**.md' billy --foo 'bar*123'
184
+ */
185
+ const rawArgv = [ '--file', '**.md', 'funky**.md', 'billy', '--foo', 'bar*123' ]
186
+
187
+ logger(rawArgv.join(" "))
188
+
189
+ const globData = getGlobGroupsFromArgs(rawArgv, {
190
+ globKeys: ['file']
191
+ })
192
+ //*
193
+ deepLogger(globData)
194
+ /** */
195
+ assert.equal(globData, {
196
+ globGroups: [ { key: 'file', raw: '--file', values: [ '**.md', 'funky**.md' ] } ],
197
+ otherOpts: [ 'billy', '--foo', 'bar*123' ]
198
+ })
199
+ })
200
+
201
+ test('Handles multiple string values and groups them', () => {
202
+ /* CLI command with list of files already passed in
203
+ node ./cli.js 'test/fixtures/md/bar.md' 'test/fixtures/output/foo.md'
204
+ */
205
+ const rawArgv = [ 'test/fixtures/md/bar.md', 'test/fixtures/output/foo.md' ]
206
+
207
+ const globData = getGlobGroupsFromArgs(rawArgv)
208
+ //*
209
+ logInput(rawArgv)
210
+ deepLogger(globData)
211
+ /** */
212
+ assert.equal(globData, {
213
+ globGroups: [
214
+ {
215
+ key: '',
216
+ raw: '',
217
+ values: [ 'test/fixtures/md/bar.md', 'test/fixtures/output/foo.md' ]
218
+ }
219
+ ],
220
+ otherOpts: []
221
+ })
222
+ })
223
+
224
+ test('Handles multiple string GLOB values and groups them', () => {
225
+ /* CLI command with list of files already passed in
226
+ node ./cli.js 'test/fixtures/md/**.md' 'test/fixtures/output/**.md'
227
+ */
228
+ const rawArgv = [ 'test/fixtures/md/**.md', 'test/fixtures/output/**.md' ]
229
+
230
+ const globData = getGlobGroupsFromArgs(rawArgv)
231
+ //*
232
+ logInput(rawArgv)
233
+ deepLogger(globData)
234
+ /** */
235
+ assert.equal(globData, {
236
+ globGroups: [
237
+ {
238
+ key: '',
239
+ raw: '',
240
+ values: [ 'test/fixtures/md/**.md', 'test/fixtures/output/**.md' ]
241
+ }
242
+ ],
243
+ otherOpts: []
244
+ })
245
+ })
246
+
247
+
248
+ test('Handles globKey set with multiple file/glob like values supplied afterwards', () => {
249
+ /* CLI command with list of files already passed in
250
+ node ./cli.js --file 'foobar.md' "funktown/bar.md" '**.md' 'funky**.md' billy --foo 'bar*123'
251
+ */
252
+ const rawArgv = [
253
+ '--file',
254
+ 'foobar.md',
255
+ 'funktown/bar.md',
256
+ '**.md',
257
+ 'funky**.md',
258
+ 'billy',
259
+ '--foo',
260
+ 'bar*123'
261
+ ]
262
+
263
+ logger(rawArgv.join(" "))
264
+
265
+ const globData = getGlobGroupsFromArgs(rawArgv, {
266
+ globKeys: ['file']
267
+ })
268
+ //*
269
+ logInput(rawArgv)
270
+ deepLogger(globData)
271
+ /** */
272
+ assert.equal(globData, {
273
+ globGroups: [ { key: 'file', raw: '--file', values: [
274
+ 'foobar.md',
275
+ 'funktown/bar.md',
276
+ '**.md',
277
+ 'funky**.md'
278
+ ]
279
+ }
280
+ ],
281
+ otherOpts: [ 'billy', '--foo', 'bar*123' ]
282
+ })
283
+ })
284
+
285
+ test('Handles mixed strings, glob strings, array strings, and regex strings', () => {
286
+ /* CLI command with list of files already passed in
287
+ node ./cli.js --file 'test/fixtures/md/**.md' 'test/fixtures/output/**.md' '[foo.md, bar.whatever.md, /patter.md/]'
288
+ */
289
+ const rawArgv = [
290
+ '--file',
291
+ 'funktown/bar.md',
292
+ 'test/fixtures/md/**.md',
293
+ 'test/fixtures/output/**.md',
294
+ '[foo.md, bar.whatever.md, /patter.md/]',
295
+ '/funk.md/'
296
+ ]
297
+
298
+ logger(rawArgv.join(" "))
299
+
300
+ const globData = getGlobGroupsFromArgs(rawArgv, {
301
+ globKeys: ['file']
302
+ })
303
+ //*
304
+ logInput(rawArgv)
305
+ deepLogger(globData)
306
+ /** */
307
+ assert.equal(globData, {
308
+ globGroups: [
309
+ {
310
+ key: 'file',
311
+ raw: '--file',
312
+ values: [
313
+ 'funktown/bar.md',
314
+ 'test/fixtures/md/**.md',
315
+ 'test/fixtures/output/**.md',
316
+ 'foo.md',
317
+ 'bar.whatever.md',
318
+ /patter\.md/,
319
+ /funk\.md/
320
+ ]
321
+ }
322
+ ],
323
+ otherOpts: []
324
+ })
325
+ })
326
+
327
+ test('Handles string arrays if globKeys set', () => {
328
+ /* CLI command with list of files already passed in
329
+ node ./cli.js --file '[**.md, /xyz**.md/]' 'funky**.md' billy --foo 'bar*123' --fuzz test/fixtures/output/**.md
330
+ */
331
+ const rawArgv = [
332
+ '--file',
333
+ '[**.md, /xyz**.md/]',
334
+ 'funky**.md',
335
+ 'billy',
336
+ '--foo',
337
+ 'bar*123',
338
+ '--fuzz',
339
+ 'test/fixtures/output/basic.md',
340
+ 'test/fixtures/output/block-no-transform.md',
341
+ 'test/fixtures/output/error-missing-transforms-two.md',
342
+ 'test/fixtures/output/error-missing-transforms.md',
343
+ 'test/fixtures/output/fixture-code.md',
344
+ 'test/fixtures/output/format-inline.md',
345
+ 'test/fixtures/output/format-with-wacky-indentation.md',
346
+ 'test/fixtures/output/go-simple.md',
347
+ 'test/fixtures/output/inline-two.md',
348
+ 'test/fixtures/output/inline.md',
349
+ 'test/fixtures/output/missing-transform.md',
350
+ 'test/fixtures/output/mixed.md',
351
+ 'test/fixtures/output/params.md',
352
+ 'test/fixtures/output/remote.md',
353
+ 'test/fixtures/output/toc.md',
354
+ 'test/fixtures/output/transform-code.md',
355
+ 'test/fixtures/output/transform-custom.md',
356
+ 'test/fixtures/output/transform-file.md',
357
+ 'test/fixtures/output/transform-remote.md',
358
+ 'test/fixtures/output/transform-toc.md',
359
+ 'test/fixtures/output/transform-wordCount.md',
360
+ 'test/fixtures/output/with-wacky-indentation.md'
361
+ ]
362
+ const globData = getGlobGroupsFromArgs(rawArgv, {
363
+ globKeys: ['file']
364
+ })
365
+ //*
366
+ logInput(rawArgv)
367
+ deepLogger(globData)
368
+ /** */
369
+ assert.equal(globData, {
370
+ globGroups: [
371
+ {
372
+ key: 'file',
373
+ raw: '--file',
374
+ values: [ '**.md', /xyz\*\*\.md/, 'funky**.md' ]
375
+ },
376
+ {
377
+ key: 'fuzz',
378
+ raw: '--fuzz',
379
+ values: [
380
+ 'test/fixtures/output/basic.md',
381
+ 'test/fixtures/output/block-no-transform.md',
382
+ 'test/fixtures/output/error-missing-transforms-two.md',
383
+ 'test/fixtures/output/error-missing-transforms.md',
384
+ 'test/fixtures/output/fixture-code.md',
385
+ 'test/fixtures/output/format-inline.md',
386
+ 'test/fixtures/output/format-with-wacky-indentation.md',
387
+ 'test/fixtures/output/go-simple.md',
388
+ 'test/fixtures/output/inline-two.md',
389
+ 'test/fixtures/output/inline.md',
390
+ 'test/fixtures/output/missing-transform.md',
391
+ 'test/fixtures/output/mixed.md',
392
+ 'test/fixtures/output/params.md',
393
+ 'test/fixtures/output/remote.md',
394
+ 'test/fixtures/output/toc.md',
395
+ 'test/fixtures/output/transform-code.md',
396
+ 'test/fixtures/output/transform-custom.md',
397
+ 'test/fixtures/output/transform-file.md',
398
+ 'test/fixtures/output/transform-remote.md',
399
+ 'test/fixtures/output/transform-toc.md',
400
+ 'test/fixtures/output/transform-wordCount.md',
401
+ 'test/fixtures/output/with-wacky-indentation.md'
402
+ ]
403
+ }
404
+ ],
405
+ otherOpts: [ 'billy', '--foo', 'bar*123' ]
406
+ })
407
+ })
408
+
409
+ test.run()
@@ -0,0 +1,12 @@
1
+
2
+ const SYNTAX = 'md'
3
+ const OPEN_WORD = 'doc-gen'
4
+ const CLOSE_WORD = 'end-doc-gen'
5
+ const DEFAULT_GLOB_PATTERN = '**/**.md'
6
+
7
+ module.exports = {
8
+ SYNTAX,
9
+ OPEN_WORD,
10
+ CLOSE_WORD,
11
+ DEFAULT_GLOB_PATTERN
12
+ }