From 6286494ce12068af20033c1ac4c8bf5ad9ec1362 Mon Sep 17 00:00:00 2001 From: MEFRREEX Date: Fri, 3 Jan 2025 11:34:58 +0200 Subject: [PATCH 1/3] docs: added example to use library --- docs/examples/file_system.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 docs/examples/file_system.md diff --git a/docs/examples/file_system.md b/docs/examples/file_system.md new file mode 100644 index 0000000..32a7a66 --- /dev/null +++ b/docs/examples/file_system.md @@ -0,0 +1,28 @@ +# File System +Example of working with the file system using scripts + +```js +// Downloading Downloading a file from url +const url = "https://repo.instancify.app/snapshots/com/instancify/scriptify/script-js/1.0.3-SNAPSHOT/maven-metadata.xml"; +const fileName = "maven-metadata.xml"; + +if (!existsFile(fileName)) { + print(`File ${fileName} not found. Downloading...`) + downloadFromUrl(url, fileName) +} + +const foundFiles = []; + +// Search all files in the current folder +listFiles("").forEach(file => { + print(`Found file in folder ${file}.`) + if (file.contains("fileName")) { + print(`File ${file} found. Delete it.`); + deleteFile(file); + } + foundFiles.push(file); +}); + +// Write all saved current actions to a file +writeFile("summary.json", JSON.stringify(foundFiles)); +``` \ No newline at end of file From 77438a177628bbcc5a00369331d2f570fe53c010 Mon Sep 17 00:00:00 2001 From: MEFRREEX Date: Fri, 3 Jan 2025 11:43:49 +0200 Subject: [PATCH 2/3] docs: update file system example --- docs/examples/file_system.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/docs/examples/file_system.md b/docs/examples/file_system.md index 32a7a66..95f2bbd 100644 --- a/docs/examples/file_system.md +++ b/docs/examples/file_system.md @@ -2,7 +2,7 @@ Example of working with the file system using scripts ```js -// Downloading Downloading a file from url +// Downloading a file from url const url = "https://repo.instancify.app/snapshots/com/instancify/scriptify/script-js/1.0.3-SNAPSHOT/maven-metadata.xml"; const fileName = "maven-metadata.xml"; @@ -16,10 +16,6 @@ const foundFiles = []; // Search all files in the current folder listFiles("").forEach(file => { print(`Found file in folder ${file}.`) - if (file.contains("fileName")) { - print(`File ${file} found. Delete it.`); - deleteFile(file); - } foundFiles.push(file); }); From 406abb5431e76af420599548040746a0c60185f6 Mon Sep 17 00:00:00 2001 From: MEFRREEX Date: Fri, 3 Jan 2025 11:58:39 +0200 Subject: [PATCH 3/3] docs: update file system example 2 --- docs/examples/file_system.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/examples/file_system.md b/docs/examples/file_system.md index 95f2bbd..6725699 100644 --- a/docs/examples/file_system.md +++ b/docs/examples/file_system.md @@ -16,6 +16,12 @@ const foundFiles = []; // Search all files in the current folder listFiles("").forEach(file => { print(`Found file in folder ${file}.`) + // Get the file name and delete the file maven-metadata.xml + const foundFileName = normalizePath(file).replace(`${normalizePath(baseDir)}/`, ""); + if (foundFileName === fileName) { + print(`File ${file} found. Delete it.`); + deleteFile(file); + } foundFiles.push(file); });