@c-time/frelio-data-json-generator 2.2.1 → 2.4.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 +46 -27
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +4 -282
- package/dist/index.js +42 -15
- package/dist/index.js.map +1 -1
- package/dist/preview/index.d.ts +39 -0
- package/dist/preview/index.js +506 -0
- package/dist/preview/index.js.map +1 -0
- package/dist/types-CKkhMZAh.d.ts +285 -0
- package/package.json +9 -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);
|
|
@@ -956,7 +956,7 @@ async function processListRecipes(contentTypeId, recipes, targets, context) {
|
|
|
956
956
|
}
|
|
957
957
|
return outputs;
|
|
958
958
|
}
|
|
959
|
-
async function
|
|
959
|
+
async function buildListPageData(contentTypeId, recipe, context) {
|
|
960
960
|
let contents = context.contentsByType.get(contentTypeId) ?? [];
|
|
961
961
|
contents = applyFilters(contents, recipe.filters);
|
|
962
962
|
contents = applySort(contents, recipe.sort);
|
|
@@ -967,6 +967,10 @@ async function processListWithoutPagination(contentTypeId, recipe, context) {
|
|
|
967
967
|
contents = contents.slice(0, recipe.limit);
|
|
968
968
|
}
|
|
969
969
|
const items = await processListItems(contents, recipe, context);
|
|
970
|
+
return { items, totalCount: items.length };
|
|
971
|
+
}
|
|
972
|
+
async function processListWithoutPagination(contentTypeId, recipe, context) {
|
|
973
|
+
const { items, totalCount } = await buildListPageData(contentTypeId, recipe, context);
|
|
970
974
|
const outputPath = sanitizePath(recipe.outputPath);
|
|
971
975
|
const pathError = validateOutputPath(outputPath);
|
|
972
976
|
if (pathError) {
|
|
@@ -986,7 +990,7 @@ async function processListWithoutPagination(contentTypeId, recipe, context) {
|
|
|
986
990
|
outputFile: toHtmlOutputPath(outputPath),
|
|
987
991
|
data: {
|
|
988
992
|
items,
|
|
989
|
-
totalCount
|
|
993
|
+
totalCount
|
|
990
994
|
}
|
|
991
995
|
};
|
|
992
996
|
return {
|
|
@@ -1338,19 +1342,42 @@ function extractRequiredContentTypes(recipe) {
|
|
|
1338
1342
|
async function detectDeletedOutputs(generatedOutputs, outputRootPath, fileSystem, targets, fullRebuild, logger) {
|
|
1339
1343
|
const deleteOutputs = [];
|
|
1340
1344
|
if (!fullRebuild) {
|
|
1341
|
-
const
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1345
|
+
const deletedContentIds = new Set(
|
|
1346
|
+
targets.filter((t) => t.reason === "deleted" && t.contentId).map((t) => t.contentId)
|
|
1347
|
+
);
|
|
1348
|
+
if (deletedContentIds.size === 0) {
|
|
1349
|
+
return deleteOutputs;
|
|
1350
|
+
}
|
|
1351
|
+
const generatedPaths = new Set(generatedOutputs.map((o) => o.path));
|
|
1352
|
+
try {
|
|
1353
|
+
const existingFiles = await fileSystem.listFiles(`${outputRootPath}/**/*.json`);
|
|
1354
|
+
const existingOutputPaths = existingFiles.filter((f) => !f.endsWith("report.json")).map((f) => f.replace(`${outputRootPath}/`, ""));
|
|
1355
|
+
for (const existingPath of existingOutputPaths) {
|
|
1356
|
+
if (generatedPaths.has(existingPath)) {
|
|
1357
|
+
continue;
|
|
1358
|
+
}
|
|
1359
|
+
let contentId;
|
|
1360
|
+
try {
|
|
1361
|
+
const raw = await fileSystem.readFile(`${outputRootPath}/${existingPath}`);
|
|
1362
|
+
const parsed = JSON.parse(raw);
|
|
1363
|
+
const value = parsed?.data?.contentId;
|
|
1364
|
+
contentId = typeof value === "string" ? value : void 0;
|
|
1365
|
+
} catch {
|
|
1366
|
+
continue;
|
|
1367
|
+
}
|
|
1368
|
+
if (contentId && deletedContentIds.has(contentId)) {
|
|
1369
|
+
deleteOutputs.push({
|
|
1370
|
+
path: existingPath,
|
|
1371
|
+
content: {
|
|
1372
|
+
type: "delete",
|
|
1373
|
+
outputFile: toHtmlOutputPath(existingPath)
|
|
1374
|
+
}
|
|
1375
|
+
});
|
|
1376
|
+
logger.debug(`Marked for deletion (unpublished/deleted): ${existingPath}`);
|
|
1377
|
+
}
|
|
1353
1378
|
}
|
|
1379
|
+
} catch {
|
|
1380
|
+
logger.debug("Could not list existing files for deletion detection");
|
|
1354
1381
|
}
|
|
1355
1382
|
return deleteOutputs;
|
|
1356
1383
|
}
|
|
@@ -1563,17 +1590,9 @@ async function main() {
|
|
|
1563
1590
|
if (!options.dryRun) {
|
|
1564
1591
|
mkdirSync(OUTPUT_ROOT, { recursive: true });
|
|
1565
1592
|
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
|
-
}
|
|
1593
|
+
const fullPath = join(OUTPUT_ROOT, output.path);
|
|
1594
|
+
mkdirSync(dirname(fullPath), { recursive: true });
|
|
1595
|
+
writeFileSync(fullPath, JSON.stringify(output.content, null, 2));
|
|
1577
1596
|
}
|
|
1578
1597
|
}
|
|
1579
1598
|
mkdirSync(dirname(REPORT_PATH), { recursive: true });
|