Giter Site home page Giter Site logo

library-version-loader-generator's Introduction

library-version-loader-generator

Script to auto generate scripts and test for libraries on PublishPress.

The script will generate three files in the library:

  • lib/Versions.php
  • lib/include.php
  • tests/wpunit/VersionsCest.php

How to use

This library should be included in the target library as dev requirement:

composer require --dev publishpress/version-loader-generator

Once installed it will be available in the vendor/bin folder.

Its requires a few settings in the composer.json file to correctly generate the files:

{
  "extra": {
    "generator": {
      "lib-class-test": "interface_exists('PublishPress\\Psr\\Container\\ContainerInterface')",
      "action-initialize-priority": "-190",
      "action-register-priority": "-200"
    }
  }
}
  • lib-class-test: this is a fragment of PHP code that will check if the target library is loaded or not.
  • action-register-priority: a negative integer that will be used as the priority of the plugins_loaded action for registering the library. The registration should always be done before the initialization.
  • action-intialize-priority: a negative integer that will be used as the priority of the plugins_loaded action for initializing the library. The initialization should always be done before the plugin using the library is initialized.

We advise the plugins using the prefixed libraries to use the plugins_loaded action with a priority of -20 or higher to initialize the plugin instead of initializing it on run time.

Add a composer script to run the generator on every update/install. On the following example we are using Strauss also, to prefix the respective library:

{
  "scripts": {
    "strauss": [
      "vendor/bin/strauss"
    ],
    "generate-files": "vendor/bin/version-loader-generator",
    "post-install-cmd": [
      "@strauss",
      "@generate-files"
    ],
    "post-update-cmd": [
      "@strauss",
      "@generate-files"
    ]
  }
}

How to test this script

vendor/bin/codecept run unit

How to test target libraries

Make sure Codeception is properly configured in the target library, for running WPUnit tests.

Add the following composer script to the composer.json file:

{
  "scripts": {
    "test": "vendor/bin/codecept run wpunit"
  }
}

Then you can just run:

composer test

library-version-loader-generator's People

Watchers

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