create-vobase 0.1.1 → 0.2.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/dist/index.js +41 -5
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,22 +1,58 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// @bun
|
|
2
3
|
|
|
3
4
|
// index.ts
|
|
5
|
+
var {$ } = globalThis.Bun;
|
|
4
6
|
import { downloadTemplate } from "giget";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
+
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
8
|
+
import { randomBytes } from "crypto";
|
|
9
|
+
import { basename, resolve } from "path";
|
|
10
|
+
import { mkdirSync } from "fs";
|
|
7
11
|
var name = process.argv[2];
|
|
8
12
|
if (!name) {
|
|
9
|
-
console.error("Usage: create
|
|
13
|
+
console.error("Usage: bun create vobase <project-name>");
|
|
10
14
|
process.exit(1);
|
|
11
15
|
}
|
|
12
16
|
var dest = resolve(process.cwd(), name);
|
|
17
|
+
var projectName = basename(dest);
|
|
13
18
|
console.log(`Creating vobase project in ${dest}...`);
|
|
14
19
|
await downloadTemplate("github:vobase/vobase/packages/template", {
|
|
15
20
|
dir: dest,
|
|
16
21
|
force: false
|
|
17
22
|
});
|
|
23
|
+
var pkgPath = resolve(dest, "package.json");
|
|
24
|
+
var pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
25
|
+
pkg.name = projectName;
|
|
26
|
+
delete pkg.private;
|
|
27
|
+
for (const depField of ["dependencies", "devDependencies"]) {
|
|
28
|
+
const deps = pkg[depField];
|
|
29
|
+
if (!deps)
|
|
30
|
+
continue;
|
|
31
|
+
for (const [dep, version] of Object.entries(deps)) {
|
|
32
|
+
if (typeof version === "string" && version.startsWith("workspace:")) {
|
|
33
|
+
const latest = (await $`npm view ${dep} version`.text()).trim();
|
|
34
|
+
deps[dep] = `^${latest}`;
|
|
35
|
+
console.log(` ${dep}: workspace:* \u2192 ^${latest}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + `
|
|
40
|
+
`);
|
|
41
|
+
var envExample = resolve(dest, ".env.example");
|
|
42
|
+
var envFile = resolve(dest, ".env");
|
|
43
|
+
if (existsSync(envExample) && !existsSync(envFile)) {
|
|
44
|
+
let env = readFileSync(envExample, "utf8");
|
|
45
|
+
const secret = randomBytes(32).toString("base64url");
|
|
46
|
+
env = env.replace(/AUTH_SECRET=.*/, `AUTH_SECRET=${secret}`);
|
|
47
|
+
writeFileSync(envFile, env);
|
|
48
|
+
}
|
|
49
|
+
mkdirSync(resolve(dest, "data"), { recursive: true });
|
|
18
50
|
console.log("Installing dependencies...");
|
|
19
|
-
|
|
51
|
+
await $`bun install`.cwd(dest);
|
|
52
|
+
console.log("Generating routes...");
|
|
53
|
+
await $`bun run scripts/generate.ts`.cwd(dest);
|
|
54
|
+
console.log("Setting up database...");
|
|
55
|
+
await $`bun run db:push`.cwd(dest);
|
|
20
56
|
console.log(`
|
|
21
57
|
Done! Your vobase project is ready.
|
|
22
58
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-vobase",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Create a new vobase project",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
|
-
"build": "bun build ./index.ts --outdir ./dist --target=
|
|
18
|
+
"build": "bun build ./index.ts --outdir ./dist --target=bun --packages=external"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"giget": "^2.0.0"
|