-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e8a680
commit be731b8
Showing
14 changed files
with
169 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const { readFile } = require('node:fs/promises'); | ||
const mime = require('mime'); | ||
const stringify = require('csv-stringify'); | ||
|
||
const testDataPath = '../test'; | ||
const directoryPath = path.join(__dirname, testDataPath); | ||
console.log("Reading files from: " + directoryPath); | ||
|
||
const generateCSV = async () => { | ||
fs.readdir(directoryPath, async (err, files) => { | ||
let csvData = []; | ||
let id = 0; // Default to 0 | ||
|
||
if (err) { | ||
return console.log('Unable to scan directory: ' + err); | ||
} | ||
|
||
// Keep only png files | ||
files = files.filter((file) => file.endsWith(".png") ); | ||
|
||
// Add Header line to CSV | ||
csvData.push(["id","content","mediaType","fileName","applicationName" ]); | ||
|
||
|
||
|
||
console.log("Found the following files: "); | ||
for (let i = 0; i < files.length; i++) { | ||
let fileName = files[i]; | ||
id++; | ||
let filePath = path.join(directoryPath, fileName); | ||
let mimeType = mime.getType(filePath); | ||
console.log(filePath + " " + mimeType ); | ||
|
||
let contents = await readFile(filePath); | ||
let contentBase64 = contents.toString('base64'); | ||
|
||
// Add header line | ||
csvData.push([id, contentBase64, mimeType, fileName,"demo content" ]); | ||
}; | ||
|
||
|
||
// Convert file to CSV and write test file | ||
stringify.stringify(csvData, (err, output) => { | ||
if (err) { | ||
console.error('Error:', err); | ||
return; | ||
} | ||
|
||
// Specify the file path where you want to save the CSV | ||
let filePath = path.join(directoryPath, './data/sap.capire.media-Media.csv'); | ||
|
||
// Write the CSV to a local file | ||
fs.writeFile(filePath, output, (err) => { | ||
if (err) { | ||
console.error('Error writing to file:', err); | ||
} else { | ||
console.log(`CSV saved to ${filePath}`); | ||
} | ||
}); | ||
}); | ||
|
||
}); | ||
} | ||
|
||
generateCSV(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "cap-media-csv-generator", | ||
"version": "1.0.0", | ||
"description": "A simple CAP project.", | ||
"repository": "https://github.com/katansapdevelop/cap-media-demo", | ||
"license": "UNLICENSED", | ||
"private": true, | ||
"dependencies": { | ||
"csv-stringify": "^6.4.4", | ||
"mime": "^3.0.0" | ||
}, | ||
"scripts": { | ||
"csv-gen": "node generator.js" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.