Giter Club home page Giter Club logo

cordovahook-patch-platform's Introduction

cordovahook-patch-platform

  

Cordova allows you to automate the process of modifying platform configuration files through config-file element in plugins. However, the provided functionality is quite limited: XML files and insertions only. You may want to modify non-XML files, replace values within files, add/delete files. This hook aims to provide declarative means of describing all possible modifications that you may want to do and thus releave you from doing any additional manual work on the newly added platform.

How to install?

npm install cordovahook-patch-platform --save

How to use inside hooks?

#!/usr/bin/env node
require('cordovahook-patch-platform');

How to describe patches?

Patches live inside patches directory in your project root. As usual in Cordova, you create subfolders for each platform.

patches/<platform>/patches.json

Here you describe your patches. The format is as follows:

{
  "*": {
    "copy": {
      "<path-to-src-file-relative-to-this-folder>": "<path-to-dest-file-relative-to-platform-folder>",
      "...": "..."
    },
      
    "inject": {
      "<path-to-file-relative-to-platform-folder>": {
        "before": {
          "<string-before-which-the-contents-of-the-file-will-be-injected>": "<path-to-file-relative-to-this-folder>",
          "...": "..."
        },
        
        "after": {
          "<string-after-which-the-contents-of-the-file-will-be-injected>": "<path-to-file-relative-to-this-folder>",
          "...": "..."
        }
      }
    },
      
    "replace": {
      "<path-to-file-relative-to-platform-folder>": {
        "<string-to-look-for>": "<replacement-string>",
        "...": "..."
      }
    },
    
    "delete": {
      "files": [
        "<path-to-file-or-folder-relative-to-platform-folder>",
        "..."
      ],

      "lines": {
        "<path-to-file-relative-to-platform-folder>": [
          "<string-that-the-line-should-contain>",
          "..."
        ]
      }
    }
  },
  
  "<preference-name>:<preference-value>": {
    "...": {
    }
  },
  
  "...": {

  }
}

So, there are 5 types of patches currently supported:

  • copy – Copying files or folders from patch directory to platform directory.
  • inject – Inject contents of a file before or after some specific place inside a file in platform directory.
  • replace – Replace strings inside a file in platform directory.
  • delete files – Delete files or folders inside platform directory.
  • delete lines – Delete lines containing specified string inside a file in platform directory.

Each such patch is defined inside a condition block. Conditions come from config.xml preference tags. They allow you to apply patches only when a certain preference value (case sensitive) is specified. For example, you may want to delete all Landscape splash screens if your app will only support Portrait.
All patches that don't require a condition should be specified under "*".

How to deal with iOS directories containing the name of your app?

Put {{appName}} inside your path. This will be resolved by the hook.

patches/<platform>/patches.js (Optional)

This module will be called by the hook after applying patches from patches.json. Here you can do some custom patches that are not supported by the hook. The module will receive your app name (from config.xml) as a parameter.

Example, please!

Refer to howtouse folder to get an understanding of how to setup this hook in your project.

Release History

  • 0.2.0 – 0.2.2 / 2015-02-08
    • Fixed a bug, which caused failure when patches.json was not defined for a platform.
    • Updated dependencies.
    • Some cleanups here and there.
  • 0.1.0 / 2014-12-26
    • First version.

cordovahook-patch-platform's People

Contributors

mircoservices 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.