create-cloud-db 1.0.2 → 1.0.4
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 +93 -0
- package/create-cloud-db.js +58 -19
- package/package.json +3 -3
- package/.env +0 -6
- package/CHANGELOG.md +0 -7
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# create-cloud-db
|
|
2
|
+
|
|
3
|
+
[NPM](https://www.npmjs.com/package/create-cloud-db)
|
|
4
|
+
|
|
5
|
+
`create-cloud-db` is a small CLI that creates a Turso database and manages the `TURSO_DATABASE_URL` and `TURSO_AUTH_TOKEN` values in your local `.env` file.
|
|
6
|
+
|
|
7
|
+
It is designed for quick local setup so you can be ready to connect from Node, frameworks, or serverless environments with minimal manual configuration.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
You must first login to turso with:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
bun i -g turso
|
|
15
|
+
turso auth login
|
|
16
|
+
|
|
17
|
+
# or
|
|
18
|
+
bun x turso auth login
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Then run:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# will ask for name
|
|
25
|
+
npm create cloud-db
|
|
26
|
+
|
|
27
|
+
# or
|
|
28
|
+
npx create-cloud-db
|
|
29
|
+
|
|
30
|
+
# or
|
|
31
|
+
npx create-cloud-db [myapp-db]
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Or install globally:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm install -g create-cloud-db
|
|
39
|
+
create-cloud-db myapp-db
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## What it does
|
|
43
|
+
|
|
44
|
+
When you run the command, the CLI:
|
|
45
|
+
|
|
46
|
+
1. Ensures you are logged into Turso via `turso auth login`.
|
|
47
|
+
2. Creates a Turso database if it does not already exist.
|
|
48
|
+
3. Generates a database URL and an auth token via the Turso CLI.
|
|
49
|
+
4. Overwrites (not appends) the `TURSO_DATABASE_URL` and `TURSO_AUTH_TOKEN` entries in your local `.env` file.
|
|
50
|
+
|
|
51
|
+
After running, your `.env` file will contain something like:
|
|
52
|
+
|
|
53
|
+
```env
|
|
54
|
+
TURSO_DATABASE_URL=libsql://your-db-name.region.turso.io
|
|
55
|
+
TURSO_AUTH_TOKEN=eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9...
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Add to package.json
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
"db:create": "create-cloud-db",
|
|
62
|
+
"db:generate": "drizzle-kit generate",
|
|
63
|
+
"db:push": "drizzle-kit push",
|
|
64
|
+
"db:studio": "drizzle-kit studio",
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Environment file behavior
|
|
68
|
+
|
|
69
|
+
- The CLI reads your existing `.env` file if present.
|
|
70
|
+
- It updates or inserts `TURSO_DATABASE_URL` and `TURSO_AUTH_TOKEN` keys.
|
|
71
|
+
- The `.env` file is rewritten, so old placeholder values are removed and replaced with valid values.
|
|
72
|
+
|
|
73
|
+
### Example with Drizzle
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
// drizzle.config.ts
|
|
77
|
+
|
|
78
|
+
import { defineConfig } from 'drizzle-kit';
|
|
79
|
+
|
|
80
|
+
export default defineConfig({
|
|
81
|
+
dialect: 'turso',
|
|
82
|
+
schema: './src/lib/db/schema.ts',
|
|
83
|
+
out: './drizzle',
|
|
84
|
+
dbCredentials: {
|
|
85
|
+
url: process.env.TURSO_DATABASE_URL || 'file:./localdb.sqlite',
|
|
86
|
+
authToken: process.env.TURSO_AUTH_TOKEN,
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## 📝 License
|
|
92
|
+
|
|
93
|
+
MIT License - Star this repo so it can grow features! 🌟
|
package/create-cloud-db.js
CHANGED
|
@@ -53,38 +53,69 @@ async function ensureLogin() {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
// Parse env file into
|
|
56
|
+
// Parse env file into array of line objects to preserve comments/whitespace
|
|
57
57
|
function readEnvFile(filePath) {
|
|
58
|
-
if (!fs.existsSync(filePath)) return
|
|
58
|
+
if (!fs.existsSync(filePath)) return [];
|
|
59
59
|
const content = fs.readFileSync(filePath, "utf8");
|
|
60
60
|
const lines = content.split(/\r?\n/);
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
for (const line of lines) {
|
|
62
|
+
return lines.map((line) => {
|
|
64
63
|
const trimmed = line.trim();
|
|
65
|
-
|
|
64
|
+
|
|
65
|
+
// Blank line
|
|
66
|
+
if (!trimmed) {
|
|
67
|
+
return { type: 'blank', line };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Comment line
|
|
71
|
+
if (trimmed.startsWith("#")) {
|
|
72
|
+
return { type: 'comment', line };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Key-value pair
|
|
66
76
|
const idx = trimmed.indexOf("=");
|
|
67
|
-
if (idx === -1)
|
|
77
|
+
if (idx === -1) {
|
|
78
|
+
return { type: 'other', line };
|
|
79
|
+
}
|
|
80
|
+
|
|
68
81
|
const key = trimmed.slice(0, idx).trim();
|
|
69
82
|
let value = trimmed.slice(idx + 1).trim();
|
|
83
|
+
|
|
84
|
+
// Remove quotes from value if present
|
|
70
85
|
if (
|
|
71
86
|
(value.startsWith('"') && value.endsWith('"')) ||
|
|
72
87
|
(value.startsWith("'") && value.endsWith("'"))
|
|
73
88
|
) {
|
|
74
89
|
value = value.slice(1, -1);
|
|
75
90
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
91
|
+
|
|
92
|
+
return { type: 'keyvalue', key, value, line };
|
|
93
|
+
});
|
|
79
94
|
}
|
|
80
95
|
|
|
81
|
-
// Write env
|
|
82
|
-
function writeEnvFile(filePath,
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
96
|
+
// Write env array back to file, preserving comments and blank lines
|
|
97
|
+
function writeEnvFile(filePath, lineArray, updates) {
|
|
98
|
+
const updatedLines = lineArray.map((item) => {
|
|
99
|
+
// If this is a key-value pair and we have an update for it
|
|
100
|
+
if (item.type === 'keyvalue' && updates[item.key] !== undefined) {
|
|
101
|
+
return `${item.key}=${updates[item.key]}`;
|
|
102
|
+
}
|
|
103
|
+
// Otherwise, preserve the original line
|
|
104
|
+
return item.line;
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Add any new keys that weren't in the original file
|
|
108
|
+
const existingKeys = new Set(
|
|
109
|
+
lineArray.filter(item => item.type === 'keyvalue').map(item => item.key)
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
for (const [key, value] of Object.entries(updates)) {
|
|
113
|
+
if (!existingKeys.has(key)) {
|
|
114
|
+
updatedLines.push(`${key}=${value}`);
|
|
115
|
+
}
|
|
86
116
|
}
|
|
87
|
-
|
|
117
|
+
|
|
118
|
+
fs.writeFileSync(filePath, updatedLines.join("\n") + "\n");
|
|
88
119
|
}
|
|
89
120
|
|
|
90
121
|
async function main() {
|
|
@@ -100,9 +131,17 @@ async function main() {
|
|
|
100
131
|
process.exit(1);
|
|
101
132
|
}
|
|
102
133
|
|
|
103
|
-
// Load existing .env into
|
|
134
|
+
// Load existing .env into line array
|
|
104
135
|
const envPath = path.join(process.cwd(), ".env");
|
|
105
|
-
const
|
|
136
|
+
const envLines = readEnvFile(envPath);
|
|
137
|
+
|
|
138
|
+
// Extract current values from line array
|
|
139
|
+
const envObj = {};
|
|
140
|
+
envLines.forEach(item => {
|
|
141
|
+
if (item.type === 'keyvalue') {
|
|
142
|
+
envObj[item.key] = item.value;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
106
145
|
|
|
107
146
|
const existingUrl = envObj.TURSO_DATABASE_URL || process.env.TURSO_DATABASE_URL;
|
|
108
147
|
const existingToken = envObj.TURSO_AUTH_TOKEN || process.env.TURSO_AUTH_TOKEN;
|
|
@@ -137,8 +176,8 @@ async function main() {
|
|
|
137
176
|
process.env.TURSO_DATABASE_URL = dbUrl;
|
|
138
177
|
process.env.TURSO_AUTH_TOKEN = authToken;
|
|
139
178
|
|
|
140
|
-
// Overwrite .env with updated values (no duplicates, no stale
|
|
141
|
-
writeEnvFile(envPath, envObj);
|
|
179
|
+
// Overwrite .env with updated values (no duplicates, no stale "not logged in" values)
|
|
180
|
+
writeEnvFile(envPath, envLines, envObj);
|
|
142
181
|
|
|
143
182
|
console.log("\nUpdated Turso environment variables (overwritten in .env):");
|
|
144
183
|
console.log(`TURSO_DATABASE_URL=${process.env.TURSO_DATABASE_URL}`);
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-cloud-db",
|
|
3
|
-
"description": "CLI to create a Turso database and
|
|
3
|
+
"description": "CLI to create a Turso database and write TURSO_* env vars to .env file",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "vtempest",
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.4",
|
|
7
7
|
"main": "create-cloud-db.js",
|
|
8
8
|
"bin": {
|
|
9
9
|
"create-cloud-db": "./create-cloud-db.js"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
|
-
"ship": "npx standard-version --release-as patch; npm publish",
|
|
12
|
+
"ship": "npx standard-version --release-as patch; rm CHANGELOG.md; npm publish",
|
|
13
13
|
"start": "node create-cloud-db.js"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
package/.env
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
TURSO_DATABASE_URL=You are not logged in, please login with turso auth login before running other commands.
|
|
3
|
-
TURSO_AUTH_TOKEN=You are not logged in, please login with turso auth login before running other commands.
|
|
4
|
-
|
|
5
|
-
TURSO_DATABASE_URL=libsql://lol-xfreestar10.aws-us-west-2.turso.io
|
|
6
|
-
TURSO_AUTH_TOKEN=eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3NjYzNzYwNjEsImlkIjoiNDUyY2M2NzUtODk2Ny00Njc5LTk4MTItNTA2MGY1YmEyMDljIiwicmlkIjoiZjdkMWFhZTMtYzEzZC00OTEyLWFjYTAtNWRkY2Y5MTZkOWI5In0.loooOtvg-8fYzl_bi032Y32KGdDjOZhbKXdGFQLfrzt7Jbu9vDLY9I8KrUtOPprRFRrCHExXkfQtIg6xmt_XCg
|
package/CHANGELOG.md
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
-
|
|
5
|
-
### [1.0.2](https://github.com/vtempest/Svelte-Starter-DOCS/compare/v1.0.1...v1.0.2) (2025-12-22)
|
|
6
|
-
|
|
7
|
-
### [1.0.1](https://github.com/vtempest/Svelte-Starter-DOCS/compare/v0.9.2...v1.0.1) (2025-12-22)
|