How to use the replace-in-file 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 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 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');
github Draggable / formeo / tools / tag.js View on Github external
changes.forEach(change =>
    replace(change)
      .then(changedFiles => {
        console.log('Modified files:', changedFiles.join(', '));
      })
      .catch(error => {
        console.error('Error occurred:', error);
      })
  );
github reergymerej / npm-boom / src / index.js View on Github external
return new Promise((resolve, reject) => {
    const options = {
      files: [
        path.join(destinationDir, 'README.md'),
        path.join(destinationDir, 'package.json'),
      ],
      replace: '{{PROJECT_NAME}}',
      with: projectName,
    };

    replace(options, (err) => {
      if (err) {
        reject(err)
      } else {
        resolve();
      }
    });
  });
}
github algolia / react-instantsearch / docgen / plugins / rev-assets.js View on Github external
function renameReferences(inFiles, files) {
  const { from, to } = files.reduce(
    (toRename, { oldPath, newPath }) => ({
      from: [
        ...toRename.from,
        new RegExp(oldPath.replace(`${DIST_PATH}/`, ''), 'g'),
      ],
      to: [...toRename.to, newPath.replace(`${DIST_PATH}/`, '')],
    }),
    { from: [], to: [] }
  );

  return replace({ from, to, files: inFiles });
}
github z-dev / rn-scaffold / src / schemesManager / index.js View on Github external
{
      xcodeSchemes: {
        Release: ['Staging'],
        Debug: [],
      },
    },
    './package.json',
  )

  const options = {
    files: './ios/test/AppDelegate.m',
    from: 'initialProperties:nil',
    to: 'initialProperties:{@"environment" : ENVIRONMENT}',
  }

  replace(options)
}
github redhat-developer-tooling / developer-platform-install / browser / model / helpers / util.js View on Github external
static replaceInFile(options) {
  return replace(options);
}
  static folderContains(folder, fileNames) {
github eclipse / codewind / src / initialize / src / controllers / replaceController.ts View on Github external
export async function replacePlaceholderNameWithProjectName(projectDir: string, projectName: string): Promise {
  const options = {
    files: path.join(projectDir, '**'),
    from: /\[PROJ_NAME_PLACEHOLDER\]/g,
    to: sanitizeName(projectName),
    glob: {
      dot: true
    }
  };

  const modifiedFiles = await replaceInFile(options);
  await replaceFilenameInFiles(projectDir, '[PROJ_NAME_PLACEHOLDER]', projectName);
}

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