How to use the replace-in-file.sync function in replace-in-file

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 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 nuxt / now-builder / src / typescript.ts View on Github external
].reduce((filesToCompile, item) => {
    let itemPath = ''
    if (typeof item === 'string') {
      itemPath = item
    } else if (typeof item === 'object' && Array.isArray(item)) {
      itemPath = item[0]
    } else if (typeof item === 'object' && typeof item.handler === 'string') {
      itemPath = item.handler
    }
    if (itemPath) {
      const srcDir = nuxtConfigFile.srcDir ? (path.relative(rootDir, nuxtConfigFile.srcDir)).replace('now_compiled', '.') : '.'
      const resolvedPath = path.resolve(rootDir, itemPath.replace(/^[@~]\//, `${srcDir}/`).replace(/\.ts$/, ''))
      if (fs.existsSync(`${resolvedPath}.ts`)) {
        filesToCompile.push(resolvedPath)
        replaceInFile.sync({
          files: path.resolve(rootDir, 'now_compiled/nuxt.config.js'),
          from: new RegExp(`(?<=['"\`])${itemPath}(?=['"\`])`, 'g'),
          to: itemPath.replace(/\.ts$/, '')
        })
      }
    }
    return filesToCompile
  }, [] as string[])
  await Promise.all(

replace-in-file

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

MIT
Latest version published 4 months ago

Package Health Score

72 / 100
Full package analysis

Popular replace-in-file functions