How to use replace-in-file - 10 common examples

To help you get started, we’ve selected a few replace-in-file examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NakedObjectsGroup / NakedObjectsFramework / Spa2 / nakedobjectsspa / prepublish.js View on Github external
var version = find.findSync("version", ".", "package.json").then(s => {

    try {
        var versionLine = s["package.json"].line[0];
        var versionSplit = versionLine.split('"');
        var version = versionSplit[3];

        // to update client version in code 
        var options2 = {
            files: ["./src/app/constants.ts"],
            from: [/clientVersion.*/g],
            to: "clientVersion = '" + version + "';"
        };

        replace.sync(options2);
    } catch (e) {
        console.error('Error occurred updating version:', e);
    }
});
github gautamsi / ews-javascript-api / scripts / build.js View on Github external
files: typingFile,
    from: [
      /\r?\n?^.*import.*\{.*\}.*from.*\;/gm,
      /\r?\nimport \* as moment from 'moment-timezone';/g,
      /^.*export.*\{.*\}.*from.*\;/gm,
      /^.*export.*\{.*\};$/gm,
      /^.*\/\/\/\s*\/gm,
      /(\r?\n\s*\/\*\*\s*\r?\n([^\*]|(\*(?!\/)))*\*\/)?\r?\n\s*private\s.*;/gm, // replace line with private and also preceding lines with jsdoc comments
      // /^\s*private\s.*;/gm, // original replacing private did not replace p
      /\r\n\r\n/g,
      /\n\n/g,
      /export declare/g,
    ],
    to: '',
  };
  replace.sync(options);
}
github admob-plus / admob-plus / packages / cordova / scripts / gen.ts View on Github external
.map(s => {
      let d = path.dirname(s.toString())
      if (d === '.') {
        d = ''
      } else {
        d = `/${d}`
      }
      return `        `
    })
    .sort()
    .join('\n')
  const iosContent = iosFiles
    .map(s => `        `)
    .sort()
    .join('\n')
  await replace({
    files: [path.join(__dirname, '../plugin.xml')],
    // tslint:disable-next-line:max-line-length
    from: /([\s\S]*ANDROID_BEGIN -->\n)[\s\S]*(\n\s+\n)[\s\S]*(\n\s+
github NakedObjectsGroup / NakedObjectsFramework / Spa2 / nakedobjectsspa / togglecss.js View on Github external
try {
        var nameLine = s["package.json"].line[0];
        var nameSplit = nameLine.split('"');
        var name = nameSplit[3];

        var newName = name.indexOf("alt") >= 0 ? "nakedobjects.spa" : "nakedobjects.alt.spa";

        var regex = new RegExp(name, "g");

        var options = {
            files: ["package.json"],
            from: regex,
            to: newName
        };

        replace.sync(options);

    } catch (e) {
        console.error('Error occurred updating name:', e);
    }
});
github JeremyEnglert / JointsWP / build / startup.js View on Github external
function changeLocalUrl(themeLocalUrl) {
  if(themeLocalUrl == "") {
    console.log(chalk.magenta.bold('Local URL was not chnanged.'));
    return;
  }
  const options = {
    files: 'webpack.config.js',
    from: /proxy: .{1,}/g,
    to: `proxy:: "${themeLocalUrl}"`,
  };
  try {
    const changes = replace.sync(options);
    console.log(chalk.magenta.bold('Local URL updated in: ') + ('config.js'));
  }
  catch (error) {
    console.error('Error occurred:', error);
  }
}
github OWASP / owasp-mstg / Tools / genpdf.js View on Github external
function preProcessRunningJs() {
  var options = {
    files: "running.js",
    from: "[DATE]",
    to: "[" + "OWASP Mobile Security Testing Guide: " + tag + "]"
  };
  try {
    const changes = replace.sync(options);
    console.log("Modified files:", changes.join(", "));
  } catch (error) {
    console.error("Error occurred:", error);
  }
}
github onevcat / UniWebView-Docs / OldDocs / archive.js View on Github external
function replaceVersionLink(fromVersion, toVersion, files) {
  const link = `\/?${fromVersion}/`;
  const reg = new RegExp(link, 'g');

  const options = {
    files: files,
    //Replacement to make (string or regex) 
    from: reg,
    to: `/archived/${toVersion}/`,
  };

  let changedFiles = replace.sync(options);
  console.log(`Modified files:\n${changedFiles.join('\n')}`);
}
github algolia / places / scripts / bump-package-version.js View on Github external
console.log('..Updating src/version.js');

const versionFile = path.join(__dirname, '../src/version.js');
const newContent = `export default '${newVersion}';\n`;
fs.writeFileSync(versionFile, newContent);

console.log('..Updating package.json');

replace.sync({
  files: [path.join(__dirname, '..', 'package.json')],
  from: `"version": "${currentVersion}"`,
  to: `"version": "${newVersion}"`,
});

replace.sync({
  files: [path.join(__dirname, '..', 'README.md')],
  from: `places.js@${currentVersion}`,
  to: `places.js@${newVersion}`,
});
github ceph / ceph / src / pybind / mgr / dashboard / frontend / environment.build.js View on Github external
const optionsOldProd = {
    files:[
      'src/environments/environment.prod.ts',
      'src/environments/environment.ts'
    ],
    from: /production: (.*)/g,
    to: "production: '{PRODUCTION}',",
    allowEmptyPaths: false,
};

try {
    let changeOldYearFiles = replace.sync(optionsOldYear);
    let changeNewYearFiles = replace.sync(optionsNewYear);
    let changeOldProdFiles = replace.sync(optionsOldProd);
    let changeProdFiles = replace.sync(optionsNewProd);
    let changeDevFiles = replace.sync(optionsNewDev);
    console.log('Environment variables have been set');
}
catch (error) {
    console.error('Error occurred:', error);
    throw error
}
github shoutem / cli / src / services / platform.js View on Github external
export async function fixPlatform(platformDir, appId) {
  const appBuilderPath = path.join(platformDir, 'scripts', 'classes', 'app-builder.js');

  if (process.platform === 'win32') {
    try {
      await replace({
        files: appBuilderPath,
        from: './gradlew',
        to: 'gradlew'
      });
    } catch (err) {
      console.log('WARN: Could not rename ./gradle to gradle');
    }

    try {
      await replace({
        files: appBuilderPath,
        from: "const apkPath = path.join('android', 'app', 'build', 'outputs', 'apk');",
        to: `const apkPath = path.join('c:/', '${appId}', 'tmp', 'ShoutemApp', 'app', 'outputs', 'apk');`
      });
    } catch (err) {
      console.log('WARN: Could not adapt client for c:\\tmp build directory');
    }

    try {
      await replace({
        files: path.join(platformDir, 'android', 'build.gradle'),
        from: '// buildDir = "C:/tmp/',
        to: `buildDir = "C:/tmp/${appId}/`
      })
    } catch (err) {
      console.log('WARN: Could not set the tmp build directory for android app');

replace-in-file

A simple utility to quickly replace text in one or more files.

MIT
Latest version published 5 days ago

Package Health Score

83 / 100
Full package analysis

Popular replace-in-file functions