Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dddb352457 | |||
| 3fe3dc96da | |||
| e953466786 | |||
| c43c37ce34 |
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "shsf-cli",
|
"name": "shsf-cli",
|
||||||
"version": "2.2.3",
|
"version": "2.2.6",
|
||||||
"description": "",
|
"description": "",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"files": [
|
"files": [
|
||||||
|
|||||||
+69
-15
@@ -4,6 +4,41 @@ import fs from "fs";
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import { createHash } from "crypto";
|
import { createHash } from "crypto";
|
||||||
|
|
||||||
|
const unpushableFiles = [
|
||||||
|
".png",
|
||||||
|
".jpg",
|
||||||
|
".jpeg",
|
||||||
|
".gif",
|
||||||
|
".bmp",
|
||||||
|
".ico",
|
||||||
|
".zip",
|
||||||
|
".tar",
|
||||||
|
".gz",
|
||||||
|
".7z",
|
||||||
|
".pdf",
|
||||||
|
".doc",
|
||||||
|
".docx",
|
||||||
|
".xls",
|
||||||
|
".xlsx",
|
||||||
|
".ppt",
|
||||||
|
".pptx",
|
||||||
|
".exe",
|
||||||
|
".dll",
|
||||||
|
".so",
|
||||||
|
".dylib",
|
||||||
|
"docker-compose.yml",
|
||||||
|
"docker-compose.yaml",
|
||||||
|
"compose.yaml",
|
||||||
|
"compose.yml",
|
||||||
|
"dockerfile",
|
||||||
|
"dockerfile.dev",
|
||||||
|
"dockerfile.prod",
|
||||||
|
".gitignore",
|
||||||
|
".env",
|
||||||
|
".gitkeep",
|
||||||
|
".md"
|
||||||
|
];
|
||||||
|
|
||||||
async function deleteNonexistentFiles(
|
async function deleteNonexistentFiles(
|
||||||
currentFiles: any[],
|
currentFiles: any[],
|
||||||
files: any[],
|
files: any[],
|
||||||
@@ -14,12 +49,13 @@ async function deleteNonexistentFiles(
|
|||||||
for (const currentFile of currentFiles) {
|
for (const currentFile of currentFiles) {
|
||||||
if (!files.some((f: any) => f.filename === currentFile.name)) {
|
if (!files.some((f: any) => f.filename === currentFile.name)) {
|
||||||
try {
|
try {
|
||||||
await client.delete(
|
await client.delete(
|
||||||
`/api/function/${options.id}/file/${currentFile.id}`,
|
`/api/function/${options.id}/file/${currentFile.id}`,
|
||||||
{
|
{
|
||||||
data: { filename: currentFile.name },
|
data: { filename: currentFile.name },
|
||||||
},
|
},
|
||||||
);} catch (error: any) {
|
);
|
||||||
|
} catch (error: any) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
console.log(
|
console.log(
|
||||||
@@ -54,10 +90,18 @@ export const pushDefinition = {
|
|||||||
);
|
);
|
||||||
const currentFiles = currentFilesResponse.data.data; // Expecting { name: string, id: string [...] }[]
|
const currentFiles = currentFilesResponse.data.data; // Expecting { name: string, id: string [...] }[]
|
||||||
|
|
||||||
const files = fs.readdirSync(options.from).map((file) => ({
|
// Read local files and filter to only include files (exclude directories)
|
||||||
filename: file,
|
const files = fs
|
||||||
content: fs.readFileSync(path.join(options.from, file), "utf-8"),
|
.readdirSync(options.from)
|
||||||
}));
|
.map((file) => {
|
||||||
|
const filePath = path.join(options.from, file);
|
||||||
|
return { filename: file, filePath };
|
||||||
|
})
|
||||||
|
.filter(({ filePath }) => fs.statSync(filePath).isFile())
|
||||||
|
.map(({ filename, filePath }) => ({
|
||||||
|
filename,
|
||||||
|
content: fs.readFileSync(filePath, "utf-8"),
|
||||||
|
}));
|
||||||
|
|
||||||
if (!options.force && files.length > 5) {
|
if (!options.force && files.length > 5) {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -76,9 +120,6 @@ export const pushDefinition = {
|
|||||||
(f: any) => f.name === file.filename,
|
(f: any) => f.name === file.filename,
|
||||||
);
|
);
|
||||||
if (currentFile) {
|
if (currentFile) {
|
||||||
// If the file content exists in the response, we can hash it.
|
|
||||||
// Note: currentFiles from /api/function/:id/files might not have content by default depending on API,
|
|
||||||
// but the original code assumes it does.
|
|
||||||
const currentFileHash = createHash("md5")
|
const currentFileHash = createHash("md5")
|
||||||
.update(currentFile.content || "")
|
.update(currentFile.content || "")
|
||||||
.digest("hex");
|
.digest("hex");
|
||||||
@@ -92,14 +133,27 @@ export const pushDefinition = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const filenameLower = file.filename.toLowerCase();
|
||||||
|
// Unpushable file check
|
||||||
|
if (unpushableFiles.some((suffix) => filenameLower.endsWith(suffix))) {
|
||||||
|
console.log(
|
||||||
|
chalk.yellow(
|
||||||
|
`Skipping ${file.filename}, it matches unpushable patterns for function ${options.id}`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
await client.put(`/api/function/${options.id}/file`, {
|
await client.put(`/api/function/${options.id}/file`, {
|
||||||
filename: file.filename,
|
filename: file.filename,
|
||||||
code: file.content,
|
code: file.content,
|
||||||
});
|
});
|
||||||
|
|
||||||
const byteSize = Buffer.byteLength(file.content, 'utf8');
|
const byteSize = Buffer.byteLength(file.content, "utf8");
|
||||||
console.log(
|
console.log(
|
||||||
chalk.green(`Pushed ${file.filename} (${byteSize} bytes) to function ${options.id}`),
|
chalk.green(
|
||||||
|
`Pushed ${file.filename} (${byteSize} bytes) to function ${options.id}`,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
pushedFilesCount++;
|
pushedFilesCount++;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user