@saidulbadhon/jssm-cli 1.5.0 → 1.5.2

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/index.js +53 -120
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2438,6 +2438,7 @@ import { join as join2 } from "path";
2438
2438
  import { homedir as homedir2 } from "os";
2439
2439
 
2440
2440
  // src/shared/constants.ts
2441
+ var DEFAULT_HOST = "https://jssm-api.jutsu.ai/api";
2441
2442
  var DEFAULT_NAMESPACE = "jssm";
2442
2443
  var CONFIG_DIR = ".jssm";
2443
2444
  var CONFIG_FILE = "config";
@@ -2551,14 +2552,14 @@ async function resolveConfig() {
2551
2552
  }
2552
2553
  let authToken;
2553
2554
  try {
2554
- const { getAuthToken: getAuthToken4 } = await Promise.resolve().then(() => (init_auth(), auth_exports));
2555
- authToken = await getAuthToken4() || void 0;
2555
+ const { getAuthToken: getAuthToken3 } = await Promise.resolve().then(() => (init_auth(), auth_exports));
2556
+ authToken = await getAuthToken3() || void 0;
2556
2557
  } catch (error) {
2557
2558
  }
2558
2559
  const resolved = {
2559
2560
  project: projectConfig.project,
2560
2561
  environment: projectConfig.environment,
2561
- host: projectConfig.host || globalConfig.host || "",
2562
+ host: projectConfig.host || globalConfig.host || DEFAULT_HOST,
2562
2563
  namespace: projectConfig.namespace || globalConfig.namespace || DEFAULT_NAMESPACE,
2563
2564
  authToken
2564
2565
  };
@@ -2627,13 +2628,6 @@ async function getEnvironments(host, apiKey, project) {
2627
2628
  const url = `${host}/projects/${project}/envs`;
2628
2629
  return apiRequest(url, apiKey);
2629
2630
  }
