From b50ebc30c35b71776d10acc2709c93981b784e2a Mon Sep 17 00:00:00 2001 From: omid Date: Wed, 17 Apr 2024 20:26:16 +0430 Subject: [PATCH] added __dirname instead of absolute path --- examples/index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/index.js b/examples/index.js index 5c7d928e..c3a4c3de 100644 --- a/examples/index.js +++ b/examples/index.js @@ -1,9 +1,16 @@ // eslint-disable-next-line @typescript-eslint/no-var-requires const { Optimizer } = require('../lib/Optimizer') +const fs = require('fs') +const path = require('path') -// read input.yaml file synconously and store it as an string -const input = require('fs').readFileSync('./examples/input.yaml', 'utf8') +// Construct absolute paths to input and output files +const inputFilePath = path.join(__dirname, 'input.yaml') +const outputFilePath = path.join(__dirname, 'output.yaml') + +// Read input.yaml file synchronously and store it as a string +const input = fs.readFileSync(inputFilePath, 'utf8') const optimizer = new Optimizer(input) + optimizer.getReport().then((report) => { console.log(report) const optimizedDocument = optimizer.getOptimizedDocument({ @@ -14,6 +21,7 @@ optimizer.getReport().then((report) => { moveToComponents: true, }, }) - //store optimizedDocument as to output.yaml - require('fs').writeFileSync('./examples/output.yaml', optimizedDocument) + + // Store optimizedDocument to output.yaml + fs.writeFileSync(outputFilePath, optimizedDocument) })