morphix-env 0.2.0 → 0.3.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.
Files changed (2) hide show
  1. package/dist/cli.js +54 -13
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -60,6 +60,8 @@ function extractPublicVars() {
60
60
 
61
61
  // src/infisical.ts
62
62
  var import_sdk = require("@infisical/sdk");
63
+ var import_child_process = require("child_process");
64
+ var import_dotenv2 = require("dotenv");
63
65
  function getInfisicalConfig() {
64
66
  const clientId = process.env.INFISICAL_CLIENT_ID;
65
67
  const clientSecret = process.env.INFISICAL_CLIENT_SECRET;
@@ -98,6 +100,32 @@ async function fetchInfisicalSecrets(config) {
98
100
  }
99
101
  return count;
100
102
  }
103
+ function hasInfisicalCLI() {
104
+ try {
105
+ (0, import_child_process.execSync)("infisical --version", { stdio: "pipe" });
106
+ return true;
107
+ } catch {
108
+ return false;
109
+ }
110
+ }
111
+ function fetchSecretsViaCLI(environment, paths) {
112
+ let count = 0;
113
+ for (const secretPath of paths) {
114
+ try {
115
+ const output = (0, import_child_process.execSync)(
116
+ `infisical export --path=${secretPath} --env=${environment} --format=dotenv`,
117
+ { encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] }
118
+ );
119
+ const vars = (0, import_dotenv2.parse)(output);
120
+ for (const [key, value] of Object.entries(vars)) {
121
+ process.env[key] = value;
122
+ count++;
123
+ }
124
+ } catch {
125
+ }
126
+ }
127
+ return count;
128
+ }
101
129
 
102
130
  // src/config.ts
103
131
  var import_fs2 = require("fs");
