@saidulbadhon/jssm-cli 1.6.4 → 1.6.6

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 +69 -12
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4143,10 +4143,19 @@ async function apiRequest(url, authToken, options = {}) {
4143
4143
  headers
4144
4144
  });
4145
4145
  if (!response.ok) {
4146
- const error = await response.json().catch(() => ({
4146
+ const errorBody = await response.json().catch(() => ({
4147
4147
  error: `HTTP ${response.status} ${response.statusText}`
4148
4148
  }));
4149
- const message = typeof error === "object" && error !== null && "error" in error && error.error ? String(error.error) : void 0;
4149
+ let message;
4150
+ if (typeof errorBody.error === "string") {
4151
+ message = errorBody.error;
4152
+ } else if (typeof errorBody.error === "object" && errorBody.error !== null && "message" in errorBody.error && typeof errorBody.error.message === "string") {
4153
+ message = errorBody.error.message;
4154
+ } else if (typeof errorBody.message === "string") {
4155
+ message = errorBody.message;
4156
+ } else if (errorBody.error) {
4157
+ message = JSON.stringify(errorBody.error);
4158
+ }
4150
4159
  throw new Error(
4151
4160
  message || `HTTP ${response.status} ${response.statusText}`
4152
4161
  );
@@ -4481,12 +4490,15 @@ async function initCommand(args2) {
4481
4490
  console.log(` ${f.relativePath} (${f.variableCount} variables)`);
4482
4491
  });
4483
4492
  const confirmUpload = await dist_default3({
4484
- message: "\nProceed with upload?",
4493
+ message: `
4494
+ Upload to ${projectName}?`,
4485
4495
  default: true
4486
4496
  });
4487
4497
  if (confirmUpload) {
4488
- console.log(`
4489
- \u2B06\uFE0F Uploading ${selectedFileInfos.length} file(s)...`);
4498
+ console.log(
4499
+ `
4500
+ \u2B06\uFE0F Uploading ${selectedFileInfos.length} file(s) to ${projectName}...`
4501
+ );
4490
4502
  let successCount = 0;
4491
4503
  let failCount = 0;
4492
4504
  for (const fileInfo of selectedFileInfos) {
@@ -4499,6 +4511,7 @@ async function initCommand(args2) {
4499
4511
  projectName,
4500
4512
  content,
4501
4513
  fileInfo.relativePath
4514
+ // environment not specified - defaults to "default" on server
4502
4515
  );
4503
4516
  console.log(` \u2705 ${fileInfo.relativePath}`);
4504
4517
  successCount++;
@@ -4552,12 +4565,16 @@ async function initCommand(args2) {
4552
4565
  // src/commands/pull.ts
4553
4566
  import { writeFile as writeFile3, mkdir as mkdir3 } from "fs/promises";
4554
4567
  import { join as join4, dirname } from "path";
4568
+ import { existsSync as existsSync2 } from "fs";
4555
4569
  async function pullCommand2(args2) {
4556
4570
  const flags = {};
4557
4571
  let pullAll = false;
4572
+ let forceOverwrite = false;
4558
4573
  for (let i = 0; i < args2.length; i++) {
4559
4574
  if (args2[i] === "--all" || args2[i] === "-a") {
4560
4575
  pullAll = true;
4576
+ } else if (args2[i] === "--force" || args2[i] === "-f") {
4577
+ forceOverwrite = true;
4561
4578
  } else if (args2[i].startsWith("-")) {
4562
4579
  const key = args2[i].replace(/^-+/, "");
4563
4580
  const value = args2[i + 1];
@@ -4587,6 +4604,17 @@ async function pullCommand2(args2) {
4587
4604
  }
4588
4605
  try {
4589
4606
  if (output) {
4607
+ const outputPath = join4(process.cwd(), output);
4608
+ if (existsSync2(outputPath) && !forceOverwrite) {
4609
+ const shouldOverwrite = await dist_default3({
4610
+ message: `\u26A0\uFE0F ${output} already exists. Overwrite?`,
4611
+ default: false
4612
+ });
4613
+ if (!shouldOverwrite) {
4614
+ console.log(`\u23ED\uFE0F Skipped ${output}`);
4615
+ return;
4616
+ }
4617
+ }
4590
4618
  console.log(`\u{1F4E5} Pulling ${output} from ${project}...`);
4591
4619
  const content = await pullEnvFile(
4592
4620
  config.host,
@@ -4594,7 +4622,6 @@ async function pullCommand2(args2) {
4594
4622
  project,
4595
4623
  output
4596
4624
  );
4597
- const outputPath = join4(process.cwd(), output);
4598
4625
  const dir = dirname(outputPath);
4599
4626
  if (dir !== process.cwd()) {
4600
4627
  await mkdir3(dir, { recursive: true });
@@ -4662,6 +4689,36 @@ async function pullCommand2(args2) {
4662
4689
  });
4663
4690
  }
4664
4691
  }
4692
+ const existingFiles = selectedFiles.filter(
4693
+ (f) => existsSync2(join4(process.cwd(), f))
4694
+ );
4695
+ if (existingFiles.length > 0 && !forceOverwrite) {
4696
+ console.log(`
4697
+ \u26A0\uFE0F The following local files already exist:`);
4698
+ existingFiles.forEach((f) => console.log(` \u2022 ${f}`));
4699
+ const overwriteChoice = await dist_default6({
4700
+ message: "\nHow would you like to proceed?",
4701
+ choices: [
4702
+ {
4703
+ name: "\u23ED\uFE0F Skip existing files (only pull new ones)",
4704
+ value: "skip"
4705
+ },
4706
+ { name: "\u{1F4DD} Overwrite all existing files", value: "overwrite" },
4707
+ { name: "\u274C Cancel", value: "cancel" }
4708
+ ]
4709
+ });
4710
+ if (overwriteChoice === "cancel") {
4711
+ console.log("\u274C Cancelled");
4712
+ return;
4713
+ }
4714
+ if (overwriteChoice === "skip") {
4715
+ selectedFiles = selectedFiles.filter((f) => !existingFiles.includes(f));
4716
+ if (selectedFiles.length === 0) {
4717
+ console.log("\u23ED\uFE0F No new files to pull");
4718
+ return;
4719
+ }
4720
+ }
4721
+ }
4665
4722
  if (selectedFiles.length === 1) {
4666
4723
  console.log(`
4667
4724
  \u{1F4E5} Pulling ${selectedFiles[0]}...`);
@@ -4674,13 +4731,13 @@ async function pullCommand2(args2) {
4674
4731
  let failCount = 0;
4675
4732
  for (const filename of selectedFiles) {
4676
4733
  try {
4734
+ const outputPath = join4(process.cwd(), filename);
4677
4735
  const content = await pullEnvFile(
4678
4736
  config.host,
4679
4737
  config.authToken,
4680
4738
  project,
4681
4739
  filename
4682
4740
  );
4683
- const outputPath = join4(process.cwd(), filename);
4684
4741
  const dir = dirname(outputPath);
4685
4742
  if (dir !== process.cwd()) {
4686
4743
  await mkdir3(dir, { recursive: true });
@@ -4754,7 +4811,7 @@ async function pushCommand2(args2) {
4754
4811
  }
4755
4812
  const project = flags.p || flags.project || config.project;
4756
4813
  const environment = flags.e || flags.env;
4757
- let input = flags.in || flags.input;
4814
+ let inputFile = flags.in || flags.input;
4758
4815
  let searchDepth = 10;
4759
4816
  if (flags.depth) {
4760
4817
  const parsedDepth = parseInt(flags.depth, 10);
@@ -4767,7 +4824,7 @@ async function pushCommand2(args2) {
4767
4824
  console.log(` This directory is initialized for ${config.project}`);
4768
4825
  }
4769
4826
  let selectedFiles = [];
4770
- if (!input) {
4827
+ if (!inputFile) {
4771
4828
  const cwd = process.cwd();
4772
4829
  const envFiles = await findEnvFiles(cwd, searchDepth);
4773
4830
  if (envFiles.length === 0) {
@@ -4823,7 +4880,7 @@ async function pushCommand2(args2) {
4823
4880
  }
4824
4881
  }
4825
4882
  } else {
4826
- selectedFiles = [input];
4883
+ selectedFiles = [inputFile];
4827
4884
  }
4828
4885
  const envSuffix = environment ? ` (env: ${environment})` : "";
4829
4886
  if (selectedFiles.length === 1) {
@@ -4879,7 +4936,7 @@ async function pushCommand2(args2) {
4879
4936
  file,
4880
4937
  // Use full relative path, not just filename
4881
4938
  environment
4882
- // Optional environment tag
4939
+ // Optional - defaults to "default" on server if not provided
4883
4940
  );
4884
4941
  if (selectedFiles.length === 1) {
4885
4942
  console.log(
@@ -5826,7 +5883,7 @@ ${import_chalk.default.bold("Usage in Docker:")}
5826
5883
 
5827
5884
  // src/utils/versionCheck.ts
5828
5885
  var PACKAGE_NAME = "@saidulbadhon/jssm-cli";
5829
- var CURRENT_VERSION = "1.6.4";
5886
+ var CURRENT_VERSION = "1.6.6";
5830
5887
  async function getLatestVersion() {
5831
5888
  try {
5832
5889
  const response = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saidulbadhon/jssm-cli",
3
- "version": "1.6.4",
3
+ "version": "1.6.6",
4
4
  "private": false,
5
5
  "description": "CLI for JSSM - Simple environment variable manager",
6
6
  "author": "Saidul Badhon",