One-file composer scripts

Overview

Melody - One-file composer scripts

Create a file named test.php:

<?php
<<<CONFIG
packages:
    - "symfony/finder: ~2.8"
CONFIG;

$finder = Symfony\Component\Finder\Finder::create()
    ->in(__DIR__)
    ->files()
    ->name('*.php')
;

foreach ($finder as $file) {
    echo $file, "\n";
}

And simply run it:

$ melody run test.php

demo

More Information

Read the documentation for more information.

Comments
  • Ask confirmation for running untrusted resources

    Ask confirmation for running untrusted resources

    Here is a proposal to the issue #32. The objective, is to avoid the execution of untrusted scripts

    • [x] Add tests
    • [x] Document it
    • [x] Remember trusted signatures
    • [x] Trust users
    $ ./bin/melody run ~/test.php  -vvv
    Hello Melody!
    
    $ ./bin/melody run 23bb3980daf65154c3d4 
    You are running an untrusted resource
      URL: https://gist.github.com/23bb3980daf65154c3d4
      Owner: lyrixx
      Created at: Fri, 17 Oct 2014 14:44:13 +0000
      Last update: Fri, 17 Oct 2014 23:45:48 +0000
      Revision: #2
    
    Do you want to continue [y/N]?y
    ----------------------------------
    Hello greg
    ----------------------------------
    
    $ ./bin/melody run 23bb3980daf65154c3d4 --trust
    ----------------------------------
    Hello greg
    ----------------------------------
    
    new feature 
    opened by jderusse 22
  • Unable to redirect nor pipe output

    Unable to redirect nor pipe output

    Hi !

    Given this very simple witness script:

    <?php
    
    <<<CONFIG
    packages:
        - "php"
    CONFIG;
    
    echo 'Hello World'.PHP_EOL;
    

    I'm unable to redirect the output to a file using standard or error output redirection:

    $ melody run hello_world.php > hello.txt
    # hello.txt remains empty
    

    Here is the strace output captured by @lyrixx that might help, showing it seems to be properly output on FD1:

    16787 write(1, "/tmp/melody/aefded2aec05bb759178"..., 131) = 131
    16787 write(1, "\n", 1)                 = 1
    16787 lstat("/tmp/melody/aefded2aec05bb75917826c8787c3c6c24a4ff56cc67f6b6522fe8105cf4bc2c5/vendor/symfony/finder/Comparator/DateComparator.php", {st_mode=S_IFREG|0644, st_size=1465, ...}) = 0
    16787 stat("/tmp/melody/aefded2aec05bb75917826c8787c3c6c24a4ff56cc67f6b6522fe8105cf4bc2c5/vendor/symfony/finder/Comparator/DateComparator.php", {st_mode=S_IFREG|0644, st_size=1465, ...}) = 0
    16787 write(1, "/tmp/melody/aefded2aec05bb759178"..., 129) = 129
    16787 write(1, "\n", 1)                 = 1
    

    Any hint ?

    ping @smaftoul, if by chance you have any idea.

    opened by ogizanagi 15
  • GC: Also take files within the root of the storagePath into account

    GC: Also take files within the root of the storagePath into account

    before only directories were cleaned up, which contained a Runner::BOOTSTRAP_FILENAME. with this change, also files within the toplevel of storagePath are deleted, when older then GarbageCollector::TTL

    opened by staabm 10
  • Allow additional data to be stored per melody script run

    Allow additional data to be stored per melody script run

    I would like to store some temporary files which are required run melody-scripts from within another app (php-console).

    If I could add somehow files to the melody's working-dir those were automatically cleaned up by the melody garbage collector, which would be highly usefull in my case. otherwise i need to create another garbage collector for my "own" temp files.

    Would you consider this something in scope of melody?

    discuss 
    opened by staabm 9
  • warn when packages are used with known vulnerabilities

    warn when packages are used with known vulnerabilities

    We should integrate with FriendsOfPHP/security-advisories and warn the user when one of the required packages contains known vulnerabilities.

    https://github.com/FriendsOfPHP/security-advisories

    opened by staabm 9
  • WIP added a getStoragePath() method

    WIP added a getStoragePath() method

    Let melody extensions/plugins also use the same working dir, which is also garbage collected by melody.

    This change should be covered by already existing integration tests.

    fixes https://github.com/sensiolabs/melody/issues/39

    opened by staabm 8
  • Stop execution when underlying composer commands fail

    Stop execution when underlying composer commands fail

    A melody script requires a proper initialized environment, including all its dependencies. When a composer command errors, let the cliExecutor do the output and stop further processing.

    Otherwise we will trigger most likely only subsequent errors. This also makes sure that the working directory will be re-initialised on next run instead of leaving it in a inconsistent state.

    opened by staabm 7
  • Add composer repositories configuration

    Add composer repositories configuration

    It is a PR for #36.

    With this PR, it is possible to use fork, private or local repositories (local maybe not useful).

    <<<CONFIG
    repositories:
        - type: vcs
          url: https://github.com/fabpot/Pimple
    packages:
        - "pimple/pimple: 1.0.2"
    

    In the implementation, I would have preferred to use the CLI composer to add a repository but without composer.json, composer throws an exception.

    composer config repositories.pimple vcs https://github.com/fabpot/Pimple
    [RuntimeException]                               
    No composer.json found in the current directory 
    
    new feature 
    opened by aaa2000 7
  • [new-feature] Ask for confirmation before running code

    [new-feature] Ask for confirmation before running code

    Hi, I think melody should ask before running code loaded from the outside and wild world, the Internet.

    The main reason for this is that melody allows you to pass in an url, a username/gistID, or just the gistID. It's not hard to type in "http://gist.github.com/gistID", but it would be even better if melody could show up useful informations before running it, like owner name, creation date, revisions count, last revision date ... And a direct link to the gist.

    Still, some might wan't to run it without interaction, so it might be useful to add a --no-interaction flag

    Thanks in advance (I'll try to do it, but can't promise anything ... and don't know how to test it)

    new feature 
    opened by punkeel 7
  • Authenticate melody to github to skip rate limit

    Authenticate melody to github to skip rate limit

    When downloading a gist, we may have a failure

    [InvalidArgumentException]                                                                                                                                                                                  
      There is an issue with your gist URL: API rate limit exceeded for W.X.Y.Z. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)  
    

    We could take the composer's one ~/.composer/auth.json or asking the user to create ours auth.json.

    new feature 
    opened by jderusse 6
