From d0a5a57c884e111f4ff9198cd66aa8bd2f8709a5 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Wed, 10 Jul 2024 14:57:20 -0400 Subject: [PATCH] dev(tools): add conflict prompt to license-headers --- package-lock.json | 15 ++++++++++++++- tools/comment-parser/main.js | 8 ++++---- tools/license-headers/main.js | 21 +++++++++++++++++++++ tools/license-headers/package.json | 1 + 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 89380bb7..fedf9fff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5033,7 +5033,6 @@ "version": "4.1.3", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz", "integrity": "sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==", - "dev": true, "license": "MIT", "engines": { "node": ">=6" @@ -6932,6 +6931,19 @@ "node": ">=10.13.0" } }, + "node_modules/enquirer": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.4.1.tgz", + "integrity": "sha512-rRqJg/6gd538VHvR3PSrdRBb/1Vy2YfzHqzvbhGIQpDRKIa4FgV/54b5Q1xYSxOOwKvjXweS26E0Q+nAMwp2pQ==", + "license": "MIT", + "dependencies": { + "ansi-colors": "^4.1.1", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8.6" + } + }, "node_modules/entities": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", @@ -14654,6 +14666,7 @@ "console-table-printer": "^2.12.1", "dedent": "^1.5.3", "diff-match-patch": "^1.0.5", + "enquirer": "^2.4.1", "js-levenshtein": "^1.1.6", "yaml": "^2.4.5" } diff --git a/tools/comment-parser/main.js b/tools/comment-parser/main.js index a6ddb8e7..68e64245 100644 --- a/tools/comment-parser/main.js +++ b/tools/comment-parser/main.js @@ -128,8 +128,7 @@ const BlockCommentParser = ({ return { parse: async (stream) => { stream.skip_whitespace(); - stream.debug('starting at', await stream.debug()) - if ( ! stream.matches(start) ) return; + if ( ! await stream.matches(start) ) return; stream.fwd(start.length); const contents = await stream.get_until(end); if ( ! contents ) return; @@ -221,7 +220,7 @@ const CommentParser = () => { javascript: { parsers: [ ['lines', { - prefix: '// ', + prefix: '//', }], ['block', { start: '/*', @@ -231,7 +230,7 @@ const CommentParser = () => { ], writers: { lines: ['lines', { - prefix: '//' + prefix: '// ' }], block: ['block', { start: '/*', @@ -312,6 +311,7 @@ const CommentParser = () => { break; } } + console.log('comment?', comment); if ( ! comment ) break; results.push(comment); } diff --git a/tools/license-headers/main.js b/tools/license-headers/main.js index 97c6414e..0716031a 100644 --- a/tools/license-headers/main.js +++ b/tools/license-headers/main.js @@ -19,6 +19,7 @@ const levenshtein = require('js-levenshtein'); const DiffMatchPatch = require('diff-match-patch'); +const enq = require('enquirer'); const dmp = new DiffMatchPatch(); const dedent = require('dedent'); @@ -121,6 +122,8 @@ const LicenseChecker = ({ break; } } + + console.log('headers', headers); const combined = headers_lines.slice(top, bottom).flat(); const combined_txt = combined.join('\n'); @@ -130,6 +133,12 @@ const LicenseChecker = ({ header2: combined_txt, }) + if ( diff_info.distance > 0.7*desired_header.length ) { + return { + has_header: false, + }; + } + diff_info.range = [ headers[top].range[0], headers[bottom-1].range[1], @@ -385,6 +394,18 @@ const cmd_sync_fn = async () => { if ( diff_info.distance !== 0 ) { counts.conflict++; process.stdout.write(`\x1B[31;1mCONFLICT\x1B[0m\n`); + process.stdout.write('\x1B[36;1m=======\x1B[0m\n'); + process.stdout.write(diff_info.term_diff); + process.stdout.write('\n\x1B[36;1m=======\x1B[0m\n'); + const prompt = new enq.Select({ + message: 'Select Action', + choices: [ + { name: 'skip', message: 'Skip' }, + { name: 'replace', message: 'Replace' }, + ] + }) + const action = await prompt.run(); + console.log('action', action); } else { counts.ok++; process.stdout.write(`\x1B[32;1mOK\x1B[0m\n`); diff --git a/tools/license-headers/package.json b/tools/license-headers/package.json index 05ced1f1..0bf0b49e 100644 --- a/tools/license-headers/package.json +++ b/tools/license-headers/package.json @@ -13,6 +13,7 @@ "console-table-printer": "^2.12.1", "dedent": "^1.5.3", "diff-match-patch": "^1.0.5", + "enquirer": "^2.4.1", "js-levenshtein": "^1.1.6", "yaml": "^2.4.5" }