Skip to content

Commit 092352c

Browse files
committed
feat: remove all environment references and use prod
1 parent e11a3a5 commit 092352c

File tree

8 files changed

+40
-73
lines changed

8 files changed

+40
-73
lines changed

packages/cli/src/cli.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import { codegenCommand } from "@/commands/codegen";
1616
import { connectCommand } from "@/commands/connect";
1717
import { Command } from "@commander-js/extra-typings";
18-
import { ascii } from "@settlemint/sdk-utils/terminal";
18+
import { ascii, cancel } from "@settlemint/sdk-utils/terminal";
1919
import pkg from "../package.json";
2020

2121
ascii();
@@ -55,4 +55,6 @@ sdkcli.addCommand(codegenCommand());
5555
* });
5656
* ```
5757
*/
58-
sdkcli.parseAsync(process.argv);
58+
sdkcli.parseAsync(process.argv).catch((reason) => {
59+
cancel(reason);
60+
});

packages/cli/src/commands/codegen.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Command } from "@commander-js/extra-typings";
33
import { loadEnv } from "@settlemint/sdk-utils/environment";
44
import { cancel, intro, outro } from "@settlemint/sdk-utils/terminal";
55
import type { DotEnv } from "@settlemint/sdk-utils/validation";
6-
import { bold, italic, underline } from "yoctocolors";
76

87
/**
98
* Creates and returns the 'connect' command for the SettleMint SDK.
@@ -16,19 +15,14 @@ import { bold, italic, underline } from "yoctocolors";
1615
export function codegenCommand(): Command {
1716
return (
1817
new Command("codegen")
19-
// Add options for various configuration parameters
20-
.option("-e, --environment <environment>", "The name of your environment, defaults to development", "development")
18+
.option("--prod", "Connect to your production environment")
2119
// Set the command description
2220
.description("Generate GraphQL and REST types and queries")
2321
// Define the action to be executed when the command is run
24-
.action(async ({ environment }) => {
25-
const selectedEnvironment = process.env.SETTLEMINT_ENVIRONMENT ?? environment;
22+
.action(async ({ prod }) => {
23+
intro("Generating GraphQL types and queries for your dApp");
2624

27-
intro(
28-
`Generating GraphQL types and queries for your dApp's ${italic(underline(bold(selectedEnvironment)))} environment`,
29-
);
30-
31-
const env: DotEnv = await loadEnv();
25+
const env: DotEnv = await loadEnv(true, !!prod);
3226

