markdown-magic 4.8.0 → 4.9.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/package.json +7 -7
- package/src/argparse/README.md +3 -8
- package/src/argparse/argparse.js +7 -313
- package/src/argparse/argparse.test.js +168 -90
- package/src/argparse/index.js +2 -2
- package/src/argparse/splitOutsideQuotes.js +3 -75
- package/src/cli-run.js +97 -166
- package/src/cli-run.test.js +71 -3
- package/src/globparse.js +14 -159
- package/src/index.dependency-graph.test.js +49 -0
- package/src/index.js +41 -11
- package/src/transforms/code/index.js +19 -13
- package/src/utils/remoteRequest.js +30 -6
- package/types/src/argparse/argparse.d.ts +2 -32
- package/types/src/argparse/argparse.d.ts.map +1 -1
- package/types/src/argparse/index.d.ts +2 -2
- package/types/src/argparse/splitOutsideQuotes.d.ts +2 -1
- package/types/src/argparse/splitOutsideQuotes.d.ts.map +1 -1
- package/types/src/cli-run.d.ts +4 -2
- package/types/src/cli-run.d.ts.map +1 -1
- package/types/src/globparse.d.ts +11 -17
- package/types/src/globparse.d.ts.map +1 -1
- package/types/src/index.d.ts +36 -9
- package/types/src/index.d.ts.map +1 -1
- package/types/src/transforms/code/index.d.ts.map +1 -1
- package/types/src/utils/remoteRequest.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markdown-magic",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.9.0",
|
|
4
4
|
"description": "Automatically update markdown files with content from external sources",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"types": "tsc --emitDeclarationOnly --outDir types",
|
|
22
22
|
"docs": "node examples/generate-readme.js",
|
|
23
23
|
"test": "uvu . '.test.([mc]js|[jt]sx?)$'",
|
|
24
|
-
"cli": "node ./cli.js --
|
|
24
|
+
"cli": "node ./cli.js --files 'README.md' --config ./md.config.js",
|
|
25
25
|
"bundle": "npm run bundle:all",
|
|
26
26
|
"bundle:all": "npm run bundle:mac && npm run bundle:linux && npm run bundle:windows",
|
|
27
27
|
"bundle:mac": "bun build ./cli.js --compile --minify --target=bun-darwin-arm64 --outfile dist/md-magic-darwin-arm64 && bun build ./cli.js --compile --minify --target=bun-darwin-x64 --outfile dist/md-magic-darwin-x64",
|
|
@@ -40,11 +40,12 @@
|
|
|
40
40
|
"url": "https://github.com/DavidWells/markdown-magic"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
+
"@davidwells/dx-args": "0.2.0",
|
|
43
44
|
"@davidwells/md-utils": "0.0.53",
|
|
44
45
|
"color-convert": "^2.0.1",
|
|
45
|
-
"comment-block-parser": "1.
|
|
46
|
-
"comment-block-replacer": "0.1.
|
|
47
|
-
"comment-block-transformer": "0.
|
|
46
|
+
"comment-block-parser": "1.6.0",
|
|
47
|
+
"comment-block-replacer": "0.1.19",
|
|
48
|
+
"comment-block-transformer": "0.8.0",
|
|
48
49
|
"globrex": "^0.1.2",
|
|
49
50
|
"gray-matter": "^4.0.3",
|
|
50
51
|
"is-glob": "^4.0.3",
|
|
@@ -54,7 +55,6 @@
|
|
|
54
55
|
"module-alias": "^2.2.3",
|
|
55
56
|
"mri": "^1.2.0",
|
|
56
57
|
"node-fetch": "^2.7.0",
|
|
57
|
-
"oparser": "^3.0.24",
|
|
58
58
|
"punycode": "^2.3.1",
|
|
59
59
|
"smart-glob": "^1.0.2",
|
|
60
60
|
"string-width": "^4.2.3"
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"publishConfig": {
|
|
71
71
|
"access": "public"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "a4b2188aaa9c6c2cc82cf81a0d6b1df249453d4a"
|
|
74
74
|
}
|
package/src/argparse/README.md
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
# Argparse
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Markdown Magic keeps this directory as a compatibility surface for older deep
|
|
4
|
+
imports. The parser implementation now lives in the `@davidwells/dx-args` workspace package.
|
|
4
5
|
|
|
5
|
-
See `argparse.test.js` for
|
|
6
|
-
|
|
7
|
-
Rules
|
|
8
|
-
|
|
9
|
-
- If single char `-x` is found, it is a boolean flag.
|
|
10
|
-
- If `-x=value` is found, it is a key value pair.
|
|
11
|
-
- If `--` is found, then all following args collected as a full arg `rest`
|
|
6
|
+
See `packages/dx-args/README.md` and `argparse.test.js` for behavior examples.
|
package/src/argparse/argparse.js
CHANGED
|
@@ -1,317 +1,11 @@
|
|
|
1
|
-
const
|
|
2
|
-
const { parse } = require('oparser')
|
|
3
|
-
const { getGlobGroupsFromArgs } = require('../globparse')
|
|
4
|
-
const { splitOutsideQuotes } = require('./splitOutsideQuotes')
|
|
5
|
-
/*
|
|
6
|
-
const yargs = require('yargs/yargs')
|
|
7
|
-
const { hideBin } = require('yargs/helpers')
|
|
8
|
-
// process.exit(1)
|
|
9
|
-
/** */
|
|
1
|
+
const { dxParse } = require('@davidwells/dx-args')
|
|
10
2
|
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
/*
|
|
16
|
-
node cli.js hahaha -y -rx yoyo nono=haha --stage prod -nice=true word = bond -ab
|
|
17
|
-
|
|
18
|
-
[
|
|
19
|
-
_ ['hahaha'],
|
|
20
|
-
'y': true,
|
|
21
|
-
'r': true,
|
|
22
|
-
'x': true,
|
|
23
|
-
'yoyo': true,
|
|
24
|
-
'nono: haha',
|
|
25
|
-
'stage': 'prod',
|
|
26
|
-
'nice': true,
|
|
27
|
-
'word': 'bond',
|
|
28
|
-
'a': true,
|
|
29
|
-
'b': true,
|
|
30
|
-
]
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
function isNegativeNumber(input) {
|
|
34
|
-
return /^-\d/g.test(input)
|
|
3
|
+
if (require.main === module) {
|
|
4
|
+
const result = dxParse(process.argv.slice(2))
|
|
5
|
+
const util = require('util')
|
|
6
|
+
console.log(util.inspect(result, false, null, true))
|
|
35
7
|
}
|
|
36
8
|
|
|
37
|
-
function uxParse(_rawArgv = [], opts = {}) {
|
|
38
|
-
/* Trim empty strings */
|
|
39
|
-
const { stripSingleDashOptions = true } = opts
|
|
40
|
-
const rawArgv = _rawArgv.filter(x => x !== '')
|
|
41
|
-
let mriOptionsOriginal = mri(rawArgv)
|
|
42
|
-
|
|
43
|
-
const yargsParsed = 'not enabled' //yargs(_rawArgv).parse()
|
|
44
|
-
let extraParse = {}
|
|
45
|
-
let globGroups = []
|
|
46
|
-
const mriOptionsClean = Object.assign({}, mriOptionsOriginal)
|
|
47
|
-
|
|
48
|
-
const _singleDashOptions = findSingleDashStrings(rawArgv)
|
|
49
|
-
console.log('_singleDashOptions', _singleDashOptions)
|
|
50
|
-
|
|
51
|
-
// Get all leading CLI commands that are strings that are not options. Stop if option is found
|
|
52
|
-
const leadingCommands = []
|
|
53
|
-
for (let i = 0; i < rawArgv.length; i++) {
|
|
54
|
-
const curr = rawArgv[i]
|
|
55
|
-
if (typeof curr === 'string' && !curr.match(/^-/) && !curr.match(IS_KEY_VALUE_START_WITH_QUOTE)) {
|
|
56
|
-
leadingCommands.push(curr)
|
|
57
|
-
} else {
|
|
58
|
-
break
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
console.log('leadingCommands', leadingCommands)
|
|
62
|
-
|
|
63
|
-
if (!rawArgv || !rawArgv.length) {
|
|
64
|
-
return {
|
|
65
|
-
leadingCommands,
|
|
66
|
-
extraParse,
|
|
67
|
-
mriOptionsOriginal,
|
|
68
|
-
globGroups
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
//*
|
|
72
|
-
console.log('rawArgv', rawArgv)
|
|
73
|
-
console.log('mri mriOptionsOriginal', mriOptionsOriginal)
|
|
74
|
-
const counter = {}
|
|
75
|
-
/** */
|
|
76
|
-
/* If raw args found, process them further */
|
|
77
|
-
if (
|
|
78
|
-
rawArgv.length
|
|
79
|
-
// && (mriOptionsOriginal._ && mriOptionsOriginal._.length || (mriOptionsOriginal.file || mriOptionsOriginal.files))
|
|
80
|
-
) {
|
|
81
|
-
// if (isGlob(rawArgv[0])) {
|
|
82
|
-
// console.log('glob', rawArgv[0])
|
|
83
|
-
// mriOptionsOriginal.glob = rawArgv[0]
|
|
84
|
-
// }
|
|
85
|
-
const globParse = getGlobGroupsFromArgs(rawArgv, {
|
|
86
|
-
/* CLI args that should be glob keys */
|
|
87
|
-
globKeys: ['files', 'file']
|
|
88
|
-
})
|
|
89
|
-
globGroups = globParse.globGroups
|
|
90
|
-
const { otherOpts } = globParse
|
|
91
|
-
console.log('globGroups', globGroups)
|
|
92
|
-
/*
|
|
93
|
-
|
|
94
|
-
console.log('globParse', globParse)
|
|
95
|
-
// deepLog(globParse)
|
|
96
|
-
process.exit(1)
|
|
97
|
-
/** */
|
|
98
|
-
/* Parse for weird CLI inputs */
|
|
99
|
-
|
|
100
|
-
/* Handle -- and - flags */
|
|
101
|
-
|
|
102
|
-
console.log('left over otherOpts after globParse', otherOpts)
|
|
103
|
-
let newArray = []
|
|
104
|
-
let dashDashSet = false
|
|
105
|
-
let rest = []
|
|
106
|
-
for (let i = 0; i < otherOpts.length; i++) {
|
|
107
|
-
const curr = otherOpts[i].trim()
|
|
108
|
-
const currIsNegativeNumber = isNegativeNumber(curr)
|
|
109
|
-
const prev = newArray[i - 1]
|
|
110
|
-
const next = otherOpts[i + 1] || ''
|
|
111
|
-
const nextNext = otherOpts[i + 2] || ''
|
|
112
|
-
const isLast = otherOpts.length === i + 1
|
|
113
|
-
const isFirst = i === 0
|
|
114
|
-
const opt = cleanOption(curr)
|
|
115
|
-
console.log('--------------------------------')
|
|
116
|
-
console.log(`current "${curr}"`)
|
|
117
|
-
console.log(`cleaned "${opt}"`)
|
|
118
|
-
console.log(`previous "${opt}"`, prev)
|
|
119
|
-
console.log(`next for "${opt}"`, next)
|
|
120
|
-
console.log(`nextNext "${opt}"`, nextNext)
|
|
121
|
-
console.log('--------------------------------')
|
|
122
|
-
|
|
123
|
-
if (dashDashSet) {
|
|
124
|
-
rest.push(curr)
|
|
125
|
-
continue
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (curr === '--') {
|
|
129
|
-
dashDashSet = true
|
|
130
|
-
continue
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
let currentIsSingleDashOption = false
|
|
134
|
-
if (curr.match(/^-[^-]/) && !currIsNegativeNumber) {
|
|
135
|
-
console.log('single dash option', curr)
|
|
136
|
-
currentIsSingleDashOption = true
|
|
137
|
-
}
|
|
138
|
-
if (currIsNegativeNumber) {
|
|
139
|
-
newArray.push(curr)
|
|
140
|
-
continue
|
|
141
|
-
}
|
|
142
|
-
// console.log('prev', prev)
|
|
143
|
-
if (curr.match(/^-+/)) {
|
|
144
|
-
const cleanX = !isNegativeNumber(curr) ? curr.replace(/^-+/, '') : curr
|
|
145
|
-
|
|
146
|
-
const nextItemIsOption = next.match(/^-+/)
|
|
147
|
-
|
|
148
|
-
if (currentIsSingleDashOption && nextItemIsOption && cleanX.length < 4) {
|
|
149
|
-
continue
|
|
150
|
-
}
|
|
151
|
-
console.log('cleanX', cleanX)
|
|
152
|
-
if (nextItemIsOption || isLast) {
|
|
153
|
-
if (cleanX.match(IS_KEY_VALUE_IN_QUOTES) || cleanX.match(IS_KEY_VALUE_START_WITH_QUOTE)) {
|
|
154
|
-
newArray.push(cleanX + ' ')
|
|
155
|
-
} else {
|
|
156
|
-
newArray.push(cleanX + '=true ')
|
|
157
|
-
}
|
|
158
|
-
continue
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// If the current option is the last option, don't add an equal sign
|
|
162
|
-
let equal = ' '
|
|
163
|
-
if (cleanX.indexOf('=') === -1 && !next.match(/=/)) {
|
|
164
|
-
equal = '='
|
|
165
|
-
}
|
|
166
|
-
if (isLast) {
|
|
167
|
-
equal = ' '
|
|
168
|
-
}
|
|
169
|
-
if (
|
|
170
|
-
nextNext.trim() === '='
|
|
171
|
-
// || nextNext.match(/=/)
|
|
172
|
-
) {
|
|
173
|
-
equal = ' '
|
|
174
|
-
}
|
|
175
|
-
const final = cleanX + equal
|
|
176
|
-
newArray.push(final)
|
|
177
|
-
continue
|
|
178
|
-
}
|
|
179
|
-
if (prev && prev.match(/=\s?$/) && (curr.match(/^\s?=/) || curr.trim() === '=')) {
|
|
180
|
-
continue
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
const trailingSpace = curr === '=' ? '' : ' '
|
|
184
|
-
newArray.push(curr + trailingSpace)
|
|
185
|
-
}
|
|
186
|
-
console.log('newArray', newArray)
|
|
187
|
-
console.log('rest', rest)
|
|
188
|
-
const optString = newArray.join('')
|
|
189
|
-
console.log('optString', optString)
|
|
190
|
-
extraParse = parse(optString)
|
|
191
|
-
const optParts = splitOutsideQuotes(optString)
|
|
192
|
-
console.log('optParts', optParts)
|
|
193
|
-
const optStringPieces = optParts
|
|
194
|
-
.filter(Boolean)
|
|
195
|
-
.map((x) => {
|
|
196
|
-
console.log('x', x)
|
|
197
|
-
return parse(x)
|
|
198
|
-
})
|
|
199
|
-
console.log('optStringPieces', optStringPieces)
|
|
200
|
-
|
|
201
|
-
for (let i = 0; i < optStringPieces.length; i++) {
|
|
202
|
-
const curr = optStringPieces[i]
|
|
203
|
-
const key = Object.keys(curr)[0]
|
|
204
|
-
if (counter[key]) {
|
|
205
|
-
counter[key]++
|
|
206
|
-
} else {
|
|
207
|
-
counter[key] = 1
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
console.log('optStringPieces counter', counter)
|
|
211
|
-
|
|
212
|
-
const propertiesSetMoreThanOnce = Object.keys(counter).filter((x) => counter[x] > 1)
|
|
213
|
-
console.log('propertiesSetMoreThanOnce', propertiesSetMoreThanOnce)
|
|
214
|
-
const singleDashStrings = findSingleDashStrings(otherOpts).map((x) => x.replace(/^-+/, ''))
|
|
215
|
-
console.log('singleDashStrings', singleDashStrings)
|
|
216
|
-
// find any duplicate values in singleDashStrings. means its an array
|
|
217
|
-
const duplicateValues = singleDashStrings.filter((x, index) => singleDashStrings.indexOf(x) !== index)
|
|
218
|
-
console.log('duplicateValues', duplicateValues)
|
|
219
|
-
if (propertiesSetMoreThanOnce.length) {
|
|
220
|
-
console.log('duplicateValues', propertiesSetMoreThanOnce)
|
|
221
|
-
for (let i = 0; i < propertiesSetMoreThanOnce.length; i++) {
|
|
222
|
-
const curr = propertiesSetMoreThanOnce[i]
|
|
223
|
-
console.log('curr', curr)
|
|
224
|
-
// get all array items with key of curr
|
|
225
|
-
const arrayItems = optStringPieces.filter((x) => Object.keys(x)[0] === curr)
|
|
226
|
-
console.log('arrayItems', arrayItems)
|
|
227
|
-
// Set to extraParse as an array
|
|
228
|
-
extraParse[curr] = arrayItems.map((x) => x[curr])
|
|
229
|
-
// Make the array items unique
|
|
230
|
-
extraParse[curr] = [...new Set(extraParse[curr])]
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
console.log('before mriOptionsOriginal', mriOptionsOriginal)
|
|
235
|
-
console.log('before extraParse', extraParse)
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
console.log('stripSingleDashOptions', stripSingleDashOptions)
|
|
239
|
-
// const STRIP_SINGLE_DASH_OPTIONS = stripSingleDashOptions
|
|
240
|
-
const STRIP_SINGLE_DASH_OPTIONS = false
|
|
241
|
-
|
|
242
|
-
if (singleDashStrings.length) {
|
|
243
|
-
for (let i = 0; i < singleDashStrings.length; i++) {
|
|
244
|
-
const curr = singleDashStrings[i]
|
|
245
|
-
const parts = curr.split('=')
|
|
246
|
-
const word = parts[0]
|
|
247
|
-
const value = parts[1]
|
|
248
|
-
const shouldStrip = (value) ? true : STRIP_SINGLE_DASH_OPTIONS
|
|
249
|
-
// Loop over all letters of single dash mriOptionsOriginal -word and remove any corresponding letter: true
|
|
250
|
-
for (let j = 0; j < word.length; j++) {
|
|
251
|
-
const letter = word[j]
|
|
252
|
-
// console.log('letter', letter)
|
|
253
|
-
if (shouldStrip && mriOptionsClean[letter]) {
|
|
254
|
-
delete mriOptionsClean[letter]
|
|
255
|
-
}
|
|
256
|
-
if (mriOptionsClean[letter] === extraParse[word]) {
|
|
257
|
-
delete mriOptionsClean[letter]
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
console.log('after mriOptionsOriginal', mriOptionsClean)
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/*
|
|
265
|
-
console.log('optStringArr', newArray)
|
|
266
|
-
console.log('optString', optString)
|
|
267
|
-
console.log('otherOpts strings', otherOpts)
|
|
268
|
-
console.log('nicely handed CLI args')
|
|
269
|
-
console.log('extraParse', extraParse)
|
|
270
|
-
process.exit(1)
|
|
271
|
-
/** */
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const mergedOptions = {
|
|
275
|
-
...mriOptionsClean,
|
|
276
|
-
...extraParse,
|
|
277
|
-
}
|
|
278
|
-
delete mergedOptions._
|
|
279
|
-
|
|
280
|
-
// @TODO hoist this bc we are do it earlier
|
|
281
|
-
Object.keys(mergedOptions).forEach((key) => {
|
|
282
|
-
const count = counter[key]
|
|
283
|
-
if (count && key.length > 1 && count > 1) {
|
|
284
|
-
console.log(`key "${key}" count ${count}`)
|
|
285
|
-
const value = Array.isArray(extraParse[key]) ? extraParse[key] : mriOptionsOriginal[key]
|
|
286
|
-
console.log('value', value)
|
|
287
|
-
if (Array.isArray(value)) {
|
|
288
|
-
mergedOptions[key] = value
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
})
|
|
292
|
-
|
|
293
|
-
return {
|
|
294
|
-
rawArgv: rawArgv.join(' '),
|
|
295
|
-
leadingCommands,
|
|
296
|
-
globGroups,
|
|
297
|
-
extraParse,
|
|
298
|
-
mriOptionsOriginal,
|
|
299
|
-
mriOptionsClean,
|
|
300
|
-
mriDiff: mriOptionsOriginal !== mriOptionsClean,
|
|
301
|
-
yargsParsed,
|
|
302
|
-
mergedOptions
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
function cleanOption(option = '') {
|
|
307
|
-
return option.replace(/^-+/, '').trim()
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
function findSingleDashStrings(arr) {
|
|
311
|
-
return arr.filter(str => str.match(/^-[^-]/))
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
|
|
315
9
|
module.exports = {
|
|
316
|
-
|
|
317
|
-
}
|
|
10
|
+
dxParse,
|
|
11
|
+
}
|