prettify-bru 1.4.0 → 1.5.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/lib/format.mjs +31 -0
- package/package.json +1 -1
package/lib/format.mjs
CHANGED
|
@@ -48,6 +48,16 @@ export async function format(originalContents, only = null) {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
if (only === null) {
|
|
52
|
+
const fileBodyBlockOutcome = formatFilePaths(fileOutcome.newContents)
|
|
53
|
+
if (fileBodyBlockOutcome.errorMessage !== null) {
|
|
54
|
+
fileOutcome.errorMessages.push(fileBodyBlockOutcome.errorMessage)
|
|
55
|
+
} else if (fileBodyBlockOutcome.changeable) {
|
|
56
|
+
fileOutcome.changeable = true
|
|
57
|
+
fileOutcome.newContents = fileBodyBlockOutcome.fileContents
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
51
61
|
const overallOutcome = formatOverallStructure(fileOutcome.newContents)
|
|
52
62
|
if (overallOutcome.changeable) {
|
|
53
63
|
fileOutcome.changeable = true
|
|
@@ -109,6 +119,27 @@ async function formatBlock(fileContents, blockName, parser) {
|
|
|
109
119
|
return outcome
|
|
110
120
|
}
|
|
111
121
|
|
|
122
|
+
/**
|
|
123
|
+
* @param {string} fileContents
|
|
124
|
+
* @returns {fileContents: string, changeable: boolean, errorMessage: ?string}
|
|
125
|
+
*/
|
|
126
|
+
function formatFilePaths(fileContents) {
|
|
127
|
+
let changeable = false
|
|
128
|
+
|
|
129
|
+
const matches = fileContents.matchAll(/file: @file\(([^)]+)\)/g)
|
|
130
|
+
|
|
131
|
+
matches.forEach(match => {
|
|
132
|
+
const path = match[1]
|
|
133
|
+
if (path.match(/\\/) !== null) {
|
|
134
|
+
const newPath = path.replaceAll('\\', '/')
|
|
135
|
+
changeable = true
|
|
136
|
+
fileContents = fileContents.replace(path, newPath)
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
return {fileContents, changeable, errorMessage: null}
|
|
141
|
+
}
|
|
142
|
+
|
|
112
143
|
/**
|
|
113
144
|
* @param {string} fileContents
|
|
114
145
|
* @returns {fileContents: string, changeable: boolean}
|