3327
try {
3428
await gqltadaSpinner(env);

packages/cli/src/commands/codegen/gqltada.spinner.ts

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ async function codegenHasura(env: DotEnv) {
9696

9797
const clientTemplate = `import { createServerHasuraClient } from "@settlemint/sdk-hasura";
9898
import type { introspection } from "../../hasura-env.d.ts";
99-
import { loadEnv } from "@settlemint/sdk-utils/environment";
100-
101-
const env = loadEnv(true, process.env.SETTLEMINT_ENVIRONMENT);
10299
103100
export const { client: hasuraClient, graphql: hasuraGraphql } = createServerHasuraClient<{
104101
introspection: introspection;
@@ -108,9 +105,9 @@ export const { client: hasuraClient, graphql: hasuraGraphql } = createServerHasu
108105
JSON: Record<string, unknown>;
109106
};
110107
}>({
111-
instance: env.SETTLEMINT_HASURA_ENDPOINT!,
112-
accessToken: env.SETTLEMINT_ACCESS_TOKEN!,
113-
adminSecret: env.SETTLEMINT_HASURA_ADMIN_SECRET!,
108+
instance: process.env.SETTLEMINT_HASURA_ENDPOINT!,
109+
accessToken: process.env.SETTLEMINT_ACCESS_TOKEN!,
110+
adminSecret: process.env.SETTLEMINT_HASURA_ADMIN_SECRET!,
114111
});`;
115112

116113
await writeTemplate(clientTemplate, "/lib/settlemint", "hasura.ts");
@@ -134,9 +131,6 @@ async function codegenPortal(env: DotEnv) {
134131

135132
const clientTemplate = `import { createServerPortalClient } from "@settlemint/sdk-portal";
136133
import type { introspection } from "../../portal-env.d.ts";
137-
import { loadEnv } from "@settlemint/sdk-utils/environment";
138-
139-
const env = loadEnv(true, process.env.SETTLEMINT_ENVIRONMENT);
140134
141135
export const { client: portalClient, graphql: portalGraphql } = createServerPortalClient<{
142136
introspection: introspection;
@@ -146,8 +140,8 @@ export const { client: portalClient, graphql: portalGraphql } = createServerPort
146140
JSON: Record<string, unknown>;
147141
};
148142
}>({
149-
instance: env.SETTLEMINT_PORTAL_GRAPHQL_ENDPOINT!,
150-
accessToken: env.SETTLEMINT_ACCESS_TOKEN!,
143+
instance: process.env.SETTLEMINT_PORTAL_GRAPHQL_ENDPOINT!,
144+
accessToken: process.env.SETTLEMINT_ACCESS_TOKEN!,
151145
});`;
152146

153147
await writeTemplate(clientTemplate, "/lib/settlemint", "portal.ts");
@@ -198,9 +192,6 @@ async function codegenTheGraph(env: DotEnv) {
198192

199193
const clientTemplate = `import { createServerTheGraphClient } from "@settlemint/sdk-thegraph";
200194
import type { introspection } from "../../the-graph-env.d.ts";
201-
import { loadEnv } from "@settlemint/sdk-utils/environment";
202-
203-
const env = loadEnv(true, process.env.SETTLEMINT_ENVIRONMENT);
204195
205196
export const { client: theGraphClient, graphql: theGraphGraphql } = createServerTheGraphClient<{
206197
introspection: introspection;
@@ -210,8 +201,8 @@ export const { client: theGraphClient, graphql: theGraphGraphql } = createServer
210201
JSON: Record<string, unknown>;
211202
};
212203
}>({
213-
instance: env.SETTLEMINT_THEGRAPH_SUBGRAPH_ENDPOINT!,
214-
accessToken: env.SETTLEMINT_ACCESS_TOKEN!,
204+
instance: process.env.SETTLEMINT_THEGRAPH_SUBGRAPH_ENDPOINT!,
205+
accessToken: process.env.SETTLEMINT_ACCESS_TOKEN!,
215206
});`;
216207

217208
await writeTemplate(clientTemplate, "/lib/settlemint", "the-graph.ts");
@@ -235,9 +226,6 @@ async function codegenTheGraphFallback(env: DotEnv) {
235226

236227
const clientTemplate = `import { createServerTheGraphClient } from "@settlemint/sdk-thegraph";
237228
import type { introspection } from "../../the-graph-fallback-env.d.ts";
238-
import { loadEnv } from "@settlemint/sdk-utils/environment";
239-
240-
const env = loadEnv(true, process.env.SETTLEMINT_ENVIRONMENT);
241229
242230
export const { client: theGraphFallbackClient, graphql: theGraphFallbackGraphql } = createServerTheGraphClient<{
243231
introspection: introspection;
@@ -247,8 +235,8 @@ export const { client: theGraphFallbackClient, graphql: theGraphFallbackGraphql
247235
JSON: Record<string, unknown>;
248236
};
249237
}>({
250-
instance: env.SETTLEMINT_THEGRAPH_SUBGRAPH_ENDPOINT_FALLBACK!,
251-
accessToken: env.SETTLEMINT_ACCESS_TOKEN!,
238+
instance: process.env.SETTLEMINT_THEGRAPH_SUBGRAPH_ENDPOINT_FALLBACK!,
239+
accessToken: process.env.SETTLEMINT_ACCESS_TOKEN!,
252240
});`;
253241

254242
await writeTemplate(clientTemplate, "/lib/settlemint", "the-graph-fallback.ts");

packages/cli/src/commands/connect.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type { DotEnv } from "@settlemint/sdk-utils";
77
import { loadEnv } from "@settlemint/sdk-utils/environment";
88
import { intro, outro } from "@settlemint/sdk-utils/terminal";
99
import isInCi from "is-in-ci";
10-
import { bold, italic, underline } from "yoctocolors";
1110
import { applicationPrompt } from "./connect/application.prompt";
1211
import { hasuraPrompt } from "./connect/hasura.prompt";
1312
import { hdPrivateKeyPrompt } from "./connect/hd-private-keys.prompt";
@@ -28,17 +27,15 @@ import { workspacePrompt } from "./connect/workspace.prompt";
2827
export function connectCommand(): Command {
2928
return (
3029
new Command("connect")
31-
// Add options for various configuration parameters
32-
.option("-e, --environment <environment>", "The name of your environment, defaults to development", "development")
30+
.option("--prod", "Connect to your production environment")
3331
.option("-a, --accept", "Accept the default and previously set values")
3432
// Set the command description
3533
.description("Connects your project to your application on SettleMint")
3634
// Define the action to be executed when the command is run
37-
.action(async ({ environment, accept }) => {
38-
const selectedEnvironment = process.env.SETTLEMINT_ENVIRONMENT ?? environment;
39-
intro(`Connecting your dApp's ${italic(underline(bold(selectedEnvironment)))} environment to SettleMint`);
35+
.action(async ({ accept, prod }) => {
36+
intro("Connecting your dApp to SettleMint");
4037
const autoAccept = !!accept || isInCi;
41-
const env: Partial<DotEnv> = await loadEnv(false);
38+
const env: Partial<DotEnv> = await loadEnv(false, !!prod);
4239

4340
const accessToken = await accessTokenPrompt(env, autoAccept);
4441
const instance = await instancePrompt(env, autoAccept);
@@ -69,8 +66,7 @@ export function connectCommand(): Command {
6966
const portal = await portalPrompt(env, middleware, autoAccept);
7067
const hdPrivateKey = await hdPrivateKeyPrompt(env, privateKey, autoAccept);
7168

72-
await writeEnvSpinner({
73-
SETTLEMINT_ENVIRONMENT: selectedEnvironment,
69+
await writeEnvSpinner(!!prod, {
7470
SETTLEMINT_ACCESS_TOKEN: accessToken,
7571
SETTLEMINT_INSTANCE: instance,
7672
SETTLEMINT_WORKSPACE: workspace.id,

packages/cli/src/commands/connect/write-env.spinner.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ import type { DotEnv } from "@settlemint/sdk-utils/validation";
1616
* "development"
1717
* );
1818
*/
19-
export async function writeEnvSpinner(env: Partial<DotEnv>) {
19+
export async function writeEnvSpinner(prod: boolean, env: Partial<DotEnv>) {
2020
return spinner({
21-
startMessage: `Saving .env.${env.SETTLEMINT_ENVIRONMENT} and .env.${env.SETTLEMINT_ENVIRONMENT}.local files`,
22-
stopMessage: `Written .env.${env.SETTLEMINT_ENVIRONMENT} and .env.${env.SETTLEMINT_ENVIRONMENT}.local file`,
21+
startMessage: "Saving .env and .env.local files",
22+
stopMessage: "Written .env and .env.local file",
2323
task: async () => {
2424
await writeEnv(
25+
prod,
2526
{
26-
SETTLEMINT_ENVIRONMENT: env.SETTLEMINT_ENVIRONMENT,
2727
SETTLEMINT_INSTANCE: env.SETTLEMINT_INSTANCE,
2828
SETTLEMINT_WORKSPACE: env.SETTLEMINT_WORKSPACE,
2929
SETTLEMINT_APPLICATION: env.SETTLEMINT_APPLICATION,
@@ -41,8 +41,8 @@ export async function writeEnvSpinner(env: Partial<DotEnv>) {
4141
);
4242

4343
await writeEnv(
44+
prod,
4445
{
45-
SETTLEMINT_ENVIRONMENT: env.SETTLEMINT_ENVIRONMENT, // needed for the filename
4646
SETTLEMINT_ACCESS_TOKEN: env.SETTLEMINT_ACCESS_TOKEN,
4747
SETTLEMINT_HASURA_ADMIN_SECRET: env.SETTLEMINT_HASURA_ADMIN_SECRET,
4848
},

packages/utils/src/environment/load-env.ts

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { join } from "node:path";
2-
import { projectRoot } from "@/filesystem.js";
31
import { cancel } from "@/terminal.js";
42
import { type DotEnv, type DotEnvPartial, DotEnvSchema, DotEnvSchemaPartial, validate } from "@/validation.js";
53
import { config } from "@dotenvx/dotenvx";
@@ -16,9 +14,10 @@ import { config } from "@dotenvx/dotenvx";
1614
* console.log(env.SETTLEMINT_INSTANCE);
1715
*/
1816
export async function loadEnv<T extends boolean = true>(
19-
validateEnv?: T,
17+
validateEnv: T,
18+
prod: boolean,
2019
): Promise<T extends true ? DotEnv : DotEnvPartial> {
21-
return loadEnvironmentEnv(validateEnv ?? true);
20+
return loadEnvironmentEnv(validateEnv, !!prod);
2221
}
2322

2423
/**
@@ -31,31 +30,17 @@ export async function loadEnv<T extends boolean = true>(
3130
*/
3231
export async function loadEnvironmentEnv<T extends boolean = true>(
3332
validateEnv: T,
34-
environment?: string,
35-
override?: boolean,
33+
prod: boolean,
3634
): Promise<T extends true ? DotEnv : DotEnvPartial> {
37-
const projectDir = await projectRoot();
38-
39-
const paths: string[] = [
40-
`.env.${process.env.NODE_ENV ?? "development"}.local`,
41-
".env.local",
42-
...(environment ? [`.env.${environment}.local`, `.env.${environment}`] : []),
43-
`.env.${process.env.NODE_ENV ?? "development"}`,
44-
".env",
45-
].map((file) => join(projectDir, file));
46-
47-
let { parsed } = config({ path: paths, logLevel: "error", override: !!override });
35+
if (prod) {
36+
process.env.NODE_ENV = "production";
37+
}
38+
let { parsed } = config({ convention: "nextjs", logLevel: "error" });
4839

4940
if (!parsed) {
5041
parsed = {};
5142
}
5243

53-
const envToUse = environment || parsed.SETTLEMINT_ENVIRONMENT || "development";
54-
55-
if (envToUse && envToUse !== environment) {
56-
return loadEnvironmentEnv(validateEnv, envToUse, true);
57-
}
58-
5944
try {
6045
return validate(validateEnv ? DotEnvSchema : DotEnvSchemaPartial, process.env) as T extends true
6146
? DotEnv

packages/utils/src/environment/write-env.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ import type { DotEnv } from "@/validation.js";
55
import { config } from "@dotenvx/dotenvx";
66
import { deepmerge } from "deepmerge-ts";
77

8-
export async function writeEnv(env: Partial<DotEnv>, secrets: boolean) {
8+
export async function writeEnv(prod: boolean, env: Partial<DotEnv>, secrets: boolean) {
99
const projectDir = await projectRoot();
1010
const envFile = join(
1111
projectDir,
12-
secrets ? `.env.${env.SETTLEMINT_ENVIRONMENT}.local` : `.env.${env.SETTLEMINT_ENVIRONMENT}`,
12+
secrets ? `.env${prod ? ".production" : ""}.local` : `.env${prod ? ".production" : ""}`,
1313
);
1414

15+
if (prod) {
16+
process.env.NODE_ENV = "production";
17+
}
1518
let { parsed: currentEnv } = config({
1619
path: envFile,
1720
logLevel: "error",

packages/utils/src/validation/dot-env.schema.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { UrlSchema } from "./url.schema.js";
66
* Schema for validating access tokens.
77
*/
88
export const DotEnvSchema = z.object({
9-
SETTLEMINT_ENVIRONMENT: z.string(),
109
SETTLEMINT_INSTANCE: UrlSchema,
1110
SETTLEMINT_ACCESS_TOKEN: AccessTokenSchema,
1211
SETTLEMINT_WORKSPACE: IdSchema,

0 commit comments

Comments
 (0)