quar 1.3.1 → 1.4.2
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/.changeset/README.md +8 -0
- package/.changeset/config.json +11 -0
- package/.github/workflows/publish.yaml +50 -0
- package/CHANGELOG.md +13 -0
- package/LICENSE +21 -21
- package/README.md +96 -95
- package/dummy_models/posts.model.js +52 -52
- package/dummy_models/user.model.js +44 -44
- package/index.js +102 -66
- package/package.json +11 -3
- package/public/scripts/insertTab.js +155 -155
- package/public/scripts/keyboardCommands.js +15 -15
- package/public/scripts/main.js +364 -364
- package/public/scripts/popup.js +25 -25
- package/public/styles/insertTab.css +73 -73
- package/public/styles/popup.css +70 -70
- package/public/styles/sidebar.css +33 -33
- package/public/styles/style.css +306 -306
- package/public/styles/variables.css +8 -8
- package/server.js +241 -241
- package/utils/loadModels.js +26 -26
- package/views/base.zare +16 -16
- package/views/components/insertTab.zare +7 -7
- package/views/components/popup.zare +11 -11
- package/views/components/sidebar.zare +11 -11
- package/views/pages/index.zare +48 -48
package/server.js
CHANGED
|
@@ -1,242 +1,242 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
|
-
import mongoose from 'mongoose';
|
|
3
|
-
import path from "path"
|
|
4
|
-
import loadModels from './utils/loadModels.js';
|
|
5
|
-
|
|
6
|
-
const app = express();
|
|
7
|
-
const PORT = 8319;
|
|
8
|
-
|
|
9
|
-
app.set('view engine', 'zare');
|
|
10
|
-
app.set("views", path.join(import.meta.dirname, "views"));
|
|
11
|
-
app.set("port", PORT);
|
|
12
|
-
|
|
13
|
-
app.use(express.static(path.join(import.meta.dirname, "public")));
|
|
14
|
-
app.use(express.json());
|
|
15
|
-
app.use(express.urlencoded({ extended: true }));
|
|
16
|
-
|
|
17
|
-
app.get('/', async (_, res) => {
|
|
18
|
-
try {
|
|
19
|
-
const modelNames = mongoose.modelNames();
|
|
20
|
-
|
|
21
|
-
modelNames.sort((a, b) => a.localeCompare(b));
|
|
22
|
-
|
|
23
|
-
const result = await Promise.all(
|
|
24
|
-
modelNames.map(async name => {
|
|
25
|
-
const model = mongoose.model(name);
|
|
26
|
-
const count = await model.countDocuments();
|
|
27
|
-
return { name, count };
|
|
28
|
-
})
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
res.render('pages/index', { models: result });
|
|
32
|
-
} catch (error) {
|
|
33
|
-
res.status(500).json({ error: error.message || "Internal server error" });
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
app.get("/models", async (_, res) => {
|
|
38
|
-
|
|
39
|
-
try {
|
|
40
|
-
|
|
41
|
-
if (!app.locals.modelPath) return res.status(409).json({ error: "model directory path not set" })
|
|
42
|
-
loadModels(app.locals.modelPath)
|
|
43
|
-
const modelNames = mongoose.modelNames();
|
|
44
|
-
modelNames.sort((a, b) => a.localeCompare(b));
|
|
45
|
-
|
|
46
|
-
const result = await Promise.all(
|
|
47
|
-
modelNames.map(async name => {
|
|
48
|
-
const model = mongoose.model(name);
|
|
49
|
-
const count = await model.countDocuments();
|
|
50
|
-
return { name, count };
|
|
51
|
-
})
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
res.status(200).json({ models: result });
|
|
55
|
-
} catch (error) {
|
|
56
|
-
res.status(500).json({ error: error.message || "Internal server error" });
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
app.get("/models/:modelName", async (req, res) => {
|
|
61
|
-
try {
|
|
62
|
-
|
|
63
|
-
const { modelName } = req.params;
|
|
64
|
-
const { page = 1, limit = 100 } = req.query;
|
|
65
|
-
const model = mongoose.model(modelName);
|
|
66
|
-
const modelSchema = model.schema.paths;
|
|
67
|
-
const documents = await model.find({}).limit(limit).skip((page - 1) * limit);
|
|
68
|
-
const totalCount = await model.countDocuments();
|
|
69
|
-
const count = documents.length;
|
|
70
|
-
const totalPages = Math.ceil(totalCount / limit);
|
|
71
|
-
|
|
72
|
-
res.status(200).json({ documents, schema: modelSchema, totalCount, count, totalPages });
|
|
73
|
-
} catch (error) {
|
|
74
|
-
console.log(error)
|
|
75
|
-
res.status(500).json({ error: error.message || "Internal server error" });
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
app.get("/schema/:modelName", async (req, res) => {
|
|
80
|
-
try {
|
|
81
|
-
const modelName = req.params.modelName;
|
|
82
|
-
const Model = mongoose.model(modelName);
|
|
83
|
-
|
|
84
|
-
if (!Model) return res.status(404).json({ error: 'Model not found' });
|
|
85
|
-
|
|
86
|
-
const paths = Model.schema.paths;
|
|
87
|
-
const schema = {};
|
|
88
|
-
|
|
89
|
-
function getSchema(paths) {
|
|
90
|
-
for (const path in paths) {
|
|
91
|
-
|
|
92
|
-
if (path === '_id' || path === '__v') continue;
|
|
93
|
-
|
|
94
|
-
if (paths[path].instance === 'Embedded') {
|
|
95
|
-
getSchema(paths[path].schema.paths);
|
|
96
|
-
continue;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const field = paths[path];
|
|
100
|
-
const fieldType = field.instance;
|
|
101
|
-
const fieldOptions = Object.assign({}, field.options);
|
|
102
|
-
|
|
103
|
-
delete fieldOptions["type"];
|
|
104
|
-
|
|
105
|
-
schema[path] = {
|
|
106
|
-
type: fieldType,
|
|
107
|
-
...fieldOptions
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
getSchema(paths)
|
|
112
|
-
|
|
113
|
-
res.status(200).json(schema);
|
|
114
|
-
} catch (error) {
|
|
115
|
-
res.status(500).json({ error: error.message || "Intenral Server Error" })
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
app.get("/id/:modelName", async (req, res) => {
|
|
120
|
-
|
|
121
|
-
try {
|
|
122
|
-
const { modelName } = req.params;
|
|
123
|
-
const Model = mongoose.model(modelName)
|
|
124
|
-
if (!Model) return res.status(404).json({ error: "model not found" });
|
|
125
|
-
|
|
126
|
-
const docs = await Model.find({});
|
|
127
|
-
const ids = [];
|
|
128
|
-
|
|
129
|
-
docs.map(doc => ids.push(doc._id))
|
|
130
|
-
|
|
131
|
-
res.status(200).json(ids)
|
|
132
|
-
} catch (error) {
|
|
133
|
-
res.status(500).json({ error: error.message || "Internal server error" })
|
|
134
|
-
}
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
app.post("/insert/:modelName", async (req, res) => {
|
|
138
|
-
|
|
139
|
-
try {
|
|
140
|
-
const { modelName } = req.params;
|
|
141
|
-
const body = req.body;
|
|
142
|
-
|
|
143
|
-
const Model = mongoose.model(modelName);
|
|
144
|
-
|
|
145
|
-
if (!Model) return res.status(404).json({ error: "model not found" });
|
|
146
|
-
|
|
147
|
-
const paths = Model.schema.paths;
|
|
148
|
-
|
|
149
|
-
function getSchema(paths) {
|
|
150
|
-
|
|
151
|
-
let schema = {};
|
|
152
|
-
for (const path in paths) {
|
|
153
|
-
|
|
154
|
-
if (path === '_id' || path === '__v') continue;
|
|
155
|
-
|
|
156
|
-
if (paths[path].instance === 'Embedded') {
|
|
157
|
-
schema[path] = getSchema(paths[path].schema.paths);
|
|
158
|
-
continue;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
schema[path] = paths[path].instance;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return schema;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const schema = getSchema(paths)
|
|
168
|
-
|
|
169
|
-
function getData(body, schema) {
|
|
170
|
-
|
|
171
|
-
let data = {};
|
|
172
|
-
|
|
173
|
-
for (const key in schema) {
|
|
174
|
-
if (typeof schema[key] === 'object' && schema[key] !== null) {
|
|
175
|
-
|
|
176
|
-
data[key] = getData(body, schema[key]);
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (Object.keys(body).includes(key)) {
|
|
181
|
-
data[key] = body[key];
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return data;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const data = getData(body, schema)
|
|
189
|
-
|
|
190
|
-
const result = await Model.create(data)
|
|
191
|
-
|
|
192
|
-
res.status(200).json(result)
|
|
193
|
-
} catch (error) {
|
|
194
|
-
res.status(500).json({ error: error.message || "Internal server error" })
|
|
195
|
-
}
|
|
196
|
-
})
|
|
197
|
-
|
|
198
|
-
app.put("/update/:modelName/:id", async (req, res) => {
|
|
199
|
-
try {
|
|
200
|
-
const { modelName, id } = req.params;
|
|
201
|
-
const model = mongoose.model(modelName);
|
|
202
|
-
const updatedDoc = req.body;
|
|
203
|
-
|
|
204
|
-
delete updatedDoc._id;
|
|
205
|
-
const result = await model.findByIdAndUpdate(id, updatedDoc, { new: true });
|
|
206
|
-
|
|
207
|
-
res.status(200).json(result);
|
|
208
|
-
} catch (error) {
|
|
209
|
-
|
|
210
|
-
res.status(500).json({ error: error.message || "Internal server error" });
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
app.delete("/delete/:modelName/:id", async (req, res) => {
|
|
215
|
-
try {
|
|
216
|
-
const { modelName, id } = req.params;
|
|
217
|
-
const model = mongoose.model(modelName);
|
|
218
|
-
|
|
219
|
-
await model.findByIdAndDelete(id);
|
|
220
|
-
const count = await model.countDocuments();
|
|
221
|
-
|
|
222
|
-
res.status(200).json({ count });
|
|
223
|
-
} catch (error) {
|
|
224
|
-
res.status(500).json({ error: error.message || "Internal server error" });
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
app.delete("/delete-all/:modelName", async (req, res) => {
|
|
229
|
-
try {
|
|
230
|
-
const { modelName } = req.params;
|
|
231
|
-
const model = mongoose.model(modelName);
|
|
232
|
-
if (!model) return res.status(404).json({ error: "model not found" });
|
|
233
|
-
|
|
234
|
-
await model.deleteMany({});
|
|
235
|
-
|
|
236
|
-
res.status(200).json({ success: true });
|
|
237
|
-
} catch (error) {
|
|
238
|
-
res.status(500).json({ error: error.message || "Internal server error" });
|
|
239
|
-
}
|
|
240
|
-
})
|
|
241
|
-
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import mongoose from 'mongoose';
|
|
3
|
+
import path from "path"
|
|
4
|
+
import loadModels from './utils/loadModels.js';
|
|
5
|
+
|
|
6
|
+
const app = express();
|
|
7
|
+
const PORT = 8319;
|
|
8
|
+
|
|
9
|
+
app.set('view engine', 'zare');
|
|
10
|
+
app.set("views", path.join(import.meta.dirname, "views"));
|
|
11
|
+
app.set("port", PORT);
|
|
12
|
+
|
|
13
|
+
app.use(express.static(path.join(import.meta.dirname, "public")));
|
|
14
|
+
app.use(express.json());
|
|
15
|
+
app.use(express.urlencoded({ extended: true }));
|
|
16
|
+
|
|
17
|
+
app.get('/', async (_, res) => {
|
|
18
|
+
try {
|
|
19
|
+
const modelNames = mongoose.modelNames();
|
|
20
|
+
|
|
21
|
+
modelNames.sort((a, b) => a.localeCompare(b));
|
|
22
|
+
|
|
23
|
+
const result = await Promise.all(
|
|
24
|
+
modelNames.map(async name => {
|
|
25
|
+
const model = mongoose.model(name);
|
|
26
|
+
const count = await model.countDocuments();
|
|
27
|
+
return { name, count };
|
|
28
|
+
})
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
res.render('pages/index', { models: result });
|
|
32
|
+
} catch (error) {
|
|
33
|
+
res.status(500).json({ error: error.message || "Internal server error" });
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
app.get("/models", async (_, res) => {
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
|
|
41
|
+
if (!app.locals.modelPath) return res.status(409).json({ error: "model directory path not set" })
|
|
42
|
+
loadModels(app.locals.modelPath)
|
|
43
|
+
const modelNames = mongoose.modelNames();
|
|
44
|
+
modelNames.sort((a, b) => a.localeCompare(b));
|
|
45
|
+
|
|
46
|
+
const result = await Promise.all(
|
|
47
|
+
modelNames.map(async name => {
|
|
48
|
+
const model = mongoose.model(name);
|
|
49
|
+
const count = await model.countDocuments();
|
|
50
|
+
return { name, count };
|
|
51
|
+
})
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
res.status(200).json({ models: result });
|
|
55
|
+
} catch (error) {
|
|
56
|
+
res.status(500).json({ error: error.message || "Internal server error" });
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
app.get("/models/:modelName", async (req, res) => {
|
|
61
|
+
try {
|
|
62
|
+
|
|
63
|
+
const { modelName } = req.params;
|
|
64
|
+
const { page = 1, limit = 100 } = req.query;
|
|
65
|
+
const model = mongoose.model(modelName);
|
|
66
|
+
const modelSchema = model.schema.paths;
|
|
67
|
+
const documents = await model.find({}).limit(limit).skip((page - 1) * limit);
|
|
68
|
+
const totalCount = await model.countDocuments();
|
|
69
|
+
const count = documents.length;
|
|
70
|
+
const totalPages = Math.ceil(totalCount / limit);
|
|
71
|
+
|
|
72
|
+
res.status(200).json({ documents, schema: modelSchema, totalCount, count, totalPages });
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.log(error)
|
|
75
|
+
res.status(500).json({ error: error.message || "Internal server error" });
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
app.get("/schema/:modelName", async (req, res) => {
|
|
80
|
+
try {
|
|
81
|
+
const modelName = req.params.modelName;
|
|
82
|
+
const Model = mongoose.model(modelName);
|
|
83
|
+
|
|
84
|
+
if (!Model) return res.status(404).json({ error: 'Model not found' });
|
|
85
|
+
|
|
86
|
+
const paths = Model.schema.paths;
|
|
87
|
+
const schema = {};
|
|
88
|
+
|
|
89
|
+
function getSchema(paths) {
|
|
90
|
+
for (const path in paths) {
|
|
91
|
+
|
|
92
|
+
if (path === '_id' || path === '__v') continue;
|
|
93
|
+
|
|
94
|
+
if (paths[path].instance === 'Embedded') {
|
|
95
|
+
getSchema(paths[path].schema.paths);
|
|
96
|
+
continue;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const field = paths[path];
|
|
100
|
+
const fieldType = field.instance;
|
|
101
|
+
const fieldOptions = Object.assign({}, field.options);
|
|
102
|
+
|
|
103
|
+
delete fieldOptions["type"];
|
|
104
|
+
|
|
105
|
+
schema[path] = {
|
|
106
|
+
type: fieldType,
|
|
107
|
+
...fieldOptions
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
getSchema(paths)
|
|
112
|
+
|
|
113
|
+
res.status(200).json(schema);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
res.status(500).json({ error: error.message || "Intenral Server Error" })
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
app.get("/id/:modelName", async (req, res) => {
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
const { modelName } = req.params;
|
|
123
|
+
const Model = mongoose.model(modelName)
|
|
124
|
+
if (!Model) return res.status(404).json({ error: "model not found" });
|
|
125
|
+
|
|
126
|
+
const docs = await Model.find({});
|
|
127
|
+
const ids = [];
|
|
128
|
+
|
|
129
|
+
docs.map(doc => ids.push(doc._id))
|
|
130
|
+
|
|
131
|
+
res.status(200).json(ids)
|
|
132
|
+
} catch (error) {
|
|
133
|
+
res.status(500).json({ error: error.message || "Internal server error" })
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
app.post("/insert/:modelName", async (req, res) => {
|
|
138
|
+
|
|
139
|
+
try {
|
|
140
|
+
const { modelName } = req.params;
|
|
141
|
+
const body = req.body;
|
|
142
|
+
|
|
143
|
+
const Model = mongoose.model(modelName);
|
|
144
|
+
|
|
145
|
+
if (!Model) return res.status(404).json({ error: "model not found" });
|
|
146
|
+
|
|
147
|
+
const paths = Model.schema.paths;
|
|
148
|
+
|
|
149
|
+
function getSchema(paths) {
|
|
150
|
+
|
|
151
|
+
let schema = {};
|
|
152
|
+
for (const path in paths) {
|
|
153
|
+
|
|
154
|
+
if (path === '_id' || path === '__v') continue;
|
|
155
|
+
|
|
156
|
+
if (paths[path].instance === 'Embedded') {
|
|
157
|
+
schema[path] = getSchema(paths[path].schema.paths);
|
|
158
|
+
continue;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
schema[path] = paths[path].instance;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return schema;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const schema = getSchema(paths)
|
|
168
|
+
|
|
169
|
+
function getData(body, schema) {
|
|
170
|
+
|
|
171
|
+
let data = {};
|
|
172
|
+
|
|
173
|
+
for (const key in schema) {
|
|
174
|
+
if (typeof schema[key] === 'object' && schema[key] !== null) {
|
|
175
|
+
|
|
176
|
+
data[key] = getData(body, schema[key]);
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (Object.keys(body).includes(key)) {
|
|
181
|
+
data[key] = body[key];
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return data;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const data = getData(body, schema)
|
|
189
|
+
|
|
190
|
+
const result = await Model.create(data)
|
|
191
|
+
|
|
192
|
+
res.status(200).json(result)
|
|
193
|
+
} catch (error) {
|
|
194
|
+
res.status(500).json({ error: error.message || "Internal server error" })
|
|
195
|
+
}
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
app.put("/update/:modelName/:id", async (req, res) => {
|
|
199
|
+
try {
|
|
200
|
+
const { modelName, id } = req.params;
|
|
201
|
+
const model = mongoose.model(modelName);
|
|
202
|
+
const updatedDoc = req.body;
|
|
203
|
+
|
|
204
|
+
delete updatedDoc._id;
|
|
205
|
+
const result = await model.findByIdAndUpdate(id, updatedDoc, { new: true });
|
|
206
|
+
|
|
207
|
+
res.status(200).json(result);
|
|
208
|
+
} catch (error) {
|
|
209
|
+
|
|
210
|
+
res.status(500).json({ error: error.message || "Internal server error" });
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
app.delete("/delete/:modelName/:id", async (req, res) => {
|
|
215
|
+
try {
|
|
216
|
+
const { modelName, id } = req.params;
|
|
217
|
+
const model = mongoose.model(modelName);
|
|
218
|
+
|
|
219
|
+
await model.findByIdAndDelete(id);
|
|
220
|
+
const count = await model.countDocuments();
|
|
221
|
+
|
|
222
|
+
res.status(200).json({ count });
|
|
223
|
+
} catch (error) {
|
|
224
|
+
res.status(500).json({ error: error.message || "Internal server error" });
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
app.delete("/delete-all/:modelName", async (req, res) => {
|
|
229
|
+
try {
|
|
230
|
+
const { modelName } = req.params;
|
|
231
|
+
const model = mongoose.model(modelName);
|
|
232
|
+
if (!model) return res.status(404).json({ error: "model not found" });
|
|
233
|
+
|
|
234
|
+
await model.deleteMany({});
|
|
235
|
+
|
|
236
|
+
res.status(200).json({ success: true });
|
|
237
|
+
} catch (error) {
|
|
238
|
+
res.status(500).json({ error: error.message || "Internal server error" });
|
|
239
|
+
}
|
|
240
|
+
})
|
|
241
|
+
|
|
242
242
|
export default app;
|
package/utils/loadModels.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import chalk from "chalk";
|
|
4
|
-
|
|
5
|
-
import { pathToFileURL } from "url";
|
|
6
|
-
|
|
7
|
-
export default (modelPath) => {
|
|
8
|
-
if (!fs.existsSync(modelPath)) {
|
|
9
|
-
console.log(
|
|
10
|
-
chalk.red.bold('[ERROR]') +
|
|
11
|
-
' The specified model path does not exist:\n ' +
|
|
12
|
-
chalk.gray(modelPath)
|
|
13
|
-
);
|
|
14
|
-
console.log('Tip: Check the path or create the folder first.');
|
|
15
|
-
process.exit(1);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
fs.readdirSync(modelPath).forEach(async (file) => {
|
|
19
|
-
if (file.endsWith('.js')) {
|
|
20
|
-
const filePath = path.join(modelPath, file);
|
|
21
|
-
const moduleUrl = pathToFileURL(filePath);
|
|
22
|
-
await import(moduleUrl.href);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
console.log(chalk.blue.bold('[INFO]'), chalk.gray("Models loaded from: " + modelPath))
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
|
|
5
|
+
import { pathToFileURL } from "url";
|
|
6
|
+
|
|
7
|
+
export default (modelPath) => {
|
|
8
|
+
if (!fs.existsSync(modelPath)) {
|
|
9
|
+
console.log(
|
|
10
|
+
chalk.red.bold('[ERROR]') +
|
|
11
|
+
' The specified model path does not exist:\n ' +
|
|
12
|
+
chalk.gray(modelPath)
|
|
13
|
+
);
|
|
14
|
+
console.log('Tip: Check the path or create the folder first.');
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
fs.readdirSync(modelPath).forEach(async (file) => {
|
|
19
|
+
if (file.endsWith('.js')) {
|
|
20
|
+
const filePath = path.join(modelPath, file);
|
|
21
|
+
const moduleUrl = pathToFileURL(filePath);
|
|
22
|
+
await import(moduleUrl.href);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
console.log(chalk.blue.bold('[INFO]'), chalk.gray("Models loaded from: " + modelPath))
|
|
27
27
|
}
|
package/views/base.zare
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import "/scripts/keyboardCommands"
|
|
2
|
-
|
|
3
|
-
serve (
|
|
4
|
-
<!DOCTYPE html>
|
|
5
|
-
<html lang="en">
|
|
6
|
-
<head>
|
|
7
|
-
<meta charset="UTF-8"/>
|
|
8
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
|
9
|
-
<title>Quar Studio</title>
|
|
10
|
-
<link rel="icon" href="/images/favicon.png" type="image/x-icon"/>
|
|
11
|
-
</head>
|
|
12
|
-
<body>
|
|
13
|
-
@(slot)
|
|
14
|
-
</body>
|
|
15
|
-
</html>
|
|
16
|
-
)
|
|
1
|
+
import "/scripts/keyboardCommands"
|
|
2
|
+
|
|
3
|
+
serve (
|
|
4
|
+
<!DOCTYPE html>
|
|
5
|
+
<html lang="en">
|
|
6
|
+
<head>
|
|
7
|
+
<meta charset="UTF-8"/>
|
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
|
9
|
+
<title>Quar Studio</title>
|
|
10
|
+
<link rel="icon" href="/images/favicon.png" type="image/x-icon"/>
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
@(slot)
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
16
|
+
)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
link "/styles/insertTab"
|
|
2
|
-
import "/scripts/insertTab"
|
|
3
|
-
|
|
4
|
-
serve (
|
|
5
|
-
<div class="insert-tab">
|
|
6
|
-
|
|
7
|
-
</div>
|
|
1
|
+
link "/styles/insertTab"
|
|
2
|
+
import "/scripts/insertTab"
|
|
3
|
+
|
|
4
|
+
serve (
|
|
5
|
+
<div class="insert-tab">
|
|
6
|
+
|
|
7
|
+
</div>
|
|
8
8
|
)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
link "/styles/popup"
|
|
2
|
-
import "/scripts/popup"
|
|
3
|
-
|
|
4
|
-
serve (
|
|
5
|
-
<div class="popup-overlay" id="popup">
|
|
6
|
-
<div class="popup-box" id="popupBox">
|
|
7
|
-
<h2 id="popupTitle">Title</h2>
|
|
8
|
-
<p id="popupMessage">Message goes here.</p>
|
|
9
|
-
<button class="close-btn" onclick="closePopup()">Close</button>
|
|
10
|
-
</div>
|
|
11
|
-
</div>
|
|
1
|
+
link "/styles/popup"
|
|
2
|
+
import "/scripts/popup"
|
|
3
|
+
|
|
4
|
+
serve (
|
|
5
|
+
<div class="popup-overlay" id="popup">
|
|
6
|
+
<div class="popup-box" id="popupBox">
|
|
7
|
+
<h2 id="popupTitle">Title</h2>
|
|
8
|
+
<p id="popupMessage">Message goes here.</p>
|
|
9
|
+
<button class="close-btn" onclick="closePopup()">Close</button>
|
|
10
|
+
</div>
|
|
11
|
+
</div>
|
|
12
12
|
)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
link "/styles/sidebar"
|
|
2
|
-
|
|
3
|
-
serve (
|
|
4
|
-
<div class="sidebar">
|
|
5
|
-
<div class="sidebar-header">All Models <button onclick="refreshSideBar()" class="btn">⭮</button></div>
|
|
6
|
-
<div class="model-wrapper">
|
|
7
|
-
@each (models:model) {
|
|
8
|
-
<div class="model" onclick="openModel('@(model.name)')">@(model.name)<span id="@(model.name)-doc-count">@(model.count)</span></div>
|
|
9
|
-
}
|
|
10
|
-
</div>
|
|
11
|
-
</div>
|
|
1
|
+
link "/styles/sidebar"
|
|
2
|
+
|
|
3
|
+
serve (
|
|
4
|
+
<div class="sidebar">
|
|
5
|
+
<div class="sidebar-header">All Models <button onclick="refreshSideBar()" class="btn">⭮</button></div>
|
|
6
|
+
<div class="model-wrapper">
|
|
7
|
+
@each (models:model) {
|
|
8
|
+
<div class="model" onclick="openModel('@(model.name)')">@(model.name)<span id="@(model.name)-doc-count">@(model.count)</span></div>
|
|
9
|
+
}
|
|
10
|
+
</div>
|
|
11
|
+
</div>
|
|
12
12
|
)
|