@@ -128,7 +156,7 @@ function loadConfig() {
128
156
  var import_cross_spawn = __toESM(require("cross-spawn"));
129
157
  var import_fs3 = require("fs");
130
158
  var import_path3 = require("path");
131
- var VERSION = "0.2.0";
159
+ var VERSION = "0.3.0";
132
160
  var DEFAULT_ENV_FILE = ".env.local";
133
161
  function parseArgs(argv) {
134
162
  const args = {
@@ -188,28 +216,41 @@ function mergeWithConfig(args, config) {
188
216
  }
189
217
  async function loadAllEnv(args, config) {
190
218
  if (!args.noInfisical) {
219
+ const env = config.infisical?.env || process.env.DEPLOY_ENV || process.env.INFISICAL_ENV || "dev";
220
+ const paths = config.infisical?.paths || ["/"];
191
221
  const infisicalConfig = config.infisical ? {
192
222
  clientId: process.env.INFISICAL_CLIENT_ID || "",
193
223
  clientSecret: process.env.INFISICAL_CLIENT_SECRET || "",
194
224
  projectId: config.infisical.projectId,
195
- environment: config.infisical.env || "dev",
196
- paths: config.infisical.paths || ["/"],
225
+ environment: env,
226
+ paths,
197
227
  siteUrl: config.infisical.siteUrl
198
228
  } : getInfisicalConfig();
199
229
  if (infisicalConfig && infisicalConfig.clientId && infisicalConfig.clientSecret) {
200
230
  try {
201
231
  const count = await fetchInfisicalSecrets(infisicalConfig);
202
- console.log(`[mx-env] Infisical: loaded ${count} secrets (${infisicalConfig.environment}: ${infisicalConfig.paths.join(", ")})`);
232
+ console.log(`[morphix-env] Infisical SDK: loaded ${count} secrets (${env}: ${paths.join(", ")})`);
233
+ } catch (e) {
234
+ console.warn(`[morphix-env] Infisical SDK: failed - ${e.message}`);
235
+ }
236
+ } else if (hasInfisicalCLI()) {
237
+ try {
238
+ const count = fetchSecretsViaCLI(env, paths);
239
+ if (count > 0) {
240
+ console.log(`[morphix-env] Infisical CLI: loaded ${count} secrets (${env}: ${paths.join(", ")})`);
241
+ } else {
242
+ console.log(`[morphix-env] Infisical CLI: no secrets found (run 'infisical login' first?)`);
243
+ }
203
244
  } catch (e) {
204
- console.warn(`[mx-env] Infisical: failed - ${e.message}`);
245
+ console.warn(`[morphix-env] Infisical CLI: failed - ${e.message}`);
205
246
  }
206
247
  } else if (args.verbose) {
207
- console.log("[mx-env] Infisical: skipped (no credentials)");
248
+ console.log("[morphix-env] Infisical: skipped (no SDK credentials, no CLI)");
208
249
  }
209
250
  }
210
251
  const overrides = loadEnvFiles(args.envFiles);
211
252
  if (overrides.length > 0) {
212
- console.log(`[mx-env] Loaded ${overrides.length} overrides from ${args.envFiles.join(", ")}`);
253
+ console.log(`[morphix-env] Loaded ${overrides.length} overrides from ${args.envFiles.join(", ")}`);
213
254
  if (args.verbose) {
214
255
  for (const o of overrides) {
215
256
  console.log(` ${o.key} (from ${o.source})`);
@@ -219,7 +260,7 @@ async function loadAllEnv(args, config) {
219
260
  }
220
261
  async function cmdRun(args, config) {
221
262
  if (args.subArgs.length === 0) {
222
- console.error("[mx-env] No command specified. Usage: mx-env run -- <command>");
263
+ console.error("[morphix-env] No command specified. Usage: mx-env run -- <command>");
223
264
  process.exit(1);
224
265
  }
225
266
  await loadAllEnv(args, config);
@@ -232,7 +273,7 @@ async function cmdRun(args, config) {
232
273
  env: process.env
233
274
  });
234
275
  if (result.error) {
235
- console.error(`[mx-env] Failed to execute: ${cmd}`, result.error.message);
276
+ console.error(`[morphix-env] Failed to execute: ${cmd}`, result.error.message);
236
277
  process.exit(1);
237
278
  }
238
279
  process.exit(result.status ?? 1);
@@ -247,7 +288,7 @@ function generateClientEnv(outFile, filter) {
247
288
  const js = `window.__ENV=${JSON.stringify(vars)};`;
248
289
  (0, import_fs3.mkdirSync)((0, import_path3.dirname)(outFile), { recursive: true });
249
290
  (0, import_fs3.writeFileSync)(outFile, js);
250
- console.log(`[mx-env] Generated ${outFile} (${Object.keys(vars).length} client vars)`);
291
+ console.log(`[morphix-env] Generated ${outFile} (${Object.keys(vars).length} client vars)`);
251
292
  }
252
293
  async function cmdGenerate(args, config) {
253
294
  const outFile = args.outFile || "public/__env.js";
@@ -288,7 +329,7 @@ process.env public vars: (${filtered.length})`);
288
329
  }
289
330
  function showHelp() {
290
331
  console.log(`
291
- mx-env v${VERSION} \u2014 MorphixAI environment variable toolkit
332
+ morphix-env v${VERSION} \u2014 MorphixAI environment variable toolkit
292
333
 
293
334
  Usage:
294
335
  mx-env run [options] -- <command> Load env + exec command
@@ -355,13 +396,13 @@ async function main() {
355
396
  break;
356
397
  default:
357
398
  if (args.command) {
358
- console.error(`[mx-env] Unknown command: ${args.command}`);
399
+ console.error(`[morphix-env] Unknown command: ${args.command}`);
359
400
  }
360
401
  showHelp();
361
402
  process.exit(args.command ? 1 : 0);
362
403
  }
363
404
  }
364
405
  main().catch((e) => {
365
- console.error("[mx-env] Fatal:", e.message);
406
+ console.error("[morphix-env] Fatal:", e.message);
366
407
  process.exit(1);
367
408
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "morphix-env",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Environment variable toolkit — Infisical integration, local overrides, and client-side runtime injection for Next.js / Vite / Express.",
5
5
  "author": "MorphixAI <dev@morphixai.com>",
6
6
  "homepage": "https://github.com/Morphicai/morphix-env#readme",