@shop-on/theme-dev-host 0.3.0 → 0.5.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/materialize.mjs +3 -22
- package/package.json +2 -2
package/dist/materialize.mjs
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import { watch } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { copyFile, mkdir, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
|
|
5
|
-
import {
|
|
5
|
+
import { currentPresetHandle } from "@shop-on/theme-contract/preset-listing";
|
|
6
|
+
import { overlayPresetListing } from "@shop-on/theme-contract/preset-materializer";
|
|
6
7
|
//#region src/materialize.ts
|
|
7
8
|
const JSON_DIRS = [
|
|
8
9
|
"sections",
|
|
@@ -40,26 +41,6 @@ async function resolveActivePreset(themeSrcDir, presetOverride) {
|
|
|
40
41
|
} catch {}
|
|
41
42
|
return currentPresetHandle(data, presetOverride);
|
|
42
43
|
}
|
|
43
|
-
async function overlayListingDir(listingDir, targetDir) {
|
|
44
|
-
let files;
|
|
45
|
-
try {
|
|
46
|
-
files = await readdir(listingDir);
|
|
47
|
-
} catch {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
await mkdir(targetDir, { recursive: true });
|
|
51
|
-
for (const file of files) {
|
|
52
|
-
if (!file.endsWith(".json") || file.startsWith("._")) continue;
|
|
53
|
-
const override = JSON.parse(await readFile(path.join(listingDir, file), "utf-8"));
|
|
54
|
-
const targetPath = path.join(targetDir, file);
|
|
55
|
-
let base = null;
|
|
56
|
-
try {
|
|
57
|
-
base = JSON.parse(await readFile(targetPath, "utf-8"));
|
|
58
|
-
} catch {}
|
|
59
|
-
const output = base === null ? override : mergePresetJson(base, override);
|
|
60
|
-
await writeFile(targetPath, `${JSON.stringify(output, null, 2)}\n`, "utf-8");
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
44
|
async function materializeThemeConfig(themeSrcDir, configDir, presetOverride) {
|
|
64
45
|
await mkdir(configDir, { recursive: true });
|
|
65
46
|
for (const dir of JSON_DIRS) await copyJsonDir(path.join(themeSrcDir, dir), path.join(configDir, dir));
|
|
@@ -75,7 +56,7 @@ async function materializeThemeConfig(themeSrcDir, configDir, presetOverride) {
|
|
|
75
56
|
const activePreset = await resolveActivePreset(themeSrcDir, presetOverride);
|
|
76
57
|
if (activePreset) {
|
|
77
58
|
const listingDir = path.join(themeSrcDir, "listings", activePreset);
|
|
78
|
-
if (await dirExists(listingDir))
|
|
59
|
+
if (await dirExists(listingDir)) await overlayPresetListing(listingDir, configDir);
|
|
79
60
|
}
|
|
80
61
|
}
|
|
81
62
|
function watchThemeConfig(themeSrcDir, configDir, opts = {}) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shop-on/theme-dev-host",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Local theme-editor dev server: serves the editor contract + proxies a theme's dev server behind one origin, so a theme runs locally and previews in a real admin theme-editor. Nucleus of the future theme CLI.",
|
|
5
5
|
"license": "SEE LICENSE IN dist/LICENSE.md",
|
|
6
6
|
"bin": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"@hono/node-server": "^2.1.5",
|
|
16
16
|
"hono": "^4.13.13",
|
|
17
17
|
"jose": "^6.2.13",
|
|
18
|
-
"@shop-on/theme-contract": "0.
|
|
18
|
+
"@shop-on/theme-contract": "0.5.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/node": "26.6.5",
|