@skafform/vite-plugin 0.1.0 → 0.1.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.
Files changed (3) hide show
  1. package/dist/index.js +11 -24
  2. package/package.json +1 -1
  3. package/types.d.ts +11 -0
package/dist/index.js CHANGED
@@ -7,8 +7,8 @@ var VIRTUAL_CONFIG = "virtual:skafform/config";
7
7
  var RESOLVED_CONFIG = "\0virtual:skafform/config";
8
8
  var VIRTUAL_SERVER_INIT = "virtual:skafform/server-init";
9
9
  var RESOLVED_SERVER_INIT = "\0virtual:skafform/server-init";
10
- var VIRTUAL_NAV = "virtual:skafform/nav";
11
- var RESOLVED_NAV = "\0virtual:skafform/nav";
10
+ var VIRTUAL_ADMIN_SECTIONS = "virtual:skafform/admin-sections";
11
+ var RESOLVED_ADMIN_SECTIONS = "\0virtual:skafform/admin-sections";
12
12
  var norm = (p) => p.replace(/\\/g, "/");
13
13
  function loadBrickIndex(root) {
14
14
  const bricksDir = resolve(root, "bricks");
@@ -93,7 +93,7 @@ ${vars}
93
93
  resolveId(id, importer) {
94
94
  if (id === VIRTUAL_CONFIG) return RESOLVED_CONFIG;
95
95
  if (id === VIRTUAL_SERVER_INIT) return RESOLVED_SERVER_INIT;
96
- if (id === VIRTUAL_NAV) return RESOLVED_NAV;
96
+ if (id === VIRTUAL_ADMIN_SECTIONS) return RESOLVED_ADMIN_SECTIONS;
97
97
  if (id.startsWith(".") && importer) {
98
98
  const themeDir = norm(resolve(root, `themes/${config.theme}`));
99
99
  const componentsDir = themeDir + "/components";
@@ -120,30 +120,17 @@ ${vars}
120
120
  customize: { ...themeJson.customize ?? {}, ...config.customize ?? {} }
121
121
  })}`;
122
122
  }
123
- if (id === RESOLVED_NAV) {
123
+ if (id === RESOLVED_ADMIN_SECTIONS) {
124
124
  const bricksConfigPath = resolve(root, "skafform-bricks.json");
125
- const themeJson = getThemeJson(config.theme);
126
- const navLocations = themeJson.nav_locations ?? config.nav_locations ?? {};
127
- const customNav = themeJson.nav ?? config.nav ?? {};
128
- const bricksConfig = existsSync(bricksConfigPath) ? JSON.parse(readFileSync(bricksConfigPath, "utf-8")) : { bricks: {} };
129
- const registry = {};
130
- for (const loc of Object.keys(navLocations)) registry[loc] = [];
131
- for (const [brickName, brick] of Object.entries(bricksConfig.bricks ?? {})) {
132
- for (const item of brick.nav ?? []) {
133
- if (registry[item.location] !== void 0) {
134
- registry[item.location].push({ ...item, order: item.order ?? 0, brick: brickName });
135
- }
136
- }
137
- }
138
- for (const [loc, items] of Object.entries(customNav)) {
139
- if (registry[loc] !== void 0) {
140
- registry[loc].push(...items.map((i) => ({ ...i, order: i.order ?? 0, brick: "config" })));
125
+ if (!existsSync(bricksConfigPath)) return "export default []";
126
+ const bricksConfig = JSON.parse(readFileSync(bricksConfigPath, "utf-8"));
127
+ const sections = [];
128
+ for (const brick of Object.values(bricksConfig.bricks ?? {})) {
129
+ for (const section of brick.adminSections ?? []) {
130
+ sections.push(section);
141
131
  }
142
132
  }
143
- for (const loc of Object.keys(registry)) {
144
- registry[loc].sort((a, b) => a.order - b.order);
145
- }
146
- return `export default ${JSON.stringify(registry)}`;
133
+ return `export default ${JSON.stringify(sections)}`;
147
134
  }
148
135
  if (id === RESOLVED_SERVER_INIT) {
149
136
  const bricksConfigPath = resolve(root, "skafform-bricks.json");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skafform/vite-plugin",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
package/types.d.ts CHANGED
@@ -18,3 +18,14 @@ declare module "virtual:skafform/config" {
18
18
  export default config
19
19
  }
20
20
 
21
+ interface SkafformAdminSection {
22
+ label: string
23
+ href: string
24
+ file: string
25
+ }
26
+
27
+ declare module "virtual:skafform/admin-sections" {
28
+ const sections: SkafformAdminSection[]
29
+ export default sections
30
+ }
31
+