webfast 0.1.20 → 0.1.21

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