alepha 0.11.7 → 0.11.10
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/README.md +55 -17
- package/dist/index.cjs +15805 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +15804 -0
- package/dist/index.js.map +1 -0
- package/package.json +36 -372
- package/src/assets/biomeJson.ts +33 -0
- package/src/assets/tsconfigJson.ts +17 -0
- package/src/assets/viteConfigTs.ts +14 -0
- package/src/commands/BiomeCommands.ts +60 -0
- package/src/commands/CoreCommands.ts +266 -0
- package/src/commands/DrizzleCommands.ts +403 -0
- package/src/commands/VerifyCommands.ts +48 -0
- package/src/commands/ViteCommands.ts +152 -0
- package/src/index.ts +35 -0
- package/src/services/ProcessRunner.ts +89 -0
- package/src/version.ts +7 -0
- package/api/files.cjs +0 -8
- package/api/files.d.ts +0 -438
- package/api/files.js +0 -1
- package/api/jobs.cjs +0 -8
- package/api/jobs.d.ts +0 -327
- package/api/jobs.js +0 -1
- package/api/notifications.cjs +0 -8
- package/api/notifications.d.ts +0 -263
- package/api/notifications.js +0 -1
- package/api/users.cjs +0 -8
- package/api/users.d.ts +0 -923
- package/api/users.js +0 -1
- package/api/verifications.cjs +0 -8
- package/api/verifications.d.ts +0 -1
- package/api/verifications.js +0 -1
- package/batch.cjs +0 -8
- package/batch.d.ts +0 -154
- package/batch.js +0 -1
- package/bucket.cjs +0 -8
- package/bucket.d.ts +0 -520
- package/bucket.js +0 -1
- package/cache/redis.cjs +0 -8
- package/cache/redis.d.ts +0 -40
- package/cache/redis.js +0 -1
- package/cache.cjs +0 -8
- package/cache.d.ts +0 -288
- package/cache.js +0 -1
- package/command.cjs +0 -8
- package/command.d.ts +0 -269
- package/command.js +0 -1
- package/core.cjs +0 -8
- package/core.d.ts +0 -1904
- package/core.js +0 -1
- package/datetime.cjs +0 -8
- package/datetime.d.ts +0 -144
- package/datetime.js +0 -1
- package/devtools.cjs +0 -8
- package/devtools.d.ts +0 -252
- package/devtools.js +0 -1
- package/email.cjs +0 -8
- package/email.d.ts +0 -187
- package/email.js +0 -1
- package/fake.cjs +0 -8
- package/fake.d.ts +0 -73
- package/fake.js +0 -1
- package/file.cjs +0 -8
- package/file.d.ts +0 -528
- package/file.js +0 -1
- package/lock/redis.cjs +0 -8
- package/lock/redis.d.ts +0 -24
- package/lock/redis.js +0 -1
- package/lock.cjs +0 -8
- package/lock.d.ts +0 -552
- package/lock.js +0 -1
- package/logger.cjs +0 -8
- package/logger.d.ts +0 -287
- package/logger.js +0 -1
- package/postgres.cjs +0 -8
- package/postgres.d.ts +0 -2143
- package/postgres.js +0 -1
- package/queue/redis.cjs +0 -8
- package/queue/redis.d.ts +0 -29
- package/queue/redis.js +0 -1
- package/queue.cjs +0 -8
- package/queue.d.ts +0 -760
- package/queue.js +0 -1
- package/react/auth.cjs +0 -8
- package/react/auth.d.ts +0 -504
- package/react/auth.js +0 -1
- package/react/form.cjs +0 -8
- package/react/form.d.ts +0 -211
- package/react/form.js +0 -1
- package/react/head.cjs +0 -8
- package/react/head.d.ts +0 -120
- package/react/head.js +0 -1
- package/react/i18n.cjs +0 -8
- package/react/i18n.d.ts +0 -168
- package/react/i18n.js +0 -1
- package/react.cjs +0 -8
- package/react.d.ts +0 -1263
- package/react.js +0 -1
- package/redis.cjs +0 -8
- package/redis.d.ts +0 -82
- package/redis.js +0 -1
- package/retry.cjs +0 -8
- package/retry.d.ts +0 -162
- package/retry.js +0 -1
- package/router.cjs +0 -8
- package/router.d.ts +0 -45
- package/router.js +0 -1
- package/scheduler.cjs +0 -8
- package/scheduler.d.ts +0 -145
- package/scheduler.js +0 -1
- package/security.cjs +0 -8
- package/security.d.ts +0 -586
- package/security.js +0 -1
- package/server/cache.cjs +0 -8
- package/server/cache.d.ts +0 -163
- package/server/cache.js +0 -1
- package/server/compress.cjs +0 -8
- package/server/compress.d.ts +0 -38
- package/server/compress.js +0 -1
- package/server/cookies.cjs +0 -8
- package/server/cookies.d.ts +0 -144
- package/server/cookies.js +0 -1
- package/server/cors.cjs +0 -8
- package/server/cors.d.ts +0 -45
- package/server/cors.js +0 -1
- package/server/health.cjs +0 -8
- package/server/health.d.ts +0 -58
- package/server/health.js +0 -1
- package/server/helmet.cjs +0 -8
- package/server/helmet.d.ts +0 -98
- package/server/helmet.js +0 -1
- package/server/links.cjs +0 -8
- package/server/links.d.ts +0 -322
- package/server/links.js +0 -1
- package/server/metrics.cjs +0 -8
- package/server/metrics.d.ts +0 -35
- package/server/metrics.js +0 -1
- package/server/multipart.cjs +0 -8
- package/server/multipart.d.ts +0 -42
- package/server/multipart.js +0 -1
- package/server/proxy.cjs +0 -8
- package/server/proxy.d.ts +0 -234
- package/server/proxy.js +0 -1
- package/server/security.cjs +0 -8
- package/server/security.d.ts +0 -92
- package/server/security.js +0 -1
- package/server/static.cjs +0 -8
- package/server/static.d.ts +0 -119
- package/server/static.js +0 -1
- package/server/swagger.cjs +0 -8
- package/server/swagger.d.ts +0 -161
- package/server/swagger.js +0 -1
- package/server.cjs +0 -8
- package/server.d.ts +0 -849
- package/server.js +0 -1
- package/topic/redis.cjs +0 -8
- package/topic/redis.d.ts +0 -42
- package/topic/redis.js +0 -1
- package/topic.cjs +0 -8
- package/topic.d.ts +0 -819
- package/topic.js +0 -1
- package/ui.cjs +0 -8
- package/ui.d.ts +0 -813
- package/ui.js +0 -1
- package/vite.cjs +0 -8
- package/vite.d.ts +0 -186
- package/vite.js +0 -1
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { access, readFile, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { $command } from "@alepha/command";
|
|
4
|
+
import { $inject, AlephaError, boot, t } from "@alepha/core";
|
|
5
|
+
import { $logger } from "@alepha/logger";
|
|
6
|
+
import { viteConfigTs } from "../assets/viteConfigTs.ts";
|
|
7
|
+
import { ProcessRunner } from "../services/ProcessRunner.ts";
|
|
8
|
+
import { CoreCommands } from "./CoreCommands.ts";
|
|
9
|
+
|
|
10
|
+
export class ViteCommands {
|
|
11
|
+
protected readonly log = $logger();
|
|
12
|
+
protected readonly runner = $inject(ProcessRunner);
|
|
13
|
+
protected readonly core = $inject(CoreCommands);
|
|
14
|
+
|
|
15
|
+
public readonly run = $command({
|
|
16
|
+
name: "run",
|
|
17
|
+
description: "Run a TypeScript file directly",
|
|
18
|
+
flags: t.object({
|
|
19
|
+
watch: t.optional(
|
|
20
|
+
t.boolean({ description: "Watch file for changes", alias: "w" }),
|
|
21
|
+
),
|
|
22
|
+
}),
|
|
23
|
+
summary: false,
|
|
24
|
+
args: t.text({ title: "path", description: "Filepath to run" }),
|
|
25
|
+
handler: async ({ args, flags }) => {
|
|
26
|
+
await this.core.ensureTsConfig();
|
|
27
|
+
await this.runner.exec(`tsx ${flags.watch ? "watch " : ""}${args}`);
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Will run the project in watch mode.
|
|
33
|
+
*
|
|
34
|
+
* - If an index.html file is found in the project root, it will run Vite in dev mode.
|
|
35
|
+
* - Otherwise, it will look for a server entry file and run it with tsx in watch mode.
|
|
36
|
+
*/
|
|
37
|
+
public readonly dev = $command({
|
|
38
|
+
name: "dev",
|
|
39
|
+
description: "Run the project in development mode",
|
|
40
|
+
args: t.optional(t.text({ title: "path", description: "Filepath to run" })),
|
|
41
|
+
handler: async ({ args }) => {
|
|
42
|
+
const root = process.cwd();
|
|
43
|
+
await this.core.ensureTsConfig(root);
|
|
44
|
+
await this.ensurePackageJson(root);
|
|
45
|
+
const entry = await boot.getServerEntry(root, args);
|
|
46
|
+
this.log.trace("Entry file found", { entry });
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
await access(join(root, "index.html"));
|
|
50
|
+
} catch {
|
|
51
|
+
this.log.trace("No index.html found, running entry file with tsx");
|
|
52
|
+
//await this.runner.exec(`tsx watch ${entry}`);
|
|
53
|
+
//return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const configPath = await this.configPath(root, args ? entry : undefined);
|
|
57
|
+
this.log.trace("Vite config found", { configPath });
|
|
58
|
+
await this.runner.exec(`vite -c=${configPath}`);
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
public readonly build = $command({
|
|
63
|
+
name: "build",
|
|
64
|
+
description: "Build the project for production",
|
|
65
|
+
args: t.optional(
|
|
66
|
+
t.text({ title: "path", description: "Filepath to build" }),
|
|
67
|
+
),
|
|
68
|
+
flags: t.object({
|
|
69
|
+
config: t.optional(
|
|
70
|
+
t.text({ aliases: ["c"], description: "Path to config file" }),
|
|
71
|
+
),
|
|
72
|
+
stats: t.optional(
|
|
73
|
+
t.boolean({
|
|
74
|
+
description: "Generate build stats report",
|
|
75
|
+
}),
|
|
76
|
+
),
|
|
77
|
+
}),
|
|
78
|
+
handler: async ({ flags, args }) => {
|
|
79
|
+
const root = process.cwd();
|
|
80
|
+
await this.core.ensureTsConfig(root);
|
|
81
|
+
await this.ensurePackageJson(root);
|
|
82
|
+
const entry = await boot.getServerEntry(root, args);
|
|
83
|
+
this.log.trace("Entry file found", { entry });
|
|
84
|
+
|
|
85
|
+
await rm("dist", { recursive: true, force: true });
|
|
86
|
+
|
|
87
|
+
// DISABLED FOR NOW (waiting for vite-rolldown)
|
|
88
|
+
// if (flags.lib) {
|
|
89
|
+
// await this.runner.exec(
|
|
90
|
+
// `tsdown${flags.config ? ` -c=${flags.config}` : ""}`,
|
|
91
|
+
// );
|
|
92
|
+
// return;
|
|
93
|
+
// }
|
|
94
|
+
|
|
95
|
+
const configPath = await this.configPath(root, args ? entry : undefined);
|
|
96
|
+
|
|
97
|
+
const env: Record<string, string> = {};
|
|
98
|
+
if (flags.stats) {
|
|
99
|
+
env.ALEPHA_BUILD_STATS = "true";
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
await this.runner.exec(`vite build -c=${configPath}`, env);
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
public readonly test = $command({
|
|
107
|
+
name: "test",
|
|
108
|
+
description: "Run tests using Vitest",
|
|
109
|
+
handler: async () => {
|
|
110
|
+
await this.core.ensureTsConfig();
|
|
111
|
+
|
|
112
|
+
const configPath = await this.configPath();
|
|
113
|
+
await this.runner.exec(`vitest run -c=${configPath}`);
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// -------------------------------------------------------------------------------------------------------------------
|
|
118
|
+
|
|
119
|
+
protected async configPath(
|
|
120
|
+
root = process.cwd(),
|
|
121
|
+
serverEntry?: string,
|
|
122
|
+
): Promise<string> {
|
|
123
|
+
try {
|
|
124
|
+
const viteConfigPath = join(root, "vite.config.ts");
|
|
125
|
+
await access(viteConfigPath);
|
|
126
|
+
return viteConfigPath;
|
|
127
|
+
} catch {
|
|
128
|
+
return this.runner.writeConfigFile(
|
|
129
|
+
"vite.config.ts",
|
|
130
|
+
viteConfigTs(serverEntry),
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
protected async ensurePackageJson(root = process.cwd()) {
|
|
136
|
+
const packageJsonPath = join(root, "package.json");
|
|
137
|
+
try {
|
|
138
|
+
await access(packageJsonPath);
|
|
139
|
+
} catch (error) {
|
|
140
|
+
throw new AlephaError(
|
|
141
|
+
"No package.json found in project root. Run 'npx alepha init' to create one.",
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const content = await readFile(packageJsonPath, "utf8");
|
|
146
|
+
const packageJson = JSON.parse(content);
|
|
147
|
+
if (!packageJson.type || packageJson.type !== "module") {
|
|
148
|
+
packageJson.type = "module";
|
|
149
|
+
await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "tsx";
|
|
3
|
+
import { $module, Alepha, run } from "@alepha/core";
|
|
4
|
+
import { BiomeCommands } from "./commands/BiomeCommands.ts";
|
|
5
|
+
import { CoreCommands } from "./commands/CoreCommands.ts";
|
|
6
|
+
import { DrizzleCommands } from "./commands/DrizzleCommands.ts";
|
|
7
|
+
import { VerifyCommands } from "./commands/VerifyCommands.ts";
|
|
8
|
+
import { ViteCommands } from "./commands/ViteCommands.ts";
|
|
9
|
+
import { ProcessRunner } from "./services/ProcessRunner.ts";
|
|
10
|
+
import { version } from "./version.ts";
|
|
11
|
+
|
|
12
|
+
const AlephaCli = $module({
|
|
13
|
+
name: "alepha.cli",
|
|
14
|
+
services: [
|
|
15
|
+
ProcessRunner,
|
|
16
|
+
CoreCommands,
|
|
17
|
+
DrizzleCommands,
|
|
18
|
+
VerifyCommands,
|
|
19
|
+
ViteCommands,
|
|
20
|
+
BiomeCommands,
|
|
21
|
+
],
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const alepha = Alepha.create({
|
|
25
|
+
env: {
|
|
26
|
+
LOG_LEVEL: "alepha.core:warn,info",
|
|
27
|
+
LOG_FORMAT: "raw",
|
|
28
|
+
CLI_NAME: "alepha",
|
|
29
|
+
CLI_DESCRIPTION: `Alepha CLI v${version} - Create and manage Alepha projects.`,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
alepha.with(AlephaCli);
|
|
34
|
+
|
|
35
|
+
run(alepha);
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { $logger } from "@alepha/logger";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Service for running external processes with logging support.
|
|
8
|
+
*
|
|
9
|
+
* This service wraps Node.js child_process functionality and provides:
|
|
10
|
+
* - Automatic logging of executed commands
|
|
11
|
+
* - Promise-based execution
|
|
12
|
+
* - Inherited stdio for seamless output
|
|
13
|
+
* - Working directory context
|
|
14
|
+
* - Config file management in node_modules/.alepha
|
|
15
|
+
*/
|
|
16
|
+
export class ProcessRunner {
|
|
17
|
+
protected readonly log = $logger();
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Execute a command using npx with inherited stdio.
|
|
21
|
+
*
|
|
22
|
+
* @param command - The command to execute (will be passed to npx)
|
|
23
|
+
* @param env - Optional environment variables to set for the command
|
|
24
|
+
* @returns Promise that resolves when the process exits
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const runner = alepha.inject(ProcessRunner);
|
|
29
|
+
* await runner.exec("tsx watch src/index.ts");
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
public async exec(
|
|
33
|
+
command: string,
|
|
34
|
+
env: Record<string, string> = {},
|
|
35
|
+
): Promise<void> {
|
|
36
|
+
this.log.debug(`Executing command: npx ${command}`, { cwd: process.cwd() });
|
|
37
|
+
|
|
38
|
+
const prog = spawn("npx", command.split(" "), {
|
|
39
|
+
stdio: "inherit",
|
|
40
|
+
cwd: process.cwd(),
|
|
41
|
+
env: {
|
|
42
|
+
...process.env,
|
|
43
|
+
...env,
|
|
44
|
+
NODE_OPTIONS: "--import tsx",
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
await new Promise<void>((resolve) =>
|
|
49
|
+
prog.on("exit", () => {
|
|
50
|
+
resolve();
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Write a configuration file to node_modules/.alepha directory.
|
|
57
|
+
*
|
|
58
|
+
* Creates the .alepha directory if it doesn't exist and writes the file with the given content.
|
|
59
|
+
*
|
|
60
|
+
* @param name - The name of the config file to create
|
|
61
|
+
* @param content - The content to write to the file
|
|
62
|
+
* @param root - The root directory (defaults to process.cwd())
|
|
63
|
+
* @returns The absolute path to the created file
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* const runner = alepha.inject(ProcessRunner);
|
|
68
|
+
* const configPath = await runner.writeConfigFile("biome.json", biomeConfig);
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
public async writeConfigFile(
|
|
72
|
+
name: string,
|
|
73
|
+
content: string,
|
|
74
|
+
root = process.cwd(),
|
|
75
|
+
): Promise<string> {
|
|
76
|
+
const dir = join(root, "node_modules", ".alepha");
|
|
77
|
+
|
|
78
|
+
await mkdir(dir, {
|
|
79
|
+
recursive: true,
|
|
80
|
+
}).catch(() => null);
|
|
81
|
+
|
|
82
|
+
const path = join(dir, name);
|
|
83
|
+
await writeFile(path, content);
|
|
84
|
+
|
|
85
|
+
this.log.debug(`Config file written: ${path}`);
|
|
86
|
+
|
|
87
|
+
return path;
|
|
88
|
+
}
|
|
89
|
+
}
|
package/src/version.ts
ADDED
package/api/files.cjs
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var m = require('@alepha/api-files');
|
|
3
|
-
Object.keys(m).forEach(function (k) {
|
|
4
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
5
|
-
enumerable: true,
|
|
6
|
-
get: function () { return m[k]; }
|
|
7
|
-
});
|
|
8
|
-
});
|