html-component-engine 0.1.1 → 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/bin/cli.js +4 -4
  2. package/package.json +1 -1
  3. package/src/index.js +47 -18
package/bin/cli.js CHANGED
@@ -39,7 +39,7 @@ function question(rl, prompt) {
39
39
  const templates = {
40
40
  'package.json': (projectName) => `{
41
41
  "name": "${projectName}",
42
- "version": "0.1.1",
42
+ "version": "0.1.2",
43
43
  "type": "module",
44
44
  "scripts": {
45
45
  "dev": "vite",
@@ -48,7 +48,7 @@ const templates = {
48
48
  },
49
49
  "devDependencies": {
50
50
  "vite": "^7.0.0",
51
- "html-component-engine": "^0.1.1"
51
+ "html-component-engine": "^0.1.2"
52
52
  }
53
53
  }
54
54
  `,
@@ -77,7 +77,7 @@ export default {
77
77
  <meta charset="UTF-8">
78
78
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
79
79
  <title>Home | My Website</title>
80
- <link rel="stylesheet" href="/assets/styles/main.css">
80
+ <link rel="stylesheet" href="./assets/styles/main.css">
81
81
  </head>
82
82
  <body>
83
83
  <Component src="Header" title="My Website" />
@@ -116,7 +116,7 @@ export default {
116
116
  <meta charset="UTF-8">
117
117
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
118
118
  <title>About | My Website</title>
119
- <link rel="stylesheet" href="/assets/styles/main.css">
119
+ <link rel="stylesheet" href="./assets/styles/main.css">
120
120
  </head>
121
121
  <body>
122
122
  <Component src="Header" title="My Website" />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "html-component-engine",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "A Vite plugin for HTML component components with a lightweight static site compiler",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/index.js CHANGED
@@ -198,8 +198,8 @@ export default function htmlComponentEngine(options = {}) {
198
198
  console.log(` ✓ Compiled: ${htmlFile} → ${outputFileName}`);
199
199
  }
200
200
 
201
- // Copy ALL assets to dist/assets
202
- await copyAllAssets(assetsRoot, this);
201
+ // Copy ALL non-HTML files from src/ to dist/ (excluding components/)
202
+ await copyAllNonComponentFiles(srcRoot, componentsDir, this);
203
203
  },
204
204
 
205
205
  /**
@@ -247,33 +247,62 @@ async function getHtmlFiles(dir, base = '', componentsDir = 'components') {
247
247
  }
248
248
 
249
249
  /**
250
- * Copy ALL assets to dist/assets/ directory
251
- * @param {string} assetsPath - Assets directory path
250
+ * Copy ALL non-HTML files under src/ to dist/ preserving paths
251
+ * Excludes any directory named componentsDir (defaults to "components").
252
+ * @param {string} srcPath - src directory path
253
+ * @param {string} componentsDir - directory name to exclude
252
254
  * @param {object} context - Rollup plugin context
253
255
  */
254
- async function copyAllAssets(assetsPath, context) {
255
- try {
256
- await fs.access(assetsPath);
257
- } catch {
258
- console.log(' No assets directory found, skipping asset copy');
259
- return;
260
- }
256
+ async function copyAllNonComponentFiles(srcPath, componentsDir = 'components', context) {
257
+ const allFiles = await getAllFilesExcludingDir(srcPath, componentsDir);
261
258
 
262
- const assetFiles = await getAllFiles(assetsPath);
259
+ let copiedCount = 0;
260
+ for (const file of allFiles) {
261
+ const relativePath = path.relative(srcPath, file).replace(/\\/g, '/');
263
262
 
264
- console.log(` Copying ${assetFiles.length} asset file(s) to assets/`);
263
+ // HTML is handled separately (compiled + emitted)
264
+ if (relativePath.toLowerCase().endsWith('.html')) continue;
265
265
 
266
- for (const file of assetFiles) {
267
- const relativePath = path.relative(assetsPath, file);
268
266
  const content = await fs.readFile(file);
269
-
270
- // Copy to dist/assets/ subdirectory
271
267
  context.emitFile({
272
268
  type: 'asset',
273
- fileName: `assets/${relativePath.replace(/\\/g, '/')}`,
269
+ fileName: relativePath,
274
270
  source: content,
275
271
  });
272
+ copiedCount++;
276
273
  }
274
+
275
+ console.log(` Copied ${copiedCount} non-HTML file(s)`);
276
+ }
277
+
278
+ /**
279
+ * Get all files recursively from a directory, excluding a directory name.
280
+ * @param {string} dir - Directory to search
281
+ * @param {string} excludedDirName - Directory name to exclude (e.g., "components")
282
+ * @returns {Promise<string[]>} - Array of absolute file paths
283
+ */
284
+ async function getAllFilesExcludingDir(dir, excludedDirName) {
285
+ const files = [];
286
+
287
+ try {
288
+ const entries = await fs.readdir(dir, { withFileTypes: true });
289
+
290
+ for (const entry of entries) {
291
+ const fullPath = path.join(dir, entry.name);
292
+
293
+ if (entry.isDirectory()) {
294
+ if (entry.name === excludedDirName) continue;
295
+ const subFiles = await getAllFilesExcludingDir(fullPath, excludedDirName);
296
+ files.push(...subFiles);
297
+ } else {
298
+ files.push(fullPath);
299
+ }
300
+ }
301
+ } catch (error) {
302
+ console.warn(`Could not read directory ${dir}: ${error.message}`);
303
+ }
304
+
305
+ return files;
277
306
  }
278
307
 
279
308
  /**