siluzan-tso-cli 1.1.68-beta.2 → 1.1.68-beta.3
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/README.md +1 -1
- package/dist/index.js +799 -457
- package/dist/skill/_meta.json +2 -2
- package/dist/skill/assets/website-diagnosis-rules.md +1 -0
- package/dist/skill/assets/website-diagnosis-tracking.md +101 -0
- package/dist/skill/references/analytics/market-analysis-guide.md +2 -2
- package/dist/skill/references/analytics/website-diagnosis-guide.md +23 -23
- package/dist/skill/references/core/playbooks.md +7 -6
- package/dist/skill/references/report-templates/website-diagnosis-report.md +14 -8
- package/dist/skill/report-templates/website-diagnosis-report.html +133 -5
- package/dist/skill/report-templates/website-diagnosis-report.md +14 -8
- package/dist/skill/scripts/install.ps1 +1 -1
- package/dist/skill/scripts/install.sh +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8504,7 +8504,34 @@ var init_phrases_en = __esm({
|
|
|
8504
8504
|
\u5E7F\u544A\u63A2\u7D22: "Ad exploration",
|
|
8505
8505
|
\u8BE2\u76D8\u4FA7\u8865\u5145: "Lead-side extras",
|
|
8506
8506
|
\u76EE\u6807\u5206\u5C42: "Goal tiers",
|
|
8507
|
-
\u8C22\u8C22: "Thank you"
|
|
8507
|
+
\u8C22\u8C22: "Thank you",
|
|
8508
|
+
"\u6D4F\u89C8\u5668\u6253\u5F00\u9875\u9762\u540E\u8BB0\u5F55\u7684 GTM \u5BB9\u5668\u4E0E GA4 \u8861\u91CF ID\u3002\u9759\u6001 HTML \u4E0D\u80FD\u4EE3\u66FF\u8FD9\u6B21\u68C0\u6D4B\u3002": "GTM containers and GA4 measurement IDs recorded after opening the page in a browser. Static HTML cannot replace this check.",
|
|
8509
|
+
"\u6D4F\u89C8\u5668\u6CA1\u80FD\u6253\u5F00\u8FD9\u4E2A\u7F51\u7AD9\uFF0C\u672C\u6B21\u6CA1\u6709 GA / GTM \u5B9E\u8BBF\u7ED3\u679C\u3002": "The browser could not open this site, so there is no GA / GTM visit result.",
|
|
8510
|
+
"\u672C\u6B21\u62A5\u544A\u672A\u9644\u5E26 GA \u4E0E GTM \u5B9E\u8BBF JSON\u3002\u8BF7\u7528\u6D4F\u89C8\u5668\u6253\u5F00\u7F51\u7AD9\u540E\uFF0C\u6309\u56FA\u5B9A\u683C\u5F0F\u5199\u5165\u518D\u91CD\u65B0 render\u3002": "This report has no GA and GTM visit JSON. Open the site in a browser, write the fixed JSON, and render again.",
|
|
8511
|
+
"GA \u4E0E GTM \u5B9E\u8BBF\u68C0\u6D4B": "GA and GTM browser check",
|
|
8512
|
+
"m5i4\uFF08\u8DDF\u8E2A\u4E0E\u5206\u6790\uFF09\u548C ci2 \u987B\u5F15\u7528\u672C\u8282\u7684 ID\u3002\u672C\u8282\u4E0D\u6539\u516D\u6A21\u5757\u603B\u5206\u3002": "m5i4 (tracking) and ci2 must cite the IDs in this section. This section does not change the six-module score.",
|
|
8513
|
+
"\u65E7\u7248 Universal Analytics": "Legacy Universal Analytics",
|
|
8514
|
+
\u9875\u9762\u811A\u672C\u76F4\u63A5\u52A0\u8F7D: "Loaded by a page script",
|
|
8515
|
+
"\u53EA\u901A\u8FC7 GTM \u52A0\u8F7D": "Loaded only through GTM",
|
|
8516
|
+
"\u9875\u9762\u811A\u672C\u548C GTM \u90FD\u6709": "Loaded by both the page script and GTM",
|
|
8517
|
+
"\u6CA1\u6709\u52A0\u8F7D GA": "GA did not load",
|
|
8518
|
+
"\u6CA1\u6709\u5217\u51FA ID": "No ID listed",
|
|
8519
|
+
\u5DF2\u68C0\u6D4B\u5230\u6807\u7B7E: "Tag found",
|
|
8520
|
+
\u672A\u68C0\u6D4B\u5230\u6807\u7B7E: "Tag not found",
|
|
8521
|
+
\u5B9E\u8BBF\u8BC1\u636E: "Visit evidence",
|
|
8522
|
+
\u62BD\u67E5\u8FC7\u7684\u9875\u9762: "Pages checked",
|
|
8523
|
+
\u8BC1\u636E\u7C7B\u578B: "Evidence type",
|
|
8524
|
+
\u770B\u5230\u4E86\u4EC0\u4E48: "What was seen",
|
|
8525
|
+
\u811A\u672C\u5730\u5740: "Script URL",
|
|
8526
|
+
\u6D4F\u89C8\u5668\u8BF7\u6C42: "Browser request",
|
|
8527
|
+
\u6570\u636E\u5C42: "Data layer",
|
|
8528
|
+
"noscript \u7247\u6BB5": "noscript snippet",
|
|
8529
|
+
\u9875\u9762\u5730\u5740: "Page URL",
|
|
8530
|
+
\u5B9E\u8BBF\u9875\u9762: "Page visited",
|
|
8531
|
+
\u5B9E\u8BBF\u65F6\u95F4: "Visited at",
|
|
8532
|
+
\u6807\u7B7E\u4ECE\u54EA\u52A0\u8F7D: "How the tag loaded",
|
|
8533
|
+
"GTM \u5BB9\u5668": "GTM container",
|
|
8534
|
+
"GA4 \u8861\u91CF ID": "GA4 measurement ID"
|
|
8508
8535
|
};
|
|
8509
8536
|
}
|
|
8510
8537
|
});
|
|
@@ -105110,22 +105137,22 @@ var init_demand_gen_report_content = __esm({
|
|
|
105110
105137
|
});
|
|
105111
105138
|
|
|
105112
105139
|
// src/commands/google-analysis/demand-gen-render.ts
|
|
105113
|
-
import
|
|
105140
|
+
import fs31 from "fs";
|
|
105114
105141
|
import fsPromises2 from "fs/promises";
|
|
105115
|
-
import
|
|
105142
|
+
import path36 from "path";
|
|
105116
105143
|
import { fileURLToPath as fileURLToPath9 } from "url";
|
|
105117
105144
|
function resolveSkillTemplatePath3(basename13) {
|
|
105118
|
-
const dir =
|
|
105145
|
+
const dir = path36.dirname(fileURLToPath9(import.meta.url));
|
|
105119
105146
|
const candidates = [
|
|
105120
|
-
|
|
105121
|
-
|
|
105122
|
-
|
|
105123
|
-
|
|
105147
|
+
path36.join(dir, "skill", "report-templates", basename13),
|
|
105148
|
+
path36.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
|
|
105149
|
+
path36.join(dir, "..", "..", "..", "assets", "siluzan-ads", "report-templates", basename13),
|
|
105150
|
+
path36.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
|
|
105124
105151
|
];
|
|
105125
105152
|
for (const candidate of candidates) {
|
|
105126
|
-
if (
|
|
105153
|
+
if (fs31.existsSync(candidate)) return candidate;
|
|
105127
105154
|
}
|
|
105128
|
-
return
|
|
105155
|
+
return path36.join(dir, "skill", "report-templates", basename13);
|
|
105129
105156
|
}
|
|
105130
105157
|
function demandGenReportTemplatePath() {
|
|
105131
105158
|
return resolveSkillTemplatePath3(TEMPLATE_BASENAME);
|
|
@@ -105146,7 +105173,7 @@ function injectDemandGenReport(html, payload) {
|
|
|
105146
105173
|
return html.replace(DEMAND_GEN_INJECT_MARKER, `window.__DEMAND_GEN_REPORT__ = ${json};`);
|
|
105147
105174
|
}
|
|
105148
105175
|
async function runDemandGenRender(opts) {
|
|
105149
|
-
const dataPath =
|
|
105176
|
+
const dataPath = path36.resolve(opts.dataFile);
|
|
105150
105177
|
const data = asDemandGenReport(await readJsonFile2(dataPath));
|
|
105151
105178
|
if (opts.lang?.trim()) data.meta.lang = opts.lang.trim();
|
|
105152
105179
|
const check = validateDemandGenReport(data);
|
|
@@ -105161,10 +105188,10 @@ ${formatDemandGenReportErrors(check)}`);
|
|
|
105161
105188
|
} catch {
|
|
105162
105189
|
throw new Error(`\u672A\u627E\u5230\u62A5\u544A\u6A21\u677F\uFF1A${templatePath}\u3002\u8BF7\u5148\u6267\u884C npm run build`);
|
|
105163
105190
|
}
|
|
105164
|
-
const outPath =
|
|
105165
|
-
opts.out ??
|
|
105191
|
+
const outPath = path36.resolve(
|
|
105192
|
+
opts.out ?? path36.join(path36.dirname(dataPath), "demand-gen-analysis-report.html")
|
|
105166
105193
|
);
|
|
105167
|
-
await fsPromises2.mkdir(
|
|
105194
|
+
await fsPromises2.mkdir(path36.dirname(outPath), { recursive: true });
|
|
105168
105195
|
await fsPromises2.writeFile(outPath, injectDemandGenReport(html, data), "utf8");
|
|
105169
105196
|
console.log(`
|
|
105170
105197
|
\u2705 Demand Gen \u6295\u653E\u6570\u636E\u5206\u6790 HTML \u5DF2\u751F\u6210\uFF1A${outPath}
|
|
@@ -105307,8 +105334,8 @@ var init_okki_display = __esm({
|
|
|
105307
105334
|
});
|
|
105308
105335
|
|
|
105309
105336
|
// src/commands/google-analysis/merge-snapshot.ts
|
|
105310
|
-
import * as
|
|
105311
|
-
import * as
|
|
105337
|
+
import * as fs32 from "fs/promises";
|
|
105338
|
+
import * as path37 from "path";
|
|
105312
105339
|
function asRecord21(value) {
|
|
105313
105340
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
105314
105341
|
return value;
|
|
@@ -105326,7 +105353,7 @@ async function readManifest(snapshotDir, accountId) {
|
|
|
105326
105353
|
const candidates = [];
|
|
105327
105354
|
if (accountId) candidates.push(googleAnalysisManifestFile(accountId));
|
|
105328
105355
|
try {
|
|
105329
|
-
const entries = await
|
|
105356
|
+
const entries = await fs32.readdir(snapshotDir);
|
|
105330
105357
|
const manifestNames = entries.filter((n) => n.startsWith("manifest") && n.endsWith(".json"));
|
|
105331
105358
|
for (const name2 of manifestNames) {
|
|
105332
105359
|
if (!candidates.includes(name2)) candidates.push(name2);
|
|
@@ -105335,7 +105362,7 @@ async function readManifest(snapshotDir, accountId) {
|
|
|
105335
105362
|
}
|
|
105336
105363
|
for (const name2 of candidates) {
|
|
105337
105364
|
try {
|
|
105338
|
-
const raw = await
|
|
105365
|
+
const raw = await fs32.readFile(path37.join(snapshotDir, name2), "utf8");
|
|
105339
105366
|
const parsed = JSON.parse(raw);
|
|
105340
105367
|
if (Array.isArray(parsed.artifacts) && parsed.artifacts.length > 0) return parsed;
|
|
105341
105368
|
} catch {
|
|
@@ -105345,7 +105372,7 @@ async function readManifest(snapshotDir, accountId) {
|
|
|
105345
105372
|
}
|
|
105346
105373
|
async function loadSectionFile(snapshotDir, file) {
|
|
105347
105374
|
try {
|
|
105348
|
-
const raw = await
|
|
105375
|
+
const raw = await fs32.readFile(path37.join(snapshotDir, file), "utf8");
|
|
105349
105376
|
const parsed = JSON.parse(raw);
|
|
105350
105377
|
if (parsed && typeof parsed === "object") return parsed;
|
|
105351
105378
|
return null;
|
|
@@ -105414,7 +105441,7 @@ async function recoverMissingReportSections(sectionMap, absDir, accountId, prefe
|
|
|
105414
105441
|
if (!accountId) return;
|
|
105415
105442
|
let entries;
|
|
105416
105443
|
try {
|
|
105417
|
-
entries = await
|
|
105444
|
+
entries = await fs32.readdir(absDir);
|
|
105418
105445
|
} catch {
|
|
105419
105446
|
return;
|
|
105420
105447
|
}
|
|
@@ -105486,7 +105513,7 @@ function sumCampaignRowsToPeriodKpis(rows) {
|
|
|
105486
105513
|
};
|
|
105487
105514
|
}
|
|
105488
105515
|
async function mergeGoogleAnalysisSnapshotIntoReport(payload, snapshotDir) {
|
|
105489
|
-
const absDir =
|
|
105516
|
+
const absDir = path37.resolve(snapshotDir);
|
|
105490
105517
|
const metaAccountId = typeof asRecord21(payload.meta)?.accountId === "string" ? asRecord21(payload.meta)?.accountId : void 0;
|
|
105491
105518
|
const manifest = await readManifest(snapshotDir, metaAccountId);
|
|
105492
105519
|
if (!manifest) {
|
|
@@ -105852,8 +105879,8 @@ var init_okki_report_content = __esm({
|
|
|
105852
105879
|
});
|
|
105853
105880
|
|
|
105854
105881
|
// src/commands/google-analysis/okki-merge-snapshot.ts
|
|
105855
|
-
import * as
|
|
105856
|
-
import * as
|
|
105882
|
+
import * as fs33 from "fs/promises";
|
|
105883
|
+
import * as path38 from "path";
|
|
105857
105884
|
function num5(value) {
|
|
105858
105885
|
const n = Number(value);
|
|
105859
105886
|
return Number.isFinite(n) ? n : void 0;
|
|
@@ -105879,7 +105906,7 @@ async function readManifest2(snapshotDir, accountId) {
|
|
|
105879
105906
|
const candidates = [];
|
|
105880
105907
|
if (accountId) candidates.push(googleAnalysisManifestFile(accountId));
|
|
105881
105908
|
try {
|
|
105882
|
-
const entries = await
|
|
105909
|
+
const entries = await fs33.readdir(snapshotDir);
|
|
105883
105910
|
for (const name2 of entries.filter((n) => n.startsWith("manifest") && n.endsWith(".json"))) {
|
|
105884
105911
|
if (!candidates.includes(name2)) candidates.push(name2);
|
|
105885
105912
|
}
|
|
@@ -105887,7 +105914,7 @@ async function readManifest2(snapshotDir, accountId) {
|
|
|
105887
105914
|
}
|
|
105888
105915
|
for (const name2 of candidates) {
|
|
105889
105916
|
try {
|
|
105890
|
-
const raw = await
|
|
105917
|
+
const raw = await fs33.readFile(path38.join(snapshotDir, name2), "utf8");
|
|
105891
105918
|
const parsed = JSON.parse(raw);
|
|
105892
105919
|
if (Array.isArray(parsed.artifacts) && parsed.artifacts.length > 0) return parsed;
|
|
105893
105920
|
} catch {
|
|
@@ -105897,7 +105924,7 @@ async function readManifest2(snapshotDir, accountId) {
|
|
|
105897
105924
|
}
|
|
105898
105925
|
async function loadSectionFile2(snapshotDir, file) {
|
|
105899
105926
|
try {
|
|
105900
|
-
const raw = await
|
|
105927
|
+
const raw = await fs33.readFile(path38.join(snapshotDir, file), "utf8");
|
|
105901
105928
|
const parsed = JSON.parse(raw);
|
|
105902
105929
|
if (parsed && typeof parsed === "object") return parsed;
|
|
105903
105930
|
return null;
|
|
@@ -105906,7 +105933,7 @@ async function loadSectionFile2(snapshotDir, file) {
|
|
|
105906
105933
|
}
|
|
105907
105934
|
}
|
|
105908
105935
|
async function mergeOkkiSnapshotIntoReport(payload, snapshotDir) {
|
|
105909
|
-
const absDir =
|
|
105936
|
+
const absDir = path38.resolve(snapshotDir);
|
|
105910
105937
|
const metaAccountId = typeof asRecord22(payload.meta)?.accountId === "string" ? asRecord22(payload.meta)?.accountId : void 0;
|
|
105911
105938
|
const manifest = await readManifest2(absDir, metaAccountId);
|
|
105912
105939
|
if (!manifest) {
|
|
@@ -105923,7 +105950,7 @@ async function mergeOkkiSnapshotIntoReport(payload, snapshotDir) {
|
|
|
105923
105950
|
if (accountId) {
|
|
105924
105951
|
let entries = [];
|
|
105925
105952
|
try {
|
|
105926
|
-
entries = await
|
|
105953
|
+
entries = await fs33.readdir(absDir);
|
|
105927
105954
|
} catch {
|
|
105928
105955
|
entries = [];
|
|
105929
105956
|
}
|
|
@@ -106446,10 +106473,10 @@ var init_okki_render_excel = __esm({
|
|
|
106446
106473
|
});
|
|
106447
106474
|
|
|
106448
106475
|
// src/commands/google-analysis/okki-render-report.ts
|
|
106449
|
-
import
|
|
106450
|
-
import
|
|
106476
|
+
import fs34 from "fs/promises";
|
|
106477
|
+
import path39 from "path";
|
|
106451
106478
|
async function readJsonFile3(filePath) {
|
|
106452
|
-
const text4 = await
|
|
106479
|
+
const text4 = await fs34.readFile(filePath, "utf8");
|
|
106453
106480
|
try {
|
|
106454
106481
|
return JSON.parse(text4);
|
|
106455
106482
|
} catch {
|
|
@@ -106463,7 +106490,7 @@ function asPayload(value) {
|
|
|
106463
106490
|
throw new Error("\u62A5\u544A\u6570\u636E\u987B\u4E3A JSON \u5BF9\u8C61");
|
|
106464
106491
|
}
|
|
106465
106492
|
async function runGoogleAnalysisOkkiRender(opts) {
|
|
106466
|
-
const dataPath =
|
|
106493
|
+
const dataPath = path39.resolve(opts.dataFile);
|
|
106467
106494
|
const snapshotDir = opts.snapshotDir?.trim();
|
|
106468
106495
|
if (!snapshotDir) {
|
|
106469
106496
|
console.error("\n\u274C okki-render \u5FC5\u987B\u4F20 --snapshot-dir\uFF08google-analysis --json-out \u76EE\u5F55\uFF09\n");
|
|
@@ -106471,7 +106498,7 @@ async function runGoogleAnalysisOkkiRender(opts) {
|
|
|
106471
106498
|
}
|
|
106472
106499
|
let data = asPayload(await readJsonFile3(dataPath));
|
|
106473
106500
|
try {
|
|
106474
|
-
data = await mergeOkkiSnapshotIntoReport(data,
|
|
106501
|
+
data = await mergeOkkiSnapshotIntoReport(data, path39.resolve(snapshotDir));
|
|
106475
106502
|
} catch (err) {
|
|
106476
106503
|
console.error(`
|
|
106477
106504
|
\u274C ${err instanceof Error ? err.message : String(err)}
|
|
@@ -106491,10 +106518,10 @@ async function runGoogleAnalysisOkkiRender(opts) {
|
|
|
106491
106518
|
);
|
|
106492
106519
|
process.exit(1);
|
|
106493
106520
|
}
|
|
106494
|
-
const outPath =
|
|
106495
|
-
opts.out ??
|
|
106521
|
+
const outPath = path39.resolve(
|
|
106522
|
+
opts.out ?? path39.join(path39.dirname(dataPath), "okki-weekly-report.xlsx")
|
|
106496
106523
|
);
|
|
106497
|
-
await
|
|
106524
|
+
await fs34.mkdir(path39.dirname(outPath), { recursive: true });
|
|
106498
106525
|
writeOkkiWeeklyExcel(outPath, data, lang);
|
|
106499
106526
|
console.log(`
|
|
106500
106527
|
\u2705 OKKI \u5468\u62A5\u5DF2\u751F\u6210\uFF1A${outPath}
|
|
@@ -106667,19 +106694,19 @@ var init_report_content = __esm({
|
|
|
106667
106694
|
});
|
|
106668
106695
|
|
|
106669
106696
|
// src/commands/google-analysis/render-report.ts
|
|
106670
|
-
import
|
|
106697
|
+
import fs35 from "fs";
|
|
106671
106698
|
import fsPromises3 from "fs/promises";
|
|
106672
|
-
import
|
|
106699
|
+
import path40 from "path";
|
|
106673
106700
|
import { fileURLToPath as fileURLToPath10 } from "url";
|
|
106674
106701
|
function resolveSkillTemplatePath4(basename13) {
|
|
106675
|
-
const dir =
|
|
106702
|
+
const dir = path40.dirname(fileURLToPath10(import.meta.url));
|
|
106676
106703
|
const candidates = [
|
|
106677
|
-
|
|
106678
|
-
|
|
106679
|
-
|
|
106704
|
+
path40.join(dir, "skill", "report-templates", basename13),
|
|
106705
|
+
path40.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
|
|
106706
|
+
path40.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
|
|
106680
106707
|
];
|
|
106681
106708
|
for (const p of candidates) {
|
|
106682
|
-
if (
|
|
106709
|
+
if (fs35.existsSync(p)) return p;
|
|
106683
106710
|
}
|
|
106684
106711
|
return candidates[0];
|
|
106685
106712
|
}
|
|
@@ -106709,10 +106736,10 @@ function injectReportData2(html, payload, lang) {
|
|
|
106709
106736
|
return localized.replace(INJECT_MARKER, `window.__GOOGLE_PERIOD_REPORT__ = ${json};`);
|
|
106710
106737
|
}
|
|
106711
106738
|
async function runGoogleAnalysisRender(opts) {
|
|
106712
|
-
const dataPath =
|
|
106739
|
+
const dataPath = path40.resolve(opts.dataFile);
|
|
106713
106740
|
let data = asRecord24(await readJsonFile4(dataPath));
|
|
106714
106741
|
if (opts.snapshotDir?.trim()) {
|
|
106715
|
-
data = await mergeGoogleAnalysisSnapshotIntoReport(data,
|
|
106742
|
+
data = await mergeGoogleAnalysisSnapshotIntoReport(data, path40.resolve(opts.snapshotDir));
|
|
106716
106743
|
}
|
|
106717
106744
|
const lang = readReportLangOrExit({ flag: opts.lang, meta: data.meta });
|
|
106718
106745
|
const contentCheck = validateGooglePeriodReportContent(data);
|
|
@@ -106739,10 +106766,10 @@ async function runGoogleAnalysisRender(opts) {
|
|
|
106739
106766
|
`);
|
|
106740
106767
|
process.exit(1);
|
|
106741
106768
|
}
|
|
106742
|
-
const outPath =
|
|
106743
|
-
opts.out ??
|
|
106769
|
+
const outPath = path40.resolve(
|
|
106770
|
+
opts.out ?? path40.join(path40.dirname(dataPath), "google-period-report.html")
|
|
106744
106771
|
);
|
|
106745
|
-
const outDir =
|
|
106772
|
+
const outDir = path40.dirname(outPath);
|
|
106746
106773
|
await fsPromises3.mkdir(outDir, { recursive: true });
|
|
106747
106774
|
await fsPromises3.writeFile(outPath, injectReportData2(html, data, lang), "utf8");
|
|
106748
106775
|
const { stats } = contentCheck;
|
|
@@ -106774,8 +106801,8 @@ var init_render_report = __esm({
|
|
|
106774
106801
|
|
|
106775
106802
|
// src/utils/batch-runner.ts
|
|
106776
106803
|
import { performance as performance2 } from "perf_hooks";
|
|
106777
|
-
import * as
|
|
106778
|
-
import * as
|
|
106804
|
+
import * as path41 from "path";
|
|
106805
|
+
import * as fs36 from "fs/promises";
|
|
106779
106806
|
async function runPool(items3, concurrencyRef, worker, signal) {
|
|
106780
106807
|
let cursor = 0;
|
|
106781
106808
|
const launch = () => {
|
|
@@ -106914,7 +106941,7 @@ async function runBatch(opts) {
|
|
|
106914
106941
|
}
|
|
106915
106942
|
const inner = {
|
|
106916
106943
|
...emptyProgress(
|
|
106917
|
-
opts.paths.runDir.split(
|
|
106944
|
+
opts.paths.runDir.split(path41.sep).pop() ?? "run",
|
|
106918
106945
|
allTasks.length,
|
|
106919
106946
|
opts.accountConcurrency,
|
|
106920
106947
|
opts.sectionConcurrency
|
|
@@ -107039,7 +107066,7 @@ async function runBatch(opts) {
|
|
|
107039
107066
|
signal: aborterToken.signal
|
|
107040
107067
|
});
|
|
107041
107068
|
await writer({
|
|
107042
|
-
snapshotDir:
|
|
107069
|
+
snapshotDir: path41.join(opts.paths.resultsDir, sanitizeAccountSegment(task.accountId)),
|
|
107043
107070
|
section: task.section,
|
|
107044
107071
|
accountId: task.accountId,
|
|
107045
107072
|
dateRange: result.dateRange,
|
|
@@ -107136,7 +107163,7 @@ async function runBatch(opts) {
|
|
|
107136
107163
|
};
|
|
107137
107164
|
}
|
|
107138
107165
|
async function writeTaskError(paths, errorsDir, task, err, cls) {
|
|
107139
|
-
const file =
|
|
107166
|
+
const file = path41.join(errorsDir, `${sanitizeSection(task.section)}.error.json`);
|
|
107140
107167
|
const payload = {
|
|
107141
107168
|
schemaVersion: 1,
|
|
107142
107169
|
taskId: task.id,
|
|
@@ -107182,10 +107209,10 @@ async function persistRunMetadata(input) {
|
|
|
107182
107209
|
accountsTotal: input.accounts.length,
|
|
107183
107210
|
invocation: input.invocation
|
|
107184
107211
|
};
|
|
107185
|
-
await
|
|
107186
|
-
await
|
|
107187
|
-
await
|
|
107188
|
-
await
|
|
107212
|
+
await fs36.mkdir(paths.runDir, { recursive: true });
|
|
107213
|
+
await fs36.mkdir(paths.stateDir, { recursive: true });
|
|
107214
|
+
await fs36.mkdir(paths.resultsDir, { recursive: true });
|
|
107215
|
+
await fs36.mkdir(paths.errorsDir, { recursive: true });
|
|
107189
107216
|
await writeRunManifest(paths, manifest);
|
|
107190
107217
|
await writeAccounts(paths, input.accounts);
|
|
107191
107218
|
return paths;
|
|
@@ -107250,7 +107277,7 @@ __export(google_analysis_batch_exports, {
|
|
|
107250
107277
|
parseAccountIds: () => parseAccountIds,
|
|
107251
107278
|
registerGoogleAnalysisBatchCommands: () => registerGoogleAnalysisBatchCommands
|
|
107252
107279
|
});
|
|
107253
|
-
import * as
|
|
107280
|
+
import * as path42 from "path";
|
|
107254
107281
|
import { performance as performance3 } from "perf_hooks";
|
|
107255
107282
|
function parseSections(input) {
|
|
107256
107283
|
if (!input || !input.trim()) return DEFAULT_SECTIONS;
|
|
@@ -107869,7 +107896,7 @@ var init_google_analysis_batch = __esm({
|
|
|
107869
107896
|
});
|
|
107870
107897
|
|
|
107871
107898
|
// src/commands/google-analysis/register-cli.ts
|
|
107872
|
-
import * as
|
|
107899
|
+
import * as path43 from "path";
|
|
107873
107900
|
import { performance as performance4 } from "perf_hooks";
|
|
107874
107901
|
import { Command } from "commander";
|
|
107875
107902
|
function normalizeAnalysisDateOpts(opts) {
|
|
@@ -108007,7 +108034,7 @@ async function runAllSections(opts) {
|
|
|
108007
108034
|
}
|
|
108008
108035
|
const succeeded = results.filter((r) => r.ok).length;
|
|
108009
108036
|
const failed = results.length - succeeded;
|
|
108010
|
-
const absoluteSnapshotDir =
|
|
108037
|
+
const absoluteSnapshotDir = path43.resolve(opts.jsonOut);
|
|
108011
108038
|
const summary = {
|
|
108012
108039
|
kind: "siluzan-tso-google-analysis-snapshot-batch",
|
|
108013
108040
|
absoluteSnapshotDir,
|
|
@@ -108290,8 +108317,8 @@ var init_google_analysis3 = __esm({
|
|
|
108290
108317
|
// src/index.ts
|
|
108291
108318
|
init_dist();
|
|
108292
108319
|
init_dist();
|
|
108293
|
-
import * as
|
|
108294
|
-
import * as
|
|
108320
|
+
import * as fs47 from "fs";
|
|
108321
|
+
import * as path58 from "path";
|
|
108295
108322
|
import { fileURLToPath as fileURLToPath16 } from "url";
|
|
108296
108323
|
import { Command as Command6 } from "commander";
|
|
108297
108324
|
|
|
@@ -108781,8 +108808,8 @@ function deriveWebUrl(apiBaseUrl) {
|
|
|
108781
108808
|
}
|
|
108782
108809
|
var TSO_UMI_ROUTE_PREFIX = "/v3umijs/tso";
|
|
108783
108810
|
function buildTsoPageWebUrl(webUrl, tsoSubRoute, extraQuery) {
|
|
108784
|
-
const
|
|
108785
|
-
const umiPath = `${TSO_UMI_ROUTE_PREFIX}/${
|
|
108811
|
+
const path59 = tsoSubRoute.replace(/^\/+/, "");
|
|
108812
|
+
const umiPath = `${TSO_UMI_ROUTE_PREFIX}/${path59}`;
|
|
108786
108813
|
const q = new URLSearchParams({ tso: umiPath });
|
|
108787
108814
|
if (extraQuery) {
|
|
108788
108815
|
for (const [key, value] of Object.entries(extraQuery)) {
|
|
@@ -108790,7 +108817,7 @@ function buildTsoPageWebUrl(webUrl, tsoSubRoute, extraQuery) {
|
|
|
108790
108817
|
if (v) q.set(key, v);
|
|
108791
108818
|
}
|
|
108792
108819
|
}
|
|
108793
|
-
return `${webUrl.replace(/\/+$/, "")}/v3/foreign_trade/tso/${
|
|
108820
|
+
return `${webUrl.replace(/\/+$/, "")}/v3/foreign_trade/tso/${path59}?${q.toString()}`;
|
|
108794
108821
|
}
|
|
108795
108822
|
function cmdConfigShow() {
|
|
108796
108823
|
const shared = readSharedConfig();
|
|
@@ -117033,7 +117060,7 @@ function cloneKeywordBlockShell(block) {
|
|
|
117033
117060
|
delete shell["matchTypeV2"];
|
|
117034
117061
|
return shell;
|
|
117035
117062
|
}
|
|
117036
|
-
function splitKeywordsForBatchJobBlockIfMixed(block,
|
|
117063
|
+
function splitKeywordsForBatchJobBlockIfMixed(block, path59, warnings) {
|
|
117037
117064
|
const declaredUi = matchTypeV2ToUi(readBlockMatchTypeRaw(block));
|
|
117038
117065
|
const entries = collectKeywordEntriesFromBlock(block);
|
|
117039
117066
|
if (entries.length === 0) return [block];
|
|
@@ -117052,7 +117079,7 @@ function splitKeywordsForBatchJobBlockIfMixed(block, path58, warnings) {
|
|
|
117052
117079
|
(ui) => matchTypeUiToV2(ui)
|
|
117053
117080
|
);
|
|
117054
117081
|
warnings.push(
|
|
117055
|
-
`${
|
|
117082
|
+
`${path59} \u542B\u591A\u79CD\u5339\u914D\u7C7B\u578B\uFF0C\u5DF2\u81EA\u52A8\u62C6\u5206\u4E3A ${groups.size} \u4E2A KeywordsForBatchJob \u5757\uFF08${labels.join("\u3001")}\uFF09`
|
|
117056
117083
|
);
|
|
117057
117084
|
const shell = cloneKeywordBlockShell(block);
|
|
117058
117085
|
const splitBlocks = [];
|
|
@@ -117072,16 +117099,16 @@ function splitKeywordsForBatchJobBlockIfMixed(block, path58, warnings) {
|
|
|
117072
117099
|
}
|
|
117073
117100
|
return splitBlocks;
|
|
117074
117101
|
}
|
|
117075
|
-
function validateKeywordCore(core,
|
|
117102
|
+
function validateKeywordCore(core, path59, errors, lengthViolations) {
|
|
117076
117103
|
const trimmed = core.trim();
|
|
117077
117104
|
if (!trimmed) {
|
|
117078
|
-
errors.push(`${
|
|
117105
|
+
errors.push(`${path59} \u5173\u952E\u8BCD\u8BCD\u5E72\u4E0D\u80FD\u4E3A\u7A7A`);
|
|
117079
117106
|
return false;
|
|
117080
117107
|
}
|
|
117081
117108
|
if (trimmed.length > GOOGLE_KEYWORD_MAX_CORE_LENGTH) {
|
|
117082
117109
|
if (lengthViolations) {
|
|
117083
117110
|
pushLengthViolation(lengthViolations, {
|
|
117084
|
-
path:
|
|
117111
|
+
path: path59,
|
|
117085
117112
|
field: "KeywordText",
|
|
117086
117113
|
kind: "keyword_core",
|
|
117087
117114
|
limit: GOOGLE_KEYWORD_MAX_CORE_LENGTH,
|
|
@@ -117091,13 +117118,13 @@ function validateKeywordCore(core, path58, errors, lengthViolations) {
|
|
|
117091
117118
|
});
|
|
117092
117119
|
}
|
|
117093
117120
|
errors.push(
|
|
117094
|
-
`${
|
|
117121
|
+
`${path59} \u5173\u952E\u8BCD\u8BCD\u5E72\u8D85\u8FC7 ${GOOGLE_KEYWORD_MAX_CORE_LENGTH} \u5B57\u7B26\uFF08\u5F53\u524D ${trimmed.length}\uFF09\uFF1A"${trimmed}"`
|
|
117095
117122
|
);
|
|
117096
117123
|
return false;
|
|
117097
117124
|
}
|
|
117098
117125
|
if (!VALID_CORE_REGEX.test(trimmed)) {
|
|
117099
117126
|
errors.push(
|
|
117100
|
-
`${
|
|
117127
|
+
`${path59} \u542B Google \u4E0D\u5141\u8BB8\u7684\u5B57\u7B26\uFF08\u8BCD\u5E72\u4EC5\u5141\u8BB8\u5B57\u6BCD/\u6570\u5B57/\u7A7A\u683C/\u8FDE\u5B57\u7B26/\u53E5\u70B9\uFF09\uFF1A"${trimmed.slice(0, 40)}${trimmed.length > 40 ? "\u2026" : ""}"`
|
|
117101
117128
|
);
|
|
117102
117129
|
return false;
|
|
117103
117130
|
}
|
|
@@ -117154,10 +117181,10 @@ function canonicalizeKeywordBatchBlock(block, resolvedMatchV2, normalizedTexts,
|
|
|
117154
117181
|
}
|
|
117155
117182
|
}
|
|
117156
117183
|
}
|
|
117157
|
-
function pushKeywordAutoFixWarning(warnings,
|
|
117184
|
+
function pushKeywordAutoFixWarning(warnings, path59, fieldLabel, trimmedRaw, formatted, declaredUi, beforeUi, matchType, inferredMatchType) {
|
|
117158
117185
|
if (inferredMatchType) {
|
|
117159
117186
|
warnings.push(
|
|
117160
|
-
`${
|
|
117187
|
+
`${path59}.${fieldLabel} \u672A\u6307\u5B9A MatchTypeV2\uFF0C\u5DF2\u6309\u8BCD\u9762\u63A8\u65AD\u4E3A ${matchTypeUiToV2(matchType)}`
|
|
117161
117188
|
);
|
|
117162
117189
|
return false;
|
|
117163
117190
|
}
|
|
@@ -117166,16 +117193,16 @@ function pushKeywordAutoFixWarning(warnings, path58, fieldLabel, trimmedRaw, for
|
|
|
117166
117193
|
}
|
|
117167
117194
|
if (declaredUi && beforeUi !== declaredUi) {
|
|
117168
117195
|
warnings.push(
|
|
117169
|
-
`${
|
|
117196
|
+
`${path59}.${fieldLabel} MatchTypeV2=${matchTypeUiToV2(declaredUi)} \u4E0E\u8BCD\u9762\u4E0D\u4E00\u81F4\uFF0C\u5DF2\u81EA\u52A8\u4FEE\u590D\u4E3A\uFF1A${formatted}`
|
|
117170
117197
|
);
|
|
117171
117198
|
return false;
|
|
117172
117199
|
}
|
|
117173
117200
|
if (formatted !== trimmedRaw) {
|
|
117174
|
-
warnings.push(`${
|
|
117201
|
+
warnings.push(`${path59}.${fieldLabel} \u5DF2\u81EA\u52A8\u4FEE\u590D\u8BCD\u9762\uFF1A${trimmedRaw} \u2192 ${formatted}`);
|
|
117175
117202
|
}
|
|
117176
117203
|
return false;
|
|
117177
117204
|
}
|
|
117178
|
-
function normalizeKeywordTextList(texts, matchTypeRaw,
|
|
117205
|
+
function normalizeKeywordTextList(texts, matchTypeRaw, path59, fieldLabel, errors, warnings, lengthViolations) {
|
|
117179
117206
|
const declaredUi = matchTypeV2ToUi(matchTypeRaw);
|
|
117180
117207
|
const normalized = [];
|
|
117181
117208
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -117184,7 +117211,7 @@ function normalizeKeywordTextList(texts, matchTypeRaw, path58, fieldLabel, error
|
|
|
117184
117211
|
for (let k = 0; k < texts.length; k++) {
|
|
117185
117212
|
const raw = texts[k];
|
|
117186
117213
|
if (typeof raw !== "string" || !raw.trim()) {
|
|
117187
|
-
errors.push(`${
|
|
117214
|
+
errors.push(`${path59}.${fieldLabel}[${k}] \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32`);
|
|
117188
117215
|
continue;
|
|
117189
117216
|
}
|
|
117190
117217
|
const trimmedRaw = collapseDuplicateSpacesInKeywordText(raw.trim());
|
|
@@ -117195,7 +117222,7 @@ function normalizeKeywordTextList(texts, matchTypeRaw, path58, fieldLabel, error
|
|
|
117195
117222
|
);
|
|
117196
117223
|
if (pushKeywordAutoFixWarning(
|
|
117197
117224
|
warnings,
|
|
117198
|
-
|
|
117225
|
+
path59,
|
|
117199
117226
|
fieldLabel,
|
|
117200
117227
|
trimmedRaw,
|
|
117201
117228
|
formatted,
|
|
@@ -117207,11 +117234,11 @@ function normalizeKeywordTextList(texts, matchTypeRaw, path58, fieldLabel, error
|
|
|
117207
117234
|
bareWrapped++;
|
|
117208
117235
|
}
|
|
117209
117236
|
const core = unwrapKeywordDisplayTextForEdit(formatted);
|
|
117210
|
-
if (!validateKeywordCore(core, `${
|
|
117237
|
+
if (!validateKeywordCore(core, `${path59}.${fieldLabel}[${k}]`, errors, lengthViolations))
|
|
117211
117238
|
continue;
|
|
117212
117239
|
const dedupeKey = `${matchTypeUiToV2(matchType)}:${core.toLowerCase()}`;
|
|
117213
117240
|
if (seen.has(dedupeKey)) {
|
|
117214
|
-
warnings.push(`${
|
|
117241
|
+
warnings.push(`${path59}.${fieldLabel}[${k}] \u4E0E\u540C\u7EC4\u91CD\u590D\uFF0C\u5DF2\u8DF3\u8FC7\uFF1A${formatted}`);
|
|
117215
117242
|
continue;
|
|
117216
117243
|
}
|
|
117217
117244
|
seen.add(dedupeKey);
|
|
@@ -117220,17 +117247,17 @@ function normalizeKeywordTextList(texts, matchTypeRaw, path58, fieldLabel, error
|
|
|
117220
117247
|
}
|
|
117221
117248
|
if (bareWrapped > 0 && declaredUi) {
|
|
117222
117249
|
warnings.push(
|
|
117223
|
-
`${
|
|
117250
|
+
`${path59}.${fieldLabel}\uFF1A${bareWrapped} \u4E2A\u88F8\u8BCD\u5DF2\u6309 MatchTypeV2=${matchTypeUiToV2(declaredUi)} \u81EA\u52A8\u4FEE\u590D\uFF08\u8865\u5168${declaredUi === "Exact" ? " [ ]" : "\u5F15\u53F7"}\uFF0C\u9884\u671F\u884C\u4E3A\uFF09`
|
|
117224
117251
|
);
|
|
117225
117252
|
}
|
|
117226
117253
|
return { normalized, resolvedUi };
|
|
117227
117254
|
}
|
|
117228
|
-
function normalizeKeywordsForBatchJobBlock(block,
|
|
117255
|
+
function normalizeKeywordsForBatchJobBlock(block, path59, errors, warnings, lengthViolations) {
|
|
117229
117256
|
const matchTypeRaw = readBlockMatchTypeRaw(block);
|
|
117230
117257
|
const declaredUi = matchTypeV2ToUi(matchTypeRaw);
|
|
117231
117258
|
if (matchTypeRaw !== void 0 && declaredUi === null) {
|
|
117232
117259
|
errors.push(
|
|
117233
|
-
`${
|
|
117260
|
+
`${path59}.MatchTypeV2 \u65E0\u6548\uFF08${String(matchTypeRaw)}\uFF09\uFF0C\u5408\u6CD5\u503C\uFF1ABROAD | PHRASE | EXACT`
|
|
117234
117261
|
);
|
|
117235
117262
|
return;
|
|
117236
117263
|
}
|
|
@@ -117245,7 +117272,7 @@ function normalizeKeywordsForBatchJobBlock(block, path58, errors, warnings, leng
|
|
|
117245
117272
|
const result = normalizeKeywordTextList(
|
|
117246
117273
|
texts,
|
|
117247
117274
|
matchTypeRaw,
|
|
117248
|
-
|
|
117275
|
+
path59,
|
|
117249
117276
|
"KeywordText",
|
|
117250
117277
|
errors,
|
|
117251
117278
|
warnings,
|
|
@@ -117254,7 +117281,7 @@ function normalizeKeywordsForBatchJobBlock(block, path58, errors, warnings, leng
|
|
|
117254
117281
|
normalizedTexts = result.normalized;
|
|
117255
117282
|
if (result.resolvedUi) resolvedUi = result.resolvedUi;
|
|
117256
117283
|
if (normalizedTexts.length === 0 && texts.length > 0) {
|
|
117257
|
-
errors.push(`${
|
|
117284
|
+
errors.push(`${path59}.KeywordText \u7ECF\u6821\u9A8C\u540E\u65E0\u6709\u6548\u5173\u952E\u8BCD\uFF0C\u8BF7\u4FEE\u6B63\u8BCD\u9762\u6216 MatchTypeV2`);
|
|
117258
117285
|
}
|
|
117259
117286
|
}
|
|
117260
117287
|
if (hasItems && items3) {
|
|
@@ -117262,12 +117289,12 @@ function normalizeKeywordsForBatchJobBlock(block, path58, errors, warnings, leng
|
|
|
117262
117289
|
for (let k = 0; k < items3.length; k++) {
|
|
117263
117290
|
const item = items3[k];
|
|
117264
117291
|
if (!item || typeof item !== "object") {
|
|
117265
|
-
errors.push(`${
|
|
117292
|
+
errors.push(`${path59}.Items[${k}] \u5FC5\u987B\u662F\u5BF9\u8C61`);
|
|
117266
117293
|
continue;
|
|
117267
117294
|
}
|
|
117268
117295
|
const raw = readItemText(item);
|
|
117269
117296
|
if (raw === null || !raw.trim()) {
|
|
117270
|
-
errors.push(`${
|
|
117297
|
+
errors.push(`${path59}.Items[${k}].Text \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32`);
|
|
117271
117298
|
continue;
|
|
117272
117299
|
}
|
|
117273
117300
|
const trimmedRaw = collapseDuplicateSpacesInKeywordText(raw.trim());
|
|
@@ -117278,7 +117305,7 @@ function normalizeKeywordsForBatchJobBlock(block, path58, errors, warnings, leng
|
|
|
117278
117305
|
);
|
|
117279
117306
|
if (pushKeywordAutoFixWarning(
|
|
117280
117307
|
warnings,
|
|
117281
|
-
|
|
117308
|
+
path59,
|
|
117282
117309
|
`Items[${k}].Text`,
|
|
117283
117310
|
trimmedRaw,
|
|
117284
117311
|
formatted,
|
|
@@ -117287,14 +117314,14 @@ function normalizeKeywordsForBatchJobBlock(block, path58, errors, warnings, leng
|
|
|
117287
117314
|
matchType,
|
|
117288
117315
|
inferredMatchType
|
|
117289
117316
|
)) {
|
|
117290
|
-
warnings.push(`${
|
|
117317
|
+
warnings.push(`${path59}.Items[${k}].Text \u5DF2\u6309\u5757\u7EA7\u5339\u914D\u7C7B\u578B\u81EA\u52A8\u4FEE\u590D\u4E3A\uFF1A${formatted}`);
|
|
117291
117318
|
}
|
|
117292
117319
|
const core = unwrapKeywordDisplayTextForEdit(formatted);
|
|
117293
|
-
if (!validateKeywordCore(core, `${
|
|
117320
|
+
if (!validateKeywordCore(core, `${path59}.Items[${k}].Text`, errors, lengthViolations))
|
|
117294
117321
|
continue;
|
|
117295
117322
|
const dedupeKey = `${matchTypeUiToV2(matchType)}:${core.toLowerCase()}`;
|
|
117296
117323
|
if (seen.has(dedupeKey)) {
|
|
117297
|
-
warnings.push(`${
|
|
117324
|
+
warnings.push(`${path59}.Items[${k}].Text \u4E0E\u540C\u7EC4\u91CD\u590D\uFF0C\u5DF2\u8DF3\u8FC7\uFF1A${formatted}`);
|
|
117298
117325
|
continue;
|
|
117299
117326
|
}
|
|
117300
117327
|
seen.add(dedupeKey);
|
|
@@ -117440,16 +117467,16 @@ function warnIfNegativeKeywordsInPositiveKeywords(campaign, warnings) {
|
|
|
117440
117467
|
const raw = texts[ki];
|
|
117441
117468
|
if (typeof raw !== "string" || !raw.trim()) continue;
|
|
117442
117469
|
const core = normalizeKeywordCoreForNegativeCheck(raw);
|
|
117443
|
-
const
|
|
117470
|
+
const path59 = `campaign.AdGroupsForBatchJob[${gi}].KeywordsForBatchJob[${bi}].KeywordText[${ki}]`;
|
|
117444
117471
|
if (plannedNegCores.has(core)) {
|
|
117445
117472
|
warnings.push(
|
|
117446
|
-
`${
|
|
117473
|
+
`${path59} \u8BCD\u9762\u300C${raw}\u300D\u5DF2\u51FA\u73B0\u5728 campaign.NegativeKeywordsForBatchJob\uFF0C\u4E0D\u5E94\u91CD\u590D\u5199\u5165\u6B63\u5411 KeywordsForBatchJob\uFF1B\u5426\u8BCD\u53EA\u653E NegativeKeywordsForBatchJob`
|
|
117447
117474
|
);
|
|
117448
117475
|
continue;
|
|
117449
117476
|
}
|
|
117450
117477
|
if (looksLikeStandaloneNegativeKeyword(core)) {
|
|
117451
117478
|
warnings.push(
|
|
117452
|
-
`${
|
|
117479
|
+
`${path59} \u8BCD\u9762\u300C${raw}\u300D\u7591\u4F3C\u5426\u5B9A\u5173\u952E\u8BCD\uFF08\u5E38\u89C1\u5426\u8BCD\u8BCD\u6839\uFF09\uFF0C\u5E94\u5199\u5165 campaign.NegativeKeywordsForBatchJob\uFF08MatchTypeV2: BROAD\uFF09\uFF0C\u52FF\u653E\u5165 KeywordsForBatchJob`
|
|
117453
117480
|
);
|
|
117454
117481
|
}
|
|
117455
117482
|
}
|
|
@@ -119668,8 +119695,8 @@ function normalizePlacementUrl(raw) {
|
|
|
119668
119695
|
if (parts.length > 2) {
|
|
119669
119696
|
throw new Error("\u7248\u4F4D\u7F51\u5740\u6700\u591A\u4E24\u7EA7\u8DEF\u5F84\uFF0C\u4F8B\u5982 http://www.domain.com/news/2024");
|
|
119670
119697
|
}
|
|
119671
|
-
const
|
|
119672
|
-
return `${url.protocol}//${host}${
|
|
119698
|
+
const path59 = parts.length > 0 ? `/${parts.join("/")}` : "";
|
|
119699
|
+
return `${url.protocol}//${host}${path59}`;
|
|
119673
119700
|
}
|
|
119674
119701
|
var GROUP_LABEL = {
|
|
119675
119702
|
sensitive: "\u654F\u611F\u5185\u5BB9",
|
|
@@ -120415,7 +120442,7 @@ async function runAdPmaxBrandsDetach(opts) {
|
|
|
120415
120442
|
\u2705 \u5DF2\u4ECE\u7CFB\u5217 ${campaignId} \u5378\u4E0B\u54C1\u724C\u5217\u8868 ${criterionId}
|
|
120416
120443
|
`);
|
|
120417
120444
|
}
|
|
120418
|
-
async function listCampaignRows(opts,
|
|
120445
|
+
async function listCampaignRows(opts, path59, label2) {
|
|
120419
120446
|
let campaignId;
|
|
120420
120447
|
try {
|
|
120421
120448
|
campaignId = requireCampaignId(opts.campaignId, label2);
|
|
@@ -120423,7 +120450,7 @@ async function listCampaignRows(opts, path58, label2) {
|
|
|
120423
120450
|
fail(err, "\u53C2\u6570");
|
|
120424
120451
|
}
|
|
120425
120452
|
const { config, base: base2, account } = accountBase(opts);
|
|
120426
|
-
const url = `${base2}/campaignmanagement/accounts/${account}/${
|
|
120453
|
+
const url = `${base2}/campaignmanagement/accounts/${account}/${path59}?campaignId=${campaignId}`;
|
|
120427
120454
|
let items3;
|
|
120428
120455
|
try {
|
|
120429
120456
|
items3 = unwrapItems(await apiFetch2(url, config, {}, opts.verbose));
|
|
@@ -120532,17 +120559,17 @@ async function runAdPmaxUrlsAdd(opts) {
|
|
|
120532
120559
|
async function runAdPmaxUrlsRemove(opts) {
|
|
120533
120560
|
await removeCampaignCriterion(opts, "pmax-urls", "\u7F51\u5740\u6392\u9664");
|
|
120534
120561
|
}
|
|
120535
|
-
async function removeCampaignCriterion(opts,
|
|
120562
|
+
async function removeCampaignCriterion(opts, path59, label2) {
|
|
120536
120563
|
let campaignId;
|
|
120537
120564
|
let criterionId;
|
|
120538
120565
|
try {
|
|
120539
|
-
campaignId = requireCampaignId(opts.campaignId,
|
|
120566
|
+
campaignId = requireCampaignId(opts.campaignId, path59);
|
|
120540
120567
|
criterionId = requireDigits(opts.criterionId, "--criterion-id");
|
|
120541
120568
|
} catch (err) {
|
|
120542
120569
|
fail(err, "\u53C2\u6570");
|
|
120543
120570
|
}
|
|
120544
120571
|
const { config, base: base2, account } = accountBase(opts);
|
|
120545
|
-
const url = `${base2}/campaignmanagement/accounts/${account}/${
|
|
120572
|
+
const url = `${base2}/campaignmanagement/accounts/${account}/${path59}/${criterionId}?campaignId=${campaignId}`;
|
|
120546
120573
|
try {
|
|
120547
120574
|
await apiDeleteRaw(url, config, { verbose: opts.verbose });
|
|
120548
120575
|
} catch (err) {
|
|
@@ -122453,7 +122480,7 @@ function buildBatchOperationSlots(cfg) {
|
|
|
122453
122480
|
const campaign = asRecord3(cfg.campaign) ?? {};
|
|
122454
122481
|
const names = Array.isArray(cfg.locations) ? cfg.locations : [];
|
|
122455
122482
|
const slots = [];
|
|
122456
|
-
const push = (kind,
|
|
122483
|
+
const push = (kind, path59, label2) => slots.push({ index: slots.length, kind, path: path59, label: label2 });
|
|
122457
122484
|
push("campaign_budget", "campaign.Budget", "\u7CFB\u5217\u9884\u7B97");
|
|
122458
122485
|
push("campaign", "campaign.Name", `\u7CFB\u5217\u300C${pickText(campaign, "Name", "name") || "\u2014"}\u300D`);
|
|
122459
122486
|
pickArray(campaign, "targetedLocations", "TargetedLocations").forEach((loc, i) => {
|
|
@@ -122936,13 +122963,13 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
|
|
|
122936
122963
|
for (let ki = 0; ki < texts.length; ki++) {
|
|
122937
122964
|
const t = texts[ki];
|
|
122938
122965
|
if (typeof t !== "string" || !t.trim()) continue;
|
|
122939
|
-
const
|
|
122966
|
+
const path59 = `${groupPath}.KeywordsForBatchJob[${bi}].KeywordText[${ki}]`;
|
|
122940
122967
|
const key = keywordKey(t, matchTypeV2);
|
|
122941
122968
|
const plannedContent = `\u8BCD\u9762: ${t} | \u5339\u914D: ${matchTypeV2}`;
|
|
122942
122969
|
if (groupAbsent) {
|
|
122943
122970
|
pushItem(items3, {
|
|
122944
122971
|
layer: "keyword",
|
|
122945
|
-
path:
|
|
122972
|
+
path: path59,
|
|
122946
122973
|
adGroupName: groupName,
|
|
122947
122974
|
plannedContent,
|
|
122948
122975
|
status: "skipped",
|
|
@@ -122954,7 +122981,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
|
|
|
122954
122981
|
if (!liveKwKeys.has(key)) {
|
|
122955
122982
|
pushItem(items3, {
|
|
122956
122983
|
layer: "keyword",
|
|
122957
|
-
path:
|
|
122984
|
+
path: path59,
|
|
122958
122985
|
adGroupName: groupName,
|
|
122959
122986
|
plannedContent,
|
|
122960
122987
|
status: "missing",
|
|
@@ -122964,7 +122991,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
|
|
|
122964
122991
|
} else {
|
|
122965
122992
|
pushItem(items3, {
|
|
122966
122993
|
layer: "keyword",
|
|
122967
|
-
path:
|
|
122994
|
+
path: path59,
|
|
122968
122995
|
adGroupName: groupName,
|
|
122969
122996
|
plannedContent,
|
|
122970
122997
|
status: "ok",
|
|
@@ -122984,7 +123011,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
|
|
|
122984
123011
|
for (let ai = 0; ai < ads.length; ai++) {
|
|
122985
123012
|
const ad = asRecord4(ads[ai]);
|
|
122986
123013
|
if (!ad) continue;
|
|
122987
|
-
const
|
|
123014
|
+
const path59 = `${groupPath}.AdsForBatchJob[${ai}]`;
|
|
122988
123015
|
const primary = pickString2(ad["headlinePart1"], ad["AdTitle"]);
|
|
122989
123016
|
const finalUrl = pickString2(ad["Finalurl"], ad["DestinationUrl"], ad["finalUrl"]);
|
|
122990
123017
|
const rsaAssets = listPlannedRsaAssets(ad, groupPath, ai, groupName);
|
|
@@ -122993,7 +123020,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
|
|
|
122993
123020
|
if (groupAbsent) {
|
|
122994
123021
|
pushItem(items3, {
|
|
122995
123022
|
layer: "ad",
|
|
122996
|
-
path:
|
|
123023
|
+
path: path59,
|
|
122997
123024
|
adGroupName: groupName,
|
|
122998
123025
|
adLabel,
|
|
122999
123026
|
plannedContent: primary ? `RSA \u9996\u6807\u9898: ${primary}${finalUrl ? ` | \u843D\u5730\u9875: ${finalUrl}` : ""}` : `AdsForBatchJob[${ai}]\uFF08\u7F3A\u5C11 headlinePart1\uFF09`,
|
|
@@ -123022,7 +123049,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
|
|
|
123022
123049
|
if (!primary) {
|
|
123023
123050
|
pushItem(items3, {
|
|
123024
123051
|
layer: "ad",
|
|
123025
|
-
path:
|
|
123052
|
+
path: path59,
|
|
123026
123053
|
adGroupName: groupName,
|
|
123027
123054
|
adLabel,
|
|
123028
123055
|
plannedContent: `AdsForBatchJob[${ai}]\uFF08\u7F3A\u5C11 headlinePart1\uFF0C\u65E0\u6CD5\u6BD4\u5BF9\u6574\u6761 RSA\uFF09`,
|
|
@@ -123050,7 +123077,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
|
|
|
123050
123077
|
const rsaFound = matchedLive != null && liveAdHasHeadline(matchedLive, primary);
|
|
123051
123078
|
pushItem(items3, {
|
|
123052
123079
|
layer: "ad",
|
|
123053
|
-
path:
|
|
123080
|
+
path: path59,
|
|
123054
123081
|
adGroupName: groupName,
|
|
123055
123082
|
adLabel,
|
|
123056
123083
|
plannedContent: `RSA \u9996\u6807\u9898: ${primary}${finalUrl ? ` | \u843D\u5730\u9875: ${finalUrl}` : ""}`,
|
|
@@ -123118,11 +123145,11 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
|
|
|
123118
123145
|
for (let ei = 0; ei < extBlocks.length; ei++) {
|
|
123119
123146
|
const ext = asRecord4(extBlocks[ei]);
|
|
123120
123147
|
const plannedContent = formatExtensionPlanned(ext);
|
|
123121
|
-
const
|
|
123148
|
+
const path59 = `campaign.ExtensionsForBatchJob[${ei}]`;
|
|
123122
123149
|
if (campaignMissing) {
|
|
123123
123150
|
pushItem(items3, {
|
|
123124
123151
|
layer: "extension",
|
|
123125
|
-
path:
|
|
123152
|
+
path: path59,
|
|
123126
123153
|
plannedContent,
|
|
123127
123154
|
status: "skipped",
|
|
123128
123155
|
liveNote: "\u7CFB\u5217\u672A\u627E\u5230\uFF0C\u8DF3\u8FC7\u9644\u52A0\u4FE1\u606F\u6BD4\u5BF9",
|
|
@@ -123134,7 +123161,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
|
|
|
123134
123161
|
const remediateCommand = !found && ext && accountId && campaignId ? buildExtensionRemediateCommandLine({ accountId, campaignId, ext }) ?? void 0 : void 0;
|
|
123135
123162
|
pushItem(items3, {
|
|
123136
123163
|
layer: "extension",
|
|
123137
|
-
path:
|
|
123164
|
+
path: path59,
|
|
123138
123165
|
plannedContent,
|
|
123139
123166
|
status: found ? "ok" : "missing",
|
|
123140
123167
|
liveNote: `\u7CFB\u5217\u7EA7\u9644\u52A0\u4FE1\u606F\u8D26\u6237\u5185 ${liveExt}/${plannedExt} \u6761`,
|
|
@@ -123161,11 +123188,11 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
|
|
|
123161
123188
|
if (!id) continue;
|
|
123162
123189
|
const displayName = locationNames[li] || pickString2(loc["locationName"], loc["name"], loc["countryOrRegion"]) || "";
|
|
123163
123190
|
const plannedContent = `locationId: ${id}${displayName ? ` | \u540D\u79F0: ${displayName}` : ""}`;
|
|
123164
|
-
const
|
|
123191
|
+
const path59 = `campaign.targetedLocations[${li}]`;
|
|
123165
123192
|
if (campaignMissing) {
|
|
123166
123193
|
pushItem(items3, {
|
|
123167
123194
|
layer: "location",
|
|
123168
|
-
path:
|
|
123195
|
+
path: path59,
|
|
123169
123196
|
plannedContent,
|
|
123170
123197
|
status: "skipped",
|
|
123171
123198
|
liveNote: "\u7CFB\u5217\u672A\u627E\u5230\uFF0C\u8DF3\u8FC7\u5730\u57DF\u6BD4\u5BF9",
|
|
@@ -123177,7 +123204,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
|
|
|
123177
123204
|
const remediateCommand = !found && accountId && campaignId ? buildGeoRemediateCommandLine({ accountId, campaignId, locationId: id }) : void 0;
|
|
123178
123205
|
pushItem(items3, {
|
|
123179
123206
|
layer: "location",
|
|
123180
|
-
path:
|
|
123207
|
+
path: path59,
|
|
123181
123208
|
plannedContent,
|
|
123182
123209
|
status: found ? "ok" : "missing",
|
|
123183
123210
|
liveNote: `\u7CFB\u5217\u5DF2\u5B9A\u5411 ${liveLocIds.size}/${plannedLocCount} \u4E2A\u5730\u57DF`,
|
|
@@ -123197,12 +123224,12 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
|
|
|
123197
123224
|
const loc = asRecord4(plannedExcl[li]);
|
|
123198
123225
|
const id = loc ? pickString2(loc["id"], loc["Id"]) : "";
|
|
123199
123226
|
if (!id) continue;
|
|
123200
|
-
const
|
|
123227
|
+
const path59 = `campaign.excludedLocations[${li}]`;
|
|
123201
123228
|
const plannedContent = `\u6392\u9664 locationId: ${id}`;
|
|
123202
123229
|
if (campaignMissing) {
|
|
123203
123230
|
pushItem(items3, {
|
|
123204
123231
|
layer: "excluded_location",
|
|
123205
|
-
path:
|
|
123232
|
+
path: path59,
|
|
123206
123233
|
plannedContent,
|
|
123207
123234
|
status: "skipped",
|
|
123208
123235
|
liveNote: "\u7CFB\u5217\u672A\u627E\u5230\uFF0C\u8DF3\u8FC7\u6392\u9664\u5730\u57DF\u6BD4\u5BF9",
|
|
@@ -123213,7 +123240,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
|
|
|
123213
123240
|
const found = liveExclIds.has(id);
|
|
123214
123241
|
pushItem(items3, {
|
|
123215
123242
|
layer: "excluded_location",
|
|
123216
|
-
path:
|
|
123243
|
+
path: path59,
|
|
123217
123244
|
plannedContent,
|
|
123218
123245
|
status: found ? "ok" : "missing",
|
|
123219
123246
|
liveNote: `\u7CFB\u5217\u5DF2\u6392\u9664 ${liveExclIds.size}/${plannedExclCount} \u4E2A\u5730\u57DF`,
|
|
@@ -124893,8 +124920,8 @@ function pmaxChannelTypesUrl(googleApiUrl) {
|
|
|
124893
124920
|
}
|
|
124894
124921
|
function pmaxCampaignUrl(googleApiUrl, accountId, campaignId) {
|
|
124895
124922
|
const base2 = googleApiUrl.replace(/\/$/, "");
|
|
124896
|
-
const
|
|
124897
|
-
return campaignId ? `${
|
|
124923
|
+
const path59 = `${base2}/accounts/${accountId}/campaign/pmax`;
|
|
124924
|
+
return campaignId ? `${path59}/${campaignId}` : path59;
|
|
124898
124925
|
}
|
|
124899
124926
|
function pmaxBrandAssetsUrl(googleApiUrl, accountId, campaignId) {
|
|
124900
124927
|
return `${pmaxCampaignUrl(googleApiUrl, accountId, campaignId)}/brand-assets`;
|
|
@@ -124904,8 +124931,8 @@ function pmaxBrandGuidelinesEnableUrl(googleApiUrl, accountId, campaignId) {
|
|
|
124904
124931
|
}
|
|
124905
124932
|
function pmaxAssetGroupUrl(googleApiUrl, accountId, assetGroupId, suffix) {
|
|
124906
124933
|
const base2 = googleApiUrl.replace(/\/$/, "");
|
|
124907
|
-
const
|
|
124908
|
-
return suffix ? `${
|
|
124934
|
+
const path59 = `${base2}/accounts/${accountId}/campaign/pmax/asset-group/${assetGroupId}`;
|
|
124935
|
+
return suffix ? `${path59}/${suffix.replace(/^\//, "")}` : path59;
|
|
124909
124936
|
}
|
|
124910
124937
|
function pmaxCampaignAssetGroupUrl(googleApiUrl, accountId, campaignId) {
|
|
124911
124938
|
const base2 = googleApiUrl.replace(/\/$/, "");
|
|
@@ -127887,8 +127914,8 @@ async function runAdPmaxImageConvert(opts) {
|
|
|
127887
127914
|
}
|
|
127888
127915
|
|
|
127889
127916
|
// src/commands/ad/pmax-brand-mgmt.ts
|
|
127890
|
-
function loadBrandConfig(
|
|
127891
|
-
const cfg = loadPmaxJsonFile(
|
|
127917
|
+
function loadBrandConfig(path59, accountId, campaignId) {
|
|
127918
|
+
const cfg = loadPmaxJsonFile(path59);
|
|
127892
127919
|
return {
|
|
127893
127920
|
...cfg,
|
|
127894
127921
|
account: String(cfg["account"] ?? accountId).trim(),
|
|
@@ -128243,12 +128270,12 @@ function demandGenConversionsValidateUrl(googleApiUrl, accountId) {
|
|
|
128243
128270
|
return `${demandGenCollectionUrl(googleApiUrl, accountId)}/conversions/validate`;
|
|
128244
128271
|
}
|
|
128245
128272
|
function demandGenAdGroupUrl(googleApiUrl, accountId, campaignId, adGroupId, suffix) {
|
|
128246
|
-
const
|
|
128247
|
-
return suffix ? `${
|
|
128273
|
+
const path59 = `${demandGenCampaignUrl(googleApiUrl, accountId, campaignId)}/ad-groups/${adGroupId}`;
|
|
128274
|
+
return suffix ? `${path59}/${suffix.replace(/^\//, "")}` : path59;
|
|
128248
128275
|
}
|
|
128249
128276
|
function demandGenAdUrl(googleApiUrl, accountId, campaignId, adGroupId, adId, suffix) {
|
|
128250
|
-
const
|
|
128251
|
-
return suffix ? `${
|
|
128277
|
+
const path59 = `${demandGenAdGroupUrl(googleApiUrl, accountId, campaignId, adGroupId)}/ads/${adId}`;
|
|
128278
|
+
return suffix ? `${path59}/${suffix.replace(/^\//, "")}` : path59;
|
|
128252
128279
|
}
|
|
128253
128280
|
function demandGenChannelReportUrl(googleApiUrl, accountId, campaignId, startDate, endDate) {
|
|
128254
128281
|
const params = new URLSearchParams({ startDate, endDate });
|
|
@@ -128352,7 +128379,7 @@ function explainCreateError(err) {
|
|
|
128352
128379
|
if (failure) return demandGenResumeHint(failure);
|
|
128353
128380
|
return err instanceof Error ? err.message : String(err);
|
|
128354
128381
|
}
|
|
128355
|
-
async function postCreate(opts,
|
|
128382
|
+
async function postCreate(opts, path59, commandLabel) {
|
|
128356
128383
|
const accountId = requireAccountId(opts.account);
|
|
128357
128384
|
const raw = loadBody(opts.configFile);
|
|
128358
128385
|
await withGoogleApi(opts, async (config, googleApiUrl) => {
|
|
@@ -128364,7 +128391,7 @@ async function postCreate(opts, path58, commandLabel) {
|
|
|
128364
128391
|
fail3(err instanceof Error ? err.message : String(err));
|
|
128365
128392
|
}
|
|
128366
128393
|
printIssues(demandGenCreateIssues(body));
|
|
128367
|
-
const url =
|
|
128394
|
+
const url = path59 ? `${demandGenCollectionUrl(googleApiUrl, accountId)}/${path59}` : demandGenCollectionUrl(googleApiUrl, accountId);
|
|
128368
128395
|
let data;
|
|
128369
128396
|
try {
|
|
128370
128397
|
data = await pmaxApiFetch(
|
|
@@ -128377,7 +128404,7 @@ async function postCreate(opts, path58, commandLabel) {
|
|
|
128377
128404
|
fail3(explainCreateError(err));
|
|
128378
128405
|
}
|
|
128379
128406
|
const payload = decorateDemandGenRead(data);
|
|
128380
|
-
if (await emit({ ...opts, account: accountId }, `ad-demand-gen-${
|
|
128407
|
+
if (await emit({ ...opts, account: accountId }, `ad-demand-gen-${path59 || "create"}`, commandLabel, payload, accountId)) {
|
|
128381
128408
|
return;
|
|
128382
128409
|
}
|
|
128383
128410
|
console.log(`
|
|
@@ -130736,9 +130763,9 @@ function metaAdContext(token) {
|
|
|
130736
130763
|
const config = loadConfig(token);
|
|
130737
130764
|
return { config, facebookApiUrl: requireFacebookApi(config) };
|
|
130738
130765
|
}
|
|
130739
|
-
function adsUrl(facebookApiUrl, account,
|
|
130766
|
+
function adsUrl(facebookApiUrl, account, path59) {
|
|
130740
130767
|
const base2 = metaAdsBaseUrl(facebookApiUrl, account);
|
|
130741
|
-
const p =
|
|
130768
|
+
const p = path59.startsWith("/") ? path59 : `/${path59}`;
|
|
130742
130769
|
return `${base2}${p}`;
|
|
130743
130770
|
}
|
|
130744
130771
|
async function metaAdGet(url, config, verbose, action) {
|
|
@@ -131945,9 +131972,9 @@ async function runMetaAdForms(opts) {
|
|
|
131945
131972
|
if (opts.after) params.set("after", opts.after);
|
|
131946
131973
|
if (opts.before) params.set("before", opts.before);
|
|
131947
131974
|
const qs = params.toString();
|
|
131948
|
-
const
|
|
131975
|
+
const path59 = `/pages/${encodeURIComponent(opts.pageId)}/forms${qs ? `?${qs}` : ""}`;
|
|
131949
131976
|
const raw = await metaAdGet(
|
|
131950
|
-
adsUrl(facebookApiUrl, digits,
|
|
131977
|
+
adsUrl(facebookApiUrl, digits, path59),
|
|
131951
131978
|
config,
|
|
131952
131979
|
opts.verbose,
|
|
131953
131980
|
"\u5217\u8868\u5355\u5931\u8D25"
|
|
@@ -137991,7 +138018,7 @@ function register27(program2) {
|
|
|
137991
138018
|
);
|
|
137992
138019
|
console.log(" \u9ED8\u8BA4\u4EA4\u4ED8 HTML\uFF1A");
|
|
137993
138020
|
console.log(
|
|
137994
|
-
" siluzan-tso website-diagnosis render --data ./diagnosis.json --collect ./snap-web/<collect>.json"
|
|
138021
|
+
" siluzan-tso website-diagnosis render --data ./diagnosis.json --collect ./snap-web/<collect>.json --tracking ./snap-web/ga-gtm.json"
|
|
137995
138022
|
);
|
|
137996
138023
|
console.log(" Skill\uFF1Areferences/analytics/website-diagnosis-guide.md\n");
|
|
137997
138024
|
console.log(" \u3010\u8D26\u6237\u5217\u8868 ARIT \u5206\u3011");
|
|
@@ -138251,7 +138278,7 @@ function buildDiagnosisScaffold(signals) {
|
|
|
138251
138278
|
};
|
|
138252
138279
|
}
|
|
138253
138280
|
);
|
|
138254
|
-
const agentHint = `\u811A\u624B\u67B6\u5DF2\u9884\u586B\u6570\u636E\u4E0D\u53EF\u7528\u9879\uFF08needsAgent=false \u52FF\u6539\u6210\u865A\u6784\u5206\uFF09\u3002\u8BF7\u4EC5\u8865\u5168 needsAgent=true \u7684\u6761\u76EE\uFF1A\u4F9D\u636E signals \u5199 issue/suggestion/score/status\uFF1B\u8865\u5168\u540E\u5220\u6389\u5404 item \u7684 needsAgent/_scaffold \u5B57\u6BB5\uFF08\u6216\u4FDD\u7559\u4EA6\u53EF\uFF0Crender \u5FFD\u7565\u672A\u77E5\u5B57\u6BB5\uFF09\uFF0C\u8BBE\u7F6E ratingId \u4E0E coreIssuesIds\u3002priorityPlan \u5FC5\u987B\u6309\u672C\u7AD9\u672A\u6EE1\u5206\u9879\u548C coreIssuesIds \u5199\u6210\u9AD8/\u4E2D/\u4F4E\u4E09\u6863\uFF08\u53EF\u7F3A\u6863\uFF09\uFF0C\u6BCF\u6761\u542B direction\u3001task\u3001adImpact\uFF0C\u7981\u6B62\u5957\u7528\u901A\u7528\u884C\u52A8\u6E05\u5355\uFF1B\u4E3A\u7A7A\u65F6 render \u4F1A\u5931\u8D25\u3002\u7136\u540E\u518D\u6267\u884C website-diagnosis render\u3002 ${signals.dataAvailability.agentHint}`;
|
|
138281
|
+
const agentHint = `\u811A\u624B\u67B6\u5DF2\u9884\u586B\u6570\u636E\u4E0D\u53EF\u7528\u9879\uFF08needsAgent=false \u52FF\u6539\u6210\u865A\u6784\u5206\uFF09\u3002\u8BF7\u4EC5\u8865\u5168 needsAgent=true \u7684\u6761\u76EE\uFF1A\u4F9D\u636E signals \u5199 issue/suggestion/score/status\uFF1B\u8865\u5168\u540E\u5220\u6389\u5404 item \u7684 needsAgent/_scaffold \u5B57\u6BB5\uFF08\u6216\u4FDD\u7559\u4EA6\u53EF\uFF0Crender \u5FFD\u7565\u672A\u77E5\u5B57\u6BB5\uFF09\uFF0C\u8BBE\u7F6E ratingId \u4E0E coreIssuesIds\u3002priorityPlan \u5FC5\u987B\u6309\u672C\u7AD9\u672A\u6EE1\u5206\u9879\u548C coreIssuesIds \u5199\u6210\u9AD8/\u4E2D/\u4F4E\u4E09\u6863\uFF08\u53EF\u7F3A\u6863\uFF09\uFF0C\u6BCF\u6761\u542B direction\u3001task\u3001adImpact\uFF0C\u7981\u6B62\u5957\u7528\u901A\u7528\u884C\u52A8\u6E05\u5355\uFF1B\u4E3A\u7A7A\u65F6 render \u4F1A\u5931\u8D25\u3002GA/GTM \u987B\u53E6\u505A\u6D4F\u89C8\u5668\u5B9E\u8BBF\uFF0C\u6309 website-diagnosis-tracking.md \u5199 JSON\uFF0Crender \u52A0 --tracking\uFF1B\u7981\u6B62\u7528 analyticsHints \u586B\u5199\u5BB9\u5668 ID\u3002\u7136\u540E\u518D\u6267\u884C website-diagnosis render\u3002 ${signals.dataAvailability.agentHint}`;
|
|
138255
138282
|
return {
|
|
138256
138283
|
url: signals.url,
|
|
138257
138284
|
analyzedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -138377,65 +138404,98 @@ function attachLandingPageMeta(lighthouse, resolved) {
|
|
|
138377
138404
|
// src/commands/website-diagnosis/shared.ts
|
|
138378
138405
|
init_dist();
|
|
138379
138406
|
init_auth();
|
|
138380
|
-
|
|
138381
|
-
|
|
138382
|
-
|
|
138383
|
-
|
|
138384
|
-
|
|
138385
|
-
|
|
138386
|
-
|
|
138387
|
-
|
|
138388
|
-
|
|
138407
|
+
import fs17 from "fs/promises";
|
|
138408
|
+
import path22 from "path";
|
|
138409
|
+
var HTML_FETCH_TIMEOUT_MS = 2e4;
|
|
138410
|
+
var HTML_FETCH_MAX_BYTES = 5 * 1024 * 1024;
|
|
138411
|
+
var HTML_FETCH_MAX_REDIRECTS = 5;
|
|
138412
|
+
var HTML_FETCH_HEADERS = {
|
|
138413
|
+
Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
|
138414
|
+
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
|
|
138415
|
+
"Accept-Encoding": "gzip, deflate, br",
|
|
138416
|
+
"Cache-Control": "no-cache",
|
|
138417
|
+
"Upgrade-Insecure-Requests": "1",
|
|
138418
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"
|
|
138419
|
+
};
|
|
138389
138420
|
function normalizeWebsiteUrl(input) {
|
|
138390
138421
|
const trimmed = String(input ?? "").trim();
|
|
138391
138422
|
if (!trimmed) return "";
|
|
138392
138423
|
if (/^https?:\/\//i.test(trimmed)) return trimmed;
|
|
138393
138424
|
return `https://${trimmed}`;
|
|
138394
138425
|
}
|
|
138395
|
-
function
|
|
138396
|
-
|
|
138397
|
-
|
|
138398
|
-
|
|
138399
|
-
|
|
138400
|
-
|
|
138401
|
-
|
|
138402
|
-
|
|
138403
|
-
|
|
138404
|
-
|
|
138405
|
-
|
|
138406
|
-
|
|
138407
|
-
|
|
138408
|
-
|
|
138426
|
+
async function fetchWebsiteHtml(websiteUrl, verbose) {
|
|
138427
|
+
const originUrl = normalizeWebsiteUrl(websiteUrl);
|
|
138428
|
+
if (!originUrl) throw new Error("\u7F51\u7AD9 URL \u4E3A\u7A7A");
|
|
138429
|
+
const started = Date.now();
|
|
138430
|
+
let current = originUrl;
|
|
138431
|
+
let referer;
|
|
138432
|
+
for (let redirectCount = 0; ; redirectCount++) {
|
|
138433
|
+
const headers = { ...HTML_FETCH_HEADERS };
|
|
138434
|
+
if (referer) headers.Referer = referer;
|
|
138435
|
+
const res = await rawRequest(current, {
|
|
138436
|
+
method: "GET",
|
|
138437
|
+
headers,
|
|
138438
|
+
timeoutMs: HTML_FETCH_TIMEOUT_MS,
|
|
138439
|
+
maxResponseBytes: HTML_FETCH_MAX_BYTES
|
|
138440
|
+
});
|
|
138441
|
+
if (res.status >= 300 && res.status < 400) {
|
|
138442
|
+
const location = res.headers.location;
|
|
138443
|
+
if (!location) throw new Error(`\u7F51\u7AD9\u8FD4\u56DE ${res.status}\uFF0C\u4F46\u6CA1\u6709 Location`);
|
|
138444
|
+
if (redirectCount >= HTML_FETCH_MAX_REDIRECTS) {
|
|
138445
|
+
throw new Error(`\u91CD\u5B9A\u5411\u6B21\u6570\u8D85\u8FC7\u9650\u5236\uFF08\u6700\u591A ${HTML_FETCH_MAX_REDIRECTS} \u6B21\uFF09`);
|
|
138446
|
+
}
|
|
138447
|
+
const next = new URL(location, current);
|
|
138448
|
+
if (next.protocol !== "http:" && next.protocol !== "https:") {
|
|
138449
|
+
throw new Error(`\u91CD\u5B9A\u5411\u534F\u8BAE\u4E0D\u652F\u6301\uFF1A${next.protocol}`);
|
|
138450
|
+
}
|
|
138451
|
+
referer = current;
|
|
138452
|
+
current = next.href;
|
|
138453
|
+
continue;
|
|
138454
|
+
}
|
|
138455
|
+
if (res.status < 200 || res.status >= 300) {
|
|
138456
|
+
const detail = verbose ? `\uFF1A${res.text.slice(0, 200)}` : "";
|
|
138457
|
+
throw new Error(`\u7F51\u7AD9 HTML \u4E0B\u8F7D\u5931\u8D25\uFF0C\u72B6\u6001\u7801 ${res.status}${detail}`);
|
|
138458
|
+
}
|
|
138459
|
+
if (!res.text.trim()) throw new Error("\u7F51\u7AD9 HTML \u5185\u5BB9\u4E3A\u7A7A");
|
|
138460
|
+
const mime = (res.headers["content-type"] ?? "text/html").split(";")[0]?.trim() || "text/html";
|
|
138461
|
+
return {
|
|
138462
|
+
originUrl,
|
|
138463
|
+
finalUrl: current === originUrl ? void 0 : current,
|
|
138464
|
+
mimeType: mime,
|
|
138465
|
+
contentLength: Buffer.byteLength(res.text, "utf8"),
|
|
138466
|
+
downloadTime: Date.now() - started,
|
|
138467
|
+
content: res.text
|
|
138468
|
+
};
|
|
138409
138469
|
}
|
|
138410
|
-
return { ok: true, value };
|
|
138411
138470
|
}
|
|
138412
|
-
async function
|
|
138413
|
-
const
|
|
138414
|
-
|
|
138415
|
-
const bodyStr = JSON.stringify({ urls: [websiteUrl] });
|
|
138416
|
-
const headers = {
|
|
138417
|
-
"Content-Type": "application/json; charset=utf-8",
|
|
138418
|
-
Accept: "application/json, text/plain, */*",
|
|
138419
|
-
"x-client-type": "tso",
|
|
138420
|
-
...config.apiKey ? { "x-api-key": config.apiKey } : { Authorization: `Bearer ${config.authToken}` },
|
|
138421
|
-
"Content-Length": String(Buffer.byteLength(bodyStr, "utf8"))
|
|
138422
|
-
};
|
|
138423
|
-
const res = await rawRequest(url, { method: "POST", headers, body: bodyStr });
|
|
138424
|
-
if (res.status < 200 || res.status >= 300) {
|
|
138425
|
-
const detail = verbose ? `\uFF1A${res.text.slice(0, 300)}` : "";
|
|
138426
|
-
throw new Error(`download-assets HTTP ${res.status}${detail}`);
|
|
138427
|
-
}
|
|
138428
|
-
let settled;
|
|
138471
|
+
async function readWebsiteHtmlFile(filePath) {
|
|
138472
|
+
const abs = path22.resolve(filePath);
|
|
138473
|
+
let size = 0;
|
|
138429
138474
|
try {
|
|
138430
|
-
|
|
138431
|
-
|
|
138432
|
-
|
|
138475
|
+
const stat2 = await fs17.stat(abs);
|
|
138476
|
+
if (!stat2.isFile()) throw new Error(`\u9996\u9875 HTML \u4E0D\u662F\u6587\u4EF6\uFF1A${abs}`);
|
|
138477
|
+
size = stat2.size;
|
|
138478
|
+
} catch (err) {
|
|
138479
|
+
if (err instanceof Error && err.message.startsWith("\u9996\u9875 HTML")) throw err;
|
|
138480
|
+
throw new Error(`\u627E\u4E0D\u5230\u9996\u9875 HTML\uFF1A${abs}`);
|
|
138433
138481
|
}
|
|
138434
|
-
const
|
|
138435
|
-
|
|
138436
|
-
|
|
138482
|
+
const fh = await fs17.open(abs, "r");
|
|
138483
|
+
try {
|
|
138484
|
+
const len = Math.min(size, HTML_FETCH_MAX_BYTES);
|
|
138485
|
+
const buf = Buffer.alloc(len);
|
|
138486
|
+
if (len > 0) await fh.read(buf, 0, len, 0);
|
|
138487
|
+
const content = buf.toString("utf8");
|
|
138488
|
+
if (!content.trim()) throw new Error("\u9996\u9875 HTML \u6587\u4EF6\u662F\u7A7A\u7684");
|
|
138489
|
+
return {
|
|
138490
|
+
originUrl: abs,
|
|
138491
|
+
mimeType: "text/html",
|
|
138492
|
+
contentLength: size,
|
|
138493
|
+
content,
|
|
138494
|
+
truncated: size > HTML_FETCH_MAX_BYTES
|
|
138495
|
+
};
|
|
138496
|
+
} finally {
|
|
138497
|
+
await fh.close();
|
|
138437
138498
|
}
|
|
138438
|
-
return picked.value;
|
|
138439
138499
|
}
|
|
138440
138500
|
|
|
138441
138501
|
// src/commands/website-diagnosis/run.ts
|
|
@@ -138512,29 +138572,42 @@ async function runWebsiteDiagnosisCollect(opts) {
|
|
|
138512
138572
|
console.error("\n\u274C \u8BF7\u63D0\u4F9B --url\n");
|
|
138513
138573
|
process.exit(1);
|
|
138514
138574
|
}
|
|
138575
|
+
if (opts.skipHtml && opts.htmlFile) {
|
|
138576
|
+
console.error("\n\u274C --html-file \u4E0E --skip-html \u4E0D\u80FD\u540C\u65F6\u4F7F\u7528\n");
|
|
138577
|
+
process.exit(1);
|
|
138578
|
+
}
|
|
138515
138579
|
let htmlMeta;
|
|
138516
138580
|
let htmlPreview;
|
|
138517
138581
|
let htmlFull;
|
|
138518
138582
|
let htmlError;
|
|
138583
|
+
let htmlSource = opts.skipHtml ? "skipped" : "cli";
|
|
138519
138584
|
let htmlAsset;
|
|
138520
|
-
if (
|
|
138585
|
+
if (opts.htmlFile) {
|
|
138586
|
+
htmlSource = "file";
|
|
138521
138587
|
try {
|
|
138522
|
-
htmlAsset = await
|
|
138523
|
-
htmlMeta = {
|
|
138524
|
-
originUrl: htmlAsset.originUrl,
|
|
138525
|
-
finalUrl: htmlAsset.finalUrl,
|
|
138526
|
-
mimeType: htmlAsset.mimeType,
|
|
138527
|
-
contentLength: htmlAsset.contentLength,
|
|
138528
|
-
downloadTime: htmlAsset.downloadTime
|
|
138529
|
-
};
|
|
138530
|
-
const content = String(htmlAsset.content ?? "");
|
|
138531
|
-
htmlPreview = content.slice(0, HTML_PREVIEW_CHARS);
|
|
138532
|
-
if (opts.includeHtml) {
|
|
138533
|
-
htmlFull = content;
|
|
138534
|
-
}
|
|
138588
|
+
htmlAsset = await readWebsiteHtmlFile(opts.htmlFile);
|
|
138535
138589
|
} catch (err) {
|
|
138536
138590
|
htmlError = err instanceof Error ? err.message : String(err);
|
|
138537
138591
|
}
|
|
138592
|
+
} else if (!opts.skipHtml) {
|
|
138593
|
+
try {
|
|
138594
|
+
htmlAsset = await fetchWebsiteHtml(websiteUrl, opts.verbose);
|
|
138595
|
+
} catch (err) {
|
|
138596
|
+
htmlError = err instanceof Error ? err.message : String(err);
|
|
138597
|
+
}
|
|
138598
|
+
}
|
|
138599
|
+
if (htmlAsset?.content) {
|
|
138600
|
+
htmlMeta = {
|
|
138601
|
+
originUrl: htmlAsset.originUrl,
|
|
138602
|
+
...htmlAsset.finalUrl ? { finalUrl: htmlAsset.finalUrl } : {},
|
|
138603
|
+
mimeType: htmlAsset.mimeType,
|
|
138604
|
+
contentLength: htmlAsset.contentLength,
|
|
138605
|
+
...htmlAsset.downloadTime != null ? { downloadTime: htmlAsset.downloadTime } : {},
|
|
138606
|
+
...htmlAsset.truncated ? { truncated: true } : {}
|
|
138607
|
+
};
|
|
138608
|
+
const content = String(htmlAsset.content);
|
|
138609
|
+
htmlPreview = content.slice(0, HTML_PREVIEW_CHARS);
|
|
138610
|
+
if (opts.includeHtml) htmlFull = content;
|
|
138538
138611
|
}
|
|
138539
138612
|
const resolved = await resolveLighthouseWithFallback({
|
|
138540
138613
|
config,
|
|
@@ -138546,7 +138619,7 @@ async function runWebsiteDiagnosisCollect(opts) {
|
|
|
138546
138619
|
url: websiteUrl,
|
|
138547
138620
|
collectedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
138548
138621
|
html: htmlBody,
|
|
138549
|
-
htmlTruncated:
|
|
138622
|
+
htmlTruncated: htmlAsset?.truncated === true,
|
|
138550
138623
|
lighthouse: resolved.lighthouse,
|
|
138551
138624
|
lighthouseWarning: resolved.lighthouseWarning,
|
|
138552
138625
|
htmlError,
|
|
@@ -138559,13 +138632,14 @@ async function runWebsiteDiagnosisCollect(opts) {
|
|
|
138559
138632
|
lighthouse: resolved.lighthouse,
|
|
138560
138633
|
...resolved.lighthouseWarning ? { lighthouseWarning: resolved.lighthouseWarning } : {},
|
|
138561
138634
|
...resolved.attempts != null ? { lighthouseAttempts: resolved.attempts } : {},
|
|
138635
|
+
htmlSource,
|
|
138562
138636
|
html: htmlMeta,
|
|
138563
138637
|
htmlPreview,
|
|
138564
138638
|
...htmlFull ? { htmlContent: htmlFull } : {},
|
|
138565
138639
|
...htmlError ? { htmlError } : {},
|
|
138566
138640
|
signals,
|
|
138567
138641
|
dataAvailability: signals.dataAvailability,
|
|
138568
|
-
agentHint: `lighthouseSource=${resolved.source}\u3002` + (resolved.source === "none" ? "Lighthouse API \u5931\u8D25\uFF1Am2i1/m5i1 \u987B status=Absent\u3001score=0\uFF0C\u7981\u6B62\u7F16\u9020\u6027\u80FD\u5206\u3002" : "TSO Lighthouse \u53EF\u7528\u3002") +
|
|
138642
|
+
agentHint: `lighthouseSource=${resolved.source}\u3002` + (resolved.source === "none" ? "Lighthouse API \u5931\u8D25\uFF1Am2i1/m5i1 \u987B status=Absent\u3001score=0\uFF0C\u7981\u6B62\u7F16\u9020\u6027\u80FD\u5206\u3002" : "TSO Lighthouse \u53EF\u7528\u3002") + (htmlSource === "file" ? " \u7ED3\u6784\u4FE1\u53F7\u6765\u81EA --html-file\uFF0CCLI \u6CA1\u6709\u518D GET \u76EE\u6807\u7AD9\u3002" : " \u8868\u5355/\u5BFC\u822A\u4EE5 signals \u4E3A\u51C6\uFF08\u5DF2\u6309\u5B8C\u6574 HTML \u62BD\u53D6\uFF09\uFF1B\u7981\u6B62\u7528 htmlPreview \u5224\u65AD\u6709\u65E0\u8868\u5355\u3002") + ` 1) \u8BFB signals + dataAvailability\uFF1B2) website-diagnosis prepare\uFF1B3) \u8865\u5168 diagnosis\uFF1B4) render\u3002 ${signals.dataAvailability.agentHint}`
|
|
138569
138643
|
};
|
|
138570
138644
|
if (await emitCliJsonOrSnapshot(
|
|
138571
138645
|
{ jsonOut: opts.jsonOut },
|
|
@@ -138583,10 +138657,10 @@ async function runWebsiteDiagnosisCollect(opts) {
|
|
|
138583
138657
|
|
|
138584
138658
|
// src/commands/website-diagnosis/prepare.ts
|
|
138585
138659
|
init_cli_json_snapshot();
|
|
138586
|
-
import
|
|
138587
|
-
import
|
|
138660
|
+
import fs18 from "fs";
|
|
138661
|
+
import path23 from "path";
|
|
138588
138662
|
function readJson(filePath) {
|
|
138589
|
-
const text4 =
|
|
138663
|
+
const text4 = fs18.readFileSync(filePath, "utf8");
|
|
138590
138664
|
try {
|
|
138591
138665
|
const v = JSON.parse(text4);
|
|
138592
138666
|
if (!v || typeof v !== "object" || Array.isArray(v)) {
|
|
@@ -138616,8 +138690,8 @@ function signalsFromCollectPayload(collect) {
|
|
|
138616
138690
|
});
|
|
138617
138691
|
}
|
|
138618
138692
|
async function runWebsiteDiagnosisPrepare(opts) {
|
|
138619
|
-
const collectPath =
|
|
138620
|
-
if (!
|
|
138693
|
+
const collectPath = path23.resolve(opts.collectFile);
|
|
138694
|
+
if (!fs18.existsSync(collectPath)) {
|
|
138621
138695
|
console.error(`
|
|
138622
138696
|
\u274C \u627E\u4E0D\u5230 collect \u6587\u4EF6\uFF1A${collectPath}
|
|
138623
138697
|
`);
|
|
@@ -138626,11 +138700,11 @@ async function runWebsiteDiagnosisPrepare(opts) {
|
|
|
138626
138700
|
const collect = readJson(collectPath);
|
|
138627
138701
|
const signals = signalsFromCollectPayload(collect);
|
|
138628
138702
|
const scaffold = buildDiagnosisScaffold(signals);
|
|
138629
|
-
const outPath =
|
|
138630
|
-
opts.out ??
|
|
138703
|
+
const outPath = path23.resolve(
|
|
138704
|
+
opts.out ?? path23.join(path23.dirname(collectPath), "diagnosis.scaffold.json")
|
|
138631
138705
|
);
|
|
138632
|
-
|
|
138633
|
-
|
|
138706
|
+
fs18.mkdirSync(path23.dirname(outPath), { recursive: true });
|
|
138707
|
+
fs18.writeFileSync(outPath, JSON.stringify(scaffold, null, 2), "utf8");
|
|
138634
138708
|
const summary = {
|
|
138635
138709
|
url: signals.url,
|
|
138636
138710
|
out: outPath,
|
|
@@ -138669,23 +138743,262 @@ async function runWebsiteDiagnosisPrepare(opts) {
|
|
|
138669
138743
|
// src/commands/website-diagnosis/render-report.ts
|
|
138670
138744
|
init_lang();
|
|
138671
138745
|
init_html();
|
|
138672
|
-
import
|
|
138746
|
+
import fs19 from "fs";
|
|
138673
138747
|
import fsPromises from "fs/promises";
|
|
138674
|
-
import
|
|
138748
|
+
import path24 from "path";
|
|
138675
138749
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
138750
|
+
|
|
138751
|
+
// src/commands/website-diagnosis/tracking-probe.ts
|
|
138752
|
+
var MISSING_TRACKING_MESSAGE = "\u7F3A\u5C11 GA/GTM \u5B9E\u8BBF JSON\u3002\u7528\u6D4F\u89C8\u5668\u6253\u5F00\u7F51\u7AD9\uFF0C\u6309 assets/website-diagnosis-tracking.md \u5199\u5165 ga-gtm.json\uFF0C\u518D\u6267\u884C website-diagnosis render --tracking <\u8BE5\u6587\u4EF6>\u3002\u4E0D\u8981\u7528 collect \u7684 HTML \u6216 signals.analyticsHints \u586B\u5199\u5BB9\u5668 ID\u3002";
|
|
138753
|
+
var TOP_KEYS = [
|
|
138754
|
+
"url",
|
|
138755
|
+
"probedAt",
|
|
138756
|
+
"source",
|
|
138757
|
+
"status",
|
|
138758
|
+
"unavailableReason",
|
|
138759
|
+
"gtm",
|
|
138760
|
+
"ga",
|
|
138761
|
+
"evidence",
|
|
138762
|
+
"pages",
|
|
138763
|
+
"summary"
|
|
138764
|
+
];
|
|
138765
|
+
var GTM_ID = /^GTM-[A-Z0-9]{4,}$/;
|
|
138766
|
+
var GA4_ID = /^G-[A-Z0-9]{4,}$/;
|
|
138767
|
+
var UA_ID = /^UA-\d+-\d+$/;
|
|
138768
|
+
var LOADED_BY = /* @__PURE__ */ new Set(["direct", "gtm", "both", "none"]);
|
|
138769
|
+
var EVIDENCE_KIND = /* @__PURE__ */ new Set(["script", "network", "datalayer", "noscript"]);
|
|
138770
|
+
function asObject(value, where) {
|
|
138771
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
138772
|
+
throw new Error(`${where} \u987B\u4E3A JSON \u5BF9\u8C61`);
|
|
138773
|
+
}
|
|
138774
|
+
return value;
|
|
138775
|
+
}
|
|
138776
|
+
function rejectUnknown(obj, allowed, where) {
|
|
138777
|
+
const extra = Object.keys(obj).filter((key) => !allowed.includes(key));
|
|
138778
|
+
if (extra.length === 0) return;
|
|
138779
|
+
throw new Error(`${where} \u542B\u672A\u652F\u6301\u7684\u5B57\u6BB5\uFF1A${extra.join("\u3001")}\u3002\u53EA\u63A5\u53D7 ${allowed.join("\u3001")}\u3002`);
|
|
138780
|
+
}
|
|
138781
|
+
function readArray(value, where) {
|
|
138782
|
+
if (!Array.isArray(value)) throw new Error(`${where} \u987B\u4E3A\u6570\u7EC4`);
|
|
138783
|
+
return value;
|
|
138784
|
+
}
|
|
138785
|
+
function dedupe(ids) {
|
|
138786
|
+
const out = [];
|
|
138787
|
+
const seen = /* @__PURE__ */ new Set();
|
|
138788
|
+
for (const id of ids) {
|
|
138789
|
+
if (seen.has(id)) continue;
|
|
138790
|
+
seen.add(id);
|
|
138791
|
+
out.push(id);
|
|
138792
|
+
}
|
|
138793
|
+
return out;
|
|
138794
|
+
}
|
|
138795
|
+
function plainText(value, where, min, max) {
|
|
138796
|
+
if (typeof value !== "string") throw new Error(`${where} \u987B\u4E3A\u5B57\u7B26\u4E32`);
|
|
138797
|
+
const text4 = value.trim();
|
|
138798
|
+
if (text4.length < min || text4.length > max) {
|
|
138799
|
+
throw new Error(`${where} \u957F\u5EA6\u987B\u5728 ${min}\u2013${max} \u5B57\uFF0C\u5F53\u524D ${text4.length}\u3002`);
|
|
138800
|
+
}
|
|
138801
|
+
if (/[<>]/.test(text4)) throw new Error(`${where} \u4E0D\u8981\u8D34 HTML\uFF0C\u53EA\u5199\u77ED\u53E5\u6216 URL\u3002`);
|
|
138802
|
+
return text4;
|
|
138803
|
+
}
|
|
138804
|
+
function readUrl(value, where) {
|
|
138805
|
+
if (typeof value !== "string") throw new Error(`${where} \u987B\u4E3A\u5B57\u7B26\u4E32`);
|
|
138806
|
+
const url = value.trim();
|
|
138807
|
+
if (!/^https?:\/\/\S+$/i.test(url) || url.length > 500) {
|
|
138808
|
+
throw new Error(`${where} \u987B\u4E3A http(s) \u5730\u5740\u3002`);
|
|
138809
|
+
}
|
|
138810
|
+
return url;
|
|
138811
|
+
}
|
|
138812
|
+
function readProbedAt(value) {
|
|
138813
|
+
if (typeof value !== "string" || !value.trim()) throw new Error("probedAt \u987B\u4E3A ISO \u65F6\u95F4\u5B57\u7B26\u4E32");
|
|
138814
|
+
const parsed = Date.parse(value);
|
|
138815
|
+
if (!Number.isFinite(parsed)) throw new Error(`probedAt \u65E0\u6CD5\u89E3\u6790\uFF1A${value}`);
|
|
138816
|
+
const year = new Date(parsed).getUTCFullYear();
|
|
138817
|
+
if (year < 2020 || year > 2100) throw new Error(`probedAt \u5E74\u4EFD\u4E0D\u5408\u7406\uFF1A${value}`);
|
|
138818
|
+
return new Date(parsed).toISOString();
|
|
138819
|
+
}
|
|
138820
|
+
function readGtmId(value, where) {
|
|
138821
|
+
if (typeof value !== "string") throw new Error(`${where} \u7684\u6BCF\u4E00\u9879\u987B\u4E3A\u5B57\u7B26\u4E32`);
|
|
138822
|
+
const id = value.trim().toUpperCase();
|
|
138823
|
+
if (!GTM_ID.test(id)) throw new Error(`${where} \u53EA\u63A5\u53D7 GTM- \u5F00\u5934\u7684\u5BB9\u5668 ID\uFF0C\u6536\u5230\u300C${value}\u300D\u3002`);
|
|
138824
|
+
return id;
|
|
138825
|
+
}
|
|
138826
|
+
function readGa4Id(value) {
|
|
138827
|
+
if (typeof value !== "string") throw new Error("ga.measurementIds \u7684\u6BCF\u4E00\u9879\u987B\u4E3A\u5B57\u7B26\u4E32");
|
|
138828
|
+
const id = value.trim().toUpperCase();
|
|
138829
|
+
if (id.startsWith("AW-")) {
|
|
138830
|
+
throw new Error(`ga.measurementIds \u4E0D\u6536\u5E7F\u544A\u8F6C\u5316 ID\u300C${id}\u300D\uFF0C\u53EA\u6536 G- \u5F00\u5934\u7684 GA4\u3002`);
|
|
138831
|
+
}
|
|
138832
|
+
if (id.startsWith("UA-")) {
|
|
138833
|
+
throw new Error(`\u300C${id}\u300D\u662F\u65E7\u7248 UA\uFF0C\u5199\u5165 ga.legacyIds\uFF0C\u4E0D\u8981\u653E\u8FDB measurementIds\u3002`);
|
|
138834
|
+
}
|
|
138835
|
+
if (!GA4_ID.test(id))
|
|
138836
|
+
throw new Error(`ga.measurementIds \u53EA\u63A5\u53D7 G- \u5F00\u5934\u7684 GA4 ID\uFF0C\u6536\u5230\u300C${value}\u300D\u3002`);
|
|
138837
|
+
return id;
|
|
138838
|
+
}
|
|
138839
|
+
function readUaId(value) {
|
|
138840
|
+
if (typeof value !== "string") throw new Error("ga.legacyIds \u7684\u6BCF\u4E00\u9879\u987B\u4E3A\u5B57\u7B26\u4E32");
|
|
138841
|
+
const id = value.trim().toUpperCase();
|
|
138842
|
+
if (!UA_ID.test(id)) throw new Error(`ga.legacyIds \u53EA\u63A5\u53D7 UA-\u6570\u5B57-\u6570\u5B57\uFF0C\u6536\u5230\u300C${value}\u300D\u3002`);
|
|
138843
|
+
return id;
|
|
138844
|
+
}
|
|
138845
|
+
function readPageGaId(value) {
|
|
138846
|
+
if (typeof value !== "string") throw new Error("pages[].gaIds \u7684\u6BCF\u4E00\u9879\u987B\u4E3A\u5B57\u7B26\u4E32");
|
|
138847
|
+
const id = value.trim().toUpperCase();
|
|
138848
|
+
if (GA4_ID.test(id) || UA_ID.test(id)) return id;
|
|
138849
|
+
throw new Error(`pages[].gaIds \u53EA\u63A5\u53D7 G- \u6216 UA- ID\uFF0C\u6536\u5230\u300C${value}\u300D\u3002`);
|
|
138850
|
+
}
|
|
138851
|
+
function assertSubset(child, parent, where) {
|
|
138852
|
+
for (const id of child) {
|
|
138853
|
+
if (!parent.includes(id)) {
|
|
138854
|
+
throw new Error(
|
|
138855
|
+
`${where} \u51FA\u73B0\u4E86\u300C${id}\u300D\uFF0C\u9876\u5C42\u5217\u8868\u91CC\u6CA1\u6709\u3002\u5148\u628A ID \u6C47\u603B\u8FDB gtm.containerIds \u6216 ga.measurementIds / ga.legacyIds\u3002`
|
|
138856
|
+
);
|
|
138857
|
+
}
|
|
138858
|
+
}
|
|
138859
|
+
}
|
|
138860
|
+
function readGtm(value) {
|
|
138861
|
+
const row = asObject(value, "gtm");
|
|
138862
|
+
rejectUnknown(row, ["present", "containerIds"], "gtm");
|
|
138863
|
+
if (typeof row.present !== "boolean") throw new Error("gtm.present \u987B\u4E3A\u5E03\u5C14\u503C");
|
|
138864
|
+
const containerIds = dedupe(
|
|
138865
|
+
readArray(row.containerIds, "gtm.containerIds").map((id) => readGtmId(id, "gtm.containerIds"))
|
|
138866
|
+
);
|
|
138867
|
+
if (containerIds.length > 8) throw new Error("gtm.containerIds \u6700\u591A 8 \u4E2A\u3002");
|
|
138868
|
+
if (row.present && containerIds.length === 0)
|
|
138869
|
+
throw new Error("gtm.present \u4E3A true \u65F6\uFF0CcontainerIds \u4E0D\u80FD\u4E3A\u7A7A\u3002");
|
|
138870
|
+
if (!row.present && containerIds.length > 0)
|
|
138871
|
+
throw new Error("gtm.present \u4E3A false \u65F6\uFF0CcontainerIds \u5FC5\u987B\u4E3A\u7A7A\u3002");
|
|
138872
|
+
return { present: row.present, containerIds };
|
|
138873
|
+
}
|
|
138874
|
+
function readGa(value, gtmPresent) {
|
|
138875
|
+
const row = asObject(value, "ga");
|
|
138876
|
+
rejectUnknown(row, ["present", "measurementIds", "legacyIds", "loadedBy"], "ga");
|
|
138877
|
+
if (typeof row.present !== "boolean") throw new Error("ga.present \u987B\u4E3A\u5E03\u5C14\u503C");
|
|
138878
|
+
const loadedBy = row.loadedBy;
|
|
138879
|
+
if (typeof loadedBy !== "string" || !LOADED_BY.has(loadedBy)) {
|
|
138880
|
+
throw new Error("ga.loadedBy \u53EA\u63A5\u53D7 direct\u3001gtm\u3001both\u3001none\u3002");
|
|
138881
|
+
}
|
|
138882
|
+
const measurementIds = dedupe(readArray(row.measurementIds, "ga.measurementIds").map(readGa4Id));
|
|
138883
|
+
const legacyIds = dedupe(readArray(row.legacyIds, "ga.legacyIds").map(readUaId));
|
|
138884
|
+
if (measurementIds.length > 8) throw new Error("ga.measurementIds \u6700\u591A 8 \u4E2A\u3002");
|
|
138885
|
+
if (legacyIds.length > 4) throw new Error("ga.legacyIds \u6700\u591A 4 \u4E2A\u3002");
|
|
138886
|
+
const by = loadedBy;
|
|
138887
|
+
if (!row.present) {
|
|
138888
|
+
if (measurementIds.length || legacyIds.length)
|
|
138889
|
+
throw new Error("ga.present \u4E3A false \u65F6\uFF0CmeasurementIds \u548C legacyIds \u5FC5\u987B\u4E3A\u7A7A\u3002");
|
|
138890
|
+
if (by !== "none") throw new Error("ga.present \u4E3A false \u65F6\uFF0CloadedBy \u5FC5\u987B\u662F none\u3002");
|
|
138891
|
+
} else {
|
|
138892
|
+
if (measurementIds.length + legacyIds.length === 0) {
|
|
138893
|
+
throw new Error("ga.present \u4E3A true \u65F6\uFF0CmeasurementIds \u6216 legacyIds \u81F3\u5C11\u6709\u4E00\u4E2A ID\u3002");
|
|
138894
|
+
}
|
|
138895
|
+
if (by === "none") throw new Error("ga.present \u4E3A true \u65F6\uFF0CloadedBy \u4E0D\u80FD\u662F none\u3002");
|
|
138896
|
+
if ((by === "gtm" || by === "both") && !gtmPresent) {
|
|
138897
|
+
throw new Error("ga.loadedBy \u4E3A gtm \u6216 both \u65F6\uFF0Cgtm.present \u5FC5\u987B\u4E3A true\u3002");
|
|
138898
|
+
}
|
|
138899
|
+
}
|
|
138900
|
+
return { present: row.present, measurementIds, legacyIds, loadedBy: by };
|
|
138901
|
+
}
|
|
138902
|
+
function readEvidence(value) {
|
|
138903
|
+
const rows = readArray(value, "evidence");
|
|
138904
|
+
if (rows.length > 12) throw new Error("evidence \u6700\u591A 12 \u6761\u3002");
|
|
138905
|
+
return rows.map((item, index) => {
|
|
138906
|
+
const row = asObject(item, `evidence[${index}]`);
|
|
138907
|
+
rejectUnknown(row, ["kind", "detail"], `evidence[${index}]`);
|
|
138908
|
+
const kind = row.kind;
|
|
138909
|
+
if (typeof kind !== "string" || !EVIDENCE_KIND.has(kind)) {
|
|
138910
|
+
throw new Error(`evidence[${index}].kind \u53EA\u63A5\u53D7 script\u3001network\u3001datalayer\u3001noscript\u3002`);
|
|
138911
|
+
}
|
|
138912
|
+
return {
|
|
138913
|
+
kind,
|
|
138914
|
+
detail: plainText(row.detail, `evidence[${index}].detail`, 4, 180)
|
|
138915
|
+
};
|
|
138916
|
+
});
|
|
138917
|
+
}
|
|
138918
|
+
function readPages(value, gtmIds, gaIds) {
|
|
138919
|
+
if (value == null) return [];
|
|
138920
|
+
const rows = readArray(value, "pages");
|
|
138921
|
+
if (rows.length > 4) throw new Error("pages \u6700\u591A 4 \u4E2A\u3002");
|
|
138922
|
+
return rows.map((item, index) => {
|
|
138923
|
+
const row = asObject(item, `pages[${index}]`);
|
|
138924
|
+
rejectUnknown(row, ["url", "gtmIds", "gaIds"], `pages[${index}]`);
|
|
138925
|
+
const pageGtm = dedupe(
|
|
138926
|
+
readArray(row.gtmIds, `pages[${index}].gtmIds`).map(
|
|
138927
|
+
(id) => readGtmId(id, `pages[${index}].gtmIds`)
|
|
138928
|
+
)
|
|
138929
|
+
);
|
|
138930
|
+
const pageGa = dedupe(readArray(row.gaIds, `pages[${index}].gaIds`).map(readPageGaId));
|
|
138931
|
+
assertSubset(pageGtm, gtmIds, `pages[${index}].gtmIds`);
|
|
138932
|
+
assertSubset(pageGa, gaIds, `pages[${index}].gaIds`);
|
|
138933
|
+
return { url: readUrl(row.url, `pages[${index}].url`), gtmIds: pageGtm, gaIds: pageGa };
|
|
138934
|
+
});
|
|
138935
|
+
}
|
|
138936
|
+
function parseTrackingProbe(raw) {
|
|
138937
|
+
const row = asObject(raw, "GA/GTM JSON");
|
|
138938
|
+
rejectUnknown(row, TOP_KEYS, "GA/GTM JSON");
|
|
138939
|
+
if (row.source !== "browser") {
|
|
138940
|
+
throw new Error(
|
|
138941
|
+
`source \u56FA\u5B9A\u4E3A "browser"\uFF0C\u6536\u5230\u300C${String(row.source)}\u300D\u3002\u8FD9\u4EFD JSON \u53EA\u80FD\u6765\u81EA\u6D4F\u89C8\u5668\u5B9E\u8BBF\u3002`
|
|
138942
|
+
);
|
|
138943
|
+
}
|
|
138944
|
+
if (row.status !== "ok" && row.status !== "unavailable") {
|
|
138945
|
+
throw new Error(`status \u53EA\u63A5\u53D7 ok \u6216 unavailable\uFF0C\u6536\u5230\u300C${String(row.status)}\u300D\u3002`);
|
|
138946
|
+
}
|
|
138947
|
+
const url = readUrl(row.url, "url");
|
|
138948
|
+
const probedAt = readProbedAt(row.probedAt);
|
|
138949
|
+
const gtm = readGtm(row.gtm);
|
|
138950
|
+
const ga = readGa(row.ga, gtm.present);
|
|
138951
|
+
const evidence = readEvidence(row.evidence);
|
|
138952
|
+
const pages = readPages(row.pages, gtm.containerIds, [...ga.measurementIds, ...ga.legacyIds]);
|
|
138953
|
+
const summary = row.summary == null || row.summary === "" ? "" : plainText(row.summary, "summary", 1, 400);
|
|
138954
|
+
if (row.status === "unavailable") {
|
|
138955
|
+
const unavailableReason = plainText(row.unavailableReason, "unavailableReason", 4, 200);
|
|
138956
|
+
if (gtm.present || ga.present || evidence.length || pages.length) {
|
|
138957
|
+
throw new Error("status \u4E3A unavailable \u65F6\uFF0C\u4E0D\u8981\u586B\u5199\u5DF2\u68C0\u6D4B\u5230\u7684 ID\u3001evidence \u6216 pages\u3002");
|
|
138958
|
+
}
|
|
138959
|
+
return {
|
|
138960
|
+
url,
|
|
138961
|
+
probedAt,
|
|
138962
|
+
source: "browser",
|
|
138963
|
+
status: "unavailable",
|
|
138964
|
+
unavailableReason,
|
|
138965
|
+
gtm,
|
|
138966
|
+
ga,
|
|
138967
|
+
evidence,
|
|
138968
|
+
pages,
|
|
138969
|
+
summary
|
|
138970
|
+
};
|
|
138971
|
+
}
|
|
138972
|
+
if (row.unavailableReason != null && String(row.unavailableReason).trim()) {
|
|
138973
|
+
throw new Error("status \u4E3A ok \u65F6\u4E0D\u8981\u5199 unavailableReason\u3002");
|
|
138974
|
+
}
|
|
138975
|
+
if ((gtm.present || ga.present) && evidence.length === 0) {
|
|
138976
|
+
throw new Error("\u68C0\u6D4B\u5230\u6807\u7B7E\u65F6\uFF0Cevidence \u81F3\u5C11\u4E00\u6761\uFF0C\u5199\u660E\u811A\u672C\u5730\u5740\u6216\u6D4F\u89C8\u5668\u8BF7\u6C42\u91CC\u7684 ID\u3002");
|
|
138977
|
+
}
|
|
138978
|
+
if (!gtm.present && !ga.present && summary.length < 8) {
|
|
138979
|
+
throw new Error("\u6CA1\u6709 GTM \u4E5F\u6CA1\u6709 GA \u65F6\uFF0Csummary \u7528\u4E00\u53E5\u8BDD\u8BF4\u660E\u770B\u8FC7\u54EA\u4E2A\u9875\u9762\u3001\u6CA1\u770B\u5230\u6807\u7B7E\u3002");
|
|
138980
|
+
}
|
|
138981
|
+
return { url, probedAt, source: "browser", status: "ok", gtm, ga, evidence, pages, summary };
|
|
138982
|
+
}
|
|
138983
|
+
function readTrackingForReport(source) {
|
|
138984
|
+
if (source === void 0) throw new Error(MISSING_TRACKING_MESSAGE);
|
|
138985
|
+
return parseTrackingProbe(source);
|
|
138986
|
+
}
|
|
138987
|
+
|
|
138988
|
+
// src/commands/website-diagnosis/render-report.ts
|
|
138676
138989
|
var TEMPLATE_BASENAMES = {
|
|
138677
138990
|
html: "website-diagnosis-report.html",
|
|
138678
138991
|
runtime: "website-diagnosis-report.runtime.js"
|
|
138679
138992
|
};
|
|
138680
138993
|
function resolveSkillTemplatePath(basename13) {
|
|
138681
|
-
const dir =
|
|
138994
|
+
const dir = path24.dirname(fileURLToPath4(import.meta.url));
|
|
138682
138995
|
const candidates = [
|
|
138683
|
-
|
|
138684
|
-
|
|
138685
|
-
|
|
138996
|
+
path24.join(dir, "skill", "report-templates", basename13),
|
|
138997
|
+
path24.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
|
|
138998
|
+
path24.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
|
|
138686
138999
|
];
|
|
138687
139000
|
for (const p of candidates) {
|
|
138688
|
-
if (
|
|
139001
|
+
if (fs19.existsSync(p)) return p;
|
|
138689
139002
|
}
|
|
138690
139003
|
return candidates[0];
|
|
138691
139004
|
}
|
|
@@ -138720,7 +139033,17 @@ function mergeCollectLighthouse(data, collect) {
|
|
|
138720
139033
|
...collect.lighthouseWarning && !data.lighthouseWarning ? { lighthouseWarning: collect.lighthouseWarning } : {}
|
|
138721
139034
|
};
|
|
138722
139035
|
}
|
|
138723
|
-
var PRIORITY_RANKS = /* @__PURE__ */ new Set([
|
|
139036
|
+
var PRIORITY_RANKS = /* @__PURE__ */ new Set([
|
|
139037
|
+
"\u9AD8",
|
|
139038
|
+
"\u4E2D",
|
|
139039
|
+
"\u4F4E",
|
|
139040
|
+
"High",
|
|
139041
|
+
"Medium",
|
|
139042
|
+
"Low",
|
|
139043
|
+
"high",
|
|
139044
|
+
"medium",
|
|
139045
|
+
"low"
|
|
139046
|
+
]);
|
|
138724
139047
|
function planItems(group) {
|
|
138725
139048
|
const items3 = group.items ?? group["\u4F18\u5316\u9879"];
|
|
138726
139049
|
return Array.isArray(items3) ? items3 : [];
|
|
@@ -138749,7 +139072,8 @@ function priorityPlanError(data) {
|
|
|
138749
139072
|
const card = item;
|
|
138750
139073
|
const direction = String(card.direction ?? card["\u4F18\u5316\u65B9\u5411"] ?? "").trim();
|
|
138751
139074
|
const task = String(card.task ?? card["\u5177\u4F53\u4EFB\u52A1"] ?? "").trim();
|
|
138752
|
-
if (!direction || !task)
|
|
139075
|
+
if (!direction || !task)
|
|
139076
|
+
return "priorityPlan \u6BCF\u6761\u90FD\u8981\u5199 direction \u548C task\uFF0C\u4E14\u4E0D\u80FD\u662F\u7A7A\u5B57\u7B26\u4E32\u3002";
|
|
138753
139077
|
itemCount2 += 1;
|
|
138754
139078
|
}
|
|
138755
139079
|
}
|
|
@@ -138766,13 +139090,25 @@ function injectReportData(html, payload, lang) {
|
|
|
138766
139090
|
return localized.replace(marker, `window.__WEBSITE_DIAGNOSIS__ = ${json};`);
|
|
138767
139091
|
}
|
|
138768
139092
|
async function runWebsiteDiagnosisRender(opts) {
|
|
138769
|
-
const dataPath =
|
|
139093
|
+
const dataPath = path24.resolve(opts.dataFile);
|
|
138770
139094
|
const dataRaw = await readJsonFile(dataPath);
|
|
138771
139095
|
let data = asRecord6(dataRaw);
|
|
138772
139096
|
if (opts.collectFile) {
|
|
138773
|
-
const collectRaw = await readJsonFile(
|
|
139097
|
+
const collectRaw = await readJsonFile(path24.resolve(opts.collectFile));
|
|
138774
139098
|
data = mergeCollectLighthouse(data, asRecord6(collectRaw));
|
|
138775
139099
|
}
|
|
139100
|
+
const trackingSource = opts.trackingFile ? await readJsonFile(path24.resolve(opts.trackingFile)) : data.tracking;
|
|
139101
|
+
let tracking;
|
|
139102
|
+
try {
|
|
139103
|
+
tracking = readTrackingForReport(trackingSource);
|
|
139104
|
+
} catch (err) {
|
|
139105
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
139106
|
+
console.error(`
|
|
139107
|
+
\u274C ${message}
|
|
139108
|
+
`);
|
|
139109
|
+
process.exit(1);
|
|
139110
|
+
}
|
|
139111
|
+
data = { ...data, tracking };
|
|
138776
139112
|
const planError = priorityPlanError(data);
|
|
138777
139113
|
if (planError) {
|
|
138778
139114
|
console.error(`
|
|
@@ -138792,14 +139128,14 @@ async function runWebsiteDiagnosisRender(opts) {
|
|
|
138792
139128
|
`);
|
|
138793
139129
|
process.exit(1);
|
|
138794
139130
|
}
|
|
138795
|
-
const outPath =
|
|
138796
|
-
opts.out ??
|
|
139131
|
+
const outPath = path24.resolve(
|
|
139132
|
+
opts.out ?? path24.join(path24.dirname(dataPath), "website-diagnosis-report.html")
|
|
138797
139133
|
);
|
|
138798
|
-
const outDir =
|
|
139134
|
+
const outDir = path24.dirname(outPath);
|
|
138799
139135
|
await fsPromises.mkdir(outDir, { recursive: true });
|
|
138800
139136
|
await fsPromises.writeFile(outPath, injectReportData(html, data, lang), "utf8");
|
|
138801
139137
|
const runtimeSrc = websiteDiagnosisRuntimePath();
|
|
138802
|
-
const runtimeOut =
|
|
139138
|
+
const runtimeOut = path24.join(outDir, TEMPLATE_BASENAMES.runtime);
|
|
138803
139139
|
let runtimeCopied = false;
|
|
138804
139140
|
try {
|
|
138805
139141
|
await fsPromises.copyFile(runtimeSrc, runtimeOut);
|
|
@@ -138823,9 +139159,7 @@ function registerWebsiteDiagnosisCommands(program2) {
|
|
|
138823
139159
|
const root = program2.command("website-diagnosis").description(
|
|
138824
139160
|
"\u7F51\u7AD9\u8BCA\u65AD\uFF1ALighthouse \u6027\u80FD\u3001HTML \u91C7\u96C6\u3001ARIT \u5386\u53F2\u5F97\u5206\uFF1B\u9ED8\u8BA4\u4EA4\u4ED8 HTML \u62A5\u544A\uFF08render \u5B50\u547D\u4EE4\uFF09"
|
|
138825
139161
|
);
|
|
138826
|
-
root.command("performance").description(
|
|
138827
|
-
"\u62C9\u53D6 Lighthouse\uFF1A\u8BF7\u6C42 TSO performance API\uFF08\u5931\u8D25\u81EA\u52A8\u91CD\u8BD5\uFF0C\u4E0D\u7F16\u9020 score/FCP\uFF09"
|
|
138828
|
-
).requiredOption("--url <url>", "\u7F51\u7AD9 URL\uFF08\u53EF\u7701\u7565 https://\uFF0C\u81EA\u52A8\u8865\u5168\uFF09").option("--token <token>", "JWT\uFF08\u9ED8\u8BA4\u8BFB config / \u73AF\u5883\u53D8\u91CF\uFF09").option("--verbose", "\u6253\u5370\u8BF7\u6C42\u8BE6\u60C5").option("--json-out <dir>", "\u843D\u76D8 cli-manifest + JSON").action(async (opts) => {
|
|
139162
|
+
root.command("performance").description("\u62C9\u53D6 Lighthouse\uFF1A\u8BF7\u6C42 TSO performance API\uFF08\u5931\u8D25\u81EA\u52A8\u91CD\u8BD5\uFF0C\u4E0D\u7F16\u9020 score/FCP\uFF09").requiredOption("--url <url>", "\u7F51\u7AD9 URL\uFF08\u53EF\u7701\u7565 https://\uFF0C\u81EA\u52A8\u8865\u5168\uFF09").option("--token <token>", "JWT\uFF08\u9ED8\u8BA4\u8BFB config / \u73AF\u5883\u53D8\u91CF\uFF09").option("--verbose", "\u6253\u5370\u8BF7\u6C42\u8BE6\u60C5").option("--json-out <dir>", "\u843D\u76D8 cli-manifest + JSON").action(async (opts) => {
|
|
138829
139163
|
await runWebsiteDiagnosisPerformance({
|
|
138830
139164
|
url: opts.url,
|
|
138831
139165
|
token: opts.token,
|
|
@@ -138843,11 +139177,15 @@ function registerWebsiteDiagnosisCommands(program2) {
|
|
|
138843
139177
|
});
|
|
138844
139178
|
root.command("collect").description(
|
|
138845
139179
|
"\u91C7\u96C6\u8BCA\u65AD\u539F\u6599\uFF1ALighthouse + \u9996\u9875 HTML\uFF1B\u843D\u76D8\u542B signals/dataAvailability\uFF08Lighthouse \u5931\u8D25\u4E0D\u963B\u65AD\uFF0C\u6807\u8BB0\u4E0D\u53EF\u7528\u5B50\u9879\uFF09"
|
|
138846
|
-
).requiredOption("--url <url>", "\u7F51\u7AD9 URL").option("--include-html", "\u843D\u76D8\u65F6\u4FDD\u7559\u5B8C\u6574 HTML\uFF08\u4F53\u79EF\u5927\uFF0C\u9ED8\u8BA4\u4EC5 preview\uFF09").option(
|
|
139180
|
+
).requiredOption("--url <url>", "\u7F51\u7AD9 URL").option("--include-html", "\u843D\u76D8\u65F6\u4FDD\u7559\u5B8C\u6574 HTML\uFF08\u4F53\u79EF\u5927\uFF0C\u9ED8\u8BA4\u4EC5 preview\uFF09").option(
|
|
139181
|
+
"--html-file <file>",
|
|
139182
|
+
"\u4F7F\u7528\u672C\u5730\u6E32\u67D3\u540E\u7684\u9996\u9875 HTML \u62BD signals\uFF0C\u4E0D\u518D GET \u76EE\u6807\u7AD9\uFF08\u4E0E\u6D4F\u89C8\u5668\u5B9E\u8BBF\u540C\u4E00\u6B21\u6253\u5F00\uFF09"
|
|
139183
|
+
).option("--skip-html", "\u4EC5\u62C9 Lighthouse\uFF0C\u4E0D\u4E0B\u8F7D\u9996\u9875 HTML").option("--token <token>", "JWT").option("--verbose", "\u6253\u5370\u8BF7\u6C42\u8BE6\u60C5").option("--json-out <dir>", "\u843D\u76D8 cli-manifest + JSON\uFF08\u63A8\u8350\uFF09").action(
|
|
138847
139184
|
async (opts) => {
|
|
138848
139185
|
await runWebsiteDiagnosisCollect({
|
|
138849
139186
|
url: opts.url,
|
|
138850
139187
|
includeHtml: opts.includeHtml,
|
|
139188
|
+
htmlFile: opts.htmlFile,
|
|
138851
139189
|
skipHtml: opts.skipHtml,
|
|
138852
139190
|
token: opts.token,
|
|
138853
139191
|
verbose: opts.verbose,
|
|
@@ -138864,18 +139202,23 @@ function registerWebsiteDiagnosisCommands(program2) {
|
|
|
138864
139202
|
jsonOut: opts.jsonOut
|
|
138865
139203
|
});
|
|
138866
139204
|
});
|
|
138867
|
-
root.command("render").description("\u6839\u636E\u8BCA\u65AD JSON \u751F\u6210 HTML \u7EC8\u7A3F\uFF08\u9ED8\u8BA4\u4EA4\u4ED8\u683C\u5F0F\uFF0Cwebsite-diagnosis-report.html\uFF09").requiredOption("--data <file>", "\u8BCA\u65AD\u7ED3\u679C JSON\uFF08getWebsiteDiagnosisData \u540C\u7ED3\u6784\uFF09").option("--collect <file>", "\u53EF\u9009\uFF1Acollect \u843D\u76D8 JSON\uFF0C\u7528\u4E8E\u5408\u5E76 lighthouse").option(
|
|
138868
|
-
|
|
138869
|
-
|
|
138870
|
-
|
|
138871
|
-
|
|
138872
|
-
|
|
138873
|
-
|
|
138874
|
-
|
|
139205
|
+
root.command("render").description("\u6839\u636E\u8BCA\u65AD JSON \u751F\u6210 HTML \u7EC8\u7A3F\uFF08\u9ED8\u8BA4\u4EA4\u4ED8\u683C\u5F0F\uFF0Cwebsite-diagnosis-report.html\uFF09").requiredOption("--data <file>", "\u8BCA\u65AD\u7ED3\u679C JSON\uFF08getWebsiteDiagnosisData \u540C\u7ED3\u6784\uFF09").option("--collect <file>", "\u53EF\u9009\uFF1Acollect \u843D\u76D8 JSON\uFF0C\u7528\u4E8E\u5408\u5E76 lighthouse").option(
|
|
139206
|
+
"--tracking <file>",
|
|
139207
|
+
"GA/GTM \u5B9E\u8BBF JSON\uFF08\u6D4F\u89C8\u5668\u6253\u5F00\u7F51\u7AD9\u540E\u6309\u56FA\u5B9A\u683C\u5F0F\u5199\u5165\uFF1B\u4E0E diagnosis.tracking \u4E8C\u9009\u4E00\uFF0C\u6587\u4EF6\u4F18\u5148\uFF09"
|
|
139208
|
+
).option("--out <file>", "\u8F93\u51FA HTML \u8DEF\u5F84\uFF08\u9ED8\u8BA4\u540C --data \u76EE\u5F55\uFF09").option("--lang <lang>", "\u7EC8\u7A3F\u8BED\u8A00\uFF1Azh \u6216 en\u3002\u8986\u76D6 JSON meta.lang\uFF1B\u90FD\u6CA1\u6709\u5219\u4E2D\u6587").action(
|
|
139209
|
+
async (opts) => {
|
|
139210
|
+
await runWebsiteDiagnosisRender({
|
|
139211
|
+
dataFile: opts.data,
|
|
139212
|
+
collectFile: opts.collect,
|
|
139213
|
+
trackingFile: opts.tracking,
|
|
139214
|
+
out: opts.out,
|
|
139215
|
+
lang: opts.lang
|
|
139216
|
+
});
|
|
139217
|
+
}
|
|
139218
|
+
);
|
|
138875
139219
|
}
|
|
138876
139220
|
|
|
138877
139221
|
// src/commands/market-analysis/run.ts
|
|
138878
|
-
init_auth();
|
|
138879
139222
|
init_cli_json_snapshot();
|
|
138880
139223
|
|
|
138881
139224
|
// src/commands/market-analysis/shared.ts
|
|
@@ -138963,9 +139306,8 @@ async function runMarketAnalysisCollect(opts) {
|
|
|
138963
139306
|
let websiteError;
|
|
138964
139307
|
const websiteUrl = normalized.website?.trim() ? normalizeWebsiteUrl(normalized.website) : "";
|
|
138965
139308
|
if (websiteUrl && !opts.skipWebsite) {
|
|
138966
|
-
const config = loadConfig(opts.token);
|
|
138967
139309
|
try {
|
|
138968
|
-
const html = await fetchWebsiteHtml(
|
|
139310
|
+
const html = await fetchWebsiteHtml(websiteUrl, opts.verbose);
|
|
138969
139311
|
websiteMeta = {
|
|
138970
139312
|
originUrl: html.originUrl,
|
|
138971
139313
|
finalUrl: html.finalUrl,
|
|
@@ -139004,8 +139346,8 @@ async function runMarketAnalysisCollect(opts) {
|
|
|
139004
139346
|
}
|
|
139005
139347
|
|
|
139006
139348
|
// src/commands/market-analysis/render-report.ts
|
|
139007
|
-
import
|
|
139008
|
-
import
|
|
139349
|
+
import fs20 from "fs/promises";
|
|
139350
|
+
import path25 from "path";
|
|
139009
139351
|
|
|
139010
139352
|
// src/commands/market-analysis/report-content.ts
|
|
139011
139353
|
var SILUZAN_ECHARTS_CDN_URL = "https://staticpn.siluzan.com/assets/slz/homeCDN/echarts.min.js";
|
|
@@ -139461,10 +139803,10 @@ function resolveMarketAnalysisHtml(data) {
|
|
|
139461
139803
|
throw new Error("JSON \u4E2D\u7F3A\u5C11 htmlContent \u6216 rawResponse \u5B57\u6BB5");
|
|
139462
139804
|
}
|
|
139463
139805
|
async function runMarketAnalysisRender(opts) {
|
|
139464
|
-
const dataPath =
|
|
139806
|
+
const dataPath = path25.resolve(opts.dataFile);
|
|
139465
139807
|
let dataRaw;
|
|
139466
139808
|
try {
|
|
139467
|
-
dataRaw = JSON.parse(await
|
|
139809
|
+
dataRaw = JSON.parse(await fs20.readFile(dataPath, "utf8"));
|
|
139468
139810
|
} catch {
|
|
139469
139811
|
console.error(`
|
|
139470
139812
|
\u274C \u65E0\u6CD5\u89E3\u6790 JSON\uFF1A${dataPath}
|
|
@@ -139507,11 +139849,11 @@ async function runMarketAnalysisRender(opts) {
|
|
|
139507
139849
|
);
|
|
139508
139850
|
process.exit(1);
|
|
139509
139851
|
}
|
|
139510
|
-
const outPath =
|
|
139511
|
-
opts.out ??
|
|
139852
|
+
const outPath = path25.resolve(
|
|
139853
|
+
opts.out ?? path25.join(path25.dirname(dataPath), "market-analysis-report.html")
|
|
139512
139854
|
);
|
|
139513
|
-
await
|
|
139514
|
-
await
|
|
139855
|
+
await fs20.mkdir(path25.dirname(outPath), { recursive: true });
|
|
139856
|
+
await fs20.writeFile(outPath, html, "utf8");
|
|
139515
139857
|
const { stats } = contentCheck;
|
|
139516
139858
|
console.log(`
|
|
139517
139859
|
\u2705 \u5E02\u573A\u5206\u6790 HTML \u62A5\u544A\u5DF2\u751F\u6210\uFF1A${outPath}
|
|
@@ -139558,12 +139900,12 @@ function registerMarketAnalysisCommands(program2) {
|
|
|
139558
139900
|
|
|
139559
139901
|
// src/commands/google-ads-diagnosis/run-collect.ts
|
|
139560
139902
|
init_auth();
|
|
139561
|
-
import
|
|
139562
|
-
import
|
|
139903
|
+
import fs25 from "fs/promises";
|
|
139904
|
+
import path29 from "path";
|
|
139563
139905
|
|
|
139564
139906
|
// src/commands/google-ads-diagnosis/shared.ts
|
|
139565
|
-
import
|
|
139566
|
-
import
|
|
139907
|
+
import fs21 from "fs";
|
|
139908
|
+
import path26 from "path";
|
|
139567
139909
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
139568
139910
|
var GOOGLE_ADS_DIAGNOSIS_TEMPLATE_BASENAME = "GoogleAdsDiagnosisReport.html";
|
|
139569
139911
|
var GOOGLE_ADS_DIAGNOSIS_DATA_MARKER = "__REPORT_DATA__";
|
|
@@ -139620,15 +139962,15 @@ function buildGoogleAdsDiagnosisNarrativeChecks() {
|
|
|
139620
139962
|
}
|
|
139621
139963
|
var GOOGLE_ADS_DIAGNOSIS_NARRATIVE_CHECKS = buildGoogleAdsDiagnosisNarrativeChecks();
|
|
139622
139964
|
function resolveSkillTemplatePath2(basename13) {
|
|
139623
|
-
const dir =
|
|
139965
|
+
const dir = path26.dirname(fileURLToPath5(import.meta.url));
|
|
139624
139966
|
const candidates = [
|
|
139625
|
-
|
|
139626
|
-
|
|
139627
|
-
|
|
139628
|
-
|
|
139967
|
+
path26.join(dir, "skill", "report-templates", basename13),
|
|
139968
|
+
path26.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
|
|
139969
|
+
path26.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13),
|
|
139970
|
+
path26.join(dir, "..", "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
|
|
139629
139971
|
];
|
|
139630
139972
|
for (const p of candidates) {
|
|
139631
|
-
if (
|
|
139973
|
+
if (fs21.existsSync(p)) return p;
|
|
139632
139974
|
}
|
|
139633
139975
|
return candidates[0];
|
|
139634
139976
|
}
|
|
@@ -139658,8 +140000,8 @@ function buildGoogleAdsDiagnosisCollectAgentHint(snapDir) {
|
|
|
139658
140000
|
}
|
|
139659
140001
|
|
|
139660
140002
|
// src/commands/google-ads-diagnosis/build-report-data.ts
|
|
139661
|
-
import
|
|
139662
|
-
import
|
|
140003
|
+
import fs23 from "fs";
|
|
140004
|
+
import path28 from "path";
|
|
139663
140005
|
|
|
139664
140006
|
// src/commands/google-ads-diagnosis/agent-brief.ts
|
|
139665
140007
|
function buildGoogleAdsDiagnosisAgentBrief(input) {
|
|
@@ -139728,8 +140070,8 @@ function buildGoogleAdsDiagnosisAgentBrief(input) {
|
|
|
139728
140070
|
|
|
139729
140071
|
// src/commands/google-ads-diagnosis/snapshot-io.ts
|
|
139730
140072
|
init_google_analysis_snapshot();
|
|
139731
|
-
import
|
|
139732
|
-
import
|
|
140073
|
+
import fs22 from "fs";
|
|
140074
|
+
import path27 from "path";
|
|
139733
140075
|
function dateRangeManifest(start, end) {
|
|
139734
140076
|
if (start && end) return { mode: "range", start, end };
|
|
139735
140077
|
return null;
|
|
@@ -139740,17 +140082,17 @@ function findSectionSnapshotFile(snapDir, section, accountId, start, end) {
|
|
|
139740
140082
|
accountId,
|
|
139741
140083
|
dateRangeManifest(start, end)
|
|
139742
140084
|
);
|
|
139743
|
-
const exactPath =
|
|
139744
|
-
if (
|
|
140085
|
+
const exactPath = path27.join(snapDir, exactName);
|
|
140086
|
+
if (fs22.existsSync(exactPath)) return exactPath;
|
|
139745
140087
|
if (start && end) return void 0;
|
|
139746
|
-
const files =
|
|
139747
|
-
return files.filter((f) => f.startsWith(`${section}-${accountId}`) && f.endsWith(".json")).sort().map((f) =>
|
|
140088
|
+
const files = fs22.readdirSync(snapDir);
|
|
140089
|
+
return files.filter((f) => f.startsWith(`${section}-${accountId}`) && f.endsWith(".json")).sort().map((f) => path27.join(snapDir, f)).at(-1);
|
|
139748
140090
|
}
|
|
139749
140091
|
function loadSectionSnapshot(snapDir, section, accountId, start, end) {
|
|
139750
140092
|
const file = findSectionSnapshotFile(snapDir, section, accountId, start, end);
|
|
139751
|
-
if (!file || !
|
|
140093
|
+
if (!file || !fs22.existsSync(file)) return null;
|
|
139752
140094
|
try {
|
|
139753
|
-
return JSON.parse(
|
|
140095
|
+
return JSON.parse(fs22.readFileSync(file, "utf8"));
|
|
139754
140096
|
} catch {
|
|
139755
140097
|
return null;
|
|
139756
140098
|
}
|
|
@@ -140196,10 +140538,10 @@ function toDailyConversionItem(row) {
|
|
|
140196
140538
|
};
|
|
140197
140539
|
}
|
|
140198
140540
|
function loadCompanyNameFromSnap(snapDir) {
|
|
140199
|
-
const file =
|
|
140200
|
-
if (!
|
|
140541
|
+
const file = path28.join(snapDir, "list-accounts-google.json");
|
|
140542
|
+
if (!fs23.existsSync(file)) return void 0;
|
|
140201
140543
|
try {
|
|
140202
|
-
const parsed = JSON.parse(
|
|
140544
|
+
const parsed = JSON.parse(fs23.readFileSync(file, "utf8"));
|
|
140203
140545
|
const item = parsed.items?.[0];
|
|
140204
140546
|
return item?.ma?.mediaCustomerName?.trim() || item?.mag?.advertiserName?.trim() || void 0;
|
|
140205
140547
|
} catch {
|
|
@@ -140856,7 +141198,7 @@ function invokeGoogleAnalysisCli(opts) {
|
|
|
140856
141198
|
}
|
|
140857
141199
|
|
|
140858
141200
|
// src/commands/google-ads-diagnosis/write-draft.ts
|
|
140859
|
-
import
|
|
141201
|
+
import fs24 from "fs/promises";
|
|
140860
141202
|
function asRecord11(value) {
|
|
140861
141203
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
140862
141204
|
return value;
|
|
@@ -140884,12 +141226,12 @@ function hasAgentNarrative(data) {
|
|
|
140884
141226
|
}
|
|
140885
141227
|
async function writeDiagnosisDraft(opts) {
|
|
140886
141228
|
try {
|
|
140887
|
-
const existing = JSON.parse(await
|
|
141229
|
+
const existing = JSON.parse(await fs24.readFile(opts.draftPath, "utf8"));
|
|
140888
141230
|
const record2 = asRecord11(existing);
|
|
140889
141231
|
if (record2 && hasAgentNarrative(record2)) return "skipped-existing-narrative";
|
|
140890
141232
|
} catch {
|
|
140891
141233
|
}
|
|
140892
|
-
await
|
|
141234
|
+
await fs24.writeFile(opts.draftPath, `${JSON.stringify(opts.reportData, null, 2)}
|
|
140893
141235
|
`, "utf8");
|
|
140894
141236
|
return "written";
|
|
140895
141237
|
}
|
|
@@ -140926,8 +141268,8 @@ async function runGoogleAdsDiagnosisCollect(opts) {
|
|
|
140926
141268
|
console.error("\n\u274C collect \u987B\u540C\u65F6\u6307\u5B9A --start \u4E0E --end\u3002\n");
|
|
140927
141269
|
process.exit(1);
|
|
140928
141270
|
}
|
|
140929
|
-
const snapDir =
|
|
140930
|
-
await
|
|
141271
|
+
const snapDir = path29.resolve(opts.jsonOut);
|
|
141272
|
+
await fs25.mkdir(snapDir, { recursive: true });
|
|
140931
141273
|
let degraded = false;
|
|
140932
141274
|
console.error(`
|
|
140933
141275
|
\u{1F4E5} google-analysis \u62C9\u6570\uFF1A\u8D26\u6237 ${accountId}\uFF0C${opts.start} ~ ${opts.end}
|
|
@@ -141023,13 +141365,13 @@ async function runGoogleAdsDiagnosisCollect(opts) {
|
|
|
141023
141365
|
agentBrief,
|
|
141024
141366
|
agentHint: buildGoogleAdsDiagnosisCollectAgentHint(snapDir)
|
|
141025
141367
|
};
|
|
141026
|
-
const collectPath =
|
|
141027
|
-
await
|
|
141368
|
+
const collectPath = path29.join(snapDir, GOOGLE_ADS_DIAGNOSIS_COLLECT_BASENAME);
|
|
141369
|
+
await fs25.writeFile(collectPath, `${JSON.stringify(collectPayload, null, 2)}
|
|
141028
141370
|
`, "utf8");
|
|
141029
|
-
const draftPath =
|
|
141371
|
+
const draftPath = path29.join(snapDir, GOOGLE_ADS_DIAGNOSIS_REPORT_BASENAME);
|
|
141030
141372
|
const draftOutcome = await writeDiagnosisDraft({ draftPath, reportData });
|
|
141031
|
-
const digestPath =
|
|
141032
|
-
await
|
|
141373
|
+
const digestPath = path29.join(snapDir, GOOGLE_ADS_DIAGNOSIS_DIGEST_BASENAME);
|
|
141374
|
+
await fs25.writeFile(
|
|
141033
141375
|
digestPath,
|
|
141034
141376
|
buildCollectDigest(reportData, {
|
|
141035
141377
|
accountId,
|
|
@@ -141071,8 +141413,8 @@ async function runGoogleAdsDiagnosisCollect(opts) {
|
|
|
141071
141413
|
}
|
|
141072
141414
|
|
|
141073
141415
|
// src/commands/google-ads-diagnosis/render-report.ts
|
|
141074
|
-
import
|
|
141075
|
-
import
|
|
141416
|
+
import fs26 from "fs/promises";
|
|
141417
|
+
import path30 from "path";
|
|
141076
141418
|
|
|
141077
141419
|
// src/commands/google-ads-diagnosis/report-content.ts
|
|
141078
141420
|
function asRecord12(value) {
|
|
@@ -141081,9 +141423,9 @@ function asRecord12(value) {
|
|
|
141081
141423
|
}
|
|
141082
141424
|
return null;
|
|
141083
141425
|
}
|
|
141084
|
-
function getNestedValue(root,
|
|
141426
|
+
function getNestedValue(root, path59) {
|
|
141085
141427
|
let cur = root;
|
|
141086
|
-
for (const key of
|
|
141428
|
+
for (const key of path59) {
|
|
141087
141429
|
const rec = asRecord12(cur);
|
|
141088
141430
|
if (!rec) return void 0;
|
|
141089
141431
|
cur = rec[key];
|
|
@@ -141738,7 +142080,7 @@ function asRecord17(value) {
|
|
|
141738
142080
|
}
|
|
141739
142081
|
async function tryLoadCollectReportData(collectPath) {
|
|
141740
142082
|
try {
|
|
141741
|
-
const raw = JSON.parse(await
|
|
142083
|
+
const raw = JSON.parse(await fs26.readFile(collectPath, "utf8"));
|
|
141742
142084
|
const root = asRecord17(raw);
|
|
141743
142085
|
const reportData = asRecord17(root?.reportData);
|
|
141744
142086
|
return reportData ?? root;
|
|
@@ -141747,10 +142089,10 @@ async function tryLoadCollectReportData(collectPath) {
|
|
|
141747
142089
|
}
|
|
141748
142090
|
}
|
|
141749
142091
|
async function runGoogleAdsDiagnosisRender(opts) {
|
|
141750
|
-
const dataPath =
|
|
142092
|
+
const dataPath = path30.resolve(opts.dataFile);
|
|
141751
142093
|
let dataRaw;
|
|
141752
142094
|
try {
|
|
141753
|
-
dataRaw = JSON.parse(await
|
|
142095
|
+
dataRaw = JSON.parse(await fs26.readFile(dataPath, "utf8"));
|
|
141754
142096
|
} catch {
|
|
141755
142097
|
console.error(`
|
|
141756
142098
|
\u274C \u65E0\u6CD5\u89E3\u6790 JSON\uFF1A${dataPath}
|
|
@@ -141759,8 +142101,8 @@ async function runGoogleAdsDiagnosisRender(opts) {
|
|
|
141759
142101
|
}
|
|
141760
142102
|
let data = asRecord17(dataRaw);
|
|
141761
142103
|
if (!opts.noMergeCollect) {
|
|
141762
|
-
const collectPath =
|
|
141763
|
-
opts.collectFile ??
|
|
142104
|
+
const collectPath = path30.resolve(
|
|
142105
|
+
opts.collectFile ?? path30.join(path30.dirname(dataPath), GOOGLE_ADS_DIAGNOSIS_COLLECT_BASENAME)
|
|
141764
142106
|
);
|
|
141765
142107
|
const collectReportData = await tryLoadCollectReportData(collectPath);
|
|
141766
142108
|
if (collectReportData) {
|
|
@@ -141789,7 +142131,7 @@ async function runGoogleAdsDiagnosisRender(opts) {
|
|
|
141789
142131
|
}
|
|
141790
142132
|
}
|
|
141791
142133
|
}
|
|
141792
|
-
data = reconcileGoldAccountInReport(data,
|
|
142134
|
+
data = reconcileGoldAccountInReport(data, path30.dirname(dataPath));
|
|
141793
142135
|
data = applyDataRenderedCopy(data);
|
|
141794
142136
|
const overview = normalizeDiagnosisOverview(data);
|
|
141795
142137
|
data = overview.data;
|
|
@@ -141845,7 +142187,7 @@ async function runGoogleAdsDiagnosisRender(opts) {
|
|
|
141845
142187
|
const templatePath = googleAdsDiagnosisReportTemplatePath();
|
|
141846
142188
|
let html;
|
|
141847
142189
|
try {
|
|
141848
|
-
html = await
|
|
142190
|
+
html = await fs26.readFile(templatePath, "utf8");
|
|
141849
142191
|
} catch {
|
|
141850
142192
|
console.error(`
|
|
141851
142193
|
\u274C \u672A\u627E\u5230\u62A5\u544A\u6A21\u677F\uFF1A${templatePath}
|
|
@@ -141864,11 +142206,11 @@ async function runGoogleAdsDiagnosisRender(opts) {
|
|
|
141864
142206
|
`);
|
|
141865
142207
|
process.exit(1);
|
|
141866
142208
|
}
|
|
141867
|
-
const outPath =
|
|
141868
|
-
opts.out ??
|
|
142209
|
+
const outPath = path30.resolve(
|
|
142210
|
+
opts.out ?? path30.join(path30.dirname(dataPath), "google-ads-diagnosis-report.html")
|
|
141869
142211
|
);
|
|
141870
|
-
await
|
|
141871
|
-
await
|
|
142212
|
+
await fs26.mkdir(path30.dirname(outPath), { recursive: true });
|
|
142213
|
+
await fs26.writeFile(outPath, rendered, "utf8");
|
|
141872
142214
|
console.log(`
|
|
141873
142215
|
\u2705 Google \u5E7F\u544A\u8BCA\u65AD HTML \u62A5\u544A\u5DF2\u751F\u6210\uFF1A${outPath}
|
|
141874
142216
|
`);
|
|
@@ -141936,8 +142278,8 @@ function registerGoogleAdsDiagnosisCommands(program2) {
|
|
|
141936
142278
|
|
|
141937
142279
|
// src/commands/google-quarterly/run-collect.ts
|
|
141938
142280
|
init_auth();
|
|
141939
|
-
import
|
|
141940
|
-
import
|
|
142281
|
+
import fs29 from "fs/promises";
|
|
142282
|
+
import path33 from "path";
|
|
141941
142283
|
|
|
141942
142284
|
// src/commands/google-quarterly/drill-country.ts
|
|
141943
142285
|
init_geo_en2zh();
|
|
@@ -142456,31 +142798,31 @@ function buildSpendPlanDefaults(currentSpend) {
|
|
|
142456
142798
|
}
|
|
142457
142799
|
|
|
142458
142800
|
// src/commands/google-quarterly/region.ts
|
|
142459
|
-
import
|
|
142460
|
-
import
|
|
142801
|
+
import fs27 from "fs";
|
|
142802
|
+
import path31 from "path";
|
|
142461
142803
|
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
142462
142804
|
var EAST_ASIA = /* @__PURE__ */ new Set(["\u4E2D\u56FD", "\u65E5\u672C", "\u97E9\u56FD", "\u671D\u9C9C", "\u8499\u53E4", "\u9999\u6E2F", "\u6FB3\u95E8", "\u53F0\u6E7E"]);
|
|
142463
142805
|
var continentMap = null;
|
|
142464
142806
|
function continentsPath() {
|
|
142465
|
-
const dir =
|
|
142807
|
+
const dir = path31.dirname(fileURLToPath6(import.meta.url));
|
|
142466
142808
|
const candidates = [
|
|
142467
142809
|
// dist/index.js → dist/skill/references/...
|
|
142468
|
-
|
|
142469
|
-
|
|
142810
|
+
path31.join(dir, "skill", "references", "analytics", "geo-continents.json"),
|
|
142811
|
+
path31.join(dir, "skill", "siluzan-ads", "references", "analytics", "geo-continents.json"),
|
|
142470
142812
|
// dist/index.js → tso-cli/assets/...
|
|
142471
|
-
|
|
142813
|
+
path31.join(dir, "..", "assets", "siluzan-ads", "references", "analytics", "geo-continents.json"),
|
|
142472
142814
|
// src/commands/google-quarterly/region.ts → tso-cli/assets/...
|
|
142473
|
-
|
|
142474
|
-
|
|
142815
|
+
path31.join(dir, "..", "..", "assets", "siluzan-ads", "references", "analytics", "geo-continents.json"),
|
|
142816
|
+
path31.join(dir, "..", "..", "..", "assets", "siluzan-ads", "references", "analytics", "geo-continents.json")
|
|
142475
142817
|
];
|
|
142476
142818
|
for (const p of candidates) {
|
|
142477
|
-
if (
|
|
142819
|
+
if (fs27.existsSync(p)) return p;
|
|
142478
142820
|
}
|
|
142479
142821
|
return candidates[0];
|
|
142480
142822
|
}
|
|
142481
142823
|
function loadContinentMap() {
|
|
142482
142824
|
if (continentMap) return continentMap;
|
|
142483
|
-
const raw = JSON.parse(
|
|
142825
|
+
const raw = JSON.parse(fs27.readFileSync(continentsPath(), "utf8"));
|
|
142484
142826
|
const map = {};
|
|
142485
142827
|
for (const [k, v] of Object.entries(raw)) {
|
|
142486
142828
|
if (k.startsWith("_")) continue;
|
|
@@ -142916,23 +143258,23 @@ function roundFacts(facts) {
|
|
|
142916
143258
|
}
|
|
142917
143259
|
|
|
142918
143260
|
// src/commands/google-quarterly/shared.ts
|
|
142919
|
-
import
|
|
142920
|
-
import
|
|
143261
|
+
import fs28 from "fs";
|
|
143262
|
+
import path32 from "path";
|
|
142921
143263
|
import { fileURLToPath as fileURLToPath7 } from "url";
|
|
142922
143264
|
var GOOGLE_QUARTERLY_COLLECT_BASENAME = "google-quarterly-collect.json";
|
|
142923
143265
|
var GOOGLE_QUARTERLY_HTML_BASENAME = "google-quarterly-report.html";
|
|
142924
143266
|
var GOOGLE_QUARTERLY_TEMPLATE_BASENAME = "google-quarterly-report.html";
|
|
142925
143267
|
var GOOGLE_QUARTERLY_INJECT_MARKER = "window.__GOOGLE_QUARTERLY_REPORT__ = window.__GOOGLE_QUARTERLY_REPORT__ || null;";
|
|
142926
143268
|
function googleQuarterlyTemplatePath() {
|
|
142927
|
-
const dir =
|
|
143269
|
+
const dir = path32.dirname(fileURLToPath7(import.meta.url));
|
|
142928
143270
|
const candidates = [
|
|
142929
|
-
|
|
142930
|
-
|
|
142931
|
-
|
|
142932
|
-
|
|
143271
|
+
path32.join(dir, "skill", "report-templates", GOOGLE_QUARTERLY_TEMPLATE_BASENAME),
|
|
143272
|
+
path32.join(dir, "skill", "siluzan-ads", "report-templates", GOOGLE_QUARTERLY_TEMPLATE_BASENAME),
|
|
143273
|
+
path32.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", GOOGLE_QUARTERLY_TEMPLATE_BASENAME),
|
|
143274
|
+
path32.join(dir, "..", "..", "..", "assets", "siluzan-ads", "report-templates", GOOGLE_QUARTERLY_TEMPLATE_BASENAME)
|
|
142933
143275
|
];
|
|
142934
143276
|
for (const p of candidates) {
|
|
142935
|
-
if (
|
|
143277
|
+
if (fs28.existsSync(p)) return p;
|
|
142936
143278
|
}
|
|
142937
143279
|
return candidates[2];
|
|
142938
143280
|
}
|
|
@@ -142958,7 +143300,7 @@ function periodSnap(dir, account, start, end, extra = []) {
|
|
|
142958
143300
|
}
|
|
142959
143301
|
async function readInquiries(file) {
|
|
142960
143302
|
if (!file?.trim()) return void 0;
|
|
142961
|
-
const raw = await
|
|
143303
|
+
const raw = await fs29.readFile(path33.resolve(file), "utf8");
|
|
142962
143304
|
return JSON.parse(raw);
|
|
142963
143305
|
}
|
|
142964
143306
|
async function runGoogleQuarterlyCollect(opts) {
|
|
@@ -142971,8 +143313,8 @@ async function runGoogleQuarterlyCollect(opts) {
|
|
|
142971
143313
|
const previous = previousRange(current.start, current.end);
|
|
142972
143314
|
const yoy = yearOverYearRange(current.start, current.end);
|
|
142973
143315
|
const months = listMonths(current.start, current.end);
|
|
142974
|
-
const snapDir =
|
|
142975
|
-
await
|
|
143316
|
+
const snapDir = path33.resolve(opts.jsonOut);
|
|
143317
|
+
await fs29.mkdir(snapDir, { recursive: true });
|
|
142976
143318
|
let degraded = false;
|
|
142977
143319
|
const run = (label2, start, end, sections) => {
|
|
142978
143320
|
console.error(`
|
|
@@ -143100,8 +143442,8 @@ async function runGoogleQuarterlyCollect(opts) {
|
|
|
143100
143442
|
planDefaults: facts.planDefaults
|
|
143101
143443
|
}
|
|
143102
143444
|
};
|
|
143103
|
-
const outFile =
|
|
143104
|
-
await
|
|
143445
|
+
const outFile = path33.join(snapDir, GOOGLE_QUARTERLY_COLLECT_BASENAME);
|
|
143446
|
+
await fs29.writeFile(outFile, JSON.stringify(payload, null, 2), "utf8");
|
|
143105
143447
|
console.log(
|
|
143106
143448
|
JSON.stringify({
|
|
143107
143449
|
kind: "siluzan-tso-google-quarterly-collect-summary",
|
|
@@ -143120,8 +143462,8 @@ async function runGoogleQuarterlyCollect(opts) {
|
|
|
143120
143462
|
}
|
|
143121
143463
|
|
|
143122
143464
|
// src/commands/google-quarterly/render-report.ts
|
|
143123
|
-
import
|
|
143124
|
-
import
|
|
143465
|
+
import fs30 from "fs/promises";
|
|
143466
|
+
import path35 from "path";
|
|
143125
143467
|
|
|
143126
143468
|
// src/commands/google-quarterly/report-content.ts
|
|
143127
143469
|
function asRecord18(value) {
|
|
@@ -143164,9 +143506,9 @@ function mergeCollectFacts(agentData, collect) {
|
|
|
143164
143506
|
|
|
143165
143507
|
// src/test-utils/report-echarts.ts
|
|
143166
143508
|
import { readFileSync as readFileSync19 } from "fs";
|
|
143167
|
-
import
|
|
143509
|
+
import path34 from "path";
|
|
143168
143510
|
import { fileURLToPath as fileURLToPath8 } from "url";
|
|
143169
|
-
var TSO_CLI_ROOT =
|
|
143511
|
+
var TSO_CLI_ROOT = path34.join(path34.dirname(fileURLToPath8(import.meta.url)), "../..");
|
|
143170
143512
|
|
|
143171
143513
|
// src/commands/google-quarterly/render-report.ts
|
|
143172
143514
|
init_lang();
|
|
@@ -143178,22 +143520,22 @@ function asRecord19(value) {
|
|
|
143178
143520
|
throw new Error("\u62A5\u544A JSON \u987B\u4E3A\u5BF9\u8C61");
|
|
143179
143521
|
}
|
|
143180
143522
|
async function runGoogleQuarterlyRender(opts) {
|
|
143181
|
-
const dataPath =
|
|
143523
|
+
const dataPath = path35.resolve(opts.dataFile);
|
|
143182
143524
|
let agentRaw;
|
|
143183
143525
|
try {
|
|
143184
|
-
agentRaw = JSON.parse(await
|
|
143526
|
+
agentRaw = JSON.parse(await fs30.readFile(dataPath, "utf8"));
|
|
143185
143527
|
} catch {
|
|
143186
143528
|
console.error(`
|
|
143187
143529
|
\u274C \u65E0\u6CD5\u89E3\u6790 JSON\uFF1A${dataPath}
|
|
143188
143530
|
`);
|
|
143189
143531
|
process.exit(1);
|
|
143190
143532
|
}
|
|
143191
|
-
const collectPath =
|
|
143192
|
-
opts.collectFile ??
|
|
143533
|
+
const collectPath = path35.resolve(
|
|
143534
|
+
opts.collectFile ?? path35.join(path35.dirname(dataPath), GOOGLE_QUARTERLY_COLLECT_BASENAME)
|
|
143193
143535
|
);
|
|
143194
143536
|
let collectRaw;
|
|
143195
143537
|
try {
|
|
143196
|
-
collectRaw = JSON.parse(await
|
|
143538
|
+
collectRaw = JSON.parse(await fs30.readFile(collectPath, "utf8"));
|
|
143197
143539
|
} catch {
|
|
143198
143540
|
console.error(`
|
|
143199
143541
|
\u274C \u65E0\u6CD5\u8BFB\u53D6 collect\uFF1A${collectPath}
|
|
@@ -143211,15 +143553,15 @@ async function runGoogleQuarterlyRender(opts) {
|
|
|
143211
143553
|
const templatePath = googleQuarterlyTemplatePath();
|
|
143212
143554
|
let html;
|
|
143213
143555
|
try {
|
|
143214
|
-
html = await
|
|
143556
|
+
html = await fs30.readFile(templatePath, "utf8");
|
|
143215
143557
|
} catch {
|
|
143216
143558
|
console.error(`
|
|
143217
143559
|
\u274C \u627E\u4E0D\u5230\u6A21\u677F\uFF1A${templatePath}
|
|
143218
143560
|
`);
|
|
143219
143561
|
process.exit(1);
|
|
143220
143562
|
}
|
|
143221
|
-
const outPath =
|
|
143222
|
-
await
|
|
143563
|
+
const outPath = path35.resolve(opts.out ?? path35.join(path35.dirname(dataPath), GOOGLE_QUARTERLY_HTML_BASENAME));
|
|
143564
|
+
await fs30.mkdir(path35.dirname(outPath), { recursive: true });
|
|
143223
143565
|
const lang = readReportLangOrExit({ flag: opts.lang, meta: merged.meta });
|
|
143224
143566
|
const periodChrome = reportPeriodChrome(
|
|
143225
143567
|
readMetaRange(merged, "current"),
|
|
@@ -143235,7 +143577,7 @@ async function runGoogleQuarterlyRender(opts) {
|
|
|
143235
143577
|
console.error("\n\u274C \u6A21\u677F\u5FC5\u987B\u4F7F\u7528 ECharts\uFF0C\u7981\u6B62 Chart.js\u3002\n");
|
|
143236
143578
|
process.exit(1);
|
|
143237
143579
|
}
|
|
143238
|
-
await
|
|
143580
|
+
await fs30.writeFile(outPath, outHtml, "utf8");
|
|
143239
143581
|
console.log(`
|
|
143240
143582
|
\u2705 ${periodChrome.reportTitle}\u5DF2\u751F\u6210\uFF1A${outPath}
|
|
143241
143583
|
`);
|
|
@@ -143375,14 +143717,14 @@ var FACEBOOK_SECTION_ALIASES = {
|
|
|
143375
143717
|
import { Command as Command2 } from "commander";
|
|
143376
143718
|
|
|
143377
143719
|
// src/commands/facebook-analysis/render-report.ts
|
|
143378
|
-
import
|
|
143720
|
+
import fs38 from "fs";
|
|
143379
143721
|
import fsPromises4 from "fs/promises";
|
|
143380
|
-
import
|
|
143722
|
+
import path45 from "path";
|
|
143381
143723
|
import { fileURLToPath as fileURLToPath11 } from "url";
|
|
143382
143724
|
|
|
143383
143725
|
// src/commands/facebook-analysis/merge-snapshot.ts
|
|
143384
|
-
import * as
|
|
143385
|
-
import * as
|
|
143726
|
+
import * as fs37 from "fs/promises";
|
|
143727
|
+
import * as path44 from "path";
|
|
143386
143728
|
|
|
143387
143729
|
// src/commands/facebook-analysis/report-metrics.ts
|
|
143388
143730
|
function asRecord25(value) {
|
|
@@ -143534,7 +143876,7 @@ function hasResults(row) {
|
|
|
143534
143876
|
|
|
143535
143877
|
// src/commands/facebook-analysis/merge-snapshot.ts
|
|
143536
143878
|
async function readManifest3(snapshotDir) {
|
|
143537
|
-
const entries = await
|
|
143879
|
+
const entries = await fs37.readdir(snapshotDir);
|
|
143538
143880
|
const manifestNames = entries.filter(
|
|
143539
143881
|
(n) => n.startsWith("report-manifest") && n.endsWith(".json")
|
|
143540
143882
|
);
|
|
@@ -143544,7 +143886,7 @@ async function readManifest3(snapshotDir) {
|
|
|
143544
143886
|
];
|
|
143545
143887
|
for (const name2 of ordered) {
|
|
143546
143888
|
try {
|
|
143547
|
-
const raw = await
|
|
143889
|
+
const raw = await fs37.readFile(path44.join(snapshotDir, name2), "utf8");
|
|
143548
143890
|
const parsed = JSON.parse(raw);
|
|
143549
143891
|
if (parsed?.artifacts?.length) return parsed;
|
|
143550
143892
|
} catch {
|
|
@@ -143554,7 +143896,7 @@ async function readManifest3(snapshotDir) {
|
|
|
143554
143896
|
}
|
|
143555
143897
|
async function loadSectionFile3(snapshotDir, file) {
|
|
143556
143898
|
try {
|
|
143557
|
-
const raw = await
|
|
143899
|
+
const raw = await fs37.readFile(path44.join(snapshotDir, file), "utf8");
|
|
143558
143900
|
return asRecord25(JSON.parse(raw));
|
|
143559
143901
|
} catch {
|
|
143560
143902
|
return null;
|
|
@@ -143598,7 +143940,7 @@ function mapAdSetRows(groups) {
|
|
|
143598
143940
|
})).sort((a, b) => (b.spend ?? 0) - (a.spend ?? 0));
|
|
143599
143941
|
}
|
|
143600
143942
|
async function mergeFacebookSnapshotIntoReport(payload, snapshotDir) {
|
|
143601
|
-
const absDir =
|
|
143943
|
+
const absDir = path44.resolve(snapshotDir);
|
|
143602
143944
|
const manifest = await readManifest3(snapshotDir);
|
|
143603
143945
|
if (!manifest) {
|
|
143604
143946
|
throw new Error(
|
|
@@ -144220,14 +144562,14 @@ var TEMPLATE_BASENAMES2 = {
|
|
|
144220
144562
|
};
|
|
144221
144563
|
var INJECT_MARKER2 = "window.__META_PERIOD_REPORT__ = window.__META_PERIOD_REPORT__ || null;";
|
|
144222
144564
|
function resolveSkillTemplatePath5(basename13) {
|
|
144223
|
-
const dir =
|
|
144565
|
+
const dir = path45.dirname(fileURLToPath11(import.meta.url));
|
|
144224
144566
|
const candidates = [
|
|
144225
|
-
|
|
144226
|
-
|
|
144227
|
-
|
|
144567
|
+
path45.join(dir, "skill", "report-templates", basename13),
|
|
144568
|
+
path45.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
|
|
144569
|
+
path45.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
|
|
144228
144570
|
];
|
|
144229
144571
|
for (const p of candidates) {
|
|
144230
|
-
if (
|
|
144572
|
+
if (fs38.existsSync(p)) return p;
|
|
144231
144573
|
}
|
|
144232
144574
|
return candidates[0];
|
|
144233
144575
|
}
|
|
@@ -144273,7 +144615,7 @@ function injectReportData3(html, payload, lang) {
|
|
|
144273
144615
|
}
|
|
144274
144616
|
function defaultOutPath(dataPath, format, out) {
|
|
144275
144617
|
if (out?.trim()) {
|
|
144276
|
-
const resolved =
|
|
144618
|
+
const resolved = path45.resolve(out);
|
|
144277
144619
|
if (format === "xlsx" && !/\.xlsx$/i.test(resolved)) {
|
|
144278
144620
|
return resolved.replace(/\.(html?)$/i, ".xlsx");
|
|
144279
144621
|
}
|
|
@@ -144282,14 +144624,14 @@ function defaultOutPath(dataPath, format, out) {
|
|
|
144282
144624
|
}
|
|
144283
144625
|
return resolved;
|
|
144284
144626
|
}
|
|
144285
|
-
const dir =
|
|
144286
|
-
return
|
|
144627
|
+
const dir = path45.dirname(dataPath);
|
|
144628
|
+
return path45.join(dir, format === "xlsx" ? "meta-period-report.xlsx" : "meta-period-report.html");
|
|
144287
144629
|
}
|
|
144288
144630
|
async function runFacebookAnalysisRender(opts) {
|
|
144289
|
-
const dataPath =
|
|
144631
|
+
const dataPath = path45.resolve(opts.dataFile);
|
|
144290
144632
|
let data = asRecord28(await readJsonFile5(dataPath));
|
|
144291
144633
|
if (opts.snapshotDir?.trim()) {
|
|
144292
|
-
data = await mergeFacebookSnapshotIntoReport(data,
|
|
144634
|
+
data = await mergeFacebookSnapshotIntoReport(data, path45.resolve(opts.snapshotDir));
|
|
144293
144635
|
}
|
|
144294
144636
|
localizeFacebookReportLabels(data);
|
|
144295
144637
|
const lang = readReportLangOrExit({ flag: opts.lang, meta: data.meta });
|
|
@@ -144309,7 +144651,7 @@ async function runFacebookAnalysisRender(opts) {
|
|
|
144309
144651
|
const written = [];
|
|
144310
144652
|
for (const format of formats) {
|
|
144311
144653
|
const outPath = defaultOutPath(dataPath, format, opts.out);
|
|
144312
|
-
await fsPromises4.mkdir(
|
|
144654
|
+
await fsPromises4.mkdir(path45.dirname(outPath), { recursive: true });
|
|
144313
144655
|
if (format === "xlsx") {
|
|
144314
144656
|
writeMetaPeriodExcel(outPath, data, lang);
|
|
144315
144657
|
} else {
|
|
@@ -144345,14 +144687,14 @@ async function runFacebookAnalysisRender(opts) {
|
|
|
144345
144687
|
}
|
|
144346
144688
|
|
|
144347
144689
|
// src/commands/facebook-analysis/diagnosis-render-report.ts
|
|
144348
|
-
import
|
|
144690
|
+
import fs40 from "fs";
|
|
144349
144691
|
import fsPromises5 from "fs/promises";
|
|
144350
|
-
import
|
|
144692
|
+
import path47 from "path";
|
|
144351
144693
|
import { fileURLToPath as fileURLToPath12 } from "url";
|
|
144352
144694
|
|
|
144353
144695
|
// src/commands/facebook-analysis/diagnosis-merge-snapshot.ts
|
|
144354
|
-
import * as
|
|
144355
|
-
import * as
|
|
144696
|
+
import * as fs39 from "fs/promises";
|
|
144697
|
+
import * as path46 from "path";
|
|
144356
144698
|
function asRecord29(value) {
|
|
144357
144699
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
144358
144700
|
return value;
|
|
@@ -144388,7 +144730,7 @@ async function readManifest4(snapshotDir, accountId) {
|
|
|
144388
144730
|
const candidates = [];
|
|
144389
144731
|
if (accountId) candidates.push(reportManifestFile(accountId));
|
|
144390
144732
|
try {
|
|
144391
|
-
const entries = await
|
|
144733
|
+
const entries = await fs39.readdir(snapshotDir);
|
|
144392
144734
|
const manifestNames = entries.filter(
|
|
144393
144735
|
(n) => n.startsWith("report-manifest") && n.endsWith(".json")
|
|
144394
144736
|
);
|
|
@@ -144402,7 +144744,7 @@ async function readManifest4(snapshotDir, accountId) {
|
|
|
144402
144744
|
}
|
|
144403
144745
|
for (const name2 of candidates) {
|
|
144404
144746
|
try {
|
|
144405
|
-
const raw = await
|
|
144747
|
+
const raw = await fs39.readFile(path46.join(snapshotDir, name2), "utf8");
|
|
144406
144748
|
const parsed = JSON.parse(raw);
|
|
144407
144749
|
if (Array.isArray(parsed.artifacts) && parsed.artifacts.length > 0) return parsed;
|
|
144408
144750
|
} catch {
|
|
@@ -144412,14 +144754,14 @@ async function readManifest4(snapshotDir, accountId) {
|
|
|
144412
144754
|
}
|
|
144413
144755
|
async function loadSectionFile4(snapshotDir, file) {
|
|
144414
144756
|
try {
|
|
144415
|
-
const raw = await
|
|
144757
|
+
const raw = await fs39.readFile(path46.join(snapshotDir, file), "utf8");
|
|
144416
144758
|
return asRecord29(JSON.parse(raw));
|
|
144417
144759
|
} catch {
|
|
144418
144760
|
return null;
|
|
144419
144761
|
}
|
|
144420
144762
|
}
|
|
144421
144763
|
async function mergeMetaDiagnosisSnapshotIntoReport(payload, snapshotDir) {
|
|
144422
|
-
const absDir =
|
|
144764
|
+
const absDir = path46.resolve(snapshotDir);
|
|
144423
144765
|
const metaAccountId = typeof asRecord29(payload.meta)?.accountId === "string" ? asRecord29(payload.meta)?.accountId : void 0;
|
|
144424
144766
|
const manifest = await readManifest4(snapshotDir, metaAccountId);
|
|
144425
144767
|
if (!manifest) {
|
|
@@ -144700,14 +145042,14 @@ init_html();
|
|
|
144700
145042
|
var TEMPLATE_BASENAME3 = "meta-account-diagnosis-report.html";
|
|
144701
145043
|
var INJECT_MARKER3 = "window.__META_DIAGNOSIS_REPORT__ = window.__META_DIAGNOSIS_REPORT__ || null;";
|
|
144702
145044
|
function resolveSkillTemplatePath6(basename13) {
|
|
144703
|
-
const dir =
|
|
145045
|
+
const dir = path47.dirname(fileURLToPath12(import.meta.url));
|
|
144704
145046
|
const candidates = [
|
|
144705
|
-
|
|
144706
|
-
|
|
144707
|
-
|
|
145047
|
+
path47.join(dir, "skill", "report-templates", basename13),
|
|
145048
|
+
path47.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
|
|
145049
|
+
path47.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
|
|
144708
145050
|
];
|
|
144709
145051
|
for (const p of candidates) {
|
|
144710
|
-
if (
|
|
145052
|
+
if (fs40.existsSync(p)) return p;
|
|
144711
145053
|
}
|
|
144712
145054
|
return candidates[0];
|
|
144713
145055
|
}
|
|
@@ -144737,10 +145079,10 @@ function injectReportData4(html, payload, lang) {
|
|
|
144737
145079
|
return localized.replace(INJECT_MARKER3, `window.__META_DIAGNOSIS_REPORT__ = ${json};`);
|
|
144738
145080
|
}
|
|
144739
145081
|
async function runFacebookAnalysisDiagnosisRender(opts) {
|
|
144740
|
-
const dataPath =
|
|
145082
|
+
const dataPath = path47.resolve(opts.dataFile);
|
|
144741
145083
|
let data = asRecord31(await readJsonFile6(dataPath));
|
|
144742
145084
|
if (opts.snapshotDir?.trim()) {
|
|
144743
|
-
data = await mergeMetaDiagnosisSnapshotIntoReport(data,
|
|
145085
|
+
data = await mergeMetaDiagnosisSnapshotIntoReport(data, path47.resolve(opts.snapshotDir));
|
|
144744
145086
|
}
|
|
144745
145087
|
const lang = readReportLangOrExit({ flag: opts.lang, meta: data.meta });
|
|
144746
145088
|
const contentCheck = validateMetaDiagnosisReportContent(data);
|
|
@@ -144767,10 +145109,10 @@ async function runFacebookAnalysisDiagnosisRender(opts) {
|
|
|
144767
145109
|
`);
|
|
144768
145110
|
process.exit(1);
|
|
144769
145111
|
}
|
|
144770
|
-
const outPath =
|
|
144771
|
-
opts.out ??
|
|
145112
|
+
const outPath = path47.resolve(
|
|
145113
|
+
opts.out ?? path47.join(path47.dirname(dataPath), "meta-account-diagnosis-report.html")
|
|
144772
145114
|
);
|
|
144773
|
-
const outDir =
|
|
145115
|
+
const outDir = path47.dirname(outPath);
|
|
144774
145116
|
await fsPromises5.mkdir(outDir, { recursive: true });
|
|
144775
145117
|
await fsPromises5.writeFile(outPath, injectReportData4(html, data, lang), "utf8");
|
|
144776
145118
|
const { stats } = contentCheck;
|
|
@@ -144788,7 +145130,7 @@ async function runFacebookAnalysisDiagnosisRender(opts) {
|
|
|
144788
145130
|
|
|
144789
145131
|
// src/commands/facebook-analysis/run-batch.ts
|
|
144790
145132
|
init_auth();
|
|
144791
|
-
import * as
|
|
145133
|
+
import * as path48 from "path";
|
|
144792
145134
|
import { performance as performance5 } from "perf_hooks";
|
|
144793
145135
|
init_version();
|
|
144794
145136
|
|
|
@@ -144890,7 +145232,7 @@ async function runAllFacebookSections(opts) {
|
|
|
144890
145232
|
const results = await runWithConcurrency2(tasks, concurrency);
|
|
144891
145233
|
const succeeded = results.filter((r) => r.ok).length;
|
|
144892
145234
|
const failed = results.length - succeeded;
|
|
144893
|
-
const absoluteSnapshotDir =
|
|
145235
|
+
const absoluteSnapshotDir = path48.resolve(opts.jsonOut);
|
|
144894
145236
|
const summary = {
|
|
144895
145237
|
kind: "siluzan-tso-facebook-analysis-snapshot-batch",
|
|
144896
145238
|
absoluteSnapshotDir,
|
|
@@ -145014,9 +145356,9 @@ function parseEffectiveStatusFilter(raw) {
|
|
|
145014
145356
|
}
|
|
145015
145357
|
return canonical.length ? canonical.join(",") : void 0;
|
|
145016
145358
|
}
|
|
145017
|
-
function facebookAdsUrl(facebookApiUrl, digits,
|
|
145359
|
+
function facebookAdsUrl(facebookApiUrl, digits, path59) {
|
|
145018
145360
|
const base2 = facebookApiUrl.replace(/\/$/, "");
|
|
145019
|
-
const p =
|
|
145361
|
+
const p = path59.startsWith("/") ? path59 : `/${path59}`;
|
|
145020
145362
|
return `${base2}/api/fb/ads/${digits}${p}`;
|
|
145021
145363
|
}
|
|
145022
145364
|
function facebookInsightsUrl(facebookApiUrl, digits, level) {
|
|
@@ -145053,7 +145395,7 @@ async function fetchFacebookAccount(config, digits, verbose) {
|
|
|
145053
145395
|
verbose
|
|
145054
145396
|
);
|
|
145055
145397
|
}
|
|
145056
|
-
async function fetchFacebookPagedList(config, digits,
|
|
145398
|
+
async function fetchFacebookPagedList(config, digits, path59, opts) {
|
|
145057
145399
|
const base2 = requireFacebookApi(config);
|
|
145058
145400
|
const items3 = [];
|
|
145059
145401
|
let after;
|
|
@@ -145068,7 +145410,7 @@ async function fetchFacebookPagedList(config, digits, path58, opts) {
|
|
|
145068
145410
|
adsetId: opts.adsetId
|
|
145069
145411
|
});
|
|
145070
145412
|
const raw = await apiFetch2(
|
|
145071
|
-
`${facebookAdsUrl(base2, digits,
|
|
145413
|
+
`${facebookAdsUrl(base2, digits, path59)}?${query}`,
|
|
145072
145414
|
config,
|
|
145073
145415
|
{},
|
|
145074
145416
|
opts.verbose
|
|
@@ -145203,7 +145545,7 @@ async function runFacebookEntityList(opts, kind) {
|
|
|
145203
145545
|
}
|
|
145204
145546
|
const pageSize = resolveFacebookPageSize(opts.pageSize);
|
|
145205
145547
|
const config = loadConfig(opts.token);
|
|
145206
|
-
const
|
|
145548
|
+
const path59 = `/${kind}`;
|
|
145207
145549
|
const labels = {
|
|
145208
145550
|
campaigns: {
|
|
145209
145551
|
section: "facebook-campaign-entities",
|
|
@@ -145216,7 +145558,7 @@ async function runFacebookEntityList(opts, kind) {
|
|
|
145216
145558
|
const meta = labels[kind];
|
|
145217
145559
|
let result;
|
|
145218
145560
|
try {
|
|
145219
|
-
result = await fetchFacebookPagedList(config, manifestId,
|
|
145561
|
+
result = await fetchFacebookPagedList(config, manifestId, path59, {
|
|
145220
145562
|
pageSize,
|
|
145221
145563
|
verbose: !!opts.verbose,
|
|
145222
145564
|
effectiveStatus,
|
|
@@ -145964,7 +146306,7 @@ function endpointHintForBingSection(def) {
|
|
|
145964
146306
|
|
|
145965
146307
|
// src/commands/bing-analysis/run-batch.ts
|
|
145966
146308
|
init_auth();
|
|
145967
|
-
import * as
|
|
146309
|
+
import * as path49 from "path";
|
|
145968
146310
|
import { performance as performance6 } from "perf_hooks";
|
|
145969
146311
|
init_version();
|
|
145970
146312
|
async function runWithConcurrency3(tasks, concurrency) {
|
|
@@ -146039,7 +146381,7 @@ async function runAllBingSections(opts) {
|
|
|
146039
146381
|
const results = await runWithConcurrency3(tasks, concurrency);
|
|
146040
146382
|
const succeeded = results.filter((r) => r.ok).length;
|
|
146041
146383
|
const failed = results.length - succeeded;
|
|
146042
|
-
const absoluteSnapshotDir =
|
|
146384
|
+
const absoluteSnapshotDir = path49.resolve(opts.jsonOut);
|
|
146043
146385
|
const summary = {
|
|
146044
146386
|
kind: "siluzan-tso-bing-analysis-snapshot-batch",
|
|
146045
146387
|
absoluteSnapshotDir,
|
|
@@ -146383,14 +146725,14 @@ Bing \u5B98\u65B9\u6708\u6D88\u8017\uFF08${id}\uFF09
|
|
|
146383
146725
|
import { Command as Command3 } from "commander";
|
|
146384
146726
|
|
|
146385
146727
|
// src/commands/bing-analysis/render-report.ts
|
|
146386
|
-
import
|
|
146728
|
+
import fs42 from "fs";
|
|
146387
146729
|
import fsPromises6 from "fs/promises";
|
|
146388
|
-
import
|
|
146730
|
+
import path51 from "path";
|
|
146389
146731
|
import { fileURLToPath as fileURLToPath13 } from "url";
|
|
146390
146732
|
|
|
146391
146733
|
// src/commands/bing-analysis/merge-snapshot.ts
|
|
146392
|
-
import * as
|
|
146393
|
-
import * as
|
|
146734
|
+
import * as fs41 from "fs/promises";
|
|
146735
|
+
import * as path50 from "path";
|
|
146394
146736
|
function asRecord33(value) {
|
|
146395
146737
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
146396
146738
|
return value;
|
|
@@ -146412,7 +146754,7 @@ function asRows2(value) {
|
|
|
146412
146754
|
}
|
|
146413
146755
|
async function loadSectionPayload(snapshotDir, file) {
|
|
146414
146756
|
try {
|
|
146415
|
-
const raw = await
|
|
146757
|
+
const raw = await fs41.readFile(path50.join(snapshotDir, file), "utf8");
|
|
146416
146758
|
return JSON.parse(raw);
|
|
146417
146759
|
} catch {
|
|
146418
146760
|
return null;
|
|
@@ -146422,7 +146764,7 @@ async function readManifest5(snapshotDir, accountId) {
|
|
|
146422
146764
|
const candidates = [];
|
|
146423
146765
|
if (accountId) candidates.push(reportManifestFile(accountId));
|
|
146424
146766
|
try {
|
|
146425
|
-
const entries = await
|
|
146767
|
+
const entries = await fs41.readdir(snapshotDir);
|
|
146426
146768
|
const manifestNames = entries.filter(
|
|
146427
146769
|
(n) => n.startsWith("report-manifest") && n.endsWith(".json")
|
|
146428
146770
|
);
|
|
@@ -146433,7 +146775,7 @@ async function readManifest5(snapshotDir, accountId) {
|
|
|
146433
146775
|
}
|
|
146434
146776
|
for (const name2 of candidates) {
|
|
146435
146777
|
try {
|
|
146436
|
-
const raw = await
|
|
146778
|
+
const raw = await fs41.readFile(path50.join(snapshotDir, name2), "utf8");
|
|
146437
146779
|
const parsed = JSON.parse(raw);
|
|
146438
146780
|
if (Array.isArray(parsed.artifacts) && parsed.artifacts.length > 0) return parsed;
|
|
146439
146781
|
} catch {
|
|
@@ -146600,7 +146942,7 @@ function mapSearchTermRows(payload) {
|
|
|
146600
146942
|
);
|
|
146601
146943
|
}
|
|
146602
146944
|
async function mergeBingAnalysisSnapshotIntoReport(payload, snapshotDir) {
|
|
146603
|
-
const absDir =
|
|
146945
|
+
const absDir = path50.resolve(snapshotDir);
|
|
146604
146946
|
const metaAccountId = typeof asRecord33(payload.meta)?.accountId === "string" ? asRecord33(payload.meta)?.accountId : void 0;
|
|
146605
146947
|
const manifest = await readManifest5(snapshotDir, metaAccountId);
|
|
146606
146948
|
if (!manifest) {
|
|
@@ -146838,14 +147180,14 @@ init_html();
|
|
|
146838
147180
|
var TEMPLATE_BASENAME4 = "bing-period-report.html";
|
|
146839
147181
|
var INJECT_MARKER4 = "window.__BING_PERIOD_REPORT__ = window.__BING_PERIOD_REPORT__ || null;";
|
|
146840
147182
|
function resolveSkillTemplatePath7(basename13) {
|
|
146841
|
-
const dir =
|
|
147183
|
+
const dir = path51.dirname(fileURLToPath13(import.meta.url));
|
|
146842
147184
|
const candidates = [
|
|
146843
|
-
|
|
146844
|
-
|
|
146845
|
-
|
|
147185
|
+
path51.join(dir, "skill", "report-templates", basename13),
|
|
147186
|
+
path51.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
|
|
147187
|
+
path51.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
|
|
146846
147188
|
];
|
|
146847
147189
|
for (const p of candidates) {
|
|
146848
|
-
if (
|
|
147190
|
+
if (fs42.existsSync(p)) return p;
|
|
146849
147191
|
}
|
|
146850
147192
|
return candidates[0];
|
|
146851
147193
|
}
|
|
@@ -146875,10 +147217,10 @@ function injectReportData5(html, payload, lang) {
|
|
|
146875
147217
|
return localized.replace(INJECT_MARKER4, `window.__BING_PERIOD_REPORT__ = ${json};`);
|
|
146876
147218
|
}
|
|
146877
147219
|
async function runBingAnalysisRender(opts) {
|
|
146878
|
-
const dataPath =
|
|
147220
|
+
const dataPath = path51.resolve(opts.dataFile);
|
|
146879
147221
|
let data = asRecord35(await readJsonFile7(dataPath));
|
|
146880
147222
|
if (opts.snapshotDir?.trim()) {
|
|
146881
|
-
data = await mergeBingAnalysisSnapshotIntoReport(data,
|
|
147223
|
+
data = await mergeBingAnalysisSnapshotIntoReport(data, path51.resolve(opts.snapshotDir));
|
|
146882
147224
|
}
|
|
146883
147225
|
const lang = readReportLangOrExit({ flag: opts.lang, meta: data.meta });
|
|
146884
147226
|
const contentCheck = validateBingPeriodReportContent(data);
|
|
@@ -146905,10 +147247,10 @@ async function runBingAnalysisRender(opts) {
|
|
|
146905
147247
|
`);
|
|
146906
147248
|
process.exit(1);
|
|
146907
147249
|
}
|
|
146908
|
-
const outPath =
|
|
146909
|
-
opts.out ??
|
|
147250
|
+
const outPath = path51.resolve(
|
|
147251
|
+
opts.out ?? path51.join(path51.dirname(dataPath), "bing-period-report.html")
|
|
146910
147252
|
);
|
|
146911
|
-
const outDir =
|
|
147253
|
+
const outDir = path51.dirname(outPath);
|
|
146912
147254
|
await fsPromises6.mkdir(outDir, { recursive: true });
|
|
146913
147255
|
await fsPromises6.writeFile(outPath, injectReportData5(html, data, lang), "utf8");
|
|
146914
147256
|
const { stats } = contentCheck;
|
|
@@ -147246,7 +147588,7 @@ async function fetchTikTokInterestList(config, account, verbose) {
|
|
|
147246
147588
|
|
|
147247
147589
|
// src/commands/tiktok-analysis/run-batch.ts
|
|
147248
147590
|
init_auth();
|
|
147249
|
-
import * as
|
|
147591
|
+
import * as path52 from "path";
|
|
147250
147592
|
import { performance as performance7 } from "perf_hooks";
|
|
147251
147593
|
init_version();
|
|
147252
147594
|
async function runWithConcurrency4(tasks, concurrency) {
|
|
@@ -147321,7 +147663,7 @@ async function runAllTikTokSections(opts) {
|
|
|
147321
147663
|
const results = await runWithConcurrency4(tasks, concurrency);
|
|
147322
147664
|
const succeeded = results.filter((r) => r.ok).length;
|
|
147323
147665
|
const failed = results.length - succeeded;
|
|
147324
|
-
const absoluteSnapshotDir =
|
|
147666
|
+
const absoluteSnapshotDir = path52.resolve(opts.jsonOut);
|
|
147325
147667
|
const summary = {
|
|
147326
147668
|
kind: "siluzan-tso-tiktok-analysis-snapshot-batch",
|
|
147327
147669
|
absoluteSnapshotDir,
|
|
@@ -147344,14 +147686,14 @@ init_auth();
|
|
|
147344
147686
|
import { Command as Command4 } from "commander";
|
|
147345
147687
|
|
|
147346
147688
|
// src/commands/tiktok-analysis/render-report.ts
|
|
147347
|
-
import
|
|
147689
|
+
import fs44 from "fs";
|
|
147348
147690
|
import fsPromises7 from "fs/promises";
|
|
147349
|
-
import
|
|
147691
|
+
import path54 from "path";
|
|
147350
147692
|
import { fileURLToPath as fileURLToPath14 } from "url";
|
|
147351
147693
|
|
|
147352
147694
|
// src/commands/tiktok-analysis/merge-snapshot.ts
|
|
147353
|
-
import * as
|
|
147354
|
-
import * as
|
|
147695
|
+
import * as fs43 from "fs/promises";
|
|
147696
|
+
import * as path53 from "path";
|
|
147355
147697
|
function asRecord36(value) {
|
|
147356
147698
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
147357
147699
|
return value;
|
|
@@ -147367,7 +147709,7 @@ function round28(value) {
|
|
|
147367
147709
|
}
|
|
147368
147710
|
async function loadSectionPayload2(snapshotDir, file) {
|
|
147369
147711
|
try {
|
|
147370
|
-
const raw = await
|
|
147712
|
+
const raw = await fs43.readFile(path53.join(snapshotDir, file), "utf8");
|
|
147371
147713
|
return JSON.parse(raw);
|
|
147372
147714
|
} catch {
|
|
147373
147715
|
return null;
|
|
@@ -147377,7 +147719,7 @@ async function readManifest6(snapshotDir, accountId) {
|
|
|
147377
147719
|
const candidates = [];
|
|
147378
147720
|
if (accountId) candidates.push(reportManifestFile(accountId));
|
|
147379
147721
|
try {
|
|
147380
|
-
const entries = await
|
|
147722
|
+
const entries = await fs43.readdir(snapshotDir);
|
|
147381
147723
|
const manifestNames = entries.filter(
|
|
147382
147724
|
(n) => n.startsWith("report-manifest") && n.endsWith(".json")
|
|
147383
147725
|
);
|
|
@@ -147388,7 +147730,7 @@ async function readManifest6(snapshotDir, accountId) {
|
|
|
147388
147730
|
}
|
|
147389
147731
|
for (const name2 of candidates) {
|
|
147390
147732
|
try {
|
|
147391
|
-
const raw = await
|
|
147733
|
+
const raw = await fs43.readFile(path53.join(snapshotDir, name2), "utf8");
|
|
147392
147734
|
const parsed = JSON.parse(raw);
|
|
147393
147735
|
if (Array.isArray(parsed.artifacts) && parsed.artifacts.length > 0) return parsed;
|
|
147394
147736
|
} catch {
|
|
@@ -147529,7 +147871,7 @@ function mapAudienceMerged(payload) {
|
|
|
147529
147871
|
};
|
|
147530
147872
|
}
|
|
147531
147873
|
async function mergeTikTokAnalysisSnapshotIntoReport(payload, snapshotDir) {
|
|
147532
|
-
const absDir =
|
|
147874
|
+
const absDir = path53.resolve(snapshotDir);
|
|
147533
147875
|
const metaAccountId = typeof asRecord36(payload.meta)?.accountId === "string" ? asRecord36(payload.meta)?.accountId : void 0;
|
|
147534
147876
|
const manifest = await readManifest6(snapshotDir, metaAccountId);
|
|
147535
147877
|
if (!manifest) {
|
|
@@ -147742,14 +148084,14 @@ init_html();
|
|
|
147742
148084
|
var TEMPLATE_BASENAME5 = "tiktok-period-report.html";
|
|
147743
148085
|
var INJECT_MARKER5 = "window.__TIKTOK_PERIOD_REPORT__ = window.__TIKTOK_PERIOD_REPORT__ || null;";
|
|
147744
148086
|
function resolveSkillTemplatePath8(basename13) {
|
|
147745
|
-
const dir =
|
|
148087
|
+
const dir = path54.dirname(fileURLToPath14(import.meta.url));
|
|
147746
148088
|
const candidates = [
|
|
147747
|
-
|
|
147748
|
-
|
|
147749
|
-
|
|
148089
|
+
path54.join(dir, "skill", "report-templates", basename13),
|
|
148090
|
+
path54.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
|
|
148091
|
+
path54.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
|
|
147750
148092
|
];
|
|
147751
148093
|
for (const p of candidates) {
|
|
147752
|
-
if (
|
|
148094
|
+
if (fs44.existsSync(p)) return p;
|
|
147753
148095
|
}
|
|
147754
148096
|
return candidates[0];
|
|
147755
148097
|
}
|
|
@@ -147779,10 +148121,10 @@ function injectReportData6(html, payload, lang) {
|
|
|
147779
148121
|
return localized.replace(INJECT_MARKER5, `window.__TIKTOK_PERIOD_REPORT__ = ${json};`);
|
|
147780
148122
|
}
|
|
147781
148123
|
async function runTikTokAnalysisRender(opts) {
|
|
147782
|
-
const dataPath =
|
|
148124
|
+
const dataPath = path54.resolve(opts.dataFile);
|
|
147783
148125
|
let data = asRecord38(await readJsonFile8(dataPath));
|
|
147784
148126
|
if (opts.snapshotDir?.trim()) {
|
|
147785
|
-
data = await mergeTikTokAnalysisSnapshotIntoReport(data,
|
|
148127
|
+
data = await mergeTikTokAnalysisSnapshotIntoReport(data, path54.resolve(opts.snapshotDir));
|
|
147786
148128
|
}
|
|
147787
148129
|
const lang = readReportLangOrExit({ flag: opts.lang, meta: data.meta });
|
|
147788
148130
|
const contentCheck = validateTikTokPeriodReportContent(data);
|
|
@@ -147809,10 +148151,10 @@ async function runTikTokAnalysisRender(opts) {
|
|
|
147809
148151
|
`);
|
|
147810
148152
|
process.exit(1);
|
|
147811
148153
|
}
|
|
147812
|
-
const outPath =
|
|
147813
|
-
opts.out ??
|
|
148154
|
+
const outPath = path54.resolve(
|
|
148155
|
+
opts.out ?? path54.join(path54.dirname(dataPath), "tiktok-period-report.html")
|
|
147814
148156
|
);
|
|
147815
|
-
const outDir =
|
|
148157
|
+
const outDir = path54.dirname(outPath);
|
|
147816
148158
|
await fsPromises7.mkdir(outDir, { recursive: true });
|
|
147817
148159
|
await fsPromises7.writeFile(outPath, injectReportData6(html, data, lang), "utf8");
|
|
147818
148160
|
const { stats } = contentCheck;
|
|
@@ -148740,7 +149082,7 @@ var YANDEX_SECTION_ALIASES = {
|
|
|
148740
149082
|
|
|
148741
149083
|
// src/commands/yandex-analysis/run-batch.ts
|
|
148742
149084
|
init_auth();
|
|
148743
|
-
import * as
|
|
149085
|
+
import * as path56 from "path";
|
|
148744
149086
|
import { performance as performance8 } from "perf_hooks";
|
|
148745
149087
|
init_version();
|
|
148746
149088
|
|
|
@@ -148880,8 +149222,8 @@ function endpointHintForYandexSection(def) {
|
|
|
148880
149222
|
}
|
|
148881
149223
|
|
|
148882
149224
|
// src/commands/yandex-analysis/merge-snapshot.ts
|
|
148883
|
-
import * as
|
|
148884
|
-
import * as
|
|
149225
|
+
import * as fs45 from "fs/promises";
|
|
149226
|
+
import * as path55 from "path";
|
|
148885
149227
|
function asRecord39(value) {
|
|
148886
149228
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
148887
149229
|
return value;
|
|
@@ -148931,7 +149273,7 @@ function pickMetrics2(row, extras = []) {
|
|
|
148931
149273
|
}
|
|
148932
149274
|
async function loadSectionPayload3(snapshotDir, file) {
|
|
148933
149275
|
try {
|
|
148934
|
-
const raw = await
|
|
149276
|
+
const raw = await fs45.readFile(path55.join(snapshotDir, file), "utf8");
|
|
148935
149277
|
return JSON.parse(raw);
|
|
148936
149278
|
} catch {
|
|
148937
149279
|
return null;
|
|
@@ -148941,7 +149283,7 @@ async function readManifest7(snapshotDir, accountId) {
|
|
|
148941
149283
|
const candidates = [];
|
|
148942
149284
|
if (accountId) candidates.push(reportManifestFile(accountId));
|
|
148943
149285
|
try {
|
|
148944
|
-
const entries = await
|
|
149286
|
+
const entries = await fs45.readdir(snapshotDir);
|
|
148945
149287
|
for (const name2 of entries.filter(
|
|
148946
149288
|
(n) => n.startsWith("report-manifest") && n.endsWith(".json")
|
|
148947
149289
|
)) {
|
|
@@ -148951,7 +149293,7 @@ async function readManifest7(snapshotDir, accountId) {
|
|
|
148951
149293
|
}
|
|
148952
149294
|
for (const name2 of candidates) {
|
|
148953
149295
|
try {
|
|
148954
|
-
const raw = await
|
|
149296
|
+
const raw = await fs45.readFile(path55.join(snapshotDir, name2), "utf8");
|
|
148955
149297
|
const parsed = JSON.parse(raw);
|
|
148956
149298
|
if (Array.isArray(parsed.artifacts) && parsed.artifacts.length > 0) return parsed;
|
|
148957
149299
|
} catch {
|
|
@@ -149110,7 +149452,7 @@ function mapDeviceRows2(payload) {
|
|
|
149110
149452
|
return asItems(payload).map((r) => pickMetrics2(r, ["device", "network"]));
|
|
149111
149453
|
}
|
|
149112
149454
|
async function mergeYandexAnalysisSnapshotIntoReport(payload, snapshotDir) {
|
|
149113
|
-
const absDir =
|
|
149455
|
+
const absDir = path55.resolve(snapshotDir);
|
|
149114
149456
|
const metaAccountId = typeof asRecord39(payload.meta)?.accountId === "string" ? asRecord39(payload.meta)?.accountId : void 0;
|
|
149115
149457
|
const manifest = await readManifest7(snapshotDir, metaAccountId);
|
|
149116
149458
|
if (!manifest) {
|
|
@@ -149296,7 +149638,7 @@ async function runAllYandexSections(opts) {
|
|
|
149296
149638
|
const results = await runWithConcurrency5(tasks, concurrency);
|
|
149297
149639
|
const succeeded = results.filter((r) => r.ok).length;
|
|
149298
149640
|
const failed = results.length - succeeded;
|
|
149299
|
-
const absoluteSnapshotDir =
|
|
149641
|
+
const absoluteSnapshotDir = path56.resolve(opts.jsonOut);
|
|
149300
149642
|
const summary = {
|
|
149301
149643
|
kind: "siluzan-tso-yandex-analysis-snapshot-batch",
|
|
149302
149644
|
absoluteSnapshotDir,
|
|
@@ -149314,9 +149656,9 @@ async function runAllYandexSections(opts) {
|
|
|
149314
149656
|
}
|
|
149315
149657
|
|
|
149316
149658
|
// src/commands/yandex-analysis/render-report.ts
|
|
149317
|
-
import
|
|
149659
|
+
import fs46 from "fs";
|
|
149318
149660
|
import fsPromises8 from "fs/promises";
|
|
149319
|
-
import
|
|
149661
|
+
import path57 from "path";
|
|
149320
149662
|
import { fileURLToPath as fileURLToPath15 } from "url";
|
|
149321
149663
|
|
|
149322
149664
|
// src/commands/yandex-analysis/report-content.ts
|
|
@@ -149523,14 +149865,14 @@ init_html();
|
|
|
149523
149865
|
var TEMPLATE_BASENAME6 = "yandex-period-report.html";
|
|
149524
149866
|
var INJECT_MARKER6 = "window.__YANDEX_PERIOD_REPORT__ = window.__YANDEX_PERIOD_REPORT__ || null;";
|
|
149525
149867
|
function resolveSkillTemplatePath9(basename13) {
|
|
149526
|
-
const dir =
|
|
149868
|
+
const dir = path57.dirname(fileURLToPath15(import.meta.url));
|
|
149527
149869
|
const candidates = [
|
|
149528
|
-
|
|
149529
|
-
|
|
149530
|
-
|
|
149870
|
+
path57.join(dir, "skill", "report-templates", basename13),
|
|
149871
|
+
path57.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
|
|
149872
|
+
path57.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
|
|
149531
149873
|
];
|
|
149532
149874
|
for (const p of candidates) {
|
|
149533
|
-
if (
|
|
149875
|
+
if (fs46.existsSync(p)) return p;
|
|
149534
149876
|
}
|
|
149535
149877
|
return candidates[0];
|
|
149536
149878
|
}
|
|
@@ -149573,10 +149915,10 @@ function injectReportData7(html, payload, lang) {
|
|
|
149573
149915
|
return localized.replace(INJECT_MARKER6, `window.__YANDEX_PERIOD_REPORT__ = ${json};`);
|
|
149574
149916
|
}
|
|
149575
149917
|
async function runYandexAnalysisRender(opts) {
|
|
149576
|
-
const dataPath =
|
|
149918
|
+
const dataPath = path57.resolve(opts.dataFile);
|
|
149577
149919
|
let data = asRecord41(await readJsonFile9(dataPath));
|
|
149578
149920
|
if (opts.snapshotDir?.trim()) {
|
|
149579
|
-
data = await mergeYandexAnalysisSnapshotIntoReport(data,
|
|
149921
|
+
data = await mergeYandexAnalysisSnapshotIntoReport(data, path57.resolve(opts.snapshotDir));
|
|
149580
149922
|
}
|
|
149581
149923
|
data = refreshWeeklyFromDaily(data);
|
|
149582
149924
|
const lang = readReportLangOrExit({ flag: opts.lang, meta: data.meta });
|
|
@@ -149602,10 +149944,10 @@ async function runYandexAnalysisRender(opts) {
|
|
|
149602
149944
|
`);
|
|
149603
149945
|
process.exit(1);
|
|
149604
149946
|
}
|
|
149605
|
-
const outPath =
|
|
149606
|
-
opts.out ??
|
|
149947
|
+
const outPath = path57.resolve(
|
|
149948
|
+
opts.out ?? path57.join(path57.dirname(dataPath), "yandex-period-report.html")
|
|
149607
149949
|
);
|
|
149608
|
-
const outDir =
|
|
149950
|
+
const outDir = path57.dirname(outPath);
|
|
149609
149951
|
await fsPromises8.mkdir(outDir, { recursive: true });
|
|
149610
149952
|
await fsPromises8.writeFile(outPath, injectReportData7(html, data, lang), "utf8");
|
|
149611
149953
|
const { stats } = contentCheck;
|
|
@@ -149706,13 +150048,13 @@ function optionalId(raw) {
|
|
|
149706
150048
|
function insightsLevelToPath(level) {
|
|
149707
150049
|
return level;
|
|
149708
150050
|
}
|
|
149709
|
-
function assertYandexAnalysisQuery(
|
|
149710
|
-
const caps = YANDEX_PATH_CAPS[
|
|
150051
|
+
function assertYandexAnalysisQuery(path59, query) {
|
|
150052
|
+
const caps = YANDEX_PATH_CAPS[path59];
|
|
149711
150053
|
if (query.timeIncrement != null && !caps.timeIncrement) {
|
|
149712
|
-
throw new Error(`--time-increment \u4E0D\u80FD\u7528\u4E8E /${
|
|
150054
|
+
throw new Error(`--time-increment \u4E0D\u80FD\u7528\u4E8E /${path59}\uFF08\u4EC5 campaigns / adgroups / ads\uFF09\u3002`);
|
|
149713
150055
|
}
|
|
149714
150056
|
if (query.network != null && !caps.network) {
|
|
149715
|
-
throw new Error(`--network \u4E0D\u80FD\u7528\u4E8E /${
|
|
150057
|
+
throw new Error(`--network \u4E0D\u80FD\u7528\u4E8E /${path59}\uFF08\u4EC5 campaigns / geo / devices\uFF09\u3002`);
|
|
149716
150058
|
}
|
|
149717
150059
|
if (query.status != null && !caps.status) {
|
|
149718
150060
|
throw new Error(`--status \u4EC5\u7528\u4E8E /ads\uFF08\u62D2\u5BA1/\u5BA1\u6838\u6001\u8D70\u7ED3\u6784\u67E5\u8BE2\uFF0C\u884C\u5185 spend \u4E3A 0\uFF09\u3002`);
|
|
@@ -149729,12 +150071,12 @@ function assertYandexAnalysisQuery(path58, query) {
|
|
|
149729
150071
|
);
|
|
149730
150072
|
}
|
|
149731
150073
|
if (query.limit != null && !caps.limit) {
|
|
149732
|
-
throw new Error(`--limit \u4E0D\u80FD\u7528\u4E8E /${
|
|
150074
|
+
throw new Error(`--limit \u4E0D\u80FD\u7528\u4E8E /${path59}\uFF08overview / daily / devices \u65E0\u6B64\u53C2\u6570\uFF09\u3002`);
|
|
149733
150075
|
}
|
|
149734
150076
|
}
|
|
149735
|
-
function buildYandexAnalysisSearchParams(
|
|
149736
|
-
assertYandexAnalysisQuery(
|
|
149737
|
-
const caps = YANDEX_PATH_CAPS[
|
|
150077
|
+
function buildYandexAnalysisSearchParams(path59, query) {
|
|
150078
|
+
assertYandexAnalysisQuery(path59, query);
|
|
150079
|
+
const caps = YANDEX_PATH_CAPS[path59];
|
|
149738
150080
|
const params = new URLSearchParams({
|
|
149739
150081
|
account: query.account,
|
|
149740
150082
|
start: query.start,
|
|
@@ -149760,10 +150102,10 @@ function buildYandexAnalysisSearchParams(path58, query) {
|
|
|
149760
150102
|
}
|
|
149761
150103
|
return params;
|
|
149762
150104
|
}
|
|
149763
|
-
async function fetchYandexAnalysisPath(config,
|
|
150105
|
+
async function fetchYandexAnalysisPath(config, path59, query, verbose) {
|
|
149764
150106
|
const yandexApiUrl = requireYandexApi(config);
|
|
149765
|
-
const params = buildYandexAnalysisSearchParams(
|
|
149766
|
-
const url = analysisUrl(yandexApiUrl,
|
|
150107
|
+
const params = buildYandexAnalysisSearchParams(path59, query);
|
|
150108
|
+
const url = analysisUrl(yandexApiUrl, path59, params.toString());
|
|
149767
150109
|
return apiFetch2(url, config, {}, verbose);
|
|
149768
150110
|
}
|
|
149769
150111
|
function unwrapYandexItems(raw) {
|
|
@@ -149827,13 +150169,13 @@ ${args.title}
|
|
|
149827
150169
|
console.log(` ${args.footnote}
|
|
149828
150170
|
`);
|
|
149829
150171
|
}
|
|
149830
|
-
async function fetchPath(opts,
|
|
150172
|
+
async function fetchPath(opts, path59, extra) {
|
|
149831
150173
|
const accountId = assertYandexAccountId(opts.account);
|
|
149832
150174
|
const { startDate, endDate } = resolveRange(opts.start, opts.end);
|
|
149833
150175
|
const config = loadConfig(opts.token);
|
|
149834
150176
|
const raw = await fetchYandexAnalysisPath(
|
|
149835
150177
|
config,
|
|
149836
|
-
|
|
150178
|
+
path59,
|
|
149837
150179
|
{
|
|
149838
150180
|
account: accountId,
|
|
149839
150181
|
start: startDate,
|
|
@@ -150357,9 +150699,9 @@ function interceptAgentCompatArgv(argv) {
|
|
|
150357
150699
|
installProcessHandlers();
|
|
150358
150700
|
function getVersion() {
|
|
150359
150701
|
try {
|
|
150360
|
-
const __dirname3 =
|
|
150361
|
-
const pkgPath =
|
|
150362
|
-
const pkg = JSON.parse(
|
|
150702
|
+
const __dirname3 = path58.dirname(fileURLToPath16(import.meta.url));
|
|
150703
|
+
const pkgPath = path58.join(__dirname3, "..", "package.json");
|
|
150704
|
+
const pkg = JSON.parse(fs47.readFileSync(pkgPath, "utf8"));
|
|
150363
150705
|
return pkg.version ?? "0.0.0";
|
|
150364
150706
|
} catch {
|
|
150365
150707
|
return "0.0.0";
|