Owner
SensioLabs
SensioLabs
A lot of scripts and packages in modern PHP demand one or more configuration classes

A lot of scripts and packages in modern PHP demand one or more configuration classes. Mostly, those are a set of properties that can be set, changed or retrieved. However, some of the configurations have a peculiar behaviour - such as boolean properties.

Carlos Artur Curvelo da Silva Matos 2 Mar 8, 2022
A composer plugin, to install differenty types of composer packages in custom directories outside the default composer default installation path which is in the vendor folder.

composer-custom-directory-installer A composer plugin, to install differenty types of composer packages in custom directories outside the default comp

Mina Nabil Sami 136 Dec 30, 2022
Composer plugin replacing placeholders in the scripts section by dynamic values

Composer Substitution Plugin The Composer Substitution plugin replaces placeholders in the scripts section by dynamic values. It also permits to cache

Fabien Villepinte 49 Jan 8, 2022
Scripts-dev directive for composer

scriptsdev for Composer It's like require-dev, but for scripts Installation Just run composer require neronmoon/scriptsdev --dev Usage After installin

Vitaliy Krasnoperov 67 May 18, 2022
Nextcloud AIO stands for Nextcloud All In One and provides easy deployment and maintenance with most features included in this one Nextcloud instance.

Nextcloud All In One Beta This is beta software and not production ready. But feel free to use it at your own risk! We expect there to be rough edges

