webfast 0.0.1
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/.vscode/launch.json +17 -0
- package/README.md +98 -0
- package/index.js +202 -0
- package/modules/express/init.js +137 -0
- package/modules/express/routes/example/link.get.js +5 -0
- package/modules/generator/init.js +10 -0
- package/package.json +34 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
{
|
2
|
+
// Use IntelliSense to learn about possible attributes.
|
3
|
+
// Hover to view descriptions of existing attributes.
|
4
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
5
|
+
"version": "0.2.0",
|
6
|
+
"configurations": [
|
7
|
+
{
|
8
|
+
"type": "node",
|
9
|
+
"request": "launch",
|
10
|
+
"name": "Launch Program",
|
11
|
+
"skipFiles": [
|
12
|
+
"<node_internals>/**"
|
13
|
+
],
|
14
|
+
"program": "${workspaceFolder}/index.js"
|
15
|
+
}
|
16
|
+
]
|
17
|
+
}
|
package/README.md
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# WebFS
|
2
|
+
|
3
|
+
WebFS is a lightweight, model-based framework developed by Hybrid Institute. It is designed for individuals who are interested in building no-code/low-code solutions and prefer an easy-to-setup development environment.
|
4
|
+
|
5
|
+
## Introduction
|
6
|
+
|
7
|
+
WebFS provides a flexible and intuitive platform for creating web applications without the need for extensive coding. It empowers users to leverage a model-based approach, making it accessible to a broader audience, including those with limited coding experience.
|
8
|
+
|
9
|
+
## Features
|
10
|
+
|
11
|
+
- **Lightweight**: Keep your projects streamlined with a minimalistic approach.
|
12
|
+
- **Model-Based**: Design and structure your applications using a model-driven paradigm.
|
13
|
+
- **No-Code/Low-Code**: Build powerful applications with ease, even if you have limited coding experience.
|
14
|
+
- **Easy to Setup**: Get started quickly with a straightforward setup process.
|
15
|
+
|
16
|
+
## Getting Started
|
17
|
+
|
18
|
+
### Prerequisites
|
19
|
+
|
20
|
+
- Node.js: Make sure you have Node.js installed. You can download it from [nodejs.org](https://nodejs.org/).
|
21
|
+
|
22
|
+
### Installation
|
23
|
+
|
24
|
+
1. Clone the repository:
|
25
|
+
|
26
|
+
```bash
|
27
|
+
git clone https://github.com/ThePhotoCodeGrapher/WebFS.git
|
28
|
+
```
|
29
|
+
|
30
|
+
2. Navigate to the project directory:
|
31
|
+
|
32
|
+
```bash
|
33
|
+
cd WebFS
|
34
|
+
```
|
35
|
+
|
36
|
+
3. Install dependencies:
|
37
|
+
|
38
|
+
```bash
|
39
|
+
npm install
|
40
|
+
```
|
41
|
+
|
42
|
+
4. Configure the port:
|
43
|
+
|
44
|
+
- The default port is set to **1221** and can be changed in the file `/modules/express/init.js`. Open this file and modify the `PORT` variable according to your preference.
|
45
|
+
|
46
|
+
5. Start the development server:
|
47
|
+
|
48
|
+
```bash
|
49
|
+
npm start
|
50
|
+
```
|
51
|
+
|
52
|
+
6. Open your browser and visit [http://localhost:1221/api](http://localhost:1221/api) to explore the dynamically structured API endpoints based on your modules in `/modules/express/routes`.
|
53
|
+
|
54
|
+
- **Example Endpoint Structure**:
|
55
|
+
- `/api/example/link` (from `link.get.js` in `/modules/express/example`)
|
56
|
+
- `/api/example/{FOLDER_NAME}/{FILE_OR_FOLDER_NAME}` (based on your project structure)
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
We welcome contributions from the community. If you'd like to contribute to WebFS, please follow our [contribution guidelines](CONTRIBUTING.md).
|
61
|
+
|
62
|
+
## Modules
|
63
|
+
|
64
|
+
### Generator Module
|
65
|
+
|
66
|
+
The `generator` module is an object-based component of WebFS that allows you to extend the functionality based on your specific requirements. This module will be automatically executed, taking into account its dependencies.
|
67
|
+
|
68
|
+
#### Dependencies
|
69
|
+
|
70
|
+
- `express.app`: This module is a prerequisite for the `generator` module.
|
71
|
+
|
72
|
+
#### Usage
|
73
|
+
|
74
|
+
The `generator` module exports an object with the following structure:
|
75
|
+
|
76
|
+
```javascript
|
77
|
+
module.exports = {
|
78
|
+
dependOn: ['express.app'],
|
79
|
+
name: 'generator',
|
80
|
+
run: function (program, name) {
|
81
|
+
console.log(`Running ${name}`);
|
82
|
+
|
83
|
+
// Here we can do whatever like grab modules for generator and represent them here
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
```
|
88
|
+
## License
|
89
|
+
|
90
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
91
|
+
|
92
|
+
## Contact
|
93
|
+
|
94
|
+
For questions or feedback, please feel free to [contact me on LinkedIn](https://linkedin.com/in/kaigartner). You can also reach out to me on Instagram: [@kaigartner](https://instagram.com/kaigartner).
|
95
|
+
|
96
|
+
---
|
97
|
+
|
98
|
+
**Hybrid Institute** - Empowering the future with innovative solutions.
|
package/index.js
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
const { readdirSync } = require("fs");
|
2
|
+
|
3
|
+
console.log(`WebFS! Program`);
|
4
|
+
let program = {
|
5
|
+
ts : Date.now(),
|
6
|
+
modules : {}
|
7
|
+
}
|
8
|
+
|
9
|
+
// Setup The Requirements
|
10
|
+
async function set(program) {
|
11
|
+
program.path = await require(`path`);
|
12
|
+
program.fs = await require(`fs`);
|
13
|
+
program.uuid = await require(`uuid`);
|
14
|
+
return program;
|
15
|
+
}
|
16
|
+
|
17
|
+
// Program Fetch
|
18
|
+
program.modules.dependOn = async function(reqFunc,program,name,callback) {
|
19
|
+
console.log(`Depend On Check`);
|
20
|
+
// Loop Through dependOn if its not true then check
|
21
|
+
for (let dependIndex in reqFunc.dependOn) {
|
22
|
+
const dependOn = reqFunc.dependOn[dependIndex];
|
23
|
+
// So we dependOn
|
24
|
+
// Check index
|
25
|
+
// If .
|
26
|
+
let split = dependOn.split(`.`);
|
27
|
+
// Now we should loop through array
|
28
|
+
let objectData = program;
|
29
|
+
let fullObjectPath = `program`;
|
30
|
+
let dependOnItem = ``;
|
31
|
+
for (let spl in split) {
|
32
|
+
// Grab object
|
33
|
+
let toCheck = split[spl];
|
34
|
+
if (objectData[toCheck] == undefined) {
|
35
|
+
await setTimeout(async function(){
|
36
|
+
return await program.modules.dependOn(reqFunc,program,name,callback);
|
37
|
+
},200);
|
38
|
+
} else {
|
39
|
+
// New object thing and og next
|
40
|
+
if (split.length-1 != spl) {
|
41
|
+
fullObjectPath = fullObjectPath + `.${toCheck}`
|
42
|
+
} else {
|
43
|
+
// Depend on
|
44
|
+
dependOnItem = toCheck;
|
45
|
+
}
|
46
|
+
objectData = objectData[toCheck];
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
let progData = await eval(fullObjectPath);
|
51
|
+
const IndexCheck = Object.keys(progData).indexOf(dependOnItem);
|
52
|
+
if (IndexCheck == -1) {
|
53
|
+
// We need to wait and try again untill we can return
|
54
|
+
console.log(`DependOn Fail: ${dependOn}`);
|
55
|
+
await setTimeout(async function(){
|
56
|
+
return await program.modules.dependOn(reqFunc,program);
|
57
|
+
},200);
|
58
|
+
} else {
|
59
|
+
console.log(`DependOn Succes: ${dependOn}`);
|
60
|
+
progData[dependOnItem] = {
|
61
|
+
depend : dependOn,
|
62
|
+
state : true,
|
63
|
+
ts : Date.now()
|
64
|
+
}
|
65
|
+
|
66
|
+
// Now include this thing then
|
67
|
+
try {
|
68
|
+
program.modules[reqFunc.name] = await reqFunc.run(program,reqFunc.name);
|
69
|
+
if (callback != undefined) {
|
70
|
+
return callback(program,name)
|
71
|
+
} else {
|
72
|
+
return program;
|
73
|
+
}
|
74
|
+
} catch(err) {
|
75
|
+
// When erro
|
76
|
+
console.error(`Error Program add depend on require`);
|
77
|
+
console.error(err);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
program.modules.fetch = async function(folder,program) {
|
84
|
+
// TO Fetch folder modules
|
85
|
+
program = await set(program);
|
86
|
+
try {
|
87
|
+
// Loop through folder and run module if js
|
88
|
+
const readPath = program.path.join(__dirname,folder);
|
89
|
+
const readDir = program.fs.readdirSync(readPath);
|
90
|
+
// Check if folder or not
|
91
|
+
await readDir.forEach(async (item) => {
|
92
|
+
const itemPath = program.path.join(readPath, item);
|
93
|
+
// Get the filename with extension
|
94
|
+
const fileNameWithExtension = program.path.basename(itemPath);
|
95
|
+
|
96
|
+
// Get the filename without extension
|
97
|
+
const fileNameWithoutExtension = program.path.parse(fileNameWithExtension).name;
|
98
|
+
|
99
|
+
console.log('Filename without extension:', fileNameWithoutExtension);
|
100
|
+
|
101
|
+
const isDirectory = program.fs.statSync(itemPath).isDirectory();
|
102
|
+
|
103
|
+
if (!isDirectory) {
|
104
|
+
// So it's file
|
105
|
+
// Run the file to know what to do but change program with the return
|
106
|
+
//program = (require(itemPath)(program));
|
107
|
+
//console.log(`Set`,itemPath);
|
108
|
+
} else {
|
109
|
+
// It's directory so read the init file
|
110
|
+
const initPath = program.path.join(itemPath,`init.js`);
|
111
|
+
|
112
|
+
// Require first
|
113
|
+
const reqFunc = require(initPath);
|
114
|
+
const theType = typeof reqFunc;
|
115
|
+
switch (theType) {
|
116
|
+
case `object`:
|
117
|
+
// It's a object so check for dependend things etc.
|
118
|
+
console.log(`Depending object`);
|
119
|
+
await program.modules.dependOn(reqFunc,program,fileNameWithoutExtension,function(program,name){
|
120
|
+
console.log(`Setup `,name)
|
121
|
+
});
|
122
|
+
break;
|
123
|
+
case `function`:
|
124
|
+
program = await (require(initPath)(program));
|
125
|
+
break;
|
126
|
+
default:
|
127
|
+
console.error(`Error Missing typeOf item`);
|
128
|
+
}
|
129
|
+
}
|
130
|
+
});
|
131
|
+
|
132
|
+
} catch(err) {
|
133
|
+
console.error(`Error Program Modules Fetch`);
|
134
|
+
console.error(err);
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
program.modules.walkDirectory = async function (directoryPath,callback,forward) {
|
139
|
+
// Read the contents of the current directory
|
140
|
+
const files = await program.fs.readdirSync(directoryPath);
|
141
|
+
|
142
|
+
let allFiles = [];
|
143
|
+
// Iterate through the files in the directory
|
144
|
+
for (let f in files) {
|
145
|
+
// Construct the full path of the current file or directory
|
146
|
+
let file = files[f];
|
147
|
+
const fullPath = await program.path.join(directoryPath, file);
|
148
|
+
|
149
|
+
// Check if the current item is a directory
|
150
|
+
const pathSync = await program.fs.statSync(fullPath);
|
151
|
+
const isDirectoryPath = await pathSync.isDirectory();
|
152
|
+
const fileExtension = await program.path.extname(fullPath);
|
153
|
+
|
154
|
+
// Get the filename without the extension
|
155
|
+
const fileName = await program.path.basename(fullPath, fileExtension);
|
156
|
+
if (isDirectoryPath) {
|
157
|
+
// If it's a directory, recursively walk through it
|
158
|
+
let pushData = await program.modules.walkDirectory(fullPath,callback,fileName);
|
159
|
+
await allFiles.push(pushData);
|
160
|
+
} else {
|
161
|
+
// If it's a file, print the path
|
162
|
+
// Get the file extension
|
163
|
+
|
164
|
+
console.log('File Extension:', fileExtension);
|
165
|
+
console.log('File Name:', fileName);
|
166
|
+
|
167
|
+
// Make Key from fileName extension
|
168
|
+
const fileData = {
|
169
|
+
extension : fileExtension,
|
170
|
+
name : fileName,
|
171
|
+
path : fullPath,
|
172
|
+
sub : []
|
173
|
+
}
|
174
|
+
|
175
|
+
if (forward != undefined) {
|
176
|
+
// PUsh it to sub
|
177
|
+
fileData.sub.push(forward);
|
178
|
+
return fileData;
|
179
|
+
} else {
|
180
|
+
|
181
|
+
await allFiles.push(fileData);
|
182
|
+
}
|
183
|
+
}
|
184
|
+
}
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
if (forward != undefined) {
|
189
|
+
// Return data
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
if (callback && forward == undefined) {
|
194
|
+
await callback(allFiles);
|
195
|
+
} else {
|
196
|
+
return allFiles;
|
197
|
+
}
|
198
|
+
}
|
199
|
+
|
200
|
+
|
201
|
+
// Run program fetch
|
202
|
+
program.modules.fetch(`modules`,program);
|
@@ -0,0 +1,137 @@
|
|
1
|
+
module.exports = async function(program) {
|
2
|
+
console.log(`Starting UP Express`);
|
3
|
+
program.express = {
|
4
|
+
ts : Date.now()
|
5
|
+
}
|
6
|
+
|
7
|
+
// Express and cors
|
8
|
+
const express = require('express');
|
9
|
+
const cors = require('cors');
|
10
|
+
const bodyParser = require('body-parser');
|
11
|
+
const port = 1221;
|
12
|
+
const basePath = `/api`;
|
13
|
+
|
14
|
+
// Run Express
|
15
|
+
const app = express();
|
16
|
+
|
17
|
+
// Setup Cors
|
18
|
+
const corsOptions = {
|
19
|
+
origin: '*', // or specify your allowed origins
|
20
|
+
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
|
21
|
+
credentials: true,
|
22
|
+
optionsSuccessStatus: 204,
|
23
|
+
};
|
24
|
+
|
25
|
+
// Use Core Options
|
26
|
+
app.use(cors(corsOptions));
|
27
|
+
|
28
|
+
// Set View Engine
|
29
|
+
app.set('view engine', 'ejs');
|
30
|
+
|
31
|
+
// Enable bodyparser
|
32
|
+
app.use(bodyParser.json());
|
33
|
+
app.use(bodyParser.urlencoded({ extended: true }));
|
34
|
+
|
35
|
+
// Let's go through the folder routes and subdirectory
|
36
|
+
const routesPath = program.path.join(__dirname,`routes`);
|
37
|
+
|
38
|
+
let exprs = {};
|
39
|
+
|
40
|
+
try {
|
41
|
+
// Get routes for route path and setup the routes for express
|
42
|
+
let routesData = await program.modules.walkDirectory(routesPath);
|
43
|
+
|
44
|
+
// Loop Through routes
|
45
|
+
for (let rI in routesData) {
|
46
|
+
// Get the current route
|
47
|
+
let route = routesData[rI];
|
48
|
+
//console.log(`Route : `,route.path);
|
49
|
+
|
50
|
+
let routePath = `${basePath}`
|
51
|
+
// Loop Through sub and create path with basePath
|
52
|
+
for (let s in route.sub) {
|
53
|
+
routePath = `${routePath}/${route.sub[s]}`
|
54
|
+
}
|
55
|
+
|
56
|
+
// Check to split name
|
57
|
+
const split = route.name.split(`.`);
|
58
|
+
route.type = `get`;
|
59
|
+
if (split.length > 1) {
|
60
|
+
// we have a get or post
|
61
|
+
route.type = split[split.length-1];
|
62
|
+
route.name = split[0];
|
63
|
+
}
|
64
|
+
|
65
|
+
// FUll Route
|
66
|
+
routePath = `${routePath}/${route.name}`;
|
67
|
+
|
68
|
+
// Create Route UUID for easy findable
|
69
|
+
const routeID = program.uuid.v4();
|
70
|
+
|
71
|
+
// Setup ID
|
72
|
+
route.tempID = routeID;
|
73
|
+
|
74
|
+
// Setup the function
|
75
|
+
try {
|
76
|
+
route.func = require(route.path);
|
77
|
+
} catch(err) {
|
78
|
+
console.error(`Error Route Func`,routePath);
|
79
|
+
console.error(err);
|
80
|
+
}
|
81
|
+
|
82
|
+
// Save route for path
|
83
|
+
route.webwalk = 0;
|
84
|
+
exprs[routePath] = route;
|
85
|
+
|
86
|
+
console.log(`Setting Up Route`);
|
87
|
+
}
|
88
|
+
|
89
|
+
// Setted Up Routes
|
90
|
+
program.express.routes = exprs;
|
91
|
+
|
92
|
+
// Now we can setup the real shizzle for the post and get situation
|
93
|
+
//req,res,program
|
94
|
+
for (let route in exprs) {
|
95
|
+
// Setup route
|
96
|
+
let routeData = exprs[route];
|
97
|
+
console.log(`Setup Route`,route);
|
98
|
+
let state = false;
|
99
|
+
try {
|
100
|
+
// This is where the magic happens when we receive an incomming request it will
|
101
|
+
// route it through the dynamice route folder
|
102
|
+
app[routeData.type](route,async (req,res) => {
|
103
|
+
try {
|
104
|
+
// Count walkthrough
|
105
|
+
exprs[route].webwalk++;
|
106
|
+
|
107
|
+
// Now passthrough func
|
108
|
+
await routeData.func(program,req,res,route);
|
109
|
+
} catch (err) {
|
110
|
+
console.error(`Error With Route:`,route);
|
111
|
+
console.error(err);
|
112
|
+
}
|
113
|
+
});
|
114
|
+
state = true;
|
115
|
+
} catch (err) {
|
116
|
+
console.error(err);
|
117
|
+
console.error(`Error Setting Up Route`);
|
118
|
+
}
|
119
|
+
|
120
|
+
// Set state
|
121
|
+
exprs[route].state = state;
|
122
|
+
}
|
123
|
+
|
124
|
+
console.log(`We have routes`);
|
125
|
+
} catch (err) {
|
126
|
+
console.error(err);
|
127
|
+
console.error(`Error Routes`);
|
128
|
+
}
|
129
|
+
|
130
|
+
|
131
|
+
app.listen(port, () => {
|
132
|
+
console.log(`Server Listening`,port,basePath);
|
133
|
+
});
|
134
|
+
|
135
|
+
program.express.app = app;
|
136
|
+
return program;
|
137
|
+
}
|
package/package.json
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
{
|
2
|
+
"name": "webfast",
|
3
|
+
"version": "0.0.1",
|
4
|
+
"description": "WebFS! Bot Application, including TON mini-apps",
|
5
|
+
"main": "index.js",
|
6
|
+
"repository": {
|
7
|
+
"type": "git",
|
8
|
+
"url": "https://github.com/ThePhotoCodeGrapher/webfs"
|
9
|
+
},
|
10
|
+
"scripts": {
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
12
|
+
},
|
13
|
+
"keywords": [
|
14
|
+
"event",
|
15
|
+
"go",
|
16
|
+
"mini",
|
17
|
+
"app",
|
18
|
+
"ton",
|
19
|
+
"telegram"
|
20
|
+
],
|
21
|
+
"author": "Kai Gartner",
|
22
|
+
"license": "ISC",
|
23
|
+
"dependencies": {
|
24
|
+
"body-parser": "^1.20.2",
|
25
|
+
"cors": "^2.8.5",
|
26
|
+
"ejs": "^3.1.9",
|
27
|
+
"express": "^4.18.2",
|
28
|
+
"fetch": "^1.1.0",
|
29
|
+
"fs": "^0.0.1-security",
|
30
|
+
"js": "^0.1.0",
|
31
|
+
"path": "^0.12.7",
|
32
|
+
"uuid": "^9.0.1"
|
33
|
+
}
|
34
|
+
}
|