@saidulbadhon/jssm-cli 1.9.0 → 1.9.5
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.
- package/dist/index.js +84 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4179,6 +4179,13 @@ async function pushEnvFile(host, apiKey, project, content, filename = ".env") {
|
|
|
4179
4179
|
body: JSON.stringify({ content, filename })
|
|
4180
4180
|
});
|
|
4181
4181
|
}
|
|
4182
|
+
async function deleteEnvFile(host, apiKey, project, filename) {
|
|
4183
|
+
const url = `${host}/projects/${encodeURIComponent(project)}/files/delete`;
|
|
4184
|
+
return apiRequest(url, apiKey, {
|
|
4185
|
+
method: "POST",
|
|
4186
|
+
body: JSON.stringify({ filename })
|
|
4187
|
+
});
|
|
4188
|
+
}
|
|
4182
4189
|
async function pullEnvFile(host, apiKey, project, filename = ".env") {
|
|
4183
4190
|
const url = `${host}/projects/${encodeURIComponent(project)}/files/pull?filename=${encodeURIComponent(
|
|
4184
4191
|
filename
|
|
@@ -4644,7 +4651,13 @@ async function pullCommand2(args2) {
|
|
|
4644
4651
|
);
|
|
4645
4652
|
const dir = dirname(outputPath);
|
|
4646
4653
|
if (dir !== process.cwd()) {
|
|
4647
|
-
|
|
4654
|
+
try {
|
|
4655
|
+
await mkdir3(dir, { recursive: true });
|
|
4656
|
+
} catch (mkdirError) {
|
|
4657
|
+
if (!(mkdirError instanceof Error) || !("code" in mkdirError) || mkdirError.code !== "EEXIST") {
|
|
4658
|
+
throw mkdirError;
|
|
4659
|
+
}
|
|
4660
|
+
}
|
|
4648
4661
|
}
|
|
4649
4662
|
await writeFile3(outputPath, content, "utf-8");
|
|
4650
4663
|
const varCount = countVariables(content);
|
|
@@ -4778,7 +4791,13 @@ async function pullCommand2(args2) {
|
|
|
4778
4791
|
);
|
|
4779
4792
|
const dir = dirname(outputPath);
|
|
4780
4793
|
if (dir !== process.cwd()) {
|
|
4781
|
-
|
|
4794
|
+
try {
|
|
4795
|
+
await mkdir3(dir, { recursive: true });
|
|
4796
|
+
} catch (mkdirError) {
|
|
4797
|
+
if (!(mkdirError instanceof Error) || !("code" in mkdirError) || mkdirError.code !== "EEXIST") {
|
|
4798
|
+
throw mkdirError;
|
|
4799
|
+
}
|
|
4800
|
+
}
|
|
4782
4801
|
}
|
|
4783
4802
|
await writeFile3(outputPath, content, "utf-8");
|
|
4784
4803
|
const varCount = countVariables(content);
|
|
@@ -4874,6 +4893,9 @@ function calculateLineDiff2(oldContent, newContent) {
|
|
|
4874
4893
|
}
|
|
4875
4894
|
return { changedLines, isNewFile: false };
|
|
4876
4895
|
}
|
|
4896
|
+
function normalizeFilePath(filePath) {
|
|
4897
|
+
return filePath.replace(/\\/g, "/");
|
|
4898
|
+
}
|
|
4877
4899
|
async function pushCommand2(args2) {
|
|
4878
4900
|
const flags = {};
|
|
4879
4901
|
for (let i = 0; i < args2.length; i++) {
|
|
@@ -4912,15 +4934,19 @@ async function pushCommand2(args2) {
|
|
|
4912
4934
|
console.log(` This directory is initialized for ${config.project}`);
|
|
4913
4935
|
}
|
|
4914
4936
|
let selectedFiles = [];
|
|
4937
|
+
let discoveredLocalFiles = [];
|
|
4938
|
+
let shouldPruneDeletedRemoteFiles = false;
|
|
4915
4939
|
if (!inputFile) {
|
|
4916
4940
|
const cwd = process.cwd();
|
|
4917
4941
|
const envFiles = await findEnvFiles(cwd, searchDepth);
|
|
4942
|
+
discoveredLocalFiles = envFiles.map((f) => normalizeFilePath(f.relativePath));
|
|
4918
4943
|
if (envFiles.length === 0) {
|
|
4919
4944
|
console.error("\u274C No .env files found");
|
|
4920
4945
|
console.error("\u{1F4A1} Create a .env file or specify one with --input <file>");
|
|
4921
4946
|
process.exit(1);
|
|
4922
4947
|
} else if (envFiles.length === 1) {
|
|
4923
|
-
selectedFiles = [envFiles[0].relativePath];
|
|
4948
|
+
selectedFiles = [normalizeFilePath(envFiles[0].relativePath)];
|
|
4949
|
+
shouldPruneDeletedRemoteFiles = true;
|
|
4924
4950
|
console.log(
|
|
4925
4951
|
`\u{1F4C4} Found ${envFiles[0].relativePath} (${envFiles[0].variableCount} variables)`
|
|
4926
4952
|
);
|
|
@@ -4947,7 +4973,8 @@ async function pushCommand2(args2) {
|
|
|
4947
4973
|
]
|
|
4948
4974
|
});
|
|
4949
4975
|
if (pushOption === "all") {
|
|
4950
|
-
selectedFiles =
|
|
4976
|
+
selectedFiles = discoveredLocalFiles;
|
|
4977
|
+
shouldPruneDeletedRemoteFiles = true;
|
|
4951
4978
|
} else {
|
|
4952
4979
|
const fileChoices = envFiles.map((file) => ({
|
|
4953
4980
|
name: `${file.relativePath} (${file.variableCount} variables)`,
|
|
@@ -4964,11 +4991,11 @@ async function pushCommand2(args2) {
|
|
|
4964
4991
|
return true;
|
|
4965
4992
|
}
|
|
4966
4993
|
});
|
|
4967
|
-
selectedFiles = selected;
|
|
4994
|
+
selectedFiles = selected.map((file) => normalizeFilePath(file));
|
|
4968
4995
|
}
|
|
4969
4996
|
}
|
|
4970
4997
|
} else {
|
|
4971
|
-
selectedFiles = [inputFile];
|
|
4998
|
+
selectedFiles = [normalizeFilePath(inputFile)];
|
|
4972
4999
|
}
|
|
4973
5000
|
if (selectedFiles.length === 1) {
|
|
4974
5001
|
console.log(`
|
|
@@ -4984,6 +5011,7 @@ async function pushCommand2(args2) {
|
|
|
4984
5011
|
let failCount = 0;
|
|
4985
5012
|
let updatedFilesCount = 0;
|
|
4986
5013
|
let newFilesCount = 0;
|
|
5014
|
+
let deletedFilesCount = 0;
|
|
4987
5015
|
let totalChangedLines = 0;
|
|
4988
5016
|
for (const file of selectedFiles) {
|
|
4989
5017
|
let fileContent = "";
|
|
@@ -5072,6 +5100,49 @@ async function pushCommand2(args2) {
|
|
|
5072
5100
|
failCount++;
|
|
5073
5101
|
}
|
|
5074
5102
|
}
|
|
5103
|
+
if (shouldPruneDeletedRemoteFiles && failCount === 0) {
|
|
5104
|
+
try {
|
|
5105
|
+
const remoteFiles = (await listEnvFiles(
|
|
5106
|
+
config.host,
|
|
5107
|
+
config.authToken,
|
|
5108
|
+
project
|
|
5109
|
+
)).map((file) => normalizeFilePath(file)).filter((value, index, self) => self.indexOf(value) === index);
|
|
5110
|
+
const localFilesSet = new Set(discoveredLocalFiles);
|
|
5111
|
+
const remoteFilesToDelete = remoteFiles.filter(
|
|
5112
|
+
(remoteFile) => !localFilesSet.has(remoteFile)
|
|
5113
|
+
);
|
|
5114
|
+
if (remoteFilesToDelete.length > 0) {
|
|
5115
|
+
console.log(
|
|
5116
|
+
`
|
|
5117
|
+
\u{1F9F9} Syncing deletions: ${remoteFilesToDelete.length} remote file(s) no longer exist locally`
|
|
5118
|
+
);
|
|
5119
|
+
for (const remoteFile of remoteFilesToDelete) {
|
|
5120
|
+
try {
|
|
5121
|
+
const result = await deleteEnvFile(
|
|
5122
|
+
config.host,
|
|
5123
|
+
config.authToken,
|
|
5124
|
+
project,
|
|
5125
|
+
remoteFile
|
|
5126
|
+
);
|
|
5127
|
+
if (result.deleted) {
|
|
5128
|
+
deletedFilesCount++;
|
|
5129
|
+
console.log(`\u{1F5D1}\uFE0F Deleted ${remoteFile} from ${project}`);
|
|
5130
|
+
} else {
|
|
5131
|
+
console.log(`\u2139\uFE0F ${remoteFile} was already absent on server`);
|
|
5132
|
+
}
|
|
5133
|
+
} catch (error) {
|
|
5134
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
5135
|
+
console.error(`\u274C ${remoteFile}: Failed to delete - ${message}`);
|
|
5136
|
+
failCount++;
|
|
5137
|
+
}
|
|
5138
|
+
}
|
|
5139
|
+
}
|
|
5140
|
+
} catch (error) {
|
|
5141
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
5142
|
+
console.error(`\u274C Failed to check remote files for deletion sync: ${message}`);
|
|
5143
|
+
failCount++;
|
|
5144
|
+
}
|
|
5145
|
+
}
|
|
5075
5146
|
if (selectedFiles.length > 1) {
|
|
5076
5147
|
console.log(`
|
|
5077
5148
|
\u{1F4CA} Summary:`);
|
|
@@ -5082,6 +5153,9 @@ async function pushCommand2(args2) {
|
|
|
5082
5153
|
if (updatedFilesCount > 0) {
|
|
5083
5154
|
console.log(` \u{1F4DD} Updated files: ${updatedFilesCount}`);
|
|
5084
5155
|
}
|
|
5156
|
+
if (deletedFilesCount > 0) {
|
|
5157
|
+
console.log(` \u{1F5D1}\uFE0F Deleted files: ${deletedFilesCount}`);
|
|
5158
|
+
}
|
|
5085
5159
|
if (totalChangedLines > 0) {
|
|
5086
5160
|
console.log(` \u{1F4CF} Total lines changed: ${totalChangedLines}`);
|
|
5087
5161
|
}
|
|
@@ -5099,6 +5173,9 @@ async function pushCommand2(args2) {
|
|
|
5099
5173
|
if (totalChangedLines > 0) {
|
|
5100
5174
|
console.log(` \u{1F4CF} Lines changed: ${totalChangedLines}`);
|
|
5101
5175
|
}
|
|
5176
|
+
if (deletedFilesCount > 0) {
|
|
5177
|
+
console.log(` \u{1F5D1}\uFE0F Remote files deleted: ${deletedFilesCount}`);
|
|
5178
|
+
}
|
|
5102
5179
|
}
|
|
5103
5180
|
if (failCount > 0) {
|
|
5104
5181
|
process.exit(1);
|
|
@@ -5950,7 +6027,7 @@ ${import_chalk.default.bold("Usage in Docker:")}
|
|
|
5950
6027
|
|
|
5951
6028
|
// src/utils/versionCheck.ts
|
|
5952
6029
|
var PACKAGE_NAME = "@saidulbadhon/jssm-cli";
|
|
5953
|
-
var CURRENT_VERSION = "1.9.
|
|
6030
|
+
var CURRENT_VERSION = "1.9.5";
|
|
5954
6031
|
async function getLatestVersion() {
|
|
5955
6032
|
try {
|
|
5956
6033
|
const response = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}`);
|