adlacruzes/composer-import-scripts

Composer plugin to import composer scripts from sources

Installs: 16 617

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:composer-plugin

1.5.1 2023-12-18 19:45 UTC

This package is auto-updated.

Last update: 2024-04-18 20:27:35 UTC


README

Minimum PHP Version Packagist Github actions

Composer import scripts is a plugin to import composer scripts from files/URLs at runtime.

I needed a simple way to import scripts and unify commands across multiple libraries. If you need a more powerful tool, you can look at the excellent composer-merge-plugin.

Imported commands have to be invoked with composer run.

Can this plugin import scripts from...

  • other composer.json files? Yes
  • public URLs? Yes

Table of Contents

Installation

composer require adlacruzes/composer-import-scripts

As of Composer 2.2.0, the allow-plugins option adds a layer of security allowing you to restrict which Composer plugins are able to execute code during a Composer run.

Use this setting to allow only packages you trust to execute code.

{
    "config": {
        "allow-plugins": {
            "adlacruzes/composer-import-scripts": true
        }
    }
}

Usage

{
    "extra": {
        "import-scripts": {
            "include": [
                "file1.json",
                "file2.json",
                "https://url.json"
            ],
            "allow_failures": false,
            "override": true
        }
    }
}

Configuration

include

  • required

include setting is a list of files to import. These files need to be valid JSON according to the import scripts schema.

allow_failures

  • optional
  • default: false

allow_failures is a setting that controls errors from the plugin. If set to true the following file errors will be ignored and zero scripts will be imported from these files:

  • Invalid JSON schema
  • Invalid file

override

  • optional
  • default: true

When override is set to true the scripts from the include setting will override the scripts with the same name defined in composer.json

JSON schema

This is the scheme files must adapt.

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
        "scripts": {
            "type": [
                "object"
            ],
            "additionalProperties": {
                "type": ["string", "array"]
            }
        }
    },
    "required": [
        "scripts"
    ]
}

An example of this schema:

{
    "scripts": {
        "one": "echo one",
        "two": "echo two",
        "three": "echo three",
        "other": [
            "echo four",
            "echo five"
        ]
    }
}