GithubHelp home page GithubHelp logo

hhy5277 / replaceinfiles Goto Github PK

View Code? Open in Web Editor NEW

This project forked from songkick/replaceinfiles

0.0 1.0 0.0 56 KB

This software is not maintained. Utility to replace a map of strings in many files

Home Page: https://www.npmjs.com/package/@songkick/replaceinfiles

License: MIT License

JavaScript 100.00%

replaceinfiles's Introduction

replace-in-files Build Status

Utility to replace a map of strings in many files

Use cases:

  • pipe from hashmark to replace references to hashmarked files - see example
  • replace dev environment paths to production
  • inject values in a config file

Not actively worked on

We're happy to accept PRs and suggestions, but be aware that this project is no longer used internally and therefore not actively maintained + improved by Songkick.

Usage

Install

npm i replaceinfiles

Create or generate a replace map, save in a file or pipe to stdin

{
  "foo": "bar",
  "hello": "goodbye",
  "world": "earth",
  "%API_URL%": "https://myservice.com/api"
}

Run

Usage: replaceinfiles [options]

Options:

    -h, --help                     output usage information
    -V, --version                  output the version number
    -s, --source <glob>            glob matching files to be updated
    -d, --dest-pattern <path>      pattern to output files
    -o, --output-path <path>       path to output report file default: stdout
    -S, --silent                   do not output report
    -r, --replace-map-path <path>  path to replace map json, default: stdin
    -e, --encoding <string>        used for both read and write, default "utf-8"

Examples

  • Streaming replace map from stdin

    cat replace-map.json | replaceinfiles -s src/*.css -d 'dist/{base}'
  • Getting replace map from file

    replaceinfiles -r replace-map.json -s src/*.css -d 'dist/{base}'
  • Write report to a file

    replaceinfiles -r replace-map.json -s src/*.css -d 'dist/{base}' > report.json
    # or
    replaceinfiles -r replace-map.json -s src/*.css -d 'dist/{base}' -o report.json

Report

replaceinfiles generates a report on stdout or specified path for you to pipe other tools if you need to.

Here is an example:

{
  "options": {
    "source": "test/src/*.txt",
    "destPattern": "test/dist/{base}",
    "outputPath": null,
    "replaceMapPath": null,
    "replaceMap": {
      "hello": "goodbye",
      "world": "earth"
    },
    "encoding": "utf-8"
  },
  "result": [
    {
      "src": "test/src/one.txt",
      "dest": "test/dist/one.txt",
      "changed": true
    },
    {
      "src": "test/src/three.txt",
      "dest": "test/dist/three.txt",
      "changed": false
    },
    {
      "src": "test/src/two.txt",
      "dest": "test/dist/two.txt",
      "changed": true
    }
  ]
}

Options details

-s, --source: A glob matching the files you want to replace from

-d, --dest-pattern: A pattern to define updated files destination. You can use all the path.parse() result values (root, dir, name, base, ext), example: -d './dist/{dir}/{name}.build{ext}'

-r, --replace-map-path: Path to a replace map JSON file ({'stringToReplace': 'replaceWithThat', '..', '...'}). stdin is used as default.

-o, --output-path: A path to write the report, default is stdout

-S, --silent: Do not output report, bypasses -o

-e, --encoding: Used for both read and write, default: utf-8

API

You can also run replaceinfiles from node.

var replaceinfiles = require('replaceinfiles');

var options = {
  source: './test/*.txt',
  destPattern: './test/dist/{base}',
  replaceMap: {
    foo: 'bar'
  }
  // or, specify a path to your replaceMap json file
  // replaceMapPath: './map.json'
};

replaceinfiles(options)
  .then(function(report){
    // ...
  })
  .catch(function(error) {
    // ...
  });

If you do not specify replaceMap or replaceMapPath then stdin will be used.

replaceinfiles's People

Contributors

arnaudrinquin avatar benhodgson87 avatar elwynelwyn avatar jackfranklin avatar rasmusvhansen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.