dev(tools): add conflict prompt to license-headers

This commit is contained in:
KernelDeimos 2024-07-10 14:57:20 -04:00
parent f006c9ed26
commit d0a5a57c88
4 changed files with 40 additions and 5 deletions

15
package-lock.json generated
View File

@ -5033,7 +5033,6 @@
"version": "4.1.3", "version": "4.1.3",
"resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz",
"integrity": "sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==", "integrity": "sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==",
"dev": true,
"license": "MIT", "license": "MIT",
"engines": { "engines": {
"node": ">=6" "node": ">=6"
@ -6932,6 +6931,19 @@
"node": ">=10.13.0" "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": { "node_modules/entities": {
"version": "4.5.0", "version": "4.5.0",
"resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz",
@ -14654,6 +14666,7 @@
"console-table-printer": "^2.12.1", "console-table-printer": "^2.12.1",
"dedent": "^1.5.3", "dedent": "^1.5.3",
"diff-match-patch": "^1.0.5", "diff-match-patch": "^1.0.5",
"enquirer": "^2.4.1",
"js-levenshtein": "^1.1.6", "js-levenshtein": "^1.1.6",
"yaml": "^2.4.5" "yaml": "^2.4.5"
} }

View File

@ -128,8 +128,7 @@ const BlockCommentParser = ({
return { return {
parse: async (stream) => { parse: async (stream) => {
stream.skip_whitespace(); stream.skip_whitespace();
stream.debug('starting at', await stream.debug()) if ( ! await stream.matches(start) ) return;
if ( ! stream.matches(start) ) return;
stream.fwd(start.length); stream.fwd(start.length);
const contents = await stream.get_until(end); const contents = await stream.get_until(end);
if ( ! contents ) return; if ( ! contents ) return;
@ -221,7 +220,7 @@ const CommentParser = () => {
javascript: { javascript: {
parsers: [ parsers: [
['lines', { ['lines', {
prefix: '// ', prefix: '//',
}], }],
['block', { ['block', {
start: '/*', start: '/*',
@ -231,7 +230,7 @@ const CommentParser = () => {
], ],
writers: { writers: {
lines: ['lines', { lines: ['lines', {
prefix: '//' prefix: '// '
}], }],
block: ['block', { block: ['block', {
start: '/*', start: '/*',
@ -312,6 +311,7 @@ const CommentParser = () => {
break; break;
} }
} }
console.log('comment?', comment);
if ( ! comment ) break; if ( ! comment ) break;
results.push(comment); results.push(comment);
} }

View File

@ -19,6 +19,7 @@
const levenshtein = require('js-levenshtein'); const levenshtein = require('js-levenshtein');
const DiffMatchPatch = require('diff-match-patch'); const DiffMatchPatch = require('diff-match-patch');
const enq = require('enquirer');
const dmp = new DiffMatchPatch(); const dmp = new DiffMatchPatch();
const dedent = require('dedent'); const dedent = require('dedent');
@ -121,6 +122,8 @@ const LicenseChecker = ({
break; break;
} }
} }
console.log('headers', headers);
const combined = headers_lines.slice(top, bottom).flat(); const combined = headers_lines.slice(top, bottom).flat();
const combined_txt = combined.join('\n'); const combined_txt = combined.join('\n');
@ -130,6 +133,12 @@ const LicenseChecker = ({
header2: combined_txt, header2: combined_txt,
}) })
if ( diff_info.distance > 0.7*desired_header.length ) {
return {
has_header: false,
};
}
diff_info.range = [ diff_info.range = [
headers[top].range[0], headers[top].range[0],
headers[bottom-1].range[1], headers[bottom-1].range[1],
@ -385,6 +394,18 @@ const cmd_sync_fn = async () => {
if ( diff_info.distance !== 0 ) { if ( diff_info.distance !== 0 ) {
counts.conflict++; counts.conflict++;
process.stdout.write(`\x1B[31;1mCONFLICT\x1B[0m\n`); 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 { } else {
counts.ok++; counts.ok++;
process.stdout.write(`\x1B[32;1mOK\x1B[0m\n`); process.stdout.write(`\x1B[32;1mOK\x1B[0m\n`);

View File

@ -13,6 +13,7 @@
"console-table-printer": "^2.12.1", "console-table-printer": "^2.12.1",
"dedent": "^1.5.3", "dedent": "^1.5.3",
"diff-match-patch": "^1.0.5", "diff-match-patch": "^1.0.5",
"enquirer": "^2.4.1",
"js-levenshtein": "^1.1.6", "js-levenshtein": "^1.1.6",
"yaml": "^2.4.5" "yaml": "^2.4.5"
} }