@rettangoli/fe 0.0.12 → 0.0.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rettangoli/fe",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "Frontend framework for building reactive web components",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/cli/build.js CHANGED
@@ -17,9 +17,8 @@ function capitalize(word) {
17
17
  }
18
18
 
19
19
  // Function to process view files - loads YAML and creates temporary JS file
20
- export const writeViewFile = (view, category, component) => {
21
- // const { category, component } = extractCategoryAndComponent(filePath);
22
- const dir = path.join(".temp", category);
20
+ export const writeViewFile = (view, category, component, tempDir) => {
21
+ const dir = path.join(tempDir, category);
23
22
  if (!existsSync(dir)) {
24
23
  mkdirSync(dir, { recursive: true });
25
24
  }
@@ -30,9 +29,9 @@ export const writeViewFile = (view, category, component) => {
30
29
  };
31
30
 
32
31
  export const bundleFile = async (options) => {
33
- const { outfile = "./vt/static/main.js", development = false } = options;
32
+ const { outfile, tempDir, development = false } = options;
34
33
  await esbuild.build({
35
- entryPoints: ["./.temp/dynamicImport.js"],
34
+ entryPoints: [path.join(tempDir, "dynamicImport.js")],
36
35
  bundle: true,
37
36
  minify: !development,
38
37
  sourcemap: !!development,
@@ -48,9 +47,26 @@ export const bundleFile = async (options) => {
48
47
  const buildRettangoliFrontend = async (options) => {
49
48
  console.log("running build with options", options);
50
49
 
51
- const { dirs = ["./example"], outfile = "./vt/static/main.js", setup = "setup.js", development = false } = options;
50
+ const {
51
+ cwd = process.cwd(),
52
+ dirs = ["./example"],
53
+ outfile = "./vt/static/main.js",
54
+ setup = "setup.js",
55
+ development = false
56
+ } = options;
57
+
58
+ // Resolve all paths relative to cwd
59
+ const resolvedDirs = dirs.map(dir => path.resolve(cwd, dir));
60
+ const resolvedSetup = path.resolve(cwd, setup);
61
+ const resolvedOutfile = path.resolve(cwd, outfile);
62
+ const tempDir = path.resolve(cwd, ".temp");
63
+
64
+ // Ensure temp directory exists
65
+ if (!existsSync(tempDir)) {
66
+ mkdirSync(tempDir, { recursive: true });
67
+ }
52
68
 
53
- const allFiles = getAllFiles(dirs).filter((filePath) => {
69
+ const allFiles = getAllFiles(resolvedDirs).filter((filePath) => {
54
70
  return (
55
71
  filePath.endsWith(".store.js") ||
56
72
  filePath.endsWith(".handlers.js") ||
@@ -86,9 +102,10 @@ const buildRettangoliFrontend = async (options) => {
86
102
 
87
103
 
88
104
  if (["handlers", "store"].includes(fileType)) {
105
+ const relativePath = path.relative(tempDir, filePath).replaceAll(path.sep, "/");
89
106
  output += `import * as ${component}${capitalize(
90
107
  fileType,
91
- )} from '../${filePath.replaceAll(path.sep, "/")}';\n`;
108
+ )} from '${relativePath}';\n`;
92
109
 
93
110
  replaceMap[count] = `${component}${capitalize(fileType)}`;
94
111
  imports[category][component][fileType] = count;
@@ -101,7 +118,7 @@ const buildRettangoliFrontend = async (options) => {
101
118
  console.error(`Error parsing template in file: ${filePath}`);
102
119
  throw error;
103
120
  }
104
- writeViewFile(view, category, component);
121
+ writeViewFile(view, category, component, tempDir);
105
122
  output += `import ${component}${capitalize(
106
123
  fileType,
107
124
  )} from './${category}/${component}.view.js';\n`;
@@ -112,9 +129,10 @@ const buildRettangoliFrontend = async (options) => {
112
129
  }
113
130
  }
114
131
 
132
+ const relativeSetup = path.relative(tempDir, resolvedSetup).replaceAll(path.sep, "/");
115
133
  output += `
116
134
  import { createComponent } from '@rettangoli/fe';
117
- import { deps, patch, h } from '../${setup}';
135
+ import { deps, patch, h } from '${relativeSetup}';
118
136
  const imports = ${JSON.stringify(imports, null, 2)};
119
137
 
120
138
  Object.keys(imports).forEach(category => {
@@ -130,11 +148,11 @@ Object.keys(imports).forEach(category => {
130
148
  output = output.replace(key, replaceMap[key]);
131
149
  });
132
150
 
133
- writeFileSync("./.temp/dynamicImport.js", output);
151
+ writeFileSync(path.join(tempDir, "dynamicImport.js"), output);
134
152
 
135
- await bundleFile({ outfile, development });
153
+ await bundleFile({ outfile: resolvedOutfile, tempDir, development });
136
154
 
137
- console.log(`Build complete. Output file: ${outfile}`);
155
+ console.log(`Build complete. Output file: ${resolvedOutfile}`);
138
156
  };
139
157
 
140
158
  export default buildRettangoliFrontend;
package/src/index.js CHANGED
@@ -1,9 +1,7 @@
1
1
  import createComponent from './createComponent.js';
2
2
  import createWebPatch from './createWebPatch.js';
3
- import { build } from './cli/index.js'
4
3
 
5
4
  export {
6
5
  createComponent,
7
6
  createWebPatch,
8
- build
9
7
  }