@skalfa/skalfa-cli 1.0.2 → 1.0.4
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/dist/commands/add-extension.js +36 -11
- package/dist/commands/create-api.js +19 -12
- package/package.json +1 -1
- package/dist/bin/aluna.js +0 -44
- package/dist/bin/kava.js +0 -70
|
@@ -20,7 +20,6 @@ exports.extensions = {
|
|
|
20
20
|
cron: "@skalfa/skalfa-cron",
|
|
21
21
|
da: "@skalfa/skalfa-da",
|
|
22
22
|
socket: "@skalfa/skalfa-socket",
|
|
23
|
-
notification: "@skalfa/notification",
|
|
24
23
|
orm: "@skalfa/skalfa-orm"
|
|
25
24
|
};
|
|
26
25
|
exports.extensionNames = Object.keys(exports.extensions);
|
|
@@ -267,16 +266,6 @@ async function scaffoldUtilityExtension(projectRoot, ext) {
|
|
|
267
266
|
// Uncomment DA block
|
|
268
267
|
content = content.replace(/\/\/ if \(process\.env\.DA_HOST[\s\S]*?\/\/ }/g, (match) => match.replace(/^\/\/ ?/gm, ""));
|
|
269
268
|
}
|
|
270
|
-
if (ext === "cron") {
|
|
271
|
-
importsToAdd.push("cron");
|
|
272
|
-
// Uncomment Cron block
|
|
273
|
-
content = content.replace(/\/\/ cron\.worker\(\)/g, "cron.worker()");
|
|
274
|
-
}
|
|
275
|
-
if (ext === "socket") {
|
|
276
|
-
importsToAdd.push("socket");
|
|
277
|
-
// Uncomment Socket block
|
|
278
|
-
content = content.replace(/\/\/ if \(process\.env\.SOCKET_PORT[\s\S]*?\/\/ }/g, (match) => match.replace(/^\/\/ ?/gm, ""));
|
|
279
|
-
}
|
|
280
269
|
// Update import statement at the top of app.ts
|
|
281
270
|
if (importsToAdd.length > 0) {
|
|
282
271
|
const importRegex = /import\s*\{\s*([\s\S]*?)\s*\}\s*from\s*["']@utils["']/;
|
|
@@ -290,6 +279,42 @@ async function scaffoldUtilityExtension(projectRoot, ext) {
|
|
|
290
279
|
}
|
|
291
280
|
node_fs_1.default.writeFileSync(appTsPath, content, "utf8");
|
|
292
281
|
}
|
|
282
|
+
// 5. Update package.json scripts for workers
|
|
283
|
+
const packageJsonPath = node_path_1.default.join(projectRoot, "package.json");
|
|
284
|
+
if (node_fs_1.default.existsSync(packageJsonPath) && ["cron", "queue", "socket"].includes(ext)) {
|
|
285
|
+
const pkg = JSON.parse(node_fs_1.default.readFileSync(packageJsonPath, "utf8"));
|
|
286
|
+
pkg.scripts = pkg.scripts || {};
|
|
287
|
+
let scriptKey = "";
|
|
288
|
+
let scriptVal = "";
|
|
289
|
+
if (ext === "cron") {
|
|
290
|
+
scriptKey = "start:cron";
|
|
291
|
+
scriptVal = "bun run app/jobs/crons/worker.cron.ts";
|
|
292
|
+
}
|
|
293
|
+
else if (ext === "queue") {
|
|
294
|
+
scriptKey = "start:queue";
|
|
295
|
+
scriptVal = "bun run app/jobs/queues/worker.queue.ts";
|
|
296
|
+
}
|
|
297
|
+
else if (ext === "socket") {
|
|
298
|
+
scriptKey = "start:socket";
|
|
299
|
+
scriptVal = "bun run app/jobs/sockets/worker.socket.ts";
|
|
300
|
+
}
|
|
301
|
+
if (scriptKey) {
|
|
302
|
+
pkg.scripts[scriptKey] = scriptVal;
|
|
303
|
+
// Update dev concurrently command
|
|
304
|
+
const devScript = pkg.scripts["dev"] || "";
|
|
305
|
+
const runCmd = `bun ${scriptKey}`;
|
|
306
|
+
if (devScript.includes("concurrently")) {
|
|
307
|
+
if (!devScript.includes(runCmd)) {
|
|
308
|
+
const cleanDev = devScript.trim();
|
|
309
|
+
pkg.scripts["dev"] = `${cleanDev} "${runCmd}"`;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
pkg.scripts["dev"] = `concurrently --raw "bun run --watch app/app.ts" "bun skalfa watch:barrels" "${runCmd}"`;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
node_fs_1.default.writeFileSync(packageJsonPath, JSON.stringify(pkg, null, 2), "utf8");
|
|
317
|
+
}
|
|
293
318
|
}
|
|
294
319
|
finally {
|
|
295
320
|
cleanup();
|
|
@@ -105,9 +105,16 @@ async function createApi(projectName) {
|
|
|
105
105
|
// Cleanup temp extract folder
|
|
106
106
|
node_fs_1.default.rmSync(tempExtractDir, { recursive: true, force: true });
|
|
107
107
|
}
|
|
108
|
-
// Cleanup git
|
|
108
|
+
// Cleanup git and github directories if present and rename package
|
|
109
109
|
(0, fs_1.removeDirectory)(node_path_1.default.join(target, ".git"));
|
|
110
|
+
(0, fs_1.removeDirectory)(node_path_1.default.join(target, ".github"));
|
|
110
111
|
renamePackage(target, packageName);
|
|
112
|
+
// Rename .npmignore to .gitignore if it exists (npm renames .gitignore to .npmignore during pack/publish)
|
|
113
|
+
const npmignorePath = node_path_1.default.join(target, ".npmignore");
|
|
114
|
+
const gitignorePath = node_path_1.default.join(target, ".gitignore");
|
|
115
|
+
if (node_fs_1.default.existsSync(npmignorePath) && !node_fs_1.default.existsSync(gitignorePath)) {
|
|
116
|
+
node_fs_1.default.renameSync(npmignorePath, gitignorePath);
|
|
117
|
+
}
|
|
111
118
|
// Customize project with selected options
|
|
112
119
|
customizeProject(target, {
|
|
113
120
|
redis: finalRedis,
|
|
@@ -139,27 +146,33 @@ function customizeProject(target, opts) {
|
|
|
139
146
|
const utilsIndexPath = node_path_1.default.join(target, "utils", "index.ts");
|
|
140
147
|
const appTsPath = node_path_1.default.join(target, "app", "app.ts");
|
|
141
148
|
const isDev = !!process.env[TEMPLATE_ENV_KEY];
|
|
142
|
-
// 1. Update dependencies in package.json
|
|
149
|
+
// 1. Update dependencies and scripts in package.json
|
|
143
150
|
if (node_fs_1.default.existsSync(packageJsonPath)) {
|
|
144
151
|
const pkg = JSON.parse(node_fs_1.default.readFileSync(packageJsonPath, "utf8"));
|
|
145
152
|
pkg.dependencies = pkg.dependencies || {};
|
|
153
|
+
pkg.scripts = pkg.scripts || {};
|
|
146
154
|
// Base ORM integration (always included)
|
|
147
155
|
pkg.dependencies["@skalfa/skalfa-orm"] = isDev ? "file:../skalfa-orm" : "^1.0.0";
|
|
148
156
|
if (isDev) {
|
|
149
157
|
pkg.dependencies["@skalfa/skalfa-api-core"] = "file:../skalfa-api-core";
|
|
150
158
|
}
|
|
159
|
+
const devCommands = ["bun run --watch app/app.ts", "bun skalfa watch:barrels"];
|
|
151
160
|
if (opts.redis) {
|
|
152
161
|
pkg.dependencies["@skalfa/skalfa-redis"] = isDev ? "file:../skalfa-redis" : "^1.0.0";
|
|
153
162
|
pkg.dependencies["ioredis"] = "^5.4.1";
|
|
154
163
|
}
|
|
155
164
|
if (opts.queue) {
|
|
156
165
|
pkg.dependencies["@skalfa/skalfa-queue"] = isDev ? "file:../skalfa-queue" : "^1.0.0";
|
|
166
|
+
pkg.scripts["start:queue"] = "bun run app/jobs/queues/worker.queue.ts";
|
|
167
|
+
devCommands.push("bun start:queue");
|
|
157
168
|
}
|
|
158
169
|
if (opts.cache) {
|
|
159
170
|
pkg.dependencies["@skalfa/skalfa-cache"] = isDev ? "file:../skalfa-cache" : "^1.0.0";
|
|
160
171
|
}
|
|
161
172
|
if (opts.cron) {
|
|
162
173
|
pkg.dependencies["@skalfa/skalfa-cron"] = isDev ? "file:../skalfa-cron" : "^1.0.0";
|
|
174
|
+
pkg.scripts["start:cron"] = "bun run app/jobs/crons/worker.cron.ts";
|
|
175
|
+
devCommands.push("bun start:cron");
|
|
163
176
|
}
|
|
164
177
|
if (opts.da) {
|
|
165
178
|
pkg.dependencies["@skalfa/skalfa-da"] = isDev ? "file:../skalfa-da" : "^1.0.0";
|
|
@@ -168,7 +181,11 @@ function customizeProject(target, opts) {
|
|
|
168
181
|
if (opts.socket) {
|
|
169
182
|
pkg.dependencies["@skalfa/skalfa-socket"] = isDev ? "file:../skalfa-socket" : "^1.0.0";
|
|
170
183
|
pkg.dependencies["socket.io"] = "^4.7.5";
|
|
184
|
+
pkg.scripts["start:socket"] = "bun run app/jobs/sockets/worker.socket.ts";
|
|
185
|
+
devCommands.push("bun start:socket");
|
|
171
186
|
}
|
|
187
|
+
// Update dev script with concurrently
|
|
188
|
+
pkg.scripts["dev"] = `concurrently --raw ${devCommands.map(cmd => `\\"${cmd}\\"`).join(" ")}`;
|
|
172
189
|
node_fs_1.default.writeFileSync(packageJsonPath, JSON.stringify(pkg, null, 2), "utf8");
|
|
173
190
|
}
|
|
174
191
|
// 2. Add path mappings in tsconfig.json
|
|
@@ -252,16 +269,6 @@ function customizeProject(target, opts) {
|
|
|
252
269
|
// Uncomment DA block
|
|
253
270
|
content = content.replace(/\/\/ if \(process\.env\.DA_HOST[\s\S]*?\/\/ }/g, (match) => match.replace(/^\/\/ ?/gm, ""));
|
|
254
271
|
}
|
|
255
|
-
if (opts.cron) {
|
|
256
|
-
importsToAdd.push("cron");
|
|
257
|
-
// Uncomment Cron block
|
|
258
|
-
content = content.replace(/\/\/ cron\.worker\(\)/g, "cron.worker()");
|
|
259
|
-
}
|
|
260
|
-
if (opts.socket) {
|
|
261
|
-
importsToAdd.push("socket");
|
|
262
|
-
// Uncomment Socket block
|
|
263
|
-
content = content.replace(/\/\/ if \(process\.env\.SOCKET_PORT[\s\S]*?\/\/ }/g, (match) => match.replace(/^\/\/ ?/gm, ""));
|
|
264
|
-
}
|
|
265
272
|
// Update import statement at the top of app.ts
|
|
266
273
|
if (importsToAdd.length > 0) {
|
|
267
274
|
const baseImports = ["controller", "db", "logger", "middleware", "storage", "registry"];
|
package/package.json
CHANGED
package/dist/bin/aluna.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const commander_1 = require("commander");
|
|
5
|
-
const add_extension_1 = require("../commands/add-extension");
|
|
6
|
-
const create_api_1 = require("../commands/create-api");
|
|
7
|
-
const pick_1 = require("../commands/pick");
|
|
8
|
-
const program = new commander_1.Command();
|
|
9
|
-
program
|
|
10
|
-
.name("aluna")
|
|
11
|
-
.description("Create Aluna API projects and install optional extensions.")
|
|
12
|
-
.version("0.1.0");
|
|
13
|
-
program
|
|
14
|
-
.command("create-api")
|
|
15
|
-
.description("Create a new API project from the local aluna-api template.")
|
|
16
|
-
.argument("<name>", "project folder and package name")
|
|
17
|
-
.action((name) => {
|
|
18
|
-
runCommand(() => (0, create_api_1.createApi)(name));
|
|
19
|
-
});
|
|
20
|
-
program
|
|
21
|
-
.command("add")
|
|
22
|
-
.description("Install an optional Aluna extension into the current project.")
|
|
23
|
-
.argument("<extension>", `extension name: ${add_extension_1.extensionNames.join(", ")}`)
|
|
24
|
-
.action((extension) => {
|
|
25
|
-
runCommand(() => (0, add_extension_1.addExtension)(extension));
|
|
26
|
-
});
|
|
27
|
-
program
|
|
28
|
-
.command("pick")
|
|
29
|
-
.description("Eject/copy a core utility from @aluna/aluna-api-core into your local utils folder for customization.")
|
|
30
|
-
.argument("<utility>", `utility name: ${pick_1.UTILITIES.join(", ")}`)
|
|
31
|
-
.action((utility) => {
|
|
32
|
-
runCommand(() => (0, pick_1.pickUtility)(utility));
|
|
33
|
-
});
|
|
34
|
-
program.parse(process.argv);
|
|
35
|
-
function runCommand(command) {
|
|
36
|
-
try {
|
|
37
|
-
command();
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
41
|
-
console.error(`Error: ${message}`);
|
|
42
|
-
process.exitCode = 1;
|
|
43
|
-
}
|
|
44
|
-
}
|
package/dist/bin/kava.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const commander_1 = require("commander");
|
|
8
|
-
const node_child_process_1 = require("node:child_process");
|
|
9
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
11
|
-
const add_extension_1 = require("../commands/add-extension");
|
|
12
|
-
const create_api_1 = require("../commands/create-api");
|
|
13
|
-
const pick_1 = require("../commands/pick");
|
|
14
|
-
const fs_1 = require("../utils/fs");
|
|
15
|
-
// Dynamic routing / forwarding logic
|
|
16
|
-
const args = process.argv.slice(2);
|
|
17
|
-
const knownCommands = ["create-api", "add", "pick"];
|
|
18
|
-
if (args.length > 0 && !knownCommands.includes(args[0]) && !["-h", "--help", "-v", "--version", "help"].includes(args[0])) {
|
|
19
|
-
const projectRoot = (0, fs_1.findProjectRoot)(process.cwd());
|
|
20
|
-
if (projectRoot) {
|
|
21
|
-
const localCliPath = node_path_1.default.join(projectRoot, "utils", "commands", "kava.ts");
|
|
22
|
-
if (node_fs_1.default.existsSync(localCliPath)) {
|
|
23
|
-
try {
|
|
24
|
-
// Forward arguments directly to local kava.ts using Bun
|
|
25
|
-
(0, node_child_process_1.execSync)(`bun run utils/commands/kava.ts ${args.join(" ")}`, { stdio: "inherit" });
|
|
26
|
-
process.exit(0);
|
|
27
|
-
}
|
|
28
|
-
catch (err) {
|
|
29
|
-
process.exit(1);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
const program = new commander_1.Command();
|
|
35
|
-
program
|
|
36
|
-
.name("kava")
|
|
37
|
-
.description("Create Kava API projects and install optional extensions.")
|
|
38
|
-
.version("0.1.0");
|
|
39
|
-
program
|
|
40
|
-
.command("create-api")
|
|
41
|
-
.description("Create a new Kava API project.")
|
|
42
|
-
.argument("<name>", "project folder and package name")
|
|
43
|
-
.action(async (name) => {
|
|
44
|
-
await runCommand(() => (0, create_api_1.createApi)(name));
|
|
45
|
-
});
|
|
46
|
-
program
|
|
47
|
-
.command("add")
|
|
48
|
-
.description("Install an optional Kava extension into the current project.")
|
|
49
|
-
.argument("<extension>", `extension name: ${add_extension_1.extensionNames.join(", ")}`)
|
|
50
|
-
.action(async (extension) => {
|
|
51
|
-
await runCommand(() => (0, add_extension_1.addExtension)(extension));
|
|
52
|
-
});
|
|
53
|
-
program
|
|
54
|
-
.command("pick")
|
|
55
|
-
.description("Eject/copy a core utility from @kava/kava-api-core into your local utils folder for customization.")
|
|
56
|
-
.argument("<utility>", `utility name: ${pick_1.UTILITIES.join(", ")}`)
|
|
57
|
-
.action(async (utility) => {
|
|
58
|
-
await runCommand(() => (0, pick_1.pickUtility)(utility));
|
|
59
|
-
});
|
|
60
|
-
program.parse(process.argv);
|
|
61
|
-
async function runCommand(command) {
|
|
62
|
-
try {
|
|
63
|
-
await command();
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
67
|
-
console.error(`Error: ${message}`);
|
|
68
|
-
process.exit(1);
|
|
69
|
-
}
|
|
70
|
-
}
|