mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
committed by
Nino Righi
parent
301f5878c2
commit
8ae990bcde
23
tools/download-file.js
Normal file
23
tools/download-file.js
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Script that downloads the swagger file from the given url
|
||||
*/
|
||||
const fetch = require('node-fetch');
|
||||
const https = require('https');
|
||||
const path = require('path');
|
||||
|
||||
const httpsAgent = new https.Agent({
|
||||
rejectUnauthorized: false,
|
||||
});
|
||||
|
||||
(async () => {
|
||||
const url = process.argv[2];
|
||||
const fileName = process.argv[3];
|
||||
const res = await fetch(url, {
|
||||
agent: httpsAgent,
|
||||
});
|
||||
|
||||
// Write the file to the disk
|
||||
const fileStream = require('fs').createWriteStream(fileName);
|
||||
res.body.pipe(fileStream);
|
||||
console.log('Swagger file downloaded successfully');
|
||||
})();
|
||||
43
tools/fix-files.js
Normal file
43
tools/fix-files.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
/**
|
||||
* Script that removes \ufffd for all files in a specified directory and its subdirectories.
|
||||
*/
|
||||
const directoryPath = process.argv[2]; // Get the target directory from command-line arguments
|
||||
|
||||
function removeInvalidChars(filePath) {
|
||||
fs.readFile(filePath, 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
console.error(`Error reading file ${filePath}:`, err);
|
||||
return;
|
||||
}
|
||||
const cleanedData = data.replace(/\ufffd/g, '');
|
||||
fs.writeFile(filePath, cleanedData, 'utf8', (err) => {
|
||||
if (err) {
|
||||
console.error(`Error writing file ${filePath}:`, err);
|
||||
} else {
|
||||
console.log(`Fixed file: ${filePath}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function traverseDirectory(dir) {
|
||||
fs.readdir(dir, { withFileTypes: true }, (err, files) => {
|
||||
if (err) {
|
||||
console.error(`Error reading directory ${dir}:`, err);
|
||||
return;
|
||||
}
|
||||
files.forEach((file) => {
|
||||
const fullPath = path.join(dir, file.name);
|
||||
if (file.isDirectory()) {
|
||||
traverseDirectory(fullPath);
|
||||
} else if (file.isFile()) {
|
||||
removeInvalidChars(fullPath);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
traverseDirectory(directoryPath);
|
||||
Reference in New Issue
Block a user