@c-time/frelio-data-json-generator 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +40 -25
- package/dist/cli.js.map +1 -1
- package/dist/index.js +36 -13
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { validateSiteRecipe, formatZodErrors } from '@c-time/frelio-types/schemas';
|
|
3
3
|
import { findAffectedOutputs } from '@c-time/frelio-dependency-map';
|
|
4
4
|
import { readFile } from 'fs/promises';
|
|
5
|
-
import { existsSync, readFileSync, mkdirSync,
|
|
5
|
+
import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'fs';
|
|
6
6
|
import { glob } from 'glob';
|
|
7
7
|
import { exec } from 'child_process';
|
|
8
8
|
import { promisify, parseArgs } from 'util';
|
|
@@ -158,7 +158,7 @@ function calculateRegenerationScope(changes, dependencyMap, recipe) {
|
|
|
158
158
|
const targets = [];
|
|
159
159
|
const seenOutputPaths = /* @__PURE__ */ new Set();
|
|
160
160
|
const addTarget = (target) => {
|
|
161
|
-
const key = `${target.outputPath}:${target.contentId ?? ""}`;
|
|
161
|
+
const key = `${target.reason}:${target.outputPath}:${target.contentId ?? ""}`;
|
|
162
162
|
if (!seenOutputPaths.has(key)) {
|
|
163
163
|
seenOutputPaths.add(key);
|
|
164
164
|
targets.push(target);
|
|
@@ -1338,19 +1338,42 @@ function extractRequiredContentTypes(recipe) {
|
|
|
1338
1338
|
async function detectDeletedOutputs(generatedOutputs, outputRootPath, fileSystem, targets, fullRebuild, logger) {
|
|
1339
1339
|
const deleteOutputs = [];
|
|
1340
1340
|
if (!fullRebuild) {
|
|
1341
|
-
const
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1341
|
+
const deletedContentIds = new Set(
|
|
1342
|
+
targets.filter((t) => t.reason === "deleted" && t.contentId).map((t) => t.contentId)
|
|
1343
|
+
);
|
|
1344
|
+
if (deletedContentIds.size === 0) {
|
|
1345
|
+
return deleteOutputs;
|
|
1346
|
+
}
|
|
1347
|
+
const generatedPaths = new Set(generatedOutputs.map((o) => o.path));
|
|
1348
|
+
try {
|
|
1349
|
+
const existingFiles = await fileSystem.listFiles(`${outputRootPath}/**/*.json`);
|
|
1350
|
+
const existingOutputPaths = existingFiles.filter((f) => !f.endsWith("report.json")).map((f) => f.replace(`${outputRootPath}/`, ""));
|
|
1351
|
+
for (const existingPath of existingOutputPaths) {
|
|
1352
|
+
if (generatedPaths.has(existingPath)) {
|
|
1353
|
+
continue;
|
|
1354
|
+
}
|
|
1355
|
+
let contentId;
|
|
1356
|
+
try {
|
|
1357
|
+
const raw = await fileSystem.readFile(`${outputRootPath}/${existingPath}`);
|
|
1358
|
+
const parsed = JSON.parse(raw);
|
|
1359
|
+
const value = parsed?.data?.contentId;
|
|
1360
|
+
contentId = typeof value === "string" ? value : void 0;
|
|
1361
|
+
} catch {
|
|
1362
|
+
continue;
|
|
1363
|
+
}
|
|
1364
|
+
if (contentId && deletedContentIds.has(contentId)) {
|
|
1365
|
+
deleteOutputs.push({
|
|
1366
|
+
path: existingPath,
|
|
1367
|
+
content: {
|
|
1368
|
+
type: "delete",
|
|
1369
|
+
outputFile: toHtmlOutputPath(existingPath)
|
|
1370
|
+
}
|
|
1371
|
+
});
|
|
1372
|
+
logger.debug(`Marked for deletion (unpublished/deleted): ${existingPath}`);
|
|
1373
|
+
}
|
|
1353
1374
|
}
|
|
1375
|
+
} catch {
|
|
1376
|
+
logger.debug("Could not list existing files for deletion detection");
|
|
1354
1377
|
}
|
|
1355
1378
|
return deleteOutputs;
|
|
1356
1379
|
}
|
|
@@ -1563,17 +1586,9 @@ async function main() {
|
|
|
1563
1586
|
if (!options.dryRun) {
|
|
1564
1587
|
mkdirSync(OUTPUT_ROOT, { recursive: true });
|
|
1565
1588
|
for (const output of result.outputs) {
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
}
|
|
1570
|
-
}
|
|
1571
|
-
for (const output of result.outputs) {
|
|
1572
|
-
if (output.content.type !== "delete") {
|
|
1573
|
-
const fullPath = join(OUTPUT_ROOT, output.path);
|
|
1574
|
-
mkdirSync(dirname(fullPath), { recursive: true });
|
|
1575
|
-
writeFileSync(fullPath, JSON.stringify(output.content, null, 2));
|
|
1576
|
-
}
|
|
1589
|
+
const fullPath = join(OUTPUT_ROOT, output.path);
|
|
1590
|
+
mkdirSync(dirname(fullPath), { recursive: true });
|
|
1591
|
+
writeFileSync(fullPath, JSON.stringify(output.content, null, 2));
|
|
1577
1592
|
}
|
|
1578
1593
|
}
|
|
1579
1594
|
mkdirSync(dirname(REPORT_PATH), { recursive: true });
|