vite-plugin-html-elements 0.1.2 → 0.1.4
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/index.d.ts.map +1 -1
- package/dist/index.js +49 -17
- package/package.json +1 -1
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAyC,MAAM,MAAM,CAAC;AAI1E,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;IAEvB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,MAAM,CAiEtE;AAyHD,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,KAAK,GAAE,OAAe,GACrB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAyC,MAAM,MAAM,CAAC;AAI1E,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;IAEvB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,MAAM,CAiEtE;AAyHD,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,KAAK,GAAE,OAAe,GACrB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA2DxB"}
|
package/dist/index.js
CHANGED
|
@@ -136,24 +136,56 @@ function parseAttributes(attrString) {
|
|
|
136
136
|
return attrs;
|
|
137
137
|
}
|
|
138
138
|
export function getHtmlEntries(srcDir, debug = false) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
139
|
+
const entries = {};
|
|
140
|
+
function scanDirectory(dir, basePath = '') {
|
|
141
|
+
try {
|
|
142
|
+
const items = readdirSync(dir, { withFileTypes: true });
|
|
143
|
+
for (const item of items) {
|
|
144
|
+
const fullPath = resolve(dir, item.name);
|
|
145
|
+
const relativePath = basePath ? `${basePath}/${item.name}` : item.name;
|
|
146
|
+
if (item.isDirectory()) {
|
|
147
|
+
// Skip elements directory
|
|
148
|
+
if (item.name === 'elements') {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
// Recursively scan subdirectories
|
|
152
|
+
scanDirectory(fullPath, relativePath);
|
|
153
|
+
}
|
|
154
|
+
else if (item.isFile() && item.name.endsWith('.html')) {
|
|
155
|
+
// Generate entry name from file path
|
|
156
|
+
let entryName;
|
|
157
|
+
if (item.name === 'index.html') {
|
|
158
|
+
// index.html in root -> 'index'
|
|
159
|
+
// index.html in blog/ -> 'blog/index'
|
|
160
|
+
entryName = basePath ? `${basePath}/index` : 'index';
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
// about.html -> 'about/index'
|
|
164
|
+
// blog/post.html -> 'blog/post/index'
|
|
165
|
+
const nameWithoutExt = item.name.replace('.html', '');
|
|
166
|
+
entryName = basePath
|
|
167
|
+
? `${basePath}/${nameWithoutExt}/index`
|
|
168
|
+
: `${nameWithoutExt}/index`;
|
|
169
|
+
}
|
|
170
|
+
entries[entryName] = fullPath;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
148
173
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
console.error(` ${errorMessage}`);
|
|
174
|
+
catch (error) {
|
|
175
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
176
|
+
console.warn(`⚠️ Could not read directory: ${dir}`);
|
|
177
|
+
if (debug) {
|
|
178
|
+
console.error(` ${errorMessage}`);
|
|
179
|
+
}
|
|
156
180
|
}
|
|
157
|
-
return {};
|
|
158
181
|
}
|
|
182
|
+
scanDirectory(srcDir);
|
|
183
|
+
if (debug) {
|
|
184
|
+
console.log(`📄 Auto-discovered routes:`);
|
|
185
|
+
Object.keys(entries).forEach((key) => {
|
|
186
|
+
const url = key === 'index' ? '/' : `/${key.replace('/index', '')}`;
|
|
187
|
+
console.log(` ${url} -> ${entries[key].replace(srcDir + '/', '')}`);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return entries;
|
|
159
191
|
}
|