@constela/start 1.8.0 → 1.8.2
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.
|
@@ -768,7 +768,7 @@ async function mdxContentToNode(content, options) {
|
|
|
768
768
|
|
|
769
769
|
// src/data/loader.ts
|
|
770
770
|
import { existsSync as existsSync3, readFileSync } from "fs";
|
|
771
|
-
import { basename, extname as extname2, join as join3 } from "path";
|
|
771
|
+
import { basename, dirname, extname as extname2, join as join3 } from "path";
|
|
772
772
|
import fg2 from "fast-glob";
|
|
773
773
|
var mdxContentToNode2 = mdxContentToNode;
|
|
774
774
|
function resolveJsonRefs(json) {
|
|
@@ -953,7 +953,18 @@ async function transformMdx(content, file, options) {
|
|
|
953
953
|
options?.components ? { components: options.components } : void 0
|
|
954
954
|
);
|
|
955
955
|
const fmSlug = frontmatter["slug"];
|
|
956
|
-
|
|
956
|
+
let slug;
|
|
957
|
+
if (typeof fmSlug === "string") {
|
|
958
|
+
slug = fmSlug;
|
|
959
|
+
} else {
|
|
960
|
+
const filename = basename(file, extname2(file));
|
|
961
|
+
if (filename === "index") {
|
|
962
|
+
const dir = dirname(file);
|
|
963
|
+
slug = dir === "." ? "index" : basename(dir);
|
|
964
|
+
} else {
|
|
965
|
+
slug = filename;
|
|
966
|
+
}
|
|
967
|
+
}
|
|
957
968
|
return {
|
|
958
969
|
file,
|
|
959
970
|
raw: content,
|
|
@@ -1424,7 +1435,7 @@ function createAdapter(options) {
|
|
|
1424
1435
|
|
|
1425
1436
|
// src/layout/resolver.ts
|
|
1426
1437
|
import { existsSync as existsSync5, statSync as statSync3, readFileSync as readFileSync3 } from "fs";
|
|
1427
|
-
import { join as join5, basename as basename2, dirname } from "path";
|
|
1438
|
+
import { join as join5, basename as basename2, dirname as dirname2 } from "path";
|
|
1428
1439
|
import fg3 from "fast-glob";
|
|
1429
1440
|
import { isLayoutProgram } from "@constela/core";
|
|
1430
1441
|
|
|
@@ -1506,7 +1517,7 @@ async function loadLayout(layoutFile) {
|
|
|
1506
1517
|
const parsed = JSON.parse(content);
|
|
1507
1518
|
const importsValue = parsed["imports"];
|
|
1508
1519
|
if (importsValue && typeof importsValue === "object" && Object.keys(importsValue).length > 0) {
|
|
1509
|
-
const layoutDir =
|
|
1520
|
+
const layoutDir = dirname2(layoutFile);
|
|
1510
1521
|
const resolvedImports = await resolveImports(
|
|
1511
1522
|
layoutDir,
|
|
1512
1523
|
importsValue
|
|
@@ -1622,7 +1633,7 @@ import { isCookieInitialExpr as isCookieInitialExpr2, ConstelaError } from "@con
|
|
|
1622
1633
|
|
|
1623
1634
|
// src/json-page-loader.ts
|
|
1624
1635
|
import { existsSync as existsSync6, readFileSync as readFileSync4 } from "fs";
|
|
1625
|
-
import { dirname as
|
|
1636
|
+
import { dirname as dirname3, join as join6, relative, resolve as resolve3 } from "path";
|
|
1626
1637
|
function validateVersion(version) {
|
|
1627
1638
|
if (version !== "1.0") {
|
|
1628
1639
|
throw new Error(`Unsupported version: ${version}. Only version "1.0" is supported.`);
|
|
@@ -1776,7 +1787,7 @@ async function loadJsonPage(baseDir, pagePath, options) {
|
|
|
1776
1787
|
throw new Error(`Missing required field "view" in page: ${filePath}`);
|
|
1777
1788
|
}
|
|
1778
1789
|
validateVersion(page.version);
|
|
1779
|
-
const pageDir =
|
|
1790
|
+
const pageDir = dirname3(filePath);
|
|
1780
1791
|
const resolvedImports = await resolveImports(pageDir, page.imports, baseDir);
|
|
1781
1792
|
const patternBaseDir = pageDir;
|
|
1782
1793
|
const normalizedData = normalizeDataSourcePatterns(baseDir, patternBaseDir, page.data);
|
|
@@ -2851,7 +2862,7 @@ async function resolveConfig(fileConfig, cliOptions) {
|
|
|
2851
2862
|
// src/build/index.ts
|
|
2852
2863
|
import { existsSync as existsSync9, readFileSync as readFileSync6 } from "fs";
|
|
2853
2864
|
import { mkdir as mkdir2, writeFile, cp, readdir } from "fs/promises";
|
|
2854
|
-
import { join as join11, dirname as
|
|
2865
|
+
import { join as join11, dirname as dirname6, relative as relative5, basename as basename4, isAbsolute as isAbsolute3, resolve as resolve4 } from "path";
|
|
2855
2866
|
import { isCookieInitialExpr as isCookieInitialExpr3 } from "@constela/core";
|
|
2856
2867
|
|
|
2857
2868
|
// src/build/bundler.ts
|
|
@@ -2859,15 +2870,15 @@ import * as esbuild from "esbuild";
|
|
|
2859
2870
|
import { existsSync as existsSync8 } from "fs";
|
|
2860
2871
|
import { mkdir, readFile } from "fs/promises";
|
|
2861
2872
|
import { createRequire } from "module";
|
|
2862
|
-
import { join as join10, dirname as
|
|
2873
|
+
import { join as join10, dirname as dirname5, isAbsolute as isAbsolute2, relative as relative4 } from "path";
|
|
2863
2874
|
import { fileURLToPath } from "url";
|
|
2864
|
-
var __dirname =
|
|
2875
|
+
var __dirname = dirname5(fileURLToPath(import.meta.url));
|
|
2865
2876
|
async function bundleRuntime(options) {
|
|
2866
2877
|
const entryContent = `
|
|
2867
2878
|
export { hydrateApp, createApp } from '@constela/runtime';
|
|
2868
2879
|
`;
|
|
2869
2880
|
const outFile = join10(options.outDir, "_constela", "runtime.js");
|
|
2870
|
-
await mkdir(
|
|
2881
|
+
await mkdir(dirname5(outFile), { recursive: true });
|
|
2871
2882
|
try {
|
|
2872
2883
|
await esbuild.build({
|
|
2873
2884
|
stdin: {
|
|
@@ -2893,7 +2904,7 @@ async function bundleCSS(options) {
|
|
|
2893
2904
|
const cssFiles = Array.isArray(options.css) ? options.css : [options.css];
|
|
2894
2905
|
const outFile = join10(options.outDir, "_constela", "styles.css");
|
|
2895
2906
|
const shouldMinify = options.minify ?? true;
|
|
2896
|
-
await mkdir(
|
|
2907
|
+
await mkdir(dirname5(outFile), { recursive: true });
|
|
2897
2908
|
const resolvedCssFiles = cssFiles.map((f) => isAbsolute2(f) ? f : join10(process.cwd(), f));
|
|
2898
2909
|
for (const fullPath of resolvedCssFiles) {
|
|
2899
2910
|
if (!existsSync8(fullPath)) {
|
|
@@ -2932,10 +2943,10 @@ async function bundleCSS(options) {
|
|
|
2932
2943
|
);
|
|
2933
2944
|
}
|
|
2934
2945
|
}
|
|
2935
|
-
const sourceDir =
|
|
2946
|
+
const sourceDir = dirname5(firstCssFile);
|
|
2936
2947
|
const sourceDirectives = options.content.map((contentPath) => {
|
|
2937
2948
|
const absolutePath = isAbsolute2(contentPath) ? contentPath : join10(process.cwd(), contentPath);
|
|
2938
|
-
const srcPath = absolutePath.includes("*") ?
|
|
2949
|
+
const srcPath = absolutePath.includes("*") ? dirname5(absolutePath.split("*")[0] ?? absolutePath) : absolutePath;
|
|
2939
2950
|
const relativePath = relative4(sourceDir, srcPath);
|
|
2940
2951
|
return `@source "${relativePath}";`;
|
|
2941
2952
|
}).join("\n");
|
|
@@ -3033,7 +3044,7 @@ function paramsToOutputPath(basePattern, params, outDir) {
|
|
|
3033
3044
|
return join11(outDir, relativePath, "index.html");
|
|
3034
3045
|
}
|
|
3035
3046
|
async function loadGetStaticPaths(pageFile) {
|
|
3036
|
-
const dir =
|
|
3047
|
+
const dir = dirname6(pageFile);
|
|
3037
3048
|
const baseName = basename4(pageFile, ".json");
|
|
3038
3049
|
const pathsFile = join11(dir, `${baseName}.paths.ts`);
|
|
3039
3050
|
if (!existsSync9(pathsFile)) {
|
|
@@ -3084,7 +3095,7 @@ async function loadLayout2(layoutName, layoutsDir) {
|
|
|
3084
3095
|
const content = readFileSync6(layoutPath, "utf-8");
|
|
3085
3096
|
const parsed = JSON.parse(content);
|
|
3086
3097
|
if (parsed.imports && Object.keys(parsed.imports).length > 0) {
|
|
3087
|
-
const layoutDir =
|
|
3098
|
+
const layoutDir = dirname6(layoutPath);
|
|
3088
3099
|
const resolvedImports = await resolveImports(layoutDir, parsed.imports);
|
|
3089
3100
|
return { ...parsed, importData: resolvedImports };
|
|
3090
3101
|
}
|
|
@@ -3416,13 +3427,13 @@ async function processLayouts(pageInfo, layoutsDir, routeParams = {}) {
|
|
|
3416
3427
|
};
|
|
3417
3428
|
return updatedPageInfo;
|
|
3418
3429
|
}
|
|
3419
|
-
async function renderPageToHtml(program, params, runtimePath, cssPath, externalImports, widgets, lang) {
|
|
3430
|
+
async function renderPageToHtml(program, params, routePath, runtimePath, cssPath, externalImports, widgets, lang) {
|
|
3420
3431
|
const normalizedProgram = {
|
|
3421
3432
|
...program,
|
|
3422
3433
|
view: normalizeViewNode(structuredClone(program.view))
|
|
3423
3434
|
};
|
|
3424
3435
|
const ctx = {
|
|
3425
|
-
url:
|
|
3436
|
+
url: routePath,
|
|
3426
3437
|
params,
|
|
3427
3438
|
query: new URLSearchParams()
|
|
3428
3439
|
};
|
|
@@ -3430,12 +3441,12 @@ async function renderPageToHtml(program, params, runtimePath, cssPath, externalI
|
|
|
3430
3441
|
const routeContext = {
|
|
3431
3442
|
params,
|
|
3432
3443
|
query: {},
|
|
3433
|
-
path:
|
|
3444
|
+
path: routePath
|
|
3434
3445
|
};
|
|
3435
3446
|
const metaTags = generateMetaTags(normalizedProgram.route, {
|
|
3436
3447
|
params,
|
|
3437
3448
|
query: {},
|
|
3438
|
-
path:
|
|
3449
|
+
path: routePath
|
|
3439
3450
|
});
|
|
3440
3451
|
const cssLinkTag = cssPath ? `<link rel="stylesheet" href="${cssPath}">` : void 0;
|
|
3441
3452
|
const head = [metaTags, cssLinkTag].filter(Boolean).join("\n") || void 0;
|
|
@@ -3489,7 +3500,7 @@ async function copyDirRecursive(srcDir, destDir, skipFiles) {
|
|
|
3489
3500
|
if (skipFiles.has(destPath)) {
|
|
3490
3501
|
continue;
|
|
3491
3502
|
}
|
|
3492
|
-
await mkdir2(
|
|
3503
|
+
await mkdir2(dirname6(destPath), { recursive: true });
|
|
3493
3504
|
await cp(srcPath, destPath);
|
|
3494
3505
|
}
|
|
3495
3506
|
}
|
|
@@ -3549,7 +3560,7 @@ async function build2(options) {
|
|
|
3549
3560
|
});
|
|
3550
3561
|
}
|
|
3551
3562
|
const absoluteRoutesDir = isAbsolute3(routesDir) ? routesDir : resolve4(routesDir);
|
|
3552
|
-
const projectRoot =
|
|
3563
|
+
const projectRoot = dirname6(dirname6(absoluteRoutesDir));
|
|
3553
3564
|
const config = await loadConfig(projectRoot);
|
|
3554
3565
|
const seoLang = options?.seo?.lang ?? config.seo?.lang;
|
|
3555
3566
|
for (const route of jsonPages) {
|
|
@@ -3579,6 +3590,11 @@ async function build2(options) {
|
|
|
3579
3590
|
for (const pathEntry of staticPathsResult) {
|
|
3580
3591
|
const params = pathEntry.params;
|
|
3581
3592
|
const outputPath = paramsToOutputPath(route.pattern, params, outDir);
|
|
3593
|
+
let routePath = route.pattern;
|
|
3594
|
+
for (const [key, value] of Object.entries(params)) {
|
|
3595
|
+
routePath = routePath.replace(`:${key}`, value);
|
|
3596
|
+
routePath = routePath.replace("*", value);
|
|
3597
|
+
}
|
|
3582
3598
|
let boundPageInfo = pageInfo;
|
|
3583
3599
|
if (pathEntry.data && pageInfo.page.getStaticPaths?.source) {
|
|
3584
3600
|
const source = pageInfo.page.getStaticPaths.source;
|
|
@@ -3598,32 +3614,27 @@ async function build2(options) {
|
|
|
3598
3614
|
processedPageInfo = await processLayouts(boundPageInfo, layoutsDir, params);
|
|
3599
3615
|
}
|
|
3600
3616
|
const program = await convertToCompiledProgram(processedPageInfo);
|
|
3601
|
-
const html = await renderPageToHtml(program, params, runtimePath, cssPath, processedPageInfo.page.externalImports, processedPageInfo.widgets, seoLang);
|
|
3602
|
-
await mkdir2(
|
|
3617
|
+
const html = await renderPageToHtml(program, params, routePath, runtimePath, cssPath, processedPageInfo.page.externalImports, processedPageInfo.widgets, seoLang);
|
|
3618
|
+
await mkdir2(dirname6(outputPath), { recursive: true });
|
|
3603
3619
|
await writeFile(outputPath, html, "utf-8");
|
|
3604
3620
|
generatedFiles.push(outputPath);
|
|
3605
3621
|
const slugValue = params["slug"];
|
|
3606
3622
|
if (slugValue && (slugValue === "index" || slugValue.endsWith("/index"))) {
|
|
3607
|
-
const parentOutputPath = join11(
|
|
3623
|
+
const parentOutputPath = join11(dirname6(dirname6(outputPath)), "index.html");
|
|
3608
3624
|
if (!generatedFiles.includes(parentOutputPath)) {
|
|
3609
|
-
await mkdir2(
|
|
3625
|
+
await mkdir2(dirname6(parentOutputPath), { recursive: true });
|
|
3610
3626
|
await writeFile(parentOutputPath, html, "utf-8");
|
|
3611
3627
|
generatedFiles.push(parentOutputPath);
|
|
3612
3628
|
}
|
|
3613
3629
|
}
|
|
3614
|
-
let routePath = route.pattern;
|
|
3615
|
-
for (const [key, value] of Object.entries(params)) {
|
|
3616
|
-
routePath = routePath.replace(`:${key}`, value);
|
|
3617
|
-
routePath = routePath.replace("*", value);
|
|
3618
|
-
}
|
|
3619
3630
|
routes.push(routePath);
|
|
3620
3631
|
}
|
|
3621
3632
|
} else {
|
|
3622
3633
|
const loader = new JsonPageLoader(projectRoot, { routesDir: absoluteRoutesDir });
|
|
3623
3634
|
let pageInfo = await loader.loadPage(relPathFromProjectRoot);
|
|
3624
3635
|
let outputPath;
|
|
3636
|
+
const routePath = pageInfo.page.route?.path ?? route.pattern;
|
|
3625
3637
|
if (pageInfo.page.route?.path) {
|
|
3626
|
-
const routePath = pageInfo.page.route.path;
|
|
3627
3638
|
const relativePath = routePath.startsWith("/") ? routePath.slice(1) : routePath;
|
|
3628
3639
|
if (relativePath === "" || relativePath === "/") {
|
|
3629
3640
|
outputPath = join11(outDir, "index.html");
|
|
@@ -3637,8 +3648,8 @@ async function build2(options) {
|
|
|
3637
3648
|
pageInfo = await processLayouts(pageInfo, layoutsDir, {});
|
|
3638
3649
|
}
|
|
3639
3650
|
const program = await convertToCompiledProgram(pageInfo);
|
|
3640
|
-
const html = await renderPageToHtml(program, {}, runtimePath, cssPath, pageInfo.page.externalImports, pageInfo.widgets, seoLang);
|
|
3641
|
-
await mkdir2(
|
|
3651
|
+
const html = await renderPageToHtml(program, {}, routePath, runtimePath, cssPath, pageInfo.page.externalImports, pageInfo.widgets, seoLang);
|
|
3652
|
+
await mkdir2(dirname6(outputPath), { recursive: true });
|
|
3642
3653
|
await writeFile(outputPath, html, "utf-8");
|
|
3643
3654
|
generatedFiles.push(outputPath);
|
|
3644
3655
|
}
|
package/dist/cli/index.js
CHANGED
package/dist/index.js
CHANGED