zyket 1.2.7 → 1.2.8
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/bin/cli.js +33 -57
- package/package.json +1 -1
- package/src/services/cache/index.js +66 -9
- package/src/utils/EnvManager.js +5 -1
package/bin/cli.js
CHANGED
|
@@ -70,7 +70,10 @@ const templateManager = new TemplateManager();
|
|
|
70
70
|
const backendFiles = defaultTemplate.filter(file => {
|
|
71
71
|
const route = file.route;
|
|
72
72
|
// Only install src and config files, not frontend
|
|
73
|
-
|
|
73
|
+
// Skip guards and handlers folders since socket is disabled by default
|
|
74
|
+
return (route.startsWith('default/src/') || route.startsWith('default/config/'))
|
|
75
|
+
&& !route.startsWith('default/src/guards/')
|
|
76
|
+
&& !route.startsWith('default/src/handlers/');
|
|
74
77
|
});
|
|
75
78
|
|
|
76
79
|
for (const file of backendFiles) {
|
|
@@ -131,67 +134,40 @@ kernel.boot().then(() => {
|
|
|
131
134
|
|
|
132
135
|
console.log('\n[ZYKET] ✅ Project initialized successfully!');
|
|
133
136
|
|
|
134
|
-
//
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
137
|
+
// Install dependencies automatically
|
|
138
|
+
console.log('\n[ZYKET] Installing dependencies...');
|
|
139
|
+
await new Promise((resolve, reject) => {
|
|
140
|
+
const npmInstall = spawn('npm', ['install'], {
|
|
141
|
+
cwd: process.cwd(),
|
|
142
|
+
stdio: 'inherit',
|
|
143
|
+
shell: true
|
|
144
|
+
});
|
|
141
145
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
npmInstall.on('close', (code) => {
|
|
152
|
-
if (code === 0) {
|
|
153
|
-
console.log('[ZYKET] ✅ Dependencies installed successfully!');
|
|
154
|
-
resolve();
|
|
155
|
-
} else {
|
|
156
|
-
reject(new Error(`npm install exited with code ${code}`));
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
npmInstall.on('error', (error) => {
|
|
161
|
-
reject(error);
|
|
162
|
-
});
|
|
146
|
+
npmInstall.on('close', (code) => {
|
|
147
|
+
if (code === 0) {
|
|
148
|
+
console.log('\n[ZYKET] ✅ Dependencies installed successfully!');
|
|
149
|
+
resolve();
|
|
150
|
+
} else {
|
|
151
|
+
reject(new Error(`npm install exited with code ${code}`));
|
|
152
|
+
}
|
|
163
153
|
});
|
|
164
154
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
type: 'confirm',
|
|
168
|
-
name: 'value',
|
|
169
|
-
message: '[ZYKET] Start the project now?',
|
|
170
|
-
initial: true
|
|
155
|
+
npmInstall.on('error', (error) => {
|
|
156
|
+
reject(error);
|
|
171
157
|
});
|
|
158
|
+
});
|
|
172
159
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
} else {
|
|
185
|
-
console.log('\n[ZYKET] Run "npm run dev" to start your application.');
|
|
186
|
-
console.log('\n[ZYKET] Happy coding! 🚀\n');
|
|
187
|
-
}
|
|
188
|
-
} else {
|
|
189
|
-
console.log('\n[ZYKET] Next steps:');
|
|
190
|
-
console.log(' 1. Run: npm install');
|
|
191
|
-
console.log(' 2. Review and update your .env file');
|
|
192
|
-
console.log(' 3. Run: npm run dev');
|
|
193
|
-
console.log('\n[ZYKET] Happy coding! 🚀\n');
|
|
194
|
-
}
|
|
160
|
+
// Start the project automatically
|
|
161
|
+
console.log('\n[ZYKET] Starting project...\n');
|
|
162
|
+
const nodeStart = spawn('node', ['index.js'], {
|
|
163
|
+
cwd: process.cwd(),
|
|
164
|
+
stdio: 'inherit',
|
|
165
|
+
shell: true
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
nodeStart.on('error', (error) => {
|
|
169
|
+
console.error('[ZYKET] Error starting project:', error);
|
|
170
|
+
});
|
|
195
171
|
},
|
|
196
172
|
'install-template': async () => {
|
|
197
173
|
const templates = templateManager.getTemplates();
|
package/package.json
CHANGED
|
@@ -3,36 +3,93 @@ const { createClient } = require("redis");
|
|
|
3
3
|
|
|
4
4
|
module.exports = class Cache extends Service {
|
|
5
5
|
#container;
|
|
6
|
-
client;
|
|
6
|
+
#client;
|
|
7
|
+
#useRedis;
|
|
8
|
+
#memoryCache;
|
|
9
|
+
#expirations;
|
|
7
10
|
|
|
8
11
|
constructor(container, url) {
|
|
9
12
|
super("cache");
|
|
10
13
|
this.#container = container;
|
|
11
|
-
this
|
|
14
|
+
this.#useRedis = !!url && url !== '';
|
|
15
|
+
|
|
16
|
+
if (this.#useRedis) {
|
|
17
|
+
this.#client = createClient({ url });
|
|
18
|
+
} else {
|
|
19
|
+
// Use in-memory cache
|
|
20
|
+
this.#memoryCache = new Map();
|
|
21
|
+
this.#expirations = new Map();
|
|
22
|
+
}
|
|
12
23
|
}
|
|
13
24
|
|
|
14
25
|
async boot() {
|
|
15
|
-
|
|
26
|
+
if (this.#useRedis) {
|
|
27
|
+
await this.#client.connect();
|
|
28
|
+
this.#container.get('logger').info('Cache service using Redis');
|
|
29
|
+
} else {
|
|
30
|
+
this.#container.get('logger').info('Cache service using in-memory cache');
|
|
31
|
+
}
|
|
16
32
|
}
|
|
17
33
|
|
|
18
34
|
async set(key, value) {
|
|
19
|
-
|
|
20
|
-
|
|
35
|
+
if (this.#useRedis) {
|
|
36
|
+
return await this.#client.set(key, value);
|
|
37
|
+
} else {
|
|
38
|
+
this.#memoryCache.set(key, value);
|
|
39
|
+
return 'OK';
|
|
40
|
+
}
|
|
21
41
|
}
|
|
22
42
|
|
|
23
43
|
async get(key) {
|
|
24
|
-
|
|
44
|
+
if (this.#useRedis) {
|
|
45
|
+
return await this.#client.get(key);
|
|
46
|
+
} else {
|
|
47
|
+
// Check if the key has expired
|
|
48
|
+
if (this.#expirations.has(key)) {
|
|
49
|
+
const expireTime = this.#expirations.get(key);
|
|
50
|
+
if (Date.now() > expireTime) {
|
|
51
|
+
this.#memoryCache.delete(key);
|
|
52
|
+
this.#expirations.delete(key);
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return this.#memoryCache.get(key) || null;
|
|
57
|
+
}
|
|
25
58
|
}
|
|
26
59
|
|
|
27
60
|
async del(key) {
|
|
28
|
-
|
|
61
|
+
if (this.#useRedis) {
|
|
62
|
+
return await this.#client.del(key);
|
|
63
|
+
} else {
|
|
64
|
+
this.#expirations.delete(key);
|
|
65
|
+
return this.#memoryCache.delete(key) ? 1 : 0;
|
|
66
|
+
}
|
|
29
67
|
}
|
|
30
68
|
|
|
31
69
|
async keys(pattern) {
|
|
32
|
-
|
|
70
|
+
if (this.#useRedis) {
|
|
71
|
+
return await this.#client.keys(pattern);
|
|
72
|
+
} else {
|
|
73
|
+
// Simple pattern matching for memory cache
|
|
74
|
+
const regex = new RegExp('^' + pattern.replace(/\*/g, '.*') + '$');
|
|
75
|
+
return Array.from(this.#memoryCache.keys()).filter(key => regex.test(key));
|
|
76
|
+
}
|
|
33
77
|
}
|
|
34
78
|
|
|
35
79
|
async expire(key, seconds) {
|
|
36
|
-
|
|
80
|
+
if (this.#useRedis) {
|
|
81
|
+
return await this.#client.expire(key, seconds);
|
|
82
|
+
} else {
|
|
83
|
+
if (this.#memoryCache.has(key)) {
|
|
84
|
+
const expireTime = Date.now() + (seconds * 1000);
|
|
85
|
+
this.#expirations.set(key, expireTime);
|
|
86
|
+
return 1;
|
|
87
|
+
}
|
|
88
|
+
return 0;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
get client() {
|
|
93
|
+
return this.#useRedis ? this.#client : null;
|
|
37
94
|
}
|
|
38
95
|
}
|
package/src/utils/EnvManager.js
CHANGED
|
@@ -12,6 +12,10 @@ module.exports = class EnvManager {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
static getDefaultSecrets() {
|
|
15
|
+
const header = `# Zyket Environment Configuration
|
|
16
|
+
# Leave CACHE_URL empty to use in-memory cache, or set to redis://localhost:6379 for Redis
|
|
17
|
+
|
|
18
|
+
`;
|
|
15
19
|
const envsToCreate = {
|
|
16
20
|
DEBUG: true,
|
|
17
21
|
PORT: 3000,
|
|
@@ -35,7 +39,7 @@ module.exports = class EnvManager {
|
|
|
35
39
|
DISABLE_VITE: true,
|
|
36
40
|
}
|
|
37
41
|
|
|
38
|
-
return Object.entries(envsToCreate).reduce((acc, [key, value]) => {
|
|
42
|
+
return header + Object.entries(envsToCreate).reduce((acc, [key, value]) => {
|
|
39
43
|
return `${acc}${key}=${value}\n`;
|
|
40
44
|
}, "");
|
|
41
45
|
}
|