alepha 0.11.9 → 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.
Files changed (166) hide show
  1. package/README.md +55 -17
  2. package/dist/index.cjs +15805 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.cts +1 -0
  5. package/dist/index.d.ts +2 -0
  6. package/dist/index.js +15804 -0
  7. package/dist/index.js.map +1 -0
  8. package/package.json +36 -365
  9. package/src/assets/biomeJson.ts +33 -0
  10. package/src/assets/tsconfigJson.ts +17 -0
  11. package/src/assets/viteConfigTs.ts +14 -0
  12. package/src/commands/BiomeCommands.ts +60 -0
  13. package/src/commands/CoreCommands.ts +266 -0
  14. package/src/commands/DrizzleCommands.ts +403 -0
  15. package/src/commands/VerifyCommands.ts +48 -0
  16. package/src/commands/ViteCommands.ts +152 -0
  17. package/src/index.ts +35 -0
  18. package/src/services/ProcessRunner.ts +89 -0
  19. package/src/version.ts +7 -0
  20. package/api/files.cjs +0 -8
  21. package/api/files.d.ts +0 -438
  22. package/api/files.js +0 -1
  23. package/api/jobs.cjs +0 -8
  24. package/api/jobs.d.ts +0 -327
  25. package/api/jobs.js +0 -1
  26. package/api/notifications.cjs +0 -8
  27. package/api/notifications.d.ts +0 -263
  28. package/api/notifications.js +0 -1
  29. package/api/users.cjs +0 -8
  30. package/api/users.d.ts +0 -923
  31. package/api/users.js +0 -1
  32. package/api/verifications.cjs +0 -8
  33. package/api/verifications.d.ts +0 -1
  34. package/api/verifications.js +0 -1
  35. package/batch.cjs +0 -8
  36. package/batch.d.ts +0 -154
  37. package/batch.js +0 -1
  38. package/bucket.cjs +0 -8
  39. package/bucket.d.ts +0 -520
  40. package/bucket.js +0 -1
  41. package/cache/redis.cjs +0 -8
  42. package/cache/redis.d.ts +0 -40
  43. package/cache/redis.js +0 -1
  44. package/cache.cjs +0 -8
  45. package/cache.d.ts +0 -288
  46. package/cache.js +0 -1
  47. package/command.cjs +0 -8
  48. package/command.d.ts +0 -269
  49. package/command.js +0 -1
  50. package/core.cjs +0 -8
  51. package/core.d.ts +0 -1904
  52. package/core.js +0 -1
  53. package/datetime.cjs +0 -8
  54. package/datetime.d.ts +0 -144
  55. package/datetime.js +0 -1
  56. package/devtools.cjs +0 -8
  57. package/devtools.d.ts +0 -252
  58. package/devtools.js +0 -1
  59. package/email.cjs +0 -8
  60. package/email.d.ts +0 -187
  61. package/email.js +0 -1
  62. package/fake.cjs +0 -8
  63. package/fake.d.ts +0 -73
  64. package/fake.js +0 -1
  65. package/file.cjs +0 -8
  66. package/file.d.ts +0 -528
  67. package/file.js +0 -1
  68. package/lock/redis.cjs +0 -8
  69. package/lock/redis.d.ts +0 -24
  70. package/lock/redis.js +0 -1
  71. package/lock.cjs +0 -8
  72. package/lock.d.ts +0 -552
  73. package/lock.js +0 -1
  74. package/logger.cjs +0 -8
  75. package/logger.d.ts +0 -287
  76. package/logger.js +0 -1
  77. package/postgres.cjs +0 -8
  78. package/postgres.d.ts +0 -2143
  79. package/postgres.js +0 -1
  80. package/queue/redis.cjs +0 -8
  81. package/queue/redis.d.ts +0 -29
  82. package/queue/redis.js +0 -1
  83. package/queue.cjs +0 -8
  84. package/queue.d.ts +0 -760
  85. package/queue.js +0 -1
  86. package/react/auth.cjs +0 -8
  87. package/react/auth.d.ts +0 -504
  88. package/react/auth.js +0 -1
  89. package/react/form.cjs +0 -8
  90. package/react/form.d.ts +0 -211
  91. package/react/form.js +0 -1
  92. package/react/head.cjs +0 -8
  93. package/react/head.d.ts +0 -120
  94. package/react/head.js +0 -1
  95. package/react/i18n.cjs +0 -8
  96. package/react/i18n.d.ts +0 -168
  97. package/react/i18n.js +0 -1
  98. package/react.cjs +0 -8
  99. package/react.d.ts +0 -1263
  100. package/react.js +0 -1
  101. package/redis.cjs +0 -8
  102. package/redis.d.ts +0 -82
  103. package/redis.js +0 -1
  104. package/retry.cjs +0 -8
  105. package/retry.d.ts +0 -162
  106. package/retry.js +0 -1
  107. package/router.cjs +0 -8
  108. package/router.d.ts +0 -45
  109. package/router.js +0 -1
  110. package/scheduler.cjs +0 -8
  111. package/scheduler.d.ts +0 -145
  112. package/scheduler.js +0 -1
  113. package/security.cjs +0 -8
  114. package/security.d.ts +0 -586
  115. package/security.js +0 -1
  116. package/server/cache.cjs +0 -8
  117. package/server/cache.d.ts +0 -163
  118. package/server/cache.js +0 -1
  119. package/server/compress.cjs +0 -8
  120. package/server/compress.d.ts +0 -38
  121. package/server/compress.js +0 -1
  122. package/server/cookies.cjs +0 -8
  123. package/server/cookies.d.ts +0 -144
  124. package/server/cookies.js +0 -1
  125. package/server/cors.cjs +0 -8
  126. package/server/cors.d.ts +0 -45
  127. package/server/cors.js +0 -1
  128. package/server/health.cjs +0 -8
  129. package/server/health.d.ts +0 -58
  130. package/server/health.js +0 -1
  131. package/server/helmet.cjs +0 -8
  132. package/server/helmet.d.ts +0 -98
  133. package/server/helmet.js +0 -1
  134. package/server/links.cjs +0 -8
  135. package/server/links.d.ts +0 -322
  136. package/server/links.js +0 -1
  137. package/server/metrics.cjs +0 -8
  138. package/server/metrics.d.ts +0 -35
  139. package/server/metrics.js +0 -1
  140. package/server/multipart.cjs +0 -8
  141. package/server/multipart.d.ts +0 -42
  142. package/server/multipart.js +0 -1
  143. package/server/proxy.cjs +0 -8
  144. package/server/proxy.d.ts +0 -234
  145. package/server/proxy.js +0 -1
  146. package/server/security.cjs +0 -8
  147. package/server/security.d.ts +0 -92
  148. package/server/security.js +0 -1
  149. package/server/static.cjs +0 -8
  150. package/server/static.d.ts +0 -119
  151. package/server/static.js +0 -1
  152. package/server/swagger.cjs +0 -8
  153. package/server/swagger.d.ts +0 -161
  154. package/server/swagger.js +0 -1
  155. package/server.cjs +0 -8
  156. package/server.d.ts +0 -849
  157. package/server.js +0 -1
  158. package/topic/redis.cjs +0 -8
  159. package/topic/redis.d.ts +0 -42
  160. package/topic/redis.js +0 -1
  161. package/topic.cjs +0 -8
  162. package/topic.d.ts +0 -819
  163. package/topic.js +0 -1
  164. package/vite.cjs +0 -8
  165. package/vite.d.ts +0 -186
  166. 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
@@ -0,0 +1,7 @@
1
+ import { readFileSync } from "node:fs";
2
+
3
+ const packageJson = JSON.parse(
4
+ readFileSync(new URL("../package.json", import.meta.url), "utf-8"),
5
+ );
6
+
7
+ export const version = packageJson.version;
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
- });