webfast 0.1.20 → 0.1.24

Sign up to get free protection for your applications and to get access to all the features.
package/index.js CHANGED
@@ -1,244 +1,247 @@
1
- const { readdirSync } = require("fs");
2
-
3
- console.log(`WebFast!! Program`);
4
- let program = {
5
- ts : Date.now(),
6
- modules : {},
7
- tmp : {}
8
- }
9
-
10
- // Setup The Requirements
11
- async function set(program) {
12
- program.path = await require(`path`);
13
- program.fs = await require(`fs`);
14
- program.uuid = require(`uuid`);
15
- program.fetch = require(`fetch`);
16
- return program;
17
- }
18
-
19
- // Program Fetch
20
- program.modules.dependOn = async function(reqFunc,program,name,callback) {
21
- console.log(`Depend On Check`);
22
-
23
- // Loop Through dependOn if its not true then check
24
- for (let dependIndex in reqFunc.dependOn) {
25
- const dependOn = reqFunc.dependOn[dependIndex];
26
- // So we dependOn
27
- // Check index
28
- // If .
29
- let split = dependOn.split(`.`);
30
- // Now we should loop through array
31
- let objectData = program;
32
- let fullObjectPath = `program`;
33
- let dependOnItem = ``;
34
- for (let spl in split) {
35
- // Grab object
36
- let toCheck = split[spl];
37
- if (objectData[toCheck] == undefined) {
38
- if (program.modules[name] != undefined) {
39
- return;
40
- } else {
41
- program.modules[name] = {
42
- ts : Date.now()
1
+ module.exports = function () {
2
+ const { readdirSync } = require("fs");
3
+
4
+ console.log(`WebFast!! Program`);
5
+ let program = {
6
+ ts : Date.now(),
7
+ modules : {},
8
+ tmp : {},
9
+ set : {}
10
+ }
11
+
12
+ // Setup The Requirements
13
+ async function set(program) {
14
+ program.path = await require(`path`);
15
+ program.fs = await require(`fs`);
16
+ program.uuid = require(`uuid`);
17
+ program.fetch = require(`fetch`);
18
+ return program;
19
+ }
20
+
21
+ // Program Fetch
22
+ program.modules.dependOn = async function(reqFunc,program,name,callback) {
23
+ console.log(`Depend On Check`);
24
+
25
+ // Loop Through dependOn if its not true then check
26
+ for (let dependIndex in reqFunc.dependOn) {
27
+ const dependOn = reqFunc.dependOn[dependIndex];
28
+ // So we dependOn
29
+ // Check index
30
+ // If .
31
+ let split = dependOn.split(`.`);
32
+ // Now we should loop through array
33
+ let objectData = program;
34
+ let fullObjectPath = `program`;
35
+ let dependOnItem = ``;
36
+ for (let spl in split) {
37
+ // Grab object
38
+ let toCheck = split[spl];
39
+ if (objectData[toCheck] == undefined) {
40
+ if (program.modules[name] != undefined) {
41
+ return;
42
+ } else {
43
+ program.modules[name] = {
44
+ ts : Date.now()
45
+ }
46
+ await setTimeout(async function(){
47
+ await program.modules.dependOn(reqFunc,program,name,callback);
48
+ },200);
43
49
  }
44
- await setTimeout(async function(){
45
- await program.modules.dependOn(reqFunc,program,name,callback);
46
- },200);
47
- }
48
- } else {
49
- // New object thing and og next
50
- if (split.length-1 != spl) {
51
- fullObjectPath = fullObjectPath + `.${toCheck}`
52
50
  } else {
53
- // Depend on
54
- dependOnItem = toCheck;
51
+ // New object thing and og next
52
+ if (split.length-1 != spl) {
53
+ fullObjectPath = fullObjectPath + `.${toCheck}`
54
+ } else {
55
+ // Depend on
56
+ dependOnItem = toCheck;
57
+ }
58
+ objectData = objectData[toCheck];
55
59
  }
56
- objectData = objectData[toCheck];
57
60
  }
58
- }
59
61
 
60
- let progData = await eval(fullObjectPath);
61
- const IndexCheck = Object.keys(progData).indexOf(dependOnItem);
62
- if (IndexCheck == -1) {
63
- // We need to wait and try again untill we can return
64
- console.log(`DependOn Fail: ${dependOn}`);
65
- await setTimeout(async function(){
66
- await program.modules.dependOn(reqFunc,program);
67
- },200);
68
- } else if (program.modules[reqFunc.name] == undefined) {
69
- console.log(`DependOn Succes: ${dependOn}`);
70
-
71
- // Loop Through to find where data to set
72
- const splitLoop = String(`${fullObjectPath}.${dependOnItem}`).split(`.`);
73
- let object;
74
- for (let s in splitLoop) {
75
- let key = splitLoop[s];
62
+ let progData = await eval(fullObjectPath);
63
+ const IndexCheck = Object.keys(progData).indexOf(dependOnItem);
64
+ if (IndexCheck == -1) {
65
+ // We need to wait and try again untill we can return
66
+ console.log(`DependOn Fail: ${dependOn}`);
67
+ await setTimeout(async function(){
68
+ await program.modules.dependOn(reqFunc,program);
69
+ },200);
70
+ } else if (program.modules[reqFunc.name] == undefined) {
71
+ console.log(`DependOn Succes: ${dependOn}`);
72
+
73
+ // Loop Through to find where data to set
74
+ const splitLoop = String(`${fullObjectPath}.${dependOnItem}`).split(`.`);
75
+ let object;
76
+ for (let s in splitLoop) {
77
+ let key = splitLoop[s];
78
+ try {
79
+ if (object == undefined) {
80
+ object = eval(key);
81
+ } else {
82
+ object = object[key];
83
+ }
84
+ if (s == splitLoop-1) {
85
+ // It's end
86
+ object = {
87
+ depend : dependOn,
88
+ state : true,
89
+ ts : Date.now()
90
+ }
91
+ }
92
+ } catch (err) {
93
+ console.error(err);
94
+ console.error(`errror boject eval set`);
95
+ return setTimeout(async function(){
96
+ await program.modules.dependOn(reqFunc,program,name,callback);
97
+ },200);
98
+ }
99
+ }
100
+ /*
101
+ progData[dependOnItem] = {
102
+ depend : dependOn,
103
+ state : true,
104
+ ts : Date.now()
105
+ } */
106
+
107
+ // Now include this thing then
76
108
  try {
77
- if (object == undefined) {
78
- object = eval(key);
109
+ program.modules[reqFunc.name] = await reqFunc.run(program,reqFunc.name);
110
+ if (callback != undefined) {
111
+ return callback(program,name)
79
112
  } else {
80
- object = object[key];
113
+ return program;
81
114
  }
82
- if (s == splitLoop-1) {
83
- // It's end
84
- object = {
85
- depend : dependOn,
86
- state : true,
87
- ts : Date.now()
88
- }
89
- }
90
- } catch (err) {
115
+ } catch(err) {
116
+ // When erro
117
+ console.error(`Error Program add depend on require`);
91
118
  console.error(err);
92
- console.error(`errror boject eval set`);
93
- return setTimeout(async function(){
94
- await program.modules.dependOn(reqFunc,program,name,callback);
95
- },200);
96
119
  }
97
120
  }
98
- /*
99
- progData[dependOnItem] = {
100
- depend : dependOn,
101
- state : true,
102
- ts : Date.now()
103
- } */
104
-
105
- // Now include this thing then
106
- try {
107
- program.modules[reqFunc.name] = await reqFunc.run(program,reqFunc.name);
108
- if (callback != undefined) {
109
- return callback(program,name)
121
+ }
122
+ }
123
+
124
+ program.modules.fetch = async function(folder,program) {
125
+ // TO Fetch folder modules
126
+ program = await set(program);
127
+ try {
128
+ // Loop through folder and run module if js
129
+ const readPath = program.path.join(__dirname,folder);
130
+ const readDir = program.fs.readdirSync(readPath);
131
+ // Check if folder or not
132
+ await readDir.forEach(async (item) => {
133
+ const itemPath = program.path.join(readPath, item);
134
+ // Get the filename with extension
135
+ const fileNameWithExtension = program.path.basename(itemPath);
136
+
137
+ // Get the filename without extension
138
+ const fileNameWithoutExtension = program.path.parse(fileNameWithExtension).name;
139
+
140
+ console.log('Filename without extension:', fileNameWithoutExtension);
141
+
142
+ const isDirectory = program.fs.statSync(itemPath).isDirectory();
143
+
144
+ if (!isDirectory) {
145
+ // So it's file
146
+ // Run the file to know what to do but change program with the return
147
+ //program = (require(itemPath)(program));
148
+ //console.log(`Set`,itemPath);
110
149
  } else {
111
- return program;
150
+ // It's directory so read the init file
151
+ const initPath = program.path.join(itemPath,`init.js`);
152
+
153
+ // Require first
154
+ const reqFunc = require(initPath);
155
+ const theType = typeof reqFunc;
156
+ switch (theType) {
157
+ case `object`:
158
+ // It's a object so check for dependend things etc.
159
+ console.log(`Depending object`);
160
+ return await program.modules.dependOn(reqFunc,program,fileNameWithoutExtension,function(program,name){
161
+ console.log(`Setup `,name)
162
+ });
163
+ break;
164
+ case `function`:
165
+ program = await (require(initPath)(program,fileNameWithExtension));
166
+ break;
167
+ default:
168
+ console.error(`Error Missing typeOf item`);
169
+ }
112
170
  }
113
- } catch(err) {
114
- // When erro
115
- console.error(`Error Program add depend on require`);
116
- console.error(err);
117
- }
171
+ });
172
+
173
+ } catch(err) {
174
+ console.error(`Error Program Modules Fetch`);
175
+ console.error(err);
118
176
  }
119
177
  }
120
- }
121
-
122
- program.modules.fetch = async function(folder,program) {
123
- // TO Fetch folder modules
124
- program = await set(program);
125
- try {
126
- // Loop through folder and run module if js
127
- const readPath = program.path.join(__dirname,folder);
128
- const readDir = program.fs.readdirSync(readPath);
129
- // Check if folder or not
130
- await readDir.forEach(async (item) => {
131
- const itemPath = program.path.join(readPath, item);
132
- // Get the filename with extension
133
- const fileNameWithExtension = program.path.basename(itemPath);
134
-
135
- // Get the filename without extension
136
- const fileNameWithoutExtension = program.path.parse(fileNameWithExtension).name;
137
-
138
- console.log('Filename without extension:', fileNameWithoutExtension);
139
-
140
- const isDirectory = program.fs.statSync(itemPath).isDirectory();
141
-
142
- if (!isDirectory) {
143
- // So it's file
144
- // Run the file to know what to do but change program with the return
145
- //program = (require(itemPath)(program));
146
- //console.log(`Set`,itemPath);
178
+
179
+ // Create tmp file path
180
+ program.modules.walkDirectory = async function (directoryPath, callback, forward, parentFileData) {
181
+ let allFiles = [];
182
+ try {
183
+ // Read the contents of the current directory
184
+ const files = await program.fs.readdirSync(directoryPath);
185
+
186
+ // Iterate through the files in the directory
187
+ for (const file of files) {
188
+ // Construct the full path of the current file or directory
189
+ const fullPath = program.path.join(directoryPath, file);
190
+
191
+ // Check if the current item is a directory
192
+ const pathSync = await program.fs.statSync(fullPath);
193
+ const isDirectoryPath = await pathSync.isDirectory();
194
+ const fileExtension = program.path.extname(fullPath);
195
+
196
+ // Get the filename without the extension
197
+ const fileName = program.path.basename(fullPath, fileExtension);
198
+
199
+ // Create a new fileData object for each file or directory
200
+ const currentFileData = {
201
+ extension: fileExtension,
202
+ name: fileName,
203
+ path: fullPath,
204
+ sub: [],
205
+ };
206
+
207
+ if (isDirectoryPath) {
208
+ // If it's a directory, recursively walk through it
209
+ let pushData = await program.modules.walkDirectory(fullPath, callback, fileName, currentFileData);
210
+ if (pushData.length !== 0) {
211
+ // Concatenate arrays instead of pushing an array
212
+ allFiles.push(currentFileData);
213
+ allFiles = allFiles.concat(pushData);
147
214
  } else {
148
- // It's directory so read the init file
149
- const initPath = program.path.join(itemPath,`init.js`);
150
-
151
- // Require first
152
- const reqFunc = require(initPath);
153
- const theType = typeof reqFunc;
154
- switch (theType) {
155
- case `object`:
156
- // It's a object so check for dependend things etc.
157
- console.log(`Depending object`);
158
- return await program.modules.dependOn(reqFunc,program,fileNameWithoutExtension,function(program,name){
159
- console.log(`Setup `,name)
160
- });
161
- break;
162
- case `function`:
163
- program = await (require(initPath)(program,fileNameWithExtension));
164
- break;
165
- default:
166
- console.error(`Error Missing typeOf item`);
167
- }
215
+ allFiles.push(currentFileData);
216
+ }
217
+ } else {
218
+ // If it's a file, print the path
219
+ console.log('File Extension:', fileExtension);
220
+ console.log('File Name:', fileName);
221
+
222
+ if (forward !== undefined) {
223
+ // Push it to sub
224
+ parentFileData.sub.push(currentFileData);
225
+ } else {
226
+ allFiles.push(currentFileData);
227
+ }
168
228
  }
169
- });
170
-
171
- } catch(err) {
172
- console.error(`Error Program Modules Fetch`);
173
- console.error(err);
174
- }
175
- }
176
-
177
- // Create tmp file path
178
- program.modules.walkDirectory = async function (directoryPath, callback, forward, parentFileData) {
179
- let allFiles = [];
180
- try {
181
- // Read the contents of the current directory
182
- const files = await program.fs.readdirSync(directoryPath);
183
-
184
- // Iterate through the files in the directory
185
- for (const file of files) {
186
- // Construct the full path of the current file or directory
187
- const fullPath = program.path.join(directoryPath, file);
188
-
189
- // Check if the current item is a directory
190
- const pathSync = await program.fs.statSync(fullPath);
191
- const isDirectoryPath = await pathSync.isDirectory();
192
- const fileExtension = program.path.extname(fullPath);
193
-
194
- // Get the filename without the extension
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
- };
204
-
205
- if (isDirectoryPath) {
206
- // If it's a directory, recursively walk through it
207
- let pushData = await program.modules.walkDirectory(fullPath, callback, fileName, currentFileData);
208
- if (pushData.length !== 0) {
209
- // Concatenate arrays instead of pushing an array
210
- allFiles.push(currentFileData);
211
- allFiles = allFiles.concat(pushData);
212
- } else {
213
- allFiles.push(currentFileData);
214
- }
215
- } else {
216
- // If it's a file, print the path
217
- console.log('File Extension:', fileExtension);
218
- console.log('File Name:', fileName);
219
-
220
- if (forward !== undefined) {
221
- // Push it to sub
222
- parentFileData.sub.push(currentFileData);
223
- } else {
224
- allFiles.push(currentFileData);
225
- }
226
229
  }
227
- }
228
-
229
- if (callback && forward === undefined) {
230
- await callback(allFiles);
231
- }
232
-
233
- return allFiles;
234
- } catch (error) {
235
- console.error('Error:', error.message);
236
- }
237
- };
238
-
230
+
231
+ if (callback && forward === undefined) {
232
+ await callback(allFiles);
233
+ }
234
+
235
+ return allFiles;
236
+ } catch (error) {
237
+ console.error('Error:', error.message);
238
+ }
239
+ };
240
+
239
241
 
240
-
241
-
242
+
243
+
242
244
 
243
- // Run program fetch
244
- program.modules.fetch(`modules`,program);
245
+ // Run program fetch
246
+ program.modules.fetch(`modules`,program);
247
+ }
@@ -264,7 +264,8 @@ module.exports = async function(program,folder) {
264
264
  console.error(`Error Setting URL`);
265
265
  }
266
266
 
267
- const teleData = program.path.join(__dirname,`telegram`);
267
+ let teleData = program.path.join(__dirname,`telegram`);
268
+
268
269
  let moduleData = await program.modules.walkDirectory(teleData);
269
270
  // Loop Through
270
271
  let telegram = {
@@ -296,6 +297,10 @@ module.exports = async function(program,folder) {
296
297
  }
297
298
 
298
299
  let middleWareFolder = program.path.join(__dirname,`telegram`,`middleware`);
300
+ if (program.set.path != undefined) {
301
+ middleWareFolder = program.path.join(program.set.path,`bots`,`telegram`,`middleware`);
302
+ }
303
+
299
304
  console.log(`MiddleWare:`,middleWareFolder);
300
305
 
301
306
  let middleWareData = program.fs.readdirSync(middleWareFolder);
@@ -333,7 +338,10 @@ module.exports = async function(program,folder) {
333
338
  telegram.middleware = middleWarFuncs;
334
339
 
335
340
  // Process scripts
336
- const scriptsPath = program.path.join(__dirname,`telegram`,`scripts`);
341
+ let scriptsPath = program.path.join(__dirname,`telegram`,`scripts`);
342
+ if (program.set.path != undefined) {
343
+ scriptsPath = program.path.join(program.set.path,`bots`,`telegram`,`scripts`);
344
+ }
337
345
 
338
346
  // Loop Through scripts folder
339
347
  let scriptsData = await program.modules.walkDirectory(scriptsPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webfast",
3
- "version": "0.1.20",
3
+ "version": "0.1.24",
4
4
  "description": "WebFast! Bot Application, including TON mini-apps",
5
5
  "main": "index.js",
6
6
  "repository": {
File without changes
File without changes
File without changes
File without changes