From 37b6cfba91bdd4280c1fc4584c8bd58bcfbd0075 Mon Sep 17 00:00:00 2001 From: Omid Nomani <122370781+omidNM24@users.noreply.github.com> Date: Thu, 18 Apr 2024 14:53:57 +0430 Subject: [PATCH] fix: added __dirname instead of absolute path (#255) Co-authored-by: Khuda Dad Nomani <32505158+KhudaDad414@users.noreply.github.com> --- examples/index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/index.js b/examples/index.js index 507639db..934f3373 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({ @@ -18,6 +25,7 @@ optimizer.getReport().then((report) => { schema: false, }, }) - //store optimizedDocument as to output.yaml - require('fs').writeFileSync('./examples/output.yaml', optimizedDocument) + + // Store optimizedDocument to output.yaml + fs.writeFileSync(outputFilePath, optimizedDocument) })