@saidulbadhon/jssm-cli 1.9.1 → 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 +70 -5
- 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
|
|
@@ -4886,6 +4893,9 @@ function calculateLineDiff2(oldContent, newContent) {
|
|
|
4886
4893
|
}
|
|
4887
4894
|
return { changedLines, isNewFile: false };
|
|
4888
4895
|
}
|
|
4896
|
+
function normalizeFilePath(filePath) {
|
|
4897
|
+
return filePath.replace(/\\/g, "/");
|
|
4898
|
+
}
|
|
4889
4899
|
async function pushCommand2(args2) {
|
|
4890
4900
|
const flags = {};
|
|
4891
4901
|
for (let i = 0; i < args2.length; i++) {
|
|
@@ -4924,15 +4934,19 @@ async function pushCommand2(args2) {
|
|
|
4924
4934
|
console.log(` This directory is initialized for ${config.project}`);
|
|
4925
4935
|
}
|
|
4926
4936
|
let selectedFiles = [];
|
|
4937
|
+
let discoveredLocalFiles = [];
|
|
4938
|
+
let shouldPruneDeletedRemoteFiles = false;
|
|
4927
4939
|
if (!inputFile) {
|
|
4928
4940
|
const cwd = process.cwd();
|
|
4929
4941
|
const envFiles = await findEnvFiles(cwd, searchDepth);
|
|
4942
|
+
discoveredLocalFiles = envFiles.map((f) => normalizeFilePath(f.relativePath));
|
|
4930
4943
|
if (envFiles.length === 0) {
|
|
4931
4944
|
console.error("\u274C No .env files found");
|
|
4932
4945
|
console.error("\u{1F4A1} Create a .env file or specify one with --input <file>");
|
|
4933
4946
|
process.exit(1);
|
|
4934
4947
|
} else if (envFiles.length === 1) {
|
|
4935
|
-
selectedFiles = [envFiles[0].relativePath];
|
|
4948
|
+
selectedFiles = [normalizeFilePath(envFiles[0].relativePath)];
|
|
4949
|
+
shouldPruneDeletedRemoteFiles = true;
|
|
4936
4950
|
console.log(
|
|
4937
4951
|
`\u{1F4C4} Found ${envFiles[0].relativePath} (${envFiles[0].variableCount} variables)`
|
|
4938
4952
|
);
|
|
@@ -4959,7 +4973,8 @@ async function pushCommand2(args2) {
|
|
|
4959
4973
|
]
|
|
4960
4974
|
});
|
|
4961
4975
|
if (pushOption === "all") {
|
|
4962
|
-
selectedFiles =
|
|
4976
|
+
selectedFiles = discoveredLocalFiles;
|
|
4977
|
+
shouldPruneDeletedRemoteFiles = true;
|
|
4963
4978
|
} else {
|
|
4964
4979
|
const fileChoices = envFiles.map((file) => ({
|
|
4965
4980
|
name: `${file.relativePath} (${file.variableCount} variables)`,
|
|
@@ -4976,11 +4991,11 @@ async function pushCommand2(args2) {
|
|
|
4976
4991
|
return true;
|
|
4977
4992
|
}
|
|
4978
4993
|
});
|
|
4979
|
-
selectedFiles = selected;
|
|
4994
|
+
selectedFiles = selected.map((file) => normalizeFilePath(file));
|
|
4980
4995
|
}
|
|
4981
4996
|
}
|
|
4982
4997
|
} else {
|
|
4983
|
-
selectedFiles = [inputFile];
|
|
4998
|
+
selectedFiles = [normalizeFilePath(inputFile)];
|
|
4984
4999
|
}
|
|
4985
5000
|
if (selectedFiles.length === 1) {
|
|
4986
5001
|
console.log(`
|
|
@@ -4996,6 +5011,7 @@ async function pushCommand2(args2) {
|
|
|
4996
5011
|
let failCount = 0;
|
|
4997
5012
|
let updatedFilesCount = 0;
|
|
4998
5013
|
let newFilesCount = 0;
|
|
5014
|
+
let deletedFilesCount = 0;
|
|
4999
5015
|
let totalChangedLines = 0;
|
|
5000
5016
|
for (const file of selectedFiles) {
|
|
5001
5017
|
let fileContent = "";
|
|
@@ -5084,6 +5100,49 @@ async function pushCommand2(args2) {
|
|
|
5084
5100
|
failCount++;
|
|
5085
5101
|
}
|
|
5086
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
|
+
}
|
|
5087
5146
|
if (selectedFiles.length > 1) {
|
|
5088
5147
|
console.log(`
|
|
5089
5148
|
\u{1F4CA} Summary:`);
|
|
@@ -5094,6 +5153,9 @@ async function pushCommand2(args2) {
|
|
|
5094
5153
|
if (updatedFilesCount > 0) {
|
|
5095
5154
|
console.log(` \u{1F4DD} Updated files: ${updatedFilesCount}`);
|
|
5096
5155
|
}
|
|
5156
|
+
if (deletedFilesCount > 0) {
|
|
5157
|
+
console.log(` \u{1F5D1}\uFE0F Deleted files: ${deletedFilesCount}`);
|
|
5158
|
+
}
|
|
5097
5159
|
if (totalChangedLines > 0) {
|
|
5098
5160
|
console.log(` \u{1F4CF} Total lines changed: ${totalChangedLines}`);
|
|
5099
5161
|
}
|
|
@@ -5111,6 +5173,9 @@ async function pushCommand2(args2) {
|
|
|
5111
5173
|
if (totalChangedLines > 0) {
|
|
5112
5174
|
console.log(` \u{1F4CF} Lines changed: ${totalChangedLines}`);
|
|
5113
5175
|
}
|
|
5176
|
+
if (deletedFilesCount > 0) {
|
|
5177
|
+
console.log(` \u{1F5D1}\uFE0F Remote files deleted: ${deletedFilesCount}`);
|
|
5178
|
+
}
|
|
5114
5179
|
}
|
|
5115
5180
|
if (failCount > 0) {
|
|
5116
5181
|
process.exit(1);
|
|
@@ -5962,7 +6027,7 @@ ${import_chalk.default.bold("Usage in Docker:")}
|
|
|
5962
6027
|
|
|
5963
6028
|
// src/utils/versionCheck.ts
|
|
5964
6029
|
var PACKAGE_NAME = "@saidulbadhon/jssm-cli";
|
|
5965
|
-
var CURRENT_VERSION = "1.9.
|
|
6030
|
+
var CURRENT_VERSION = "1.9.5";
|
|
5966
6031
|
async function getLatestVersion() {
|
|
5967
6032
|
try {
|
|
5968
6033
|
const response = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}`);
|