velora-dev 0.9.0
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/LICENSE +202 -0
- package/README.md +21 -0
- package/dist/config.d.ts +21 -0
- package/dist/config.js +65 -0
- package/dist/docker.d.ts +4 -0
- package/dist/docker.js +32 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +16 -0
- package/dist/plugin-project.d.ts +1 -0
- package/dist/plugin-project.js +20 -0
- package/dist/sandbox.d.ts +2 -0
- package/dist/sandbox.js +167 -0
- package/docker/compose.yml +39 -0
- package/package.json +31 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# velora-dev
|
|
2
|
+
|
|
3
|
+
A local dev sandbox for the Velora CMS server: spins up a database
|
|
4
|
+
container (PostgreSQL or MySQL via Docker, or SQLite with no container) for
|
|
5
|
+
a chosen dialect and starts the server against it, generating the matching
|
|
6
|
+
Prisma schema variant along the way. Intended to be run from within a
|
|
7
|
+
Velora monorepo checkout.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install --save-dev velora-dev
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npx velora-dev --db=postgresql
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Part of [Velora](https://github.com/velora-cms/velora). Apache-2.0.
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare class SandboxError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
declare const DIALECTS: readonly ["sqlite", "postgres", "mysql"];
|
|
5
|
+
export type SandboxDialect = (typeof DIALECTS)[number];
|
|
6
|
+
export interface SandboxConfig {
|
|
7
|
+
dialect: SandboxDialect;
|
|
8
|
+
repoRoot: string;
|
|
9
|
+
cwd: string;
|
|
10
|
+
stateDir: string;
|
|
11
|
+
serverPort: number;
|
|
12
|
+
adminPort: number;
|
|
13
|
+
contentDatabaseUrl: string;
|
|
14
|
+
prismaDatabaseUrl: string;
|
|
15
|
+
prismaClientDir: string;
|
|
16
|
+
composeService: "postgres-sandbox" | "mysql-sandbox" | null;
|
|
17
|
+
adminEmail: string;
|
|
18
|
+
adminPassword: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function resolveSandboxConfig(argv: string[], cwd: string): SandboxConfig;
|
|
21
|
+
export {};
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
export class SandboxError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "SandboxError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const DIALECTS = ["sqlite", "postgres", "mysql"];
|
|
11
|
+
// Forward slashes everywhere: Prisma file: URLs and generator output
|
|
12
|
+
// paths both accept them on Windows, and they keep tests platform-stable.
|
|
13
|
+
function fwd(path) {
|
|
14
|
+
return path.replaceAll("\\", "/");
|
|
15
|
+
}
|
|
16
|
+
const CONTENT_URLS = {
|
|
17
|
+
sqlite: (stateDir) => `file:${stateDir}/content.db`,
|
|
18
|
+
postgres: () => "postgres://velora:velora@localhost:5435/velora_sandbox",
|
|
19
|
+
mysql: () => "mysql://velora:velora@localhost:3308/velora_sandbox",
|
|
20
|
+
};
|
|
21
|
+
const COMPOSE_SERVICES = {
|
|
22
|
+
sqlite: null,
|
|
23
|
+
postgres: "postgres-sandbox",
|
|
24
|
+
mysql: "mysql-sandbox",
|
|
25
|
+
};
|
|
26
|
+
const USAGE = "Usage: velora-dev start [--db sqlite|postgres|mysql]";
|
|
27
|
+
export function resolveSandboxConfig(argv, cwd) {
|
|
28
|
+
let values;
|
|
29
|
+
let positionals;
|
|
30
|
+
try {
|
|
31
|
+
({ values, positionals } = parseArgs({
|
|
32
|
+
args: argv,
|
|
33
|
+
allowPositionals: true,
|
|
34
|
+
options: { db: { type: "string" } },
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
39
|
+
throw new SandboxError(`${USAGE} — ${reason}`);
|
|
40
|
+
}
|
|
41
|
+
if (positionals[0] !== "start" || positionals.length !== 1) {
|
|
42
|
+
throw new SandboxError('Usage: velora-dev start [--db sqlite|postgres|mysql] — "start" is the only command.');
|
|
43
|
+
}
|
|
44
|
+
const dialect = (values.db ?? "sqlite");
|
|
45
|
+
if (!DIALECTS.includes(dialect)) {
|
|
46
|
+
throw new SandboxError(`Unknown --db "${values.db}". Valid values: sqlite, postgres, mysql.`);
|
|
47
|
+
}
|
|
48
|
+
// packages/velora-dev/src/config.ts → three levels up is the repo root.
|
|
49
|
+
const repoRoot = fwd(resolve(dirname(fileURLToPath(import.meta.url)), "..", "..", ".."));
|
|
50
|
+
const stateDir = fwd(join(cwd, ".velora-dev"));
|
|
51
|
+
return {
|
|
52
|
+
dialect,
|
|
53
|
+
repoRoot,
|
|
54
|
+
cwd: fwd(cwd),
|
|
55
|
+
stateDir,
|
|
56
|
+
serverPort: 3100,
|
|
57
|
+
adminPort: 5273,
|
|
58
|
+
contentDatabaseUrl: CONTENT_URLS[dialect](stateDir),
|
|
59
|
+
prismaDatabaseUrl: `file:${stateDir}/prisma.db`,
|
|
60
|
+
prismaClientDir: `${stateDir}/prisma-client`,
|
|
61
|
+
composeService: COMPOSE_SERVICES[dialect],
|
|
62
|
+
adminEmail: "admin@velora.dev",
|
|
63
|
+
adminPassword: "velora",
|
|
64
|
+
};
|
|
65
|
+
}
|
package/dist/docker.d.ts
ADDED
package/dist/docker.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { SandboxError } from "./config.js";
|
|
4
|
+
// All docker interaction is synchronous — each step must finish before
|
|
5
|
+
// the next starts, and none is long-running (compose --wait blocks until
|
|
6
|
+
// the healthcheck passes). shell:true throughout: Windows resolves
|
|
7
|
+
// docker/pnpm through .cmd shims.
|
|
8
|
+
function composeFile(config) {
|
|
9
|
+
return join(config.repoRoot, "packages", "velora-dev", "docker", "compose.yml");
|
|
10
|
+
}
|
|
11
|
+
export function assertDockerAvailable(dialect) {
|
|
12
|
+
const result = spawnSync("docker", ["info"], { shell: true, stdio: "ignore" });
|
|
13
|
+
if (result.status !== 0) {
|
|
14
|
+
throw new SandboxError(`Docker is required for --db=${dialect}. Start Docker Desktop (or the docker daemon) and retry.`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function composeUp(config) {
|
|
18
|
+
if (!config.composeService)
|
|
19
|
+
return;
|
|
20
|
+
const result = spawnSync("docker", ["compose", "-p", "velora-dev", "-f", composeFile(config), "up", "-d", "--wait", config.composeService], { shell: true, stdio: "inherit" });
|
|
21
|
+
if (result.status !== 0) {
|
|
22
|
+
throw new SandboxError(`docker compose up failed for ${config.composeService} (see output above).`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function composeStop(config) {
|
|
26
|
+
if (!config.composeService)
|
|
27
|
+
return;
|
|
28
|
+
spawnSync("docker", ["compose", "-p", "velora-dev", "-f", composeFile(config), "stop", config.composeService], {
|
|
29
|
+
shell: true,
|
|
30
|
+
stdio: "ignore",
|
|
31
|
+
});
|
|
32
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { SandboxError, resolveSandboxConfig } from "./config.js";
|
|
3
|
+
import { startSandbox } from "./sandbox.js";
|
|
4
|
+
async function main() {
|
|
5
|
+
const config = resolveSandboxConfig(process.argv.slice(2), process.cwd());
|
|
6
|
+
await startSandbox(config);
|
|
7
|
+
}
|
|
8
|
+
main().catch((error) => {
|
|
9
|
+
if (error instanceof SandboxError) {
|
|
10
|
+
console.error(`\n[velora-dev] ${error.message}`);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
console.error(error);
|
|
14
|
+
}
|
|
15
|
+
process.exit(1);
|
|
16
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function detectPluginProject(cwd: string): boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
// Implicit detection (no CLI flag): a directory counts as a plugin
|
|
4
|
+
// project when it depends on @velora-cms/plugin-sdk and has its own Vite
|
|
5
|
+
// config — the same two facts every create-velora-plugin scaffold and
|
|
6
|
+
// hand-built plugin (google-maps) share.
|
|
7
|
+
export function detectPluginProject(cwd) {
|
|
8
|
+
const packageJsonPath = join(cwd, "package.json");
|
|
9
|
+
if (!existsSync(packageJsonPath))
|
|
10
|
+
return false;
|
|
11
|
+
if (!existsSync(join(cwd, "vite.config.ts")))
|
|
12
|
+
return false;
|
|
13
|
+
try {
|
|
14
|
+
const pkg = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
15
|
+
return Boolean(pkg.dependencies?.["@velora-cms/plugin-sdk"]);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
package/dist/sandbox.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
+
import { randomBytes } from "node:crypto";
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { SandboxError } from "./config.js";
|
|
6
|
+
import { toSqliteSchema } from "@velora-cms/prisma-variants";
|
|
7
|
+
import { assertDockerAvailable, composeStop, composeUp } from "./docker.js";
|
|
8
|
+
import { detectPluginProject } from "./plugin-project.js";
|
|
9
|
+
// The start orchestration, in spec order: state dir → database up →
|
|
10
|
+
// prisma prep → seed → spawn server+admin → readiness → banner.
|
|
11
|
+
// Ctrl-C: kill children, stop containers (data kept).
|
|
12
|
+
function sandboxEnv(config, jwtSecret) {
|
|
13
|
+
// PluginRegistryService's install() compatibility gate needs the
|
|
14
|
+
// FULL dialect name ("postgresql", not the sandbox's "postgres"
|
|
15
|
+
// shorthand) — mapped once here so register-local-plugin.ts doesn't
|
|
16
|
+
// need to know about velora-dev's own naming convention.
|
|
17
|
+
const activeDialect = config.dialect === "postgres" ? "postgresql" : config.dialect;
|
|
18
|
+
return {
|
|
19
|
+
...process.env,
|
|
20
|
+
PORT: String(config.serverPort),
|
|
21
|
+
HOST: "127.0.0.1",
|
|
22
|
+
DATABASE_URL: config.prismaDatabaseUrl,
|
|
23
|
+
VELORA_CONTENT_DATABASE_URL: config.contentDatabaseUrl,
|
|
24
|
+
VELORA_PRISMA_CLIENT_DIR: config.prismaClientDir,
|
|
25
|
+
JWT_SECRET: jwtSecret,
|
|
26
|
+
VELORA_API_PROXY: `http://localhost:${config.serverPort}`,
|
|
27
|
+
VELORA_SANDBOX_ADMIN_EMAIL: config.adminEmail,
|
|
28
|
+
VELORA_SANDBOX_ADMIN_PASSWORD: config.adminPassword,
|
|
29
|
+
VELORA_PLUGIN_ACTIVE_DIALECT: activeDialect,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function loadOrCreateJwtSecret(config) {
|
|
33
|
+
const file = join(config.stateDir, "jwt-secret");
|
|
34
|
+
if (existsSync(file))
|
|
35
|
+
return readFileSync(file, "utf8").trim();
|
|
36
|
+
const secret = randomBytes(32).toString("hex");
|
|
37
|
+
writeFileSync(file, secret);
|
|
38
|
+
return secret;
|
|
39
|
+
}
|
|
40
|
+
function runStep(name, command, args, config, env) {
|
|
41
|
+
console.log(`[velora-dev] ${name}…`);
|
|
42
|
+
const result = spawnSync(command, args, { shell: true, stdio: "inherit", cwd: config.repoRoot, env });
|
|
43
|
+
if (result.status !== 0) {
|
|
44
|
+
throw new SandboxError(`${name} failed (exit ${result.status}). See output above.`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function preparePrisma(config, env) {
|
|
48
|
+
const source = readFileSync(join(config.repoRoot, "apps", "server", "prisma", "schema.prisma"), "utf8");
|
|
49
|
+
// The variant schema must live inside apps/server, not the sandbox state
|
|
50
|
+
// dir: `prisma generate` resolves `prisma`/`@prisma/client` by walking up
|
|
51
|
+
// from the schema file's own directory (not from the invoking cwd), and
|
|
52
|
+
// pnpm's workspace hoisting only installs those packages under
|
|
53
|
+
// apps/server/node_modules, never at the repo root. A schema file placed
|
|
54
|
+
// outside apps/server can't find them, so Prisma's CLI falls back to an
|
|
55
|
+
// auto-install that runs `pnpm add prisma -D` against the repo root —
|
|
56
|
+
// which fails outright since that's a workspace root, not a package.
|
|
57
|
+
// `prisma db push` has no such requirement (it never resolves
|
|
58
|
+
// @prisma/client), which is why only `generate` broke.
|
|
59
|
+
const variantPath = join(config.repoRoot, "apps", "server", "prisma", ".velora-dev-sandbox.schema.prisma");
|
|
60
|
+
writeFileSync(variantPath, toSqliteSchema(source, config.prismaClientDir));
|
|
61
|
+
runStep("prisma db push", "pnpm", ["--filter", "@velora-cms/server", "exec", "prisma", "db", "push", "--schema", variantPath, "--skip-generate"], config, env);
|
|
62
|
+
runStep("prisma generate", "pnpm", ["--filter", "@velora-cms/server", "exec", "prisma", "generate", "--schema", variantPath], config, env);
|
|
63
|
+
}
|
|
64
|
+
function killTree(child) {
|
|
65
|
+
if (child.pid === undefined || child.exitCode !== null)
|
|
66
|
+
return;
|
|
67
|
+
if (process.platform === "win32") {
|
|
68
|
+
spawnSync("taskkill", ["/pid", String(child.pid), "/t", "/f"], { stdio: "ignore", shell: true });
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
child.kill();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function waitFor(name, url, child, timeoutMs) {
|
|
75
|
+
const deadline = Date.now() + timeoutMs;
|
|
76
|
+
while (Date.now() < deadline) {
|
|
77
|
+
if (child.exitCode !== null) {
|
|
78
|
+
throw new SandboxError(`${name} exited before becoming ready (exit ${child.exitCode}) — if the port is in use, another sandbox or dev instance is probably running.`);
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const response = await fetch(url);
|
|
82
|
+
if (response.ok)
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
// not up yet
|
|
87
|
+
}
|
|
88
|
+
await new Promise((resolveWait) => setTimeout(resolveWait, 500));
|
|
89
|
+
}
|
|
90
|
+
throw new SandboxError(`${name} did not become ready within ${timeoutMs / 1000}s (${url}).`);
|
|
91
|
+
}
|
|
92
|
+
export async function startSandbox(config) {
|
|
93
|
+
mkdirSync(config.stateDir, { recursive: true });
|
|
94
|
+
const jwtSecret = loadOrCreateJwtSecret(config);
|
|
95
|
+
const env = sandboxEnv(config, jwtSecret);
|
|
96
|
+
if (config.composeService) {
|
|
97
|
+
assertDockerAvailable(config.dialect);
|
|
98
|
+
composeUp(config);
|
|
99
|
+
}
|
|
100
|
+
const children = [];
|
|
101
|
+
const spawnChild = (args, cwd = config.repoRoot) => {
|
|
102
|
+
const child = spawn("pnpm", args, { shell: true, stdio: "inherit", cwd, env });
|
|
103
|
+
children.push(child);
|
|
104
|
+
return child;
|
|
105
|
+
};
|
|
106
|
+
const teardown = (code) => {
|
|
107
|
+
for (const child of children)
|
|
108
|
+
killTree(child);
|
|
109
|
+
composeStop(config);
|
|
110
|
+
process.exit(code);
|
|
111
|
+
};
|
|
112
|
+
process.on("SIGINT", () => {
|
|
113
|
+
console.log("\n[velora-dev] shutting down…");
|
|
114
|
+
teardown(0);
|
|
115
|
+
});
|
|
116
|
+
const pluginPort = 5474;
|
|
117
|
+
const isPluginProject = detectPluginProject(config.cwd);
|
|
118
|
+
try {
|
|
119
|
+
preparePrisma(config, env);
|
|
120
|
+
runStep("seed", "pnpm", ["--filter", "@velora-cms/server", "exec", "tsx", "src/sandbox/seed-sandbox.ts"], config, env);
|
|
121
|
+
writeFileSync(join(config.stateDir, "credentials.json"), JSON.stringify({ url: `http://localhost:${config.adminPort}`, email: config.adminEmail, password: config.adminPassword }, null, 2));
|
|
122
|
+
if (isPluginProject) {
|
|
123
|
+
console.log(`[velora-dev] plugin project detected at ${config.cwd} — starting its dev server…`);
|
|
124
|
+
const pluginChild = spawnChild(["exec", "vite", "--port", String(pluginPort), "--strictPort"], config.cwd);
|
|
125
|
+
// A federation-remote-only project has no index.html, so vite's dev
|
|
126
|
+
// server 404s on "/" forever — poll the file it actually exposes.
|
|
127
|
+
await waitFor("plugin dev server", `http://localhost:${pluginPort}/remoteEntry.js`, pluginChild, 60_000);
|
|
128
|
+
runStep("register local plugin", "pnpm", [
|
|
129
|
+
"--filter",
|
|
130
|
+
"@velora-cms/server",
|
|
131
|
+
"exec",
|
|
132
|
+
"tsx",
|
|
133
|
+
"src/sandbox/register-local-plugin.ts",
|
|
134
|
+
config.cwd,
|
|
135
|
+
`http://localhost:${pluginPort}/remoteEntry.js`,
|
|
136
|
+
], config, env);
|
|
137
|
+
}
|
|
138
|
+
console.log("[velora-dev] starting server + admin…");
|
|
139
|
+
const server = spawnChild(["--filter", "@velora-cms/server", "exec", "tsx", "watch", "src/index.ts"]);
|
|
140
|
+
const admin = spawnChild([
|
|
141
|
+
"--filter",
|
|
142
|
+
"@velora-cms/admin-ui",
|
|
143
|
+
"exec",
|
|
144
|
+
"vite",
|
|
145
|
+
"--port",
|
|
146
|
+
String(config.adminPort),
|
|
147
|
+
"--strictPort",
|
|
148
|
+
]);
|
|
149
|
+
await waitFor("server", `http://localhost:${config.serverPort}/api/health`, server, 60_000);
|
|
150
|
+
await waitFor("admin UI", `http://localhost:${config.adminPort}`, admin, 60_000);
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
for (const child of children)
|
|
154
|
+
killTree(child);
|
|
155
|
+
composeStop(config);
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
console.log(`
|
|
159
|
+
┌─────────────────────────────────────────────┐
|
|
160
|
+
│ Velora sandbox is ready (${config.dialect.padEnd(8)}) │
|
|
161
|
+
│ │
|
|
162
|
+
│ Admin: http://localhost:${config.adminPort} │
|
|
163
|
+
│ Login: ${config.adminEmail} │
|
|
164
|
+
│ Password: ${config.adminPassword} │
|
|
165
|
+
${isPluginProject ? `│ Plugin: http://localhost:${pluginPort} (hot reload on) │\n` : ""}│ Ctrl-C stops everything (data is kept). │
|
|
166
|
+
└─────────────────────────────────────────────┘`);
|
|
167
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
services:
|
|
2
|
+
postgres-sandbox:
|
|
3
|
+
image: postgres:16-alpine
|
|
4
|
+
environment:
|
|
5
|
+
POSTGRES_USER: velora
|
|
6
|
+
POSTGRES_PASSWORD: velora
|
|
7
|
+
POSTGRES_DB: velora_sandbox
|
|
8
|
+
ports:
|
|
9
|
+
# 5435: distinct from the repo's dev (5434) and test (5433) databases.
|
|
10
|
+
- "5435:5432"
|
|
11
|
+
volumes:
|
|
12
|
+
- postgres-sandbox-data:/var/lib/postgresql/data
|
|
13
|
+
healthcheck:
|
|
14
|
+
test: ["CMD-SHELL", "pg_isready -U velora -d velora_sandbox"]
|
|
15
|
+
interval: 2s
|
|
16
|
+
timeout: 3s
|
|
17
|
+
retries: 30
|
|
18
|
+
|
|
19
|
+
mysql-sandbox:
|
|
20
|
+
image: mysql:8.4
|
|
21
|
+
environment:
|
|
22
|
+
MYSQL_ROOT_PASSWORD: velora
|
|
23
|
+
MYSQL_USER: velora
|
|
24
|
+
MYSQL_PASSWORD: velora
|
|
25
|
+
MYSQL_DATABASE: velora_sandbox
|
|
26
|
+
ports:
|
|
27
|
+
# 3308: distinct from the repo's mysql-test (3307).
|
|
28
|
+
- "3308:3306"
|
|
29
|
+
volumes:
|
|
30
|
+
- mysql-sandbox-data:/var/lib/mysql
|
|
31
|
+
healthcheck:
|
|
32
|
+
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-uvelora", "-pvelora"]
|
|
33
|
+
interval: 2s
|
|
34
|
+
timeout: 3s
|
|
35
|
+
retries: 45
|
|
36
|
+
|
|
37
|
+
volumes:
|
|
38
|
+
postgres-sandbox-data:
|
|
39
|
+
mysql-sandbox-data:
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "velora-dev",
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"velora-dev": "dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"docker"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/velora-cms/velora.git",
|
|
16
|
+
"directory": "packages/velora-dev"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@velora-cms/prisma-variants": "0.9.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "20.19.43"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc -p .",
|
|
29
|
+
"test": "vitest run"
|
|
30
|
+
}
|
|
31
|
+
}
|