Nextcloud 1.1k Jan 4, 2023
Ied plugin composer - Inspired Plugin Composer: Create, publish and edit plugins from within Textpattern CMS.

ied_plugin_composer Create, publish and edit plugins from within Textpattern CMS. Creates a new page under the Extensions tab where you can edit and e

Stef Dawson 8 Oct 3, 2020
Magento-composer-installer - Composer installer for Magento modules

!!! support the maintainer of this project via Patreon: https://www.patreon.com/Flyingmana Magento Composer Installer The purpose of this project is t

null 213 Sep 24, 2022
Composer Repository Manager for selling Magento 2 extension and offering composer installation for ordered packages.

Magento 2 Composer Repository Credits We got inspired by https://github.com/Genmato. Composer Repository for Magento 2 This extension works as a Magen

EAdesign 18 Dec 16, 2021
Composer registry manager that help to easily switch to the composer repository you want

CRM - Composer Registry Manager Composer Registry Manager can help you easily and quickly switch between different composer repositories. 简体中文 Install

Tao 500 Dec 29, 2022
Composer plugin that wraps all composer vendor packages inside your own namespace. Intended for WordPress plugins.

Imposter Plugin Composer plugin that wraps all composer vendor packages inside your own namespace. Intended for WordPress plugins. Built with ♥ by Typ

Typist Tech 127 Dec 17, 2022
Dependency graph visualization for composer.json (PHP + Composer)

clue/graph-composer Graph visualization for your project's composer.json and its dependencies: Table of contents Usage graph-composer show graph-compo

Christian Lück 797 Jan 5, 2023
Composer Registrar Composer Plugin for Magento 2

This module add a global registration.php that replace the default glob search performed for each request to discover the components not installed from composer.

OpenGento 3 Mar 22, 2022
Drupal Composer Scaffold - A flexible Composer project scaffold builder

This project provides a composer plugin for placing scaffold files (like index.php, update.php, …) from the drupal/core project into their desired location inside the web root. Only individual files may be scaffolded with this plugin.

Drupal 44 Sep 22, 2022
Victor The Cleaner for Composer - This tool removes unnecessary files and directories from Composer vendor directory.

Victor The Cleaner for Composer This tool removes unnecessary files and directories from Composer vendor directory. The Cleaner leaves only directorie

David Grudl 133 Oct 26, 2022
Opinionated version of Wikimedia composer-merge-plugin to work in pair with Bamarni composer-bin-plugin.

Composer Inheritance Plugin Opinionated version of Wikimedia composer-merge-plugin to work in pair with bamarni/composer-bin-plugin. Usage If you are

Théo FIDRY 25 Dec 2, 2022
Magento commands to find translations that are present in one CSV file but not in another, and to translate CSV dicts with DeepL

Hyvä Themes - Magento translation CSV comparison command hyva-themes/magento2-i18n-csv-diff This module adds the bin/magento i18n:diff-csv and i18n:tr

Hyvä 6 Oct 26, 2022
Block malicious scripts using botscout.com protection for your laravel app

Laravel BotScout Protect your website against automated scripts using the botscout.com API. Installation You can install the package via composer: com

Nicolas Beauvais 64 Jul 30, 2022
The simplest way to create a dynamic sitemap for your self-coded website which you have made by using PHP/HTML/CSS/Js etc... Scripts.

Sitemap_index.xml The simplest way to create a dynamic sitemap for your self-coded website which you have made by using PHP/HTML/CSS/Js etc... Scripts

Tanish Raj 1 Oct 16, 2021
Run PHP scripts on the fly at runtime on a PocketMine-MP server (useful for debugging)

Scripter Run PHP scripts on the fly at runtime on a PocketMine-MP server. This is useful for runtime debugging, when you don't want to restart the ser

Dylan's PocketMine-MP Plugins 15 Jul 28, 2022