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.
@@ -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,CA4BxB"}
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
- try {
140
- const htmlFiles = readdirSync(srcDir).filter((file) => file.endsWith('.html'));
141
- const entries = {};
142
- htmlFiles.forEach((file) => {
143
- const name = file.replace('.html', '');
144
- entries[name] = resolve(srcDir, file);
145
- });
146
- if (debug) {
147
- console.log(`📄 Auto-discovered HTML files: ${Object.keys(entries).join(', ')}`);
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
- return entries;
150
- }
151
- catch (error) {
152
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
153
- console.warn(`⚠️ Could not read directory: ${srcDir}`);
154
- if (debug) {
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-html-elements",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Modular HTML without the JavaScript",
5
5
  "author": "Vincent Medina",
6
6
  "license": "MIT",