Skip to content

Commit 026e0ef

Browse files
committed
✨ Envs! And hot .env file stucco reload in "dev" command
1 parent 8e43ba7 commit 026e0ef

File tree

10 files changed

+57
-23
lines changed

10 files changed

+57
-23
lines changed

package-lock.json

Lines changed: 19 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-editor-cli",
3-
"version": "0.7.7",
3+
"version": "0.7.8",
44
"description": "GraphQL -> anything. Use GraphQL as your source of truth. GraphQL Editor Official CLI.",
55
"main": "lib/api.js",
66
"author": "Artur Czemiel",
@@ -49,6 +49,7 @@
4949
"chalk": "^5.0.1",
5050
"clipboardy": "^3.0.0",
5151
"conf": "^10.2.0",
52+
"dotenv": "^16.0.3",
5253
"execa": "^6.1.0",
5354
"express": "^4.18.1",
5455
"fast-glob": "^3.2.12",

packages/cli/src/commands/cloud/server.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,18 @@ export const CommandSync = async ({
5959
schemaPath: path.join(TEMPPATH, DEPLOY_FILE),
6060
basePath: TEMPPATH,
6161
cwd: TEMPPATH,
62-
envs: hasMongoInProject
63-
? {
64-
MONGO_URL: hasMongoInProject,
65-
}
66-
: undefined,
6762
});
63+
const envs = hasMongoInProject
64+
? {
65+
MONGO_URL: hasMongoInProject,
66+
}
67+
: undefined;
6868

6969
const tsServer = typescriptServer({
7070
searchPath: TEMPPATH,
7171
onCreate: async () => {
7272
try {
73-
await onCreateStucco();
73+
await onCreateStucco({ envs });
7474
logger('tsc success', 'success');
7575
} finally {
7676
}

packages/cli/src/commands/common/dev.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { DEPLOY_FILE, STUCCO_FILE } from '@/gshared/constants/index.js';
55
import path from 'path';
66
import fs from 'fs';
77
import process from 'node:process';
8+
import * as dotenv from 'dotenv';
89

910
let killing = false;
1011
let changingFile = false;
@@ -17,14 +18,20 @@ export const CommandDev = async () => {
1718
const tsServer = typescriptServer({
1819
searchPath: './',
1920
onCreate: async () => {
20-
await onCreateStucco();
21+
const envFile = getEnvFile();
22+
await onCreateStucco({
23+
envs: envFile,
24+
});
2125
},
2226
});
2327
const fileServer = fs.watch(process.cwd(), (e, f) => {
2428
if (changingFile) return;
2529
if (f === STUCCO_FILE || f.startsWith('.env')) {
30+
const envFile = getEnvFile();
2631
changingFile = true;
27-
onCreateStucco().then((e) => {
32+
onCreateStucco({
33+
envs: envFile,
34+
}).then((e) => {
2835
changingFile = false;
2936
});
3037
}
@@ -48,3 +55,13 @@ export const CommandDev = async () => {
4855
});
4956
return;
5057
};
58+
59+
const getEnvFile = () => {
60+
const dir = fs.readdirSync(process.cwd());
61+
const envFile = dir.find((e) => e.startsWith('.env'));
62+
if (envFile) {
63+
const filePath = path.join(process.cwd(), envFile);
64+
const fileContent = fs.readFileSync(filePath, 'utf-8');
65+
return dotenv.parse(fileContent);
66+
}
67+
};

packages/cli/src/common/stucco/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export const stuccoRun = async (props?: {
3939
configPath?: string;
4040
basePath?: string;
4141
cwd?: string;
42-
envs?: Record<string, string>;
4342
}) => {
4443
const nodeModules = findNodeModules(props?.basePath || process.cwd());
4544
const stuccoPath = path.join(nodeModules, '.bin');
@@ -55,7 +54,7 @@ export const stuccoRun = async (props?: {
5554
let taskRunning = false;
5655

5756
return {
58-
onCreateStucco: async () => {
57+
onCreateStucco: async (stuccoProps?: { envs?: Record<string, string> }) => {
5958
if (taskRunning) return;
6059
taskRunning = true;
6160
try {
@@ -67,7 +66,7 @@ export const stuccoRun = async (props?: {
6766
cwd: props?.cwd,
6867
cmd: bin,
6968
basePath: props?.basePath,
70-
envs: props?.envs,
69+
envs: stuccoProps?.envs,
7170
});
7271
} finally {
7372
taskRunning = false;

packages/sandbox/.env.local

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DUPA=kdsndsklndksa

packages/sandbox/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "sandbox",
33
"private": true,
4-
"version": "0.7.9",
4+
"version": "0.7.10",
55
"description": "GraphQL -> anything. Use GraphQL as your source of truth. GraphQL Editor Official CLI.",
66
"author": "Artur Czemiel",
77
"license": "MIT",

packages/sandbox/src/handler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const handler = async () => {
2+
return process.env.DUPA;
3+
};

packages/sandbox/stucco.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
{
22
"resolvers": {
3-
"Query.rest": {
4-
"name": "dsda",
5-
"description": "dsdsaaaaadsadsaadsd",
3+
"Query.restProxy": {
64
"resolve": {
7-
"name": "Query.rest.handler"
5+
"name": "lib/handler"
86
}
97
}
108
}

0 commit comments

Comments
 (0)