nginx-pretty 1.0.1 → 1.0.2
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/beautifier/index.js +8 -3
- package/cli.js +5 -1
- package/package.json +1 -1
package/beautifier/index.js
CHANGED
|
@@ -206,16 +206,21 @@ function perform_alignment(lines) {
|
|
|
206
206
|
/**
|
|
207
207
|
* Format NGINX config contents into a readable format.
|
|
208
208
|
* Pipeline: clean_lines -> join_opening_bracket -> perform_indentation -> perform_alignment
|
|
209
|
+
* Input is normalized (line endings, trailing newlines) so formatting is idempotent.
|
|
209
210
|
*
|
|
210
211
|
* @param {string} contents - Raw NGINX config file contents
|
|
211
|
-
* @returns {string} Formatted config
|
|
212
|
+
* @returns {string} Formatted config (no trailing newline)
|
|
212
213
|
*/
|
|
213
214
|
function format(contents) {
|
|
214
|
-
|
|
215
|
+
const normalized = contents
|
|
216
|
+
.replace(/\r\n/g, '\n')
|
|
217
|
+
.replace(/\r/g, '\n')
|
|
218
|
+
.replace(/\n+$/, '');
|
|
219
|
+
let lines = clean_lines(normalized);
|
|
215
220
|
lines = join_opening_bracket(lines);
|
|
216
221
|
lines = perform_indentation(lines);
|
|
217
222
|
lines = perform_alignment(lines);
|
|
218
|
-
return lines.join('\n');
|
|
223
|
+
return lines.join('\n').replace(/\n+$/, '');
|
|
219
224
|
}
|
|
220
225
|
|
|
221
226
|
module.exports = { format };
|
package/cli.js
CHANGED
|
@@ -159,14 +159,18 @@ function main() {
|
|
|
159
159
|
|
|
160
160
|
console.log('🆕 Ensuring', tempPath, 'is writable...');
|
|
161
161
|
console.log('🎨 Formatting the copied config...');
|
|
162
|
+
console.log('Working on file:', tempPath);
|
|
162
163
|
|
|
163
164
|
const formattedContent = format(originalContent);
|
|
164
165
|
|
|
165
166
|
fs.writeFileSync(tempPath, formattedContent, { mode: 0o644 });
|
|
167
|
+
console.log('Success.');
|
|
168
|
+
console.log('');
|
|
166
169
|
|
|
167
170
|
runDiff(originalPath, tempPath)
|
|
168
171
|
.then((diffOutput) => {
|
|
169
172
|
if (diffOutput === null) {
|
|
173
|
+
console.log('🔍 Showing unified diff (ORIGINAL vs FORMATTED):');
|
|
170
174
|
console.log('✅ No changes detected.');
|
|
171
175
|
try {
|
|
172
176
|
fs.unlinkSync(tempPath);
|
|
@@ -175,7 +179,7 @@ function main() {
|
|
|
175
179
|
return;
|
|
176
180
|
}
|
|
177
181
|
|
|
178
|
-
console.log('
|
|
182
|
+
console.log('🔍 Showing unified diff (ORIGINAL vs FORMATTED):');
|
|
179
183
|
console.log(diffOutput);
|
|
180
184
|
console.log('❌ Changes detected. Review diff and rerun if needed.');
|
|
181
185
|
|
package/package.json
CHANGED