ai-localize-reporting 1.0.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/dist/index.d.mts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +174 -0
- package/dist/index.mjs +135 -0
- package/package.json +34 -0
- package/src/cli-reporter.ts +29 -0
- package/src/html-reporter.ts +74 -0
- package/src/index.ts +3 -0
- package/src/report-builder.ts +35 -0
- package/tsconfig.json +6 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ScanResult, ValidationResult, CloudFrontAsset, Report } from '@ai-localize/shared';
|
|
2
|
+
|
|
3
|
+
interface ReportInput {
|
|
4
|
+
scanResult: ScanResult;
|
|
5
|
+
validationResult?: ValidationResult;
|
|
6
|
+
uploadedAssets?: CloudFrontAsset[];
|
|
7
|
+
replacedUrls?: number;
|
|
8
|
+
}
|
|
9
|
+
declare function buildReport(input: ReportInput): Report;
|
|
10
|
+
|
|
11
|
+
declare function generateHtmlReport(report: Report, outputPath: string): void;
|
|
12
|
+
|
|
13
|
+
declare function printCliSummary(report: Report): void;
|
|
14
|
+
|
|
15
|
+
export { type ReportInput, buildReport, generateHtmlReport, printCliSummary };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ScanResult, ValidationResult, CloudFrontAsset, Report } from '@ai-localize/shared';
|
|
2
|
+
|
|
3
|
+
interface ReportInput {
|
|
4
|
+
scanResult: ScanResult;
|
|
5
|
+
validationResult?: ValidationResult;
|
|
6
|
+
uploadedAssets?: CloudFrontAsset[];
|
|
7
|
+
replacedUrls?: number;
|
|
8
|
+
}
|
|
9
|
+
declare function buildReport(input: ReportInput): Report;
|
|
10
|
+
|
|
11
|
+
declare function generateHtmlReport(report: Report, outputPath: string): void;
|
|
12
|
+
|
|
13
|
+
declare function printCliSummary(report: Report): void;
|
|
14
|
+
|
|
15
|
+
export { type ReportInput, buildReport, generateHtmlReport, printCliSummary };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
buildReport: () => buildReport,
|
|
34
|
+
generateHtmlReport: () => generateHtmlReport,
|
|
35
|
+
printCliSummary: () => printCliSummary
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
|
|
39
|
+
// src/report-builder.ts
|
|
40
|
+
function buildReport(input) {
|
|
41
|
+
const { scanResult, validationResult, uploadedAssets = [], replacedUrls = 0 } = input;
|
|
42
|
+
return {
|
|
43
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
44
|
+
duration: scanResult.duration,
|
|
45
|
+
framework: scanResult.framework,
|
|
46
|
+
filesScanned: scanResult.scannedFiles,
|
|
47
|
+
hardcodedTexts: scanResult.detectedTexts.length,
|
|
48
|
+
localeKeysGenerated: new Set(scanResult.detectedTexts.map((d) => d.suggestedKey)).size,
|
|
49
|
+
unusedKeys: validationResult?.warnings.filter((w) => w.type === "unused-key").length || 0,
|
|
50
|
+
missingTranslations: validationResult?.errors.filter((e) => e.type === "missing-key").length || 0,
|
|
51
|
+
languages: [],
|
|
52
|
+
assets: {
|
|
53
|
+
totalAssets: scanResult.assets.length,
|
|
54
|
+
uploadedAssets: uploadedAssets.length,
|
|
55
|
+
replacedUrls,
|
|
56
|
+
legacyCdnUrls: scanResult.legacyCdnUrls.length
|
|
57
|
+
},
|
|
58
|
+
details: {
|
|
59
|
+
detectedTexts: scanResult.detectedTexts,
|
|
60
|
+
missingKeys: validationResult?.errors.filter((e) => e.type === "missing-key") || [],
|
|
61
|
+
unusedKeysList: validationResult?.warnings.filter((w) => w.type === "unused-key").map((w) => w.key) || [],
|
|
62
|
+
assets: uploadedAssets
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/html-reporter.ts
|
|
68
|
+
var fs = __toESM(require("fs"));
|
|
69
|
+
var path = __toESM(require("path"));
|
|
70
|
+
var import_shared = require("@ai-localize/shared");
|
|
71
|
+
function generateHtmlReport(report, outputPath) {
|
|
72
|
+
(0, import_shared.ensureDir)(path.dirname(outputPath));
|
|
73
|
+
const html = `<!DOCTYPE html>
|
|
74
|
+
<html lang="en">
|
|
75
|
+
<head>
|
|
76
|
+
<meta charset="UTF-8">
|
|
77
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
78
|
+
<title>ai-localize Report - ${report.timestamp}</title>
|
|
79
|
+
<style>
|
|
80
|
+
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; max-width: 1200px; margin: 0 auto; padding: 24px; background: #f5f5f5; }
|
|
81
|
+
h1 { color: #1a1a2e; } h2 { color: #16213e; border-bottom: 2px solid #0f3460; padding-bottom: 8px; }
|
|
82
|
+
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin: 24px 0; }
|
|
83
|
+
.stat-card { background: white; border-radius: 8px; padding: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); text-align: center; }
|
|
84
|
+
.stat-number { font-size: 2.5rem; font-weight: 700; color: #0f3460; }
|
|
85
|
+
.stat-label { color: #666; font-size: 0.9rem; margin-top: 4px; }
|
|
86
|
+
.error { color: #e53e3e; } .warning { color: #d69e2e; } .success { color: #38a169; }
|
|
87
|
+
table { width: 100%; border-collapse: collapse; background: white; border-radius: 8px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
|
|
88
|
+
th { background: #0f3460; color: white; padding: 12px 16px; text-align: left; }
|
|
89
|
+
td { padding: 10px 16px; border-bottom: 1px solid #f0f0f0; }
|
|
90
|
+
tr:hover td { background: #f8f9ff; }
|
|
91
|
+
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 0.75rem; font-weight: 600; }
|
|
92
|
+
.badge-blue { background: #ebf4ff; color: #2b6cb0; }
|
|
93
|
+
.badge-red { background: #fff5f5; color: #c53030; }
|
|
94
|
+
.badge-green { background: #f0fff4; color: #276749; }
|
|
95
|
+
</style>
|
|
96
|
+
</head>
|
|
97
|
+
<body>
|
|
98
|
+
<h1>\u{1F310} ai-localize Report</h1>
|
|
99
|
+
<p><strong>Generated:</strong> ${report.timestamp} | <strong>Framework:</strong> ${report.framework} | <strong>Duration:</strong> ${report.duration}ms</p>
|
|
100
|
+
|
|
101
|
+
<div class="stats">
|
|
102
|
+
<div class="stat-card"><div class="stat-number">${report.filesScanned}</div><div class="stat-label">Files Scanned</div></div>
|
|
103
|
+
<div class="stat-card"><div class="stat-number error">${report.hardcodedTexts}</div><div class="stat-label">Hardcoded Texts</div></div>
|
|
104
|
+
<div class="stat-card"><div class="stat-number success">${report.localeKeysGenerated}</div><div class="stat-label">Keys Generated</div></div>
|
|
105
|
+
<div class="stat-card"><div class="stat-number warning">${report.unusedKeys}</div><div class="stat-label">Unused Keys</div></div>
|
|
106
|
+
<div class="stat-card"><div class="stat-number error">${report.missingTranslations}</div><div class="stat-label">Missing Translations</div></div>
|
|
107
|
+
<div class="stat-card"><div class="stat-number">${report.assets.uploadedAssets}</div><div class="stat-label">Assets Uploaded</div></div>
|
|
108
|
+
</div>
|
|
109
|
+
|
|
110
|
+
${report.details.detectedTexts.length > 0 ? `
|
|
111
|
+
<h2>Hardcoded Texts (${report.details.detectedTexts.length})</h2>
|
|
112
|
+
<table>
|
|
113
|
+
<thead><tr><th>File</th><th>Line</th><th>Text</th><th>Suggested Key</th><th>Context</th></tr></thead>
|
|
114
|
+
<tbody>
|
|
115
|
+
${report.details.detectedTexts.slice(0, 100).map((t) => `
|
|
116
|
+
<tr>
|
|
117
|
+
<td><code>${t.filePath.split("/").slice(-3).join("/")}</code></td>
|
|
118
|
+
<td>${t.line}</td>
|
|
119
|
+
<td>${t.text.slice(0, 60)}${t.text.length > 60 ? "..." : ""}</td>
|
|
120
|
+
<td><span class="badge badge-blue">${t.suggestedKey}</span></td>
|
|
121
|
+
<td><span class="badge badge-green">${t.context}</span></td>
|
|
122
|
+
</tr>`).join("")}
|
|
123
|
+
${report.details.detectedTexts.length > 100 ? `<tr><td colspan="5" style="text-align:center;color:#666">...and ${report.details.detectedTexts.length - 100} more</td></tr>` : ""}
|
|
124
|
+
</tbody>
|
|
125
|
+
</table>` : ""}
|
|
126
|
+
|
|
127
|
+
${report.details.missingKeys.length > 0 ? `
|
|
128
|
+
<h2>Missing Translations (${report.details.missingKeys.length})</h2>
|
|
129
|
+
<table>
|
|
130
|
+
<thead><tr><th>Key</th><th>Language</th><th>Message</th></tr></thead>
|
|
131
|
+
<tbody>
|
|
132
|
+
${report.details.missingKeys.map((e) => `<tr><td><code>${e.key}</code></td><td><span class="badge badge-red">${e.language || ""}</span></td><td>${e.message}</td></tr>`).join("")}
|
|
133
|
+
</tbody>
|
|
134
|
+
</table>` : ""}
|
|
135
|
+
|
|
136
|
+
</body>
|
|
137
|
+
</html>`;
|
|
138
|
+
fs.writeFileSync(outputPath, html, "utf-8");
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// src/cli-reporter.ts
|
|
142
|
+
function printCliSummary(report) {
|
|
143
|
+
const lines = [
|
|
144
|
+
"",
|
|
145
|
+
"\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557",
|
|
146
|
+
"\u2551 ai-localize-core Report Summary \u2551",
|
|
147
|
+
"\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D",
|
|
148
|
+
"",
|
|
149
|
+
` Framework : ${report.framework}`,
|
|
150
|
+
` Timestamp : ${report.timestamp}`,
|
|
151
|
+
` Duration : ${report.duration}ms`,
|
|
152
|
+
"",
|
|
153
|
+
" \u2500\u2500\u2500 Localization \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500",
|
|
154
|
+
` Files Scanned : ${report.filesScanned}`,
|
|
155
|
+
` Hardcoded Texts : ${report.hardcodedTexts}`,
|
|
156
|
+
` Keys Generated : ${report.localeKeysGenerated}`,
|
|
157
|
+
` Missing Trans. : ${report.missingTranslations}`,
|
|
158
|
+
` Unused Keys : ${report.unusedKeys}`,
|
|
159
|
+
"",
|
|
160
|
+
" \u2500\u2500\u2500 Assets / CDN \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500",
|
|
161
|
+
` Total Assets : ${report.assets.totalAssets}`,
|
|
162
|
+
` Uploaded Assets : ${report.assets.uploadedAssets}`,
|
|
163
|
+
` Replaced URLs : ${report.assets.replacedUrls}`,
|
|
164
|
+
`Legacy CDN URLs : ${report.assets.legacyCdnUrls}`,
|
|
165
|
+
""
|
|
166
|
+
];
|
|
167
|
+
console.log(lines.join("\n"));
|
|
168
|
+
}
|
|
169
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
170
|
+
0 && (module.exports = {
|
|
171
|
+
buildReport,
|
|
172
|
+
generateHtmlReport,
|
|
173
|
+
printCliSummary
|
|
174
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// src/report-builder.ts
|
|
2
|
+
function buildReport(input) {
|
|
3
|
+
const { scanResult, validationResult, uploadedAssets = [], replacedUrls = 0 } = input;
|
|
4
|
+
return {
|
|
5
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6
|
+
duration: scanResult.duration,
|
|
7
|
+
framework: scanResult.framework,
|
|
8
|
+
filesScanned: scanResult.scannedFiles,
|
|
9
|
+
hardcodedTexts: scanResult.detectedTexts.length,
|
|
10
|
+
localeKeysGenerated: new Set(scanResult.detectedTexts.map((d) => d.suggestedKey)).size,
|
|
11
|
+
unusedKeys: validationResult?.warnings.filter((w) => w.type === "unused-key").length || 0,
|
|
12
|
+
missingTranslations: validationResult?.errors.filter((e) => e.type === "missing-key").length || 0,
|
|
13
|
+
languages: [],
|
|
14
|
+
assets: {
|
|
15
|
+
totalAssets: scanResult.assets.length,
|
|
16
|
+
uploadedAssets: uploadedAssets.length,
|
|
17
|
+
replacedUrls,
|
|
18
|
+
legacyCdnUrls: scanResult.legacyCdnUrls.length
|
|
19
|
+
},
|
|
20
|
+
details: {
|
|
21
|
+
detectedTexts: scanResult.detectedTexts,
|
|
22
|
+
missingKeys: validationResult?.errors.filter((e) => e.type === "missing-key") || [],
|
|
23
|
+
unusedKeysList: validationResult?.warnings.filter((w) => w.type === "unused-key").map((w) => w.key) || [],
|
|
24
|
+
assets: uploadedAssets
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// src/html-reporter.ts
|
|
30
|
+
import * as fs from "fs";
|
|
31
|
+
import * as path from "path";
|
|
32
|
+
import { ensureDir } from "@ai-localize/shared";
|
|
33
|
+
function generateHtmlReport(report, outputPath) {
|
|
34
|
+
ensureDir(path.dirname(outputPath));
|
|
35
|
+
const html = `<!DOCTYPE html>
|
|
36
|
+
<html lang="en">
|
|
37
|
+
<head>
|
|
38
|
+
<meta charset="UTF-8">
|
|
39
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
40
|
+
<title>ai-localize Report - ${report.timestamp}</title>
|
|
41
|
+
<style>
|
|
42
|
+
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; max-width: 1200px; margin: 0 auto; padding: 24px; background: #f5f5f5; }
|
|
43
|
+
h1 { color: #1a1a2e; } h2 { color: #16213e; border-bottom: 2px solid #0f3460; padding-bottom: 8px; }
|
|
44
|
+
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin: 24px 0; }
|
|
45
|
+
.stat-card { background: white; border-radius: 8px; padding: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); text-align: center; }
|
|
46
|
+
.stat-number { font-size: 2.5rem; font-weight: 700; color: #0f3460; }
|
|
47
|
+
.stat-label { color: #666; font-size: 0.9rem; margin-top: 4px; }
|
|
48
|
+
.error { color: #e53e3e; } .warning { color: #d69e2e; } .success { color: #38a169; }
|
|
49
|
+
table { width: 100%; border-collapse: collapse; background: white; border-radius: 8px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
|
|
50
|
+
th { background: #0f3460; color: white; padding: 12px 16px; text-align: left; }
|
|
51
|
+
td { padding: 10px 16px; border-bottom: 1px solid #f0f0f0; }
|
|
52
|
+
tr:hover td { background: #f8f9ff; }
|
|
53
|
+
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 0.75rem; font-weight: 600; }
|
|
54
|
+
.badge-blue { background: #ebf4ff; color: #2b6cb0; }
|
|
55
|
+
.badge-red { background: #fff5f5; color: #c53030; }
|
|
56
|
+
.badge-green { background: #f0fff4; color: #276749; }
|
|
57
|
+
</style>
|
|
58
|
+
</head>
|
|
59
|
+
<body>
|
|
60
|
+
<h1>\u{1F310} ai-localize Report</h1>
|
|
61
|
+
<p><strong>Generated:</strong> ${report.timestamp} | <strong>Framework:</strong> ${report.framework} | <strong>Duration:</strong> ${report.duration}ms</p>
|
|
62
|
+
|
|
63
|
+
<div class="stats">
|
|
64
|
+
<div class="stat-card"><div class="stat-number">${report.filesScanned}</div><div class="stat-label">Files Scanned</div></div>
|
|
65
|
+
<div class="stat-card"><div class="stat-number error">${report.hardcodedTexts}</div><div class="stat-label">Hardcoded Texts</div></div>
|
|
66
|
+
<div class="stat-card"><div class="stat-number success">${report.localeKeysGenerated}</div><div class="stat-label">Keys Generated</div></div>
|
|
67
|
+
<div class="stat-card"><div class="stat-number warning">${report.unusedKeys}</div><div class="stat-label">Unused Keys</div></div>
|
|
68
|
+
<div class="stat-card"><div class="stat-number error">${report.missingTranslations}</div><div class="stat-label">Missing Translations</div></div>
|
|
69
|
+
<div class="stat-card"><div class="stat-number">${report.assets.uploadedAssets}</div><div class="stat-label">Assets Uploaded</div></div>
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
${report.details.detectedTexts.length > 0 ? `
|
|
73
|
+
<h2>Hardcoded Texts (${report.details.detectedTexts.length})</h2>
|
|
74
|
+
<table>
|
|
75
|
+
<thead><tr><th>File</th><th>Line</th><th>Text</th><th>Suggested Key</th><th>Context</th></tr></thead>
|
|
76
|
+
<tbody>
|
|
77
|
+
${report.details.detectedTexts.slice(0, 100).map((t) => `
|
|
78
|
+
<tr>
|
|
79
|
+
<td><code>${t.filePath.split("/").slice(-3).join("/")}</code></td>
|
|
80
|
+
<td>${t.line}</td>
|
|
81
|
+
<td>${t.text.slice(0, 60)}${t.text.length > 60 ? "..." : ""}</td>
|
|
82
|
+
<td><span class="badge badge-blue">${t.suggestedKey}</span></td>
|
|
83
|
+
<td><span class="badge badge-green">${t.context}</span></td>
|
|
84
|
+
</tr>`).join("")}
|
|
85
|
+
${report.details.detectedTexts.length > 100 ? `<tr><td colspan="5" style="text-align:center;color:#666">...and ${report.details.detectedTexts.length - 100} more</td></tr>` : ""}
|
|
86
|
+
</tbody>
|
|
87
|
+
</table>` : ""}
|
|
88
|
+
|
|
89
|
+
${report.details.missingKeys.length > 0 ? `
|
|
90
|
+
<h2>Missing Translations (${report.details.missingKeys.length})</h2>
|
|
91
|
+
<table>
|
|
92
|
+
<thead><tr><th>Key</th><th>Language</th><th>Message</th></tr></thead>
|
|
93
|
+
<tbody>
|
|
94
|
+
${report.details.missingKeys.map((e) => `<tr><td><code>${e.key}</code></td><td><span class="badge badge-red">${e.language || ""}</span></td><td>${e.message}</td></tr>`).join("")}
|
|
95
|
+
</tbody>
|
|
96
|
+
</table>` : ""}
|
|
97
|
+
|
|
98
|
+
</body>
|
|
99
|
+
</html>`;
|
|
100
|
+
fs.writeFileSync(outputPath, html, "utf-8");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/cli-reporter.ts
|
|
104
|
+
function printCliSummary(report) {
|
|
105
|
+
const lines = [
|
|
106
|
+
"",
|
|
107
|
+
"\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557",
|
|
108
|
+
"\u2551 ai-localize-core Report Summary \u2551",
|
|
109
|
+
"\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D",
|
|
110
|
+
"",
|
|
111
|
+
` Framework : ${report.framework}`,
|
|
112
|
+
` Timestamp : ${report.timestamp}`,
|
|
113
|
+
` Duration : ${report.duration}ms`,
|
|
114
|
+
"",
|
|
115
|
+
" \u2500\u2500\u2500 Localization \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500",
|
|
116
|
+
` Files Scanned : ${report.filesScanned}`,
|
|
117
|
+
` Hardcoded Texts : ${report.hardcodedTexts}`,
|
|
118
|
+
` Keys Generated : ${report.localeKeysGenerated}`,
|
|
119
|
+
` Missing Trans. : ${report.missingTranslations}`,
|
|
120
|
+
` Unused Keys : ${report.unusedKeys}`,
|
|
121
|
+
"",
|
|
122
|
+
" \u2500\u2500\u2500 Assets / CDN \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500",
|
|
123
|
+
` Total Assets : ${report.assets.totalAssets}`,
|
|
124
|
+
` Uploaded Assets : ${report.assets.uploadedAssets}`,
|
|
125
|
+
` Replaced URLs : ${report.assets.replacedUrls}`,
|
|
126
|
+
`Legacy CDN URLs : ${report.assets.legacyCdnUrls}`,
|
|
127
|
+
""
|
|
128
|
+
];
|
|
129
|
+
console.log(lines.join("\n"));
|
|
130
|
+
}
|
|
131
|
+
export {
|
|
132
|
+
buildReport,
|
|
133
|
+
generateHtmlReport,
|
|
134
|
+
printCliSummary
|
|
135
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ai-localize-reporting",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Localization scan reporting: JSON, HTML, CLI summary",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"ai-localize-shared": "1.0.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"tsup": "^8.0.1",
|
|
20
|
+
"typescript": "^5.3.3",
|
|
21
|
+
"vitest": "^1.2.1"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
29
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
30
|
+
"typecheck": "tsc --noEmit",
|
|
31
|
+
"test": "vitest run",
|
|
32
|
+
"lint": "eslint src --ext .ts"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Report } from "@ai-localize/shared";
|
|
2
|
+
|
|
3
|
+
export function printCliSummary(report: Report): void {
|
|
4
|
+
const lines = [
|
|
5
|
+
"",
|
|
6
|
+
"╔════════════════════════════════════════════════════╗",
|
|
7
|
+
"║ ai-localize-core Report Summary ║",
|
|
8
|
+
"╚════════════════════════════════════════════════════╝",
|
|
9
|
+
"",
|
|
10
|
+
` Framework : ${report.framework}`,
|
|
11
|
+
` Timestamp : ${report.timestamp}`,
|
|
12
|
+
` Duration : ${report.duration}ms`,
|
|
13
|
+
"",
|
|
14
|
+
" ─── Localization ────────────────────────────────",
|
|
15
|
+
` Files Scanned : ${report.filesScanned}`,
|
|
16
|
+
` Hardcoded Texts : ${report.hardcodedTexts}`,
|
|
17
|
+
` Keys Generated : ${report.localeKeysGenerated}`,
|
|
18
|
+
` Missing Trans. : ${report.missingTranslations}`,
|
|
19
|
+
` Unused Keys : ${report.unusedKeys}`,
|
|
20
|
+
"",
|
|
21
|
+
" ─── Assets / CDN ────────────────────────────────",
|
|
22
|
+
` Total Assets : ${report.assets.totalAssets}`,
|
|
23
|
+
` Uploaded Assets : ${report.assets.uploadedAssets}`,
|
|
24
|
+
` Replaced URLs : ${report.assets.replacedUrls}`,
|
|
25
|
+
`Legacy CDN URLs : ${report.assets.legacyCdnUrls}`,
|
|
26
|
+
"",
|
|
27
|
+
];
|
|
28
|
+
console.log(lines.join('\n'));
|
|
29
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Report } from "@ai-localize/shared";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import { ensureDir } from "@ai-localize/shared";
|
|
5
|
+
|
|
6
|
+
export function generateHtmlReport(report: Report, outputPath: string): void {
|
|
7
|
+
ensureDir(path.dirname(outputPath));
|
|
8
|
+
const html = `<!DOCTYPE html>
|
|
9
|
+
<html lang="en">
|
|
10
|
+
<head>
|
|
11
|
+
<meta charset="UTF-8">
|
|
12
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
13
|
+
<title>ai-localize Report - ${report.timestamp}</title>
|
|
14
|
+
<style>
|
|
15
|
+
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; max-width: 1200px; margin: 0 auto; padding: 24px; background: #f5f5f5; }
|
|
16
|
+
h1 { color: #1a1a2e; } h2 { color: #16213e; border-bottom: 2px solid #0f3460; padding-bottom: 8px; }
|
|
17
|
+
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin: 24px 0; }
|
|
18
|
+
.stat-card { background: white; border-radius: 8px; padding: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); text-align: center; }
|
|
19
|
+
.stat-number { font-size: 2.5rem; font-weight: 700; color: #0f3460; }
|
|
20
|
+
.stat-label { color: #666; font-size: 0.9rem; margin-top: 4px; }
|
|
21
|
+
.error { color: #e53e3e; } .warning { color: #d69e2e; } .success { color: #38a169; }
|
|
22
|
+
table { width: 100%; border-collapse: collapse; background: white; border-radius: 8px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
|
|
23
|
+
th { background: #0f3460; color: white; padding: 12px 16px; text-align: left; }
|
|
24
|
+
td { padding: 10px 16px; border-bottom: 1px solid #f0f0f0; }
|
|
25
|
+
tr:hover td { background: #f8f9ff; }
|
|
26
|
+
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 0.75rem; font-weight: 600; }
|
|
27
|
+
.badge-blue { background: #ebf4ff; color: #2b6cb0; }
|
|
28
|
+
.badge-red { background: #fff5f5; color: #c53030; }
|
|
29
|
+
.badge-green { background: #f0fff4; color: #276749; }
|
|
30
|
+
</style>
|
|
31
|
+
</head>
|
|
32
|
+
<body>
|
|
33
|
+
<h1>🌐 ai-localize Report</h1>
|
|
34
|
+
<p><strong>Generated:</strong> ${report.timestamp} | <strong>Framework:</strong> ${report.framework} | <strong>Duration:</strong> ${report.duration}ms</p>
|
|
35
|
+
|
|
36
|
+
<div class="stats">
|
|
37
|
+
<div class="stat-card"><div class="stat-number">${report.filesScanned}</div><div class="stat-label">Files Scanned</div></div>
|
|
38
|
+
<div class="stat-card"><div class="stat-number error">${report.hardcodedTexts}</div><div class="stat-label">Hardcoded Texts</div></div>
|
|
39
|
+
<div class="stat-card"><div class="stat-number success">${report.localeKeysGenerated}</div><div class="stat-label">Keys Generated</div></div>
|
|
40
|
+
<div class="stat-card"><div class="stat-number warning">${report.unusedKeys}</div><div class="stat-label">Unused Keys</div></div>
|
|
41
|
+
<div class="stat-card"><div class="stat-number error">${report.missingTranslations}</div><div class="stat-label">Missing Translations</div></div>
|
|
42
|
+
<div class="stat-card"><div class="stat-number">${report.assets.uploadedAssets}</div><div class="stat-label">Assets Uploaded</div></div>
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
${report.details.detectedTexts.length > 0 ? `
|
|
46
|
+
<h2>Hardcoded Texts (${report.details.detectedTexts.length})</h2>
|
|
47
|
+
<table>
|
|
48
|
+
<thead><tr><th>File</th><th>Line</th><th>Text</th><th>Suggested Key</th><th>Context</th></tr></thead>
|
|
49
|
+
<tbody>
|
|
50
|
+
${report.details.detectedTexts.slice(0, 100).map((t) => `
|
|
51
|
+
<tr>
|
|
52
|
+
<td><code>${t.filePath.split("/").slice(-3).join("/")}</code></td>
|
|
53
|
+
<td>${t.line}</td>
|
|
54
|
+
<td>${t.text.slice(0, 60)}${t.text.length > 60 ? "..." : ""}</td>
|
|
55
|
+
<td><span class="badge badge-blue">${t.suggestedKey}</span></td>
|
|
56
|
+
<td><span class="badge badge-green">${t.context}</span></td>
|
|
57
|
+
</tr>`).join("")}
|
|
58
|
+
${report.details.detectedTexts.length > 100 ? `<tr><td colspan="5" style="text-align:center;color:#666">...and ${report.details.detectedTexts.length - 100} more</td></tr>` : ""}
|
|
59
|
+
</tbody>
|
|
60
|
+
</table>` : ""}
|
|
61
|
+
|
|
62
|
+
${report.details.missingKeys.length > 0 ? `
|
|
63
|
+
<h2>Missing Translations (${report.details.missingKeys.length})</h2>
|
|
64
|
+
<table>
|
|
65
|
+
<thead><tr><th>Key</th><th>Language</th><th>Message</th></tr></thead>
|
|
66
|
+
<tbody>
|
|
67
|
+
${report.details.missingKeys.map((e) => `<tr><td><code>${e.key}</code></td><td><span class="badge badge-red">${e.language || ""}</span></td><td>${e.message}</td></tr>`).join("")}
|
|
68
|
+
</tbody>
|
|
69
|
+
</table>` : ""}
|
|
70
|
+
|
|
71
|
+
</body>
|
|
72
|
+
</html>`;
|
|
73
|
+
fs.writeFileSync(outputPath, html, "utf-8");
|
|
74
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ScanResult, ValidationResult, Report, CloudFrontAsset } from "@ai-localize/shared";
|
|
2
|
+
|
|
3
|
+
export interface ReportInput {
|
|
4
|
+
scanResult: ScanResult;
|
|
5
|
+
validationResult?: ValidationResult;
|
|
6
|
+
uploadedAssets?: CloudFrontAsset[];
|
|
7
|
+
replacedUrls?: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function buildReport(input: ReportInput): Report {
|
|
11
|
+
const { scanResult, validationResult, uploadedAssets = [], replacedUrls = 0 } = input;
|
|
12
|
+
return {
|
|
13
|
+
timestamp: new Date().toISOString(),
|
|
14
|
+
duration: scanResult.duration,
|
|
15
|
+
framework: scanResult.framework,
|
|
16
|
+
filesScanned: scanResult.scannedFiles,
|
|
17
|
+
hardcodedTexts: scanResult.detectedTexts.length,
|
|
18
|
+
localeKeysGenerated: new Set(scanResult.detectedTexts.map((d) => d.suggestedKey)).size,
|
|
19
|
+
unusedKeys: validationResult?.warnings.filter((w) => w.type === "unused-key").length || 0,
|
|
20
|
+
missingTranslations: validationResult?.errors.filter((e) => e.type === "missing-key").length || 0,
|
|
21
|
+
languages: [],
|
|
22
|
+
assets: {
|
|
23
|
+
totalAssets: scanResult.assets.length,
|
|
24
|
+
uploadedAssets: uploadedAssets.length,
|
|
25
|
+
replacedUrls,
|
|
26
|
+
legacyCdnUrls: scanResult.legacyCdnUrls.length,
|
|
27
|
+
},
|
|
28
|
+
details: {
|
|
29
|
+
detectedTexts: scanResult.detectedTexts,
|
|
30
|
+
missingKeys: validationResult?.errors.filter((e) => e.type === "missing-key") || [],
|
|
31
|
+
unusedKeysList: validationResult?.warnings.filter((w) => w.type === "unused-key").map((w) => w.key) || [],
|
|
32
|
+
assets: uploadedAssets,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|