Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ryzr committed Feb 11, 2019
0 parents commit 23508fa
Show file tree
Hide file tree
Showing 6 changed files with 432 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
composer.phar
composer.lock
vendor/
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 Franz Liedke

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# LocalPackages

Automatically symlink composer packages post-install/update for easier local development

## Installation

LocalPackages can be installed globally or per project, with Composer:

Globally (recommended): `composer global require ryzr/localpackages`
Per project: `composer require --dev ryzr/localpackages`

## Usage

1. Create a `composer.localpackages.json` file in your project root directory. This file will contain your mapping of paths to locally developed packages
2. Populate it with paths, in the following JSON format:
```
{
"paths": [
"~/path/to/your/package",
"~/path/to/your/other-package",
]
}
```
3. Since the configuration you will provide is unique to your environment, it would be best practice to add `composer.localpackages.json` to your `.gitignore` file.
4. `composer install` or `composer update`. LocalPackages will scan the directories specified in your `composer.localpackages.json` file for packages. If, for example, you used the configuration above and `~/path/to/your/package` contains a `composer.json` file for `your/package`, your project will symlink any `your/package` dependency to `~/path/to/your/package` automatically.

## Known Issues

If anything weird happens and you get stuck, try `rm -r vendor/ composer.lock && composer install`. If that doesn't work, blame me.

- I don't believe this works when using `composer require your/package`. Just run `composer update your/package` afterwards, and everything should symlink

## License

This code is published under the [MIT License](http://opensource.org/licenses/MIT).
This means you can do almost anything with it, as long as the copyright notice and the accompanying license file is left intact.

## Contributing

I wish I had more time for open-source contributions, but unfortunately I don't. Currently, this package serves my needs, and thus won't receive many/any feature updates.

However, if you run into any bugs, feel free to open an issue to bring my attention to it, or even better, submit a pull-request.

## Thanks

This package is a super-simplified version of [franzl/studio](https://github.com/franzliedke/studio).

The only difference is a couple of fixes for my needs, and a bunch of stuff removed that I didn't need. Check it out, as it may suit you better.
37 changes: 37 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "ryzr/localpackages",
"description": "Automatically symlink composer packages post-install/update for easier local development",
"keywords": ["composer", "development", "workflow"],
"type": "composer-plugin",
"license": "MIT",
"authors": [
{
"name": "Ryan",
"email": "[email protected]",
"homepage": "https://github.com/ryzr",
"role": "Developer"
},
{
"name": "Franz Liedke",
"homepage": "http://www.franzliedke.de/"
}
],
"autoload": {
"psr-4": {
"LocalPackages\\": "src"
}
},
"require": {
"composer-plugin-api": "^1.0"
},
"require-dev": {
"composer/composer": "dev-master",
"phpspec/phpspec": "~2.3"
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
},
"class": "LocalPackages\\Plugin"
}
}
111 changes: 111 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php

namespace LocalPackages;

class Config
{
protected $paths;

protected $loaded = false;

protected $file;

const FILENAME = 'composer.localpackages.json';

public function __construct($file)
{
$this->file = $file;
}

public static function make($file = null)
{
if (is_null($file)) {
$file = sprintf('%s/%s', getcwd(), static::FILENAME);
}

return new static($file);
}

protected function readPaths()
{
if (! file_exists($this->file)) return [];

$data = $this->readFromFile();

return $this->deserializePaths($data);
}

public function getPaths()
{
if (! $this->loaded) {
$this->paths = $this->readPaths();
$this->loaded = true;
}

return $this->paths;
}

public function addPath($path)
{
// Ensure paths are loaded
$this->getPaths();

$this->paths[] = $path;
$this->dump();
}

public function removePath($path)
{
// Ensure paths are loaded
$this->getPaths();

$this->paths = array_filter($this->paths, function ($existing) use ($path) {
return $existing !== $path;
});

$this->dump();
}

public function hasPackages()
{
// Ensure paths are loaded
$this->getPaths();

return ! empty($this->paths);
}

protected function dump()
{
$this->writeToFile(
$this->serializePaths($this->paths)
);
}

protected function writeToFile(array $data)
{
file_put_contents(
$this->file,
json_encode(
$data,
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
) . "\n"
);
}

public function deserializePaths($obj)
{
return $obj['paths'];
}

public function serializePaths(array $paths)
{
sort($paths);

return ['paths' => array_values($paths)];
}

protected function readFromFile()
{
return json_decode(file_get_contents($this->file), true);
}
}
Loading

0 comments on commit 23508fa

Please sign in to comment.