2630
- async function pushVariables(host, apiKey, project, environment, variables) {
2631
- const url = `${host}/projects/${project}/envs/${environment}/push`;
2632
- return apiRequest(url, apiKey, {
2633
- method: "POST",
2634
- body: JSON.stringify({ variables })
2635
- });
2636
- }
2637
2631
  async function pushEnvFile(host, apiKey, project, environment, content, filename = ".env") {
2638
2632
  const url = `${host}/projects/${project}/envs/${environment}/push-file`;
2639
2633
  return apiRequest(url, apiKey, {
@@ -2753,60 +2747,6 @@ async function getRepositoryType(rootPath) {
2753
2747
  return isMonorepoResult ? "monorepo" : "normal";
2754
2748
  }
2755
2749
 
2756
- // src/utils/envParser.ts
2757
- import { readFile as readFile4 } from "fs/promises";
2758
- function parseEnvFile(content) {
2759
- const variables = [];
2760
- const lines = content.split("\n");
2761
- for (const line of lines) {
2762
- const trimmed = line.trim();
2763
- if (!trimmed || trimmed.startsWith("#")) {
2764
- continue;
2765
- }
2766
- const match = trimmed.match(/^([A-Z0-9_]+)=(.*)$/);
2767
- if (match) {
2768
- const [, key, value] = match;
2769
- let cleanValue = value.trim();
2770
- if (cleanValue.startsWith('"') && cleanValue.endsWith('"') || cleanValue.startsWith("'") && cleanValue.endsWith("'")) {
2771
- cleanValue = cleanValue.slice(1, -1);
2772
- }
2773
- variables.push({ key, value: cleanValue });
2774
- }
2775
- }
2776
- return variables;
2777
- }
2778
- async function readEnvFile(filePath) {
2779
- try {
2780
- const content = await readFile4(filePath, "utf-8");
2781
- return parseEnvFile(content);
2782
- } catch (error) {
2783
- if (error.code === "ENOENT") {
2784
- return [];
2785
- }
2786
- throw error;
2787
- }
2788
- }
2789
- function formatVariablesPreview(variables, maxDisplay = 5) {
2790
- if (variables.length === 0) {
2791
- return " (no variables)";
2792
- }
2793
- const preview = variables.slice(0, maxDisplay).map((v) => {
2794
- const valuePreview = v.value.length > 30 ? v.value.substring(0, 30) + "..." : v.value;
2795
- return ` ${v.key}=${valuePreview}`;
2796
- }).join("\n");
2797
- if (variables.length > maxDisplay) {
2798
- return `${preview}
2799
- ... and ${variables.length - maxDisplay} more`;
2800
- }
2801
- return preview;
2802
- }
2803
- function validateVariableName(name) {
2804
- return /^[A-Z0-9_]+$/.test(name);
2805
- }
2806
- function getInvalidVariableNames(variables) {
2807
- return variables.filter((v) => !validateVariableName(v.key)).map((v) => v.key);
2808
- }
2809
-
2810
2750
  // src/commands/pull.ts
2811
2751
  import { writeFile as writeFile3, mkdir as mkdir3 } from "fs/promises";
2812
2752
  import { join as join4, dirname } from "path";
@@ -2990,7 +2930,7 @@ function countVariables(content) {
2990
2930
  }
2991
2931
 
2992
2932
  // src/commands/push.ts
2993
- import { readFile as readFile5 } from "fs/promises";
2933
+ import { readFile as readFile4 } from "fs/promises";
2994
2934
  import { join as join5 } from "path";
2995
2935
  async function pushCommand(args2) {
2996
2936
  const flags = {};
@@ -3110,7 +3050,7 @@ async function pushCommand(args2) {
3110
3050
  let fileSize = 0;
3111
3051
  try {
3112
3052
  const inputPath = join5(process.cwd(), file);
3113
- fileContent = await readFile5(inputPath, "utf-8");
3053
+ fileContent = await readFile4(inputPath, "utf-8");
3114
3054
  fileSize = Buffer.byteLength(fileContent, "utf-8");
3115
3055
  const variables = parseVariables(fileContent, file);
3116
3056
  if (variables.length === 0) {
@@ -3443,13 +3383,13 @@ async function initCommand(args2) {
3443
3383
  default: true
3444
3384
  });
3445
3385
  if (shouldUpload) {
3446
- let selectedFiles;
3386
+ let selectedFileInfos;
3447
3387
  if (repoType === "monorepo" && envFiles.length > 1) {
3448
3388
  const fileChoices = envFiles.map((file) => ({
3449
3389
  name: `${file.relativePath} (${file.variableCount} variables)`,
3450
- value: file.path
3390
+ value: file.relativePath
3451
3391
  }));
3452
- selectedFiles = await dist_default2({
3392
+ const selectedPaths = await dist_default2({
3453
3393
  message: "Select .env files to upload:",
3454
3394
  choices: fileChoices,
3455
3395
  validate: (answer) => {
@@ -3459,66 +3399,59 @@ async function initCommand(args2) {
3459
3399
  return true;
3460
3400
  }
3461
3401
  });
3462
- } else {
3463
- selectedFiles = [envFiles[0].path];
3464
- }
3465
- const allVariables = [];
3466
- const variablesByFile = /* @__PURE__ */ new Map();
3467
- for (const filePath of selectedFiles) {
3468
- const variables = await readEnvFile(filePath);
3469
- variablesByFile.set(filePath, variables);
3470
- for (const variable of variables) {
3471
- const existingIndex = allVariables.findIndex(
3472
- (v) => v.key === variable.key
3473
- );
3474
- if (existingIndex >= 0) {
3475
- allVariables[existingIndex] = variable;
3476
- } else {
3477
- allVariables.push(variable);
3478
- }
3479
- }
3480
- }
3481
- const invalidNames = getInvalidVariableNames(allVariables);
3482
- if (invalidNames.length > 0) {
3483
- console.log("\n\u26A0\uFE0F Warning: Some variable names are invalid:");
3484
- invalidNames.forEach((name) => console.log(` ${name}`));
3485
- console.log(
3486
- " Variable names must contain only uppercase letters, numbers, and underscores"
3487
- );
3488
- const continueAnyway = await dist_default3({
3489
- message: "Continue with valid variables only?",
3490
- default: true
3491
- });
3492
- if (!continueAnyway) {
3493
- console.log("\n\u274C Upload cancelled");
3494
- process.exit(0);
3495
- }
3496
- const validVariables = allVariables.filter(
3497
- (v) => !invalidNames.includes(v.key)
3402
+ selectedFileInfos = envFiles.filter(
3403
+ (f) => selectedPaths.includes(f.relativePath)
3498
3404
  );
3499
- allVariables.length = 0;
3500
- allVariables.push(...validVariables);
3405
+ } else {
3406
+ selectedFileInfos = [envFiles[0]];
3501
3407
  }
3502
- console.log(`
3503
- \u{1F4CB} Variables to upload (${allVariables.length} total):`);
3504
- console.log(formatVariablesPreview(allVariables, 10));
3408
+ const totalVars = selectedFileInfos.reduce(
3409
+ (sum, f) => sum + f.variableCount,
3410
+ 0
3411
+ );
3412
+ console.log(
3413
+ `
3414
+ \u{1F4CB} Files to upload (${selectedFileInfos.length} files, ${totalVars} total variables):`
3415
+ );
3416
+ selectedFileInfos.forEach((f) => {
3417
+ console.log(` ${f.relativePath} (${f.variableCount} variables)`);
3418
+ });
3505
3419
  const confirmUpload = await dist_default3({
3506
3420
  message: "\nProceed with upload?",
3507
3421
  default: true
3508
3422
  });
3509
3423
  if (confirmUpload) {
3510
3424
  console.log(`
3511
- \u2B06\uFE0F Uploading ${allVariables.length} variables...`);
3512
- await pushVariables(
3513
- host,
3514
- authToken,
3515
- projectName,
3516
- environmentName,
3517
- allVariables
3518
- );
3519
- console.log(`\u2705 Variables uploaded successfully`);
3425
+ \u2B06\uFE0F Uploading ${selectedFileInfos.length} file(s)...`);
3426
+ let successCount = 0;
3427
+ let failCount = 0;
3428
+ for (const fileInfo of selectedFileInfos) {
3429
+ try {
3430
+ const { readFile: readFileAsync } = await import("fs/promises");
3431
+ const content = await readFileAsync(fileInfo.path, "utf-8");
3432
+ await pushEnvFile(
3433
+ host,
3434
+ authToken,
3435
+ projectName,
3436
+ environmentName,
3437
+ content,
3438
+ fileInfo.relativePath
3439
+ );
3440
+ console.log(` \u2705 ${fileInfo.relativePath}`);
3441
+ successCount++;
3442
+ } catch (error) {
3443
+ console.log(` \u274C ${fileInfo.relativePath}: ${error.message}`);
3444
+ failCount++;
3445
+ }
3446
+ }
3447
+ if (failCount === 0) {
3448
+ console.log(`\u2705 All files uploaded successfully`);
3449
+ } else {
3450
+ console.log(`
3451
+ \u26A0\uFE0F ${successCount} succeeded, ${failCount} failed`);
3452
+ }
3520
3453
  } else {
3521
- console.log("\n\u23ED\uFE0F Skipping variable upload");
3454
+ console.log("\n\u23ED\uFE0F Skipping file upload");
3522
3455
  }
3523
3456
  }
3524
3457
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saidulbadhon/jssm-cli",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "private": false,
5
5
  "description": "CLI for JSSM - Simple environment variable manager",
6
6
  "author": "Zahidul Islam",