Repository navigation
Expand file tree
/
Copy pathprototype.ts
More file actions
103 lines (100 loc) · 3.42 KB
/
Copy pathprototype.ts
File metadata and controls
103 lines (100 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import fs from 'node:fs';
import path from 'node:path';
import { performance } from 'node:perf_hooks';
import { runCmdSync } from '@agent-device/host-kit/command';
const root = path.resolve(import.meta.dirname, '../..');
const cli = path.join(root, 'node_modules/jscpd/run-jscpd.js');
const output = path.join(root, '.tmp/native-dupes-prototypes');
const pair = [
'packages/platform-apple/src/core/__tests__/display-inventory.test.ts',
'packages/platform-apple/src/__tests__/simctl-facade.test.ts',
];
const variants = [
{ name: 'mild-50-5', tokens: 50, lines: 5, mode: 'mild', extra: [] },
{ name: 'weak-50-5', tokens: 50, lines: 5, mode: 'weak', extra: [] },
{ name: 'weak-70-5', tokens: 70, lines: 5, mode: 'weak', extra: [] },
{ name: 'weak-100-8', tokens: 100, lines: 8, mode: 'weak', extra: [] },
{ name: 'weak-30-3', tokens: 30, lines: 3, mode: 'weak', extra: [] },
{ name: 'weak-20-3', tokens: 20, lines: 3, mode: 'weak', extra: [] },
{
name: 'renamed-50-5',
tokens: 50,
lines: 5,
mode: 'weak',
extra: ['--ignore-identifiers=consistent'],
},
{ name: 'gap-30-3', tokens: 30, lines: 3, mode: 'weak', extra: ['--max-gap-lines', '8'] },
];
type Report = {
statistics: {
total: { clones: number; duplicatedLines: number; percentage: number; sources: number };
};
duplicates: Array<{
firstFile: { name: string; start: number; end: number };
secondFile: { name: string; start: number; end: number };
}>;
};
const rows = [];
for (const variant of variants) {
for (const scope of ['native', 'duo'] as const) {
const destination = path.join(output, `${variant.name}-${scope}`);
const start = performance.now();
runCmdSync(
process.execPath,
[
cli,
'--config',
'.jscpd-native.json',
...(scope === 'duo' ? pair : []),
...(scope === 'duo' ? ['--format', 'typescript'] : []),
'--mode',
variant.mode,
'--min-tokens',
String(variant.tokens),
'--min-lines',
String(variant.lines),
...variant.extra,
'--workers',
'2',
'--absolute',
'--reporters',
'json',
'--output',
destination,
],
{ cwd: root },
);
const report: Report = JSON.parse(
fs.readFileSync(path.join(destination, 'jscpd-report.json'), 'utf8'),
);
const { clones, duplicatedLines, percentage, sources } = report.statistics.total;
const fold = report.duplicates.filter((clone) =>
[clone.firstFile, clone.secondFile].some((file) => file.name.endsWith('/fold-helper/Fold.m')),
).length;
const duoPanels = report.duplicates.filter(
(clone) =>
clone.firstFile.name !== clone.secondFile.name &&
[clone.firstFile, clone.secondFile].some(
(file) =>
file.name.endsWith('/simctl-facade.test.ts') && file.start <= 50 && file.end >= 34,
),
).length;
const row = {
variant: variant.name,
scope,
sources,
clones,
duplicatedLines,
percentage: Number(percentage.toFixed(2)),
fold,
duoPanels,
milliseconds: Math.round(performance.now() - start),
};
rows.push(row);
console.log(
`${variant.name} ${scope}: ${clones} clones, ${row.percentage}%, Fold=${fold}, Duo panels=${duoPanels}, ${row.milliseconds}ms`,
);
}
}
fs.writeFileSync(path.join(output, 'summary.json'), `${JSON.stringify(rows, null, 2)}\n`);
console.log(`Reports: ${output}`);