webfast 0.1.11 → 0.1.12

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.
@@ -0,0 +1,19 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title><%= title %></title>
7
+ </head>
8
+ <body>
9
+
10
+ <h1>Hello, <%= name %>!</h1>
11
+
12
+ <ul>
13
+ <% fruits.forEach(function(fruit) { %>
14
+ <li><%= fruit %></li>
15
+ <% }); %>
16
+ </ul>
17
+
18
+ </body>
19
+ </html>
package/index.js CHANGED
@@ -3,7 +3,8 @@ const { readdirSync } = require("fs");
3
3
  console.log(`WebFast!! Program`);
4
4
  let program = {
5
5
  ts : Date.now(),
6
- modules : {}
6
+ modules : {},
7
+ tmp : {}
7
8
  }
8
9
 
9
10
  // Setup The Requirements
@@ -154,7 +155,7 @@ program.modules.fetch = async function(folder,program) {
154
155
  case `object`:
155
156
  // It's a object so check for dependend things etc.
156
157
  console.log(`Depending object`);
157
- await program.modules.dependOn(reqFunc,program,fileNameWithoutExtension,function(program,name){
158
+ return await program.modules.dependOn(reqFunc,program,fileNameWithoutExtension,function(program,name){
158
159
  console.log(`Setup `,name)
159
160
  });
160
161
  break;
@@ -173,70 +174,70 @@ program.modules.fetch = async function(folder,program) {
173
174
  }
174
175
  }
175
176
 
176
- program.modules.walkDirectory = async function (directoryPath, callback, forward) {
177
+ // Create tmp file path
178
+ program.modules.walkDirectory = async function (directoryPath, callback, forward, parentFileData) {
179
+ let allFiles = [];
177
180
  try {
178
181
  // Read the contents of the current directory
179
182
  const files = await program.fs.readdirSync(directoryPath);
180
183
 
181
- let allFiles = [];
182
-
183
184
  // Iterate through the files in the directory
184
- for (let f in files) {
185
+ for (const file of files) {
185
186
  // Construct the full path of the current file or directory
186
- let file = files[f];
187
- const fullPath = await program.path.join(directoryPath, file);
187
+ const fullPath = program.path.join(directoryPath, file);
188
188
 
189
189
  // Check if the current item is a directory
190
190
  const pathSync = await program.fs.statSync(fullPath);
191
191
  const isDirectoryPath = await pathSync.isDirectory();
192
- const fileExtension = await program.path.extname(fullPath);
192
+ const fileExtension = program.path.extname(fullPath);
193
193
 
194
194
  // Get the filename without the extension
195
- const fileName = await program.path.basename(fullPath, fileExtension);
195
+ const fileName = program.path.basename(fullPath, fileExtension);
196
+
197
+ // Create a new fileData object for each file or directory
198
+ const currentFileData = {
199
+ extension: fileExtension,
200
+ name: fileName,
201
+ path: fullPath,
202
+ sub: [],
203
+ };
196
204
 
197
205
  if (isDirectoryPath) {
198
206
  // If it's a directory, recursively walk through it
199
- let pushData = await program.modules.walkDirectory(fullPath, callback, fileName);
207
+ let pushData = await program.modules.walkDirectory(fullPath, callback, fileName, currentFileData);
200
208
  if (pushData.length !== 0) {
201
- allFiles = allFiles.concat(pushData); // Concatenate arrays instead of pushing an array
209
+ // Concatenate arrays instead of pushing an array
210
+ allFiles.push(currentFileData);
211
+ allFiles = allFiles.concat(pushData);
212
+ } else {
213
+ allFiles.push(currentFileData);
202
214
  }
203
215
  } else {
204
216
  // If it's a file, print the path
205
217
  console.log('File Extension:', fileExtension);
206
218
  console.log('File Name:', fileName);
207
219
 
208
- // Make Key from fileName extension
209
- const fileData = {
210
- extension: fileExtension,
211
- name: fileName,
212
- path: fullPath,
213
- sub: [],
214
- };
215
-
216
220
  if (forward !== undefined) {
217
221
  // Push it to sub
218
- fileData.sub.push(forward);
222
+ parentFileData.sub.push(currentFileData);
219
223
  } else {
220
- allFiles.push(fileData);
224
+ allFiles.push(currentFileData);
221
225
  }
222
226
  }
223
227
  }
224
228
 
225
- if (forward !== undefined) {
226
- // Return data
227
- return allFiles;
228
- }
229
-
230
229
  if (callback && forward === undefined) {
231
230
  await callback(allFiles);
232
- } else {
233
- return allFiles;
234
231
  }
232
+
233
+ return allFiles;
235
234
  } catch (error) {
236
235
  console.error('Error:', error.message);
237
236
  }
238
237
  };
239
238
 
239
+
240
+
240
241
 
241
242
 
242
243
  // Run program fetch
@@ -230,8 +230,18 @@ module.exports = async function(program,folder) {
230
230
 
231
231
  // Try to load it
232
232
  try {
233
- telegram.functions[key] = require(module.path);
234
- console.log(`Having The Module`,module);
233
+ const pathSync = await program.fs.statSync(module.path);
234
+ const isDirectoryPath = await pathSync.isDirectory();
235
+ const fileExtension = program.path.extname(module.path);
236
+
237
+ // Check if directory
238
+ if (isDirectoryPath) {
239
+ // It's directory so don't do anything yet
240
+ console.log(`It's Directory fo something`);
241
+ } else {
242
+ telegram.functions[key] = require(module.path);
243
+ console.log(`Having The Module`,module);
244
+ }
235
245
  } catch (err) {
236
246
  console.error(err);
237
247
  console.error(`Error Setting Up Telegram Module`);
@@ -20,8 +20,19 @@ module.exports = {
20
20
  // Create module in setModule
21
21
  try {
22
22
  // We have set module
23
- const runModule = await require(module.path)(program,module);
24
- setModule[module.name] = runModule;
23
+ const pathSync = await program.fs.statSync(module.path);
24
+ const isDirectoryPath = await pathSync.isDirectory();
25
+ const fileExtension = program.path.extname(module.path);
26
+
27
+ // Check if directory
28
+ if (isDirectoryPath) {
29
+ // It's directory so don't do anything yet
30
+ console.log(`It's Directory init bots`);
31
+ } else {
32
+ const runModule = await require(module.path)(program,module);
33
+ setModule[module.name] = runModule;
34
+ }
35
+
25
36
  } catch (err) {
26
37
  console.error(err);
27
38
  console.error(`Error Setting Module Data`,module.name);
@@ -47,11 +47,10 @@ module.exports = async function(program) {
47
47
  let route = routesData[rI];
48
48
  //console.log(`Route : `,route.path);
49
49
 
50
- let routePath = `${basePath}`
50
+ let routePath = `${basePath}/${route.name}`
51
51
  // Loop Through sub and create path with basePath
52
- for (let s in route.sub) {
53
- routePath = `${routePath}/${route.sub[s]}`
54
- }
52
+
53
+ console.log(`Set Route Name`);
55
54
 
56
55
  // Check to split name
57
56
  const split = route.name.split(`.`);
@@ -63,7 +62,7 @@ module.exports = async function(program) {
63
62
  }
64
63
 
65
64
  // FUll Route
66
- routePath = `${routePath}/${route.name}`;
65
+ //routePath = `${routePath}/${route.name}`;
67
66
 
68
67
  // Create Route UUID for easy findable
69
68
  const routeID = program.uuid.v4();
@@ -73,7 +72,40 @@ module.exports = async function(program) {
73
72
 
74
73
  // Setup the function
75
74
  try {
76
- route.func = require(route.path);
75
+ const pathSync = await program.fs.statSync(route.path);
76
+ const isDirectoryPath = await pathSync.isDirectory();
77
+ const fileExtension = program.path.extname(route.path);
78
+ console.log(`If it's directory or not`);
79
+
80
+ // Check if directory
81
+ if (isDirectoryPath) {
82
+ console.log(`It's directoyr`);
83
+ // Create routes now
84
+ for (let s in route.sub) {
85
+ const subData = route.sub[rI];
86
+ if (subData != undefined) {
87
+ const routeName = subData.name.replace(`.get`,``).replace(`.post`,``);
88
+ routePath = `${routePath}/${routeName}`
89
+
90
+ // Create type
91
+ const subDataSplit = subData.name.split(`.`);
92
+ const type = subDataSplit[subDataSplit.length-1];
93
+
94
+ subData.name = routeName;
95
+ delete subData.sub;
96
+ subData.type = type;
97
+
98
+ // Create func
99
+ subData.func = require(subData.path);
100
+ // Set route
101
+ exprs[routePath] = subData;
102
+ }
103
+ }
104
+
105
+
106
+ } else {
107
+ route.func = require(route.path);
108
+ }
77
109
  } catch(err) {
78
110
  console.error(`Error Route Func`,routePath);
79
111
  console.error(err);
@@ -81,7 +113,6 @@ module.exports = async function(program) {
81
113
 
82
114
  // Save route for path
83
115
  route.webwalk = 0;
84
- exprs[routePath] = route;
85
116
 
86
117
  console.log(`Setting Up Route`);
87
118
  }
@@ -96,6 +127,7 @@ module.exports = async function(program) {
96
127
  let routeData = exprs[route];
97
128
  console.log(`Setup Route`,route);
98
129
  let state = false;
130
+
99
131
  try {
100
132
  // This is where the magic happens when we receive an incomming request it will
101
133
  // route it through the dynamice route folder
@@ -0,0 +1,12 @@
1
+ module.exports = async function(program,req,res,route) {
2
+ console.log(`Create`);
3
+ const fullPath = program.path.join(__dirname, `..`,`..`,`..`,`..`,`ejs`,`example`,`list.ejs`);
4
+
5
+ // Render the EJS template
6
+ res.render(fullPath, {
7
+ title: 'EJS Example',
8
+ name: 'John Doe',
9
+ isAdmin: true,
10
+ fruits: ['Apple', 'Banana', 'Orange']
11
+ });
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webfast",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "WebFast! Bot Application, including TON mini-apps",
5
5
  "main": "index.js",
6
6
  "repository": {