Skip to content

Instantly share code, notes, and snippets.

@iamnewton
Last active December 4, 2019 22:26
Show Gist options
  • Save iamnewton/b28bf10822bf7fef8dee83bd568e534b to your computer and use it in GitHub Desktop.
Save iamnewton/b28bf10822bf7fef8dee83bd568e534b to your computer and use it in GitHub Desktop.

Revisions

  1. iamnewton revised this gist Dec 4, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions readFile.js
    Original file line number Diff line number Diff line change
    @@ -12,9 +12,9 @@ const readFile = () => {
    // read line by line and modify a line and rewrite it back
    readInterface.on('line', function(line) {
    if (line.includes('projectVersion')) {
    this.output.write('sonar.projectVersion=2020.1.0\n');
    this.output.write('sonar.projectVersion=2020.1.0\n');
    } else {
    this.output.write(`${line}\n`);
    this.output.write(`${line}\n`);
    }
    });
    };
  2. iamnewton created this gist Dec 4, 2019.
    20 changes: 20 additions & 0 deletions readFile.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    const fs = require('fs');
    const readline = require('readline');

    const readFile = () => {
    // create readline interface and output to a new file; can't figure out how to write to same file
    const readInterface = readline.createInterface({
    input: fs.createReadStream(findup('sonar-project.properties')),
    output: fs.createWriteStream('sonar-project.properties.temp'),
    console: false
    });

    // read line by line and modify a line and rewrite it back
    readInterface.on('line', function(line) {
    if (line.includes('projectVersion')) {
    this.output.write('sonar.projectVersion=2020.1.0\n');
    } else {
    this.output.write(`${line}\n`);
    }
    });
    };