@shophost/rest-api 2.0.21 → 2.0.23
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 +1 -1
- package/package.json +2 -1
- package/scripts/shophost-rest-api.mjs +51 -1
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ import { ManufacturerSchema } from "@shophost/rest-api/schemas";
|
|
|
46
46
|
|
|
47
47
|
The published package now includes a small CLI so a fresh project can push the packaged Prisma schema to its own database.
|
|
48
48
|
|
|
49
|
-
1. Set one of these environment variables in your app
|
|
49
|
+
1. Set one of these environment variables in your app shell, `.env`, or `.env.local`:
|
|
50
50
|
- `DATABASE_URL`
|
|
51
51
|
- `POSTGRES_PRISMA_URL`
|
|
52
52
|
2. Run:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shophost/rest-api",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.23",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"shophost-rest-api": "./scripts/shophost-rest-api.mjs"
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
"axios": "^1.8.2",
|
|
77
77
|
"better-auth": "^1.5.5",
|
|
78
78
|
"date-fns": "^4.1.0",
|
|
79
|
+
"dotenv": "^16.4.7",
|
|
79
80
|
"hono": "^4.10.6",
|
|
80
81
|
"http-status-codes": "^2.3.0",
|
|
81
82
|
"nanoid": "^5.1.3",
|
|
@@ -5,6 +5,7 @@ import { existsSync } from "node:fs";
|
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
6
|
import { dirname, join } from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
|
+
import dotenv from "dotenv";
|
|
8
9
|
|
|
9
10
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
10
11
|
const packageRoot = join(__dirname, "..");
|
|
@@ -26,6 +27,8 @@ Examples:
|
|
|
26
27
|
shophost-rest-api db push --url "postgres://..."
|
|
27
28
|
|
|
28
29
|
Environment:
|
|
30
|
+
.env.local
|
|
31
|
+
.env
|
|
29
32
|
DATABASE_URL
|
|
30
33
|
POSTGRES_PRISMA_URL
|
|
31
34
|
`);
|
|
@@ -56,6 +59,51 @@ function getDbPushArgs(argv) {
|
|
|
56
59
|
return argv.slice(2);
|
|
57
60
|
}
|
|
58
61
|
|
|
62
|
+
function expandEnvValue(value, env) {
|
|
63
|
+
return value.replace(
|
|
64
|
+
/\\?\$(?:\{([A-Za-z_][A-Za-z0-9_]*)\}|([A-Za-z_][A-Za-z0-9_]*))/g,
|
|
65
|
+
(match, bracedName, plainName) => {
|
|
66
|
+
if (match.startsWith("\\")) {
|
|
67
|
+
return match.slice(1);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const variableName = bracedName ?? plainName;
|
|
71
|
+
return env[variableName] ?? "";
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function applyParsedEnv(parsed, shouldOverride) {
|
|
77
|
+
if (!parsed) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
for (const [key, rawValue] of Object.entries(parsed)) {
|
|
82
|
+
if (!shouldOverride && process.env[key] !== undefined) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
process.env[key] = expandEnvValue(rawValue, process.env);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function loadEnvFiles() {
|
|
91
|
+
for (const envFile of [".env", ".env.local"]) {
|
|
92
|
+
const envPath = join(process.cwd(), envFile);
|
|
93
|
+
|
|
94
|
+
if (!existsSync(envPath)) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const result = dotenv.config({
|
|
99
|
+
path: envPath,
|
|
100
|
+
override: envFile === ".env.local",
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
applyParsedEnv(result.parsed, envFile === ".env.local");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
59
107
|
const argv = process.argv.slice(2);
|
|
60
108
|
|
|
61
109
|
if (
|
|
@@ -89,6 +137,8 @@ if (reservedFlag) {
|
|
|
89
137
|
process.exit(1);
|
|
90
138
|
}
|
|
91
139
|
|
|
140
|
+
loadEnvFiles();
|
|
141
|
+
|
|
92
142
|
if (!existsSync(schemaPath)) {
|
|
93
143
|
console.error(`Missing Prisma schema at ${schemaPath}`);
|
|
94
144
|
process.exit(1);
|
|
@@ -113,7 +163,7 @@ if (
|
|
|
113
163
|
!process.env.POSTGRES_PRISMA_URL
|
|
114
164
|
) {
|
|
115
165
|
console.error(
|
|
116
|
-
"Set DATABASE_URL or POSTGRES_PRISMA_URL before running `shophost-rest-api db push`."
|
|
166
|
+
"Set DATABASE_URL or POSTGRES_PRISMA_URL, or add it to `.env.local` / `.env`, before running `shophost-rest-api db push`."
|
|
117
167
|
);
|
|
118
168
|
process.exit(1);
|
|
119
169
|
}
|