From f941a2d2c62f468576c91d99dc30851c21610d6d Mon Sep 17 00:00:00 2001 From: Nek Date: Tue, 18 Feb 2014 11:46:38 +0100 Subject: [PATCH 1/7] Added support for paths with / for windows --- src/Yohang/DependencyTools.php | 53 ++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/src/Yohang/DependencyTools.php b/src/Yohang/DependencyTools.php index 0eda273..6161b08 100644 --- a/src/Yohang/DependencyTools.php +++ b/src/Yohang/DependencyTools.php @@ -4,6 +4,7 @@ use Symfony\Component\Process\ProcessBuilder; use Symfony\Component\Process\ExecutableFinder; +use Composer\Script\Event; /** * Simple static class that installs non-composer dependencies @@ -13,10 +14,29 @@ class DependencyTools { /** - * @param $event + * @param Event $event + * @throws \RuntimeException + */ + public static function installDeps(Event $event) + { + static::setup($event, 'install'); + } + + /** + * @param Event $event + * @throws \RuntimeException + */ + public static function updateDeps(Event $event) + { + static::setup($event, 'update'); + } + + /** + * @param Event $event + * @param string type * @throws \RuntimeException */ - public static function installDeps($event) + protected static function setup(Event $event, $type) { $options = static::getOptions($event); if (false !== $options['npm']) { @@ -24,7 +44,7 @@ public static function installDeps($event) static::execCommand( $options['npm'], 'npm', - array('install'), + array($type), 'An error occuring when installing NPM dependencies' ); } @@ -33,15 +53,15 @@ public static function installDeps($event) static::execCommand( $options['bower'], 'bower', - array('install'), + array($type), 'An error occuring when installing Bower dependencies' ); } } + /** * @param $event - * * @return array */ protected static function getOptions($event) @@ -74,6 +94,8 @@ protected static function execCommand($options, $cmd, array $args, $ifError) $cmd = $executableFinder->find($cmd); } + $cmd = static::guessCorrectPath($cmd); + $out = ''; $process = ProcessBuilder::create(array_merge(array($cmd), $args))->getProcess(); if (isset($options['timeout'])) { @@ -85,4 +107,25 @@ protected static function execCommand($options, $cmd, array $args, $ifError) throw new \RuntimeException($ifError."\n\n".$out); } } + + /** + * This is a fix for windows that need path with "\" instead of "/" + * + * @param string $path + * @return string + */ + protected static function guessCorrectPath($path) + { + if (DIRECTORY_SEPARATOR === '/') { + if (!file_exists($path)) { + $path = str_replace('\\', '/', $path); + } + } else { + if (!file_exists($path)) { + $path = str_replace('/', '\\', $path); + } + } + + return $path; + } } From 2fd50ef65c2b259690c978c8b76a4f617325d860 Mon Sep 17 00:00:00 2001 From: Nek Date: Tue, 18 Feb 2014 11:47:49 +0100 Subject: [PATCH 2/7] Fixed documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 47b9b15..eb726dd 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Add this lines to your composer.json file (only works with root file) : "Yohang\\DependencyTools::installDeps" ], "post-update-cmd": [ - "Yohang\\DependencyTools::installDeps" + "Yohang\\DependencyTools::updateDeps" ] }, "extra": { From a1f761d5980ea1f6a65b3cdd8600109c820f2b7e Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Thu, 12 Jun 2014 00:09:46 +0200 Subject: [PATCH 3/7] Added gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2659611 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +composer.lock From 1b12c92d8c5c24b1c2f6e4a7d05ce8111a24826a Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Thu, 12 Jun 2014 00:45:37 +0200 Subject: [PATCH 4/7] Release new version --- .gitignore | 2 ++ .travis.yml | 17 +++++++++++++++++ LICENSE | 2 +- README.md | 4 +++- composer.json | 14 ++++++++++++-- phpspec.yml.dist | 2 ++ spec/Yohang/DependencyToolsSpec.php | 14 ++++++++++++++ src/Yohang/DependencyTools.php | 5 +++-- 8 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 .travis.yml create mode 100644 phpspec.yml.dist create mode 100644 spec/Yohang/DependencyToolsSpec.php diff --git a/.gitignore b/.gitignore index 2659611..3f04135 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ composer.lock +vendor/ +phpspec.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c9eb398 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,17 @@ +language: php + +php: + - 5.4 + - 5.5 + - hhvm + +matrix: + allow_failures: + - php: hhvm + +before_script: + - cp phpspec.yml.dist phpspec.yml + - composer install + +script: + - bin/phpspec run --format nyan.cat diff --git a/LICENSE b/LICENSE index 3481b37..61c97f9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2012 Fréquence Web +Copyright (c) 2012 Fréquence Web & Nekland Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index eb726dd..b0dc71a 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ Install NPM & Bower dependencies with Composer This simple tools allows you to run `npm install` and/or `bower install` each time you run composer install / update. +*Note: This is Windows-compatible !* + Usage ----- @@ -12,7 +14,7 @@ Add this lines to your composer.json file (only works with root file) : { "require": { - "yohang/dependency-tools": "1.0.*" + "yohang/dependency-tools": "1.1.*" }, "scripts": { "post-install-cmd": [ diff --git a/composer.json b/composer.json index 94c0aba..a9269d4 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { - "name": "yohang/dependency-tools", + "name": "nekland/dependency-tools", "description": "A simple Composer script to install NPM and/or Bower dependencies", "keywords": ["dependency", "bower", "npm", "composer"], - "homepage": "https://github.com/yohang/dependency-tools", + "homepage": "https://github.com/nekland/dependency-tools", "type": "library", "license": "MIT", "authors": [ @@ -10,12 +10,22 @@ "name": "Yohan Giarelli", "email": "yohan@giarel.li", "homepage": "http://yohan.giarel.li" + }, + { + "name": "Maxime Veber", + "email": "nek.dev@gmail.com", + "homepage": "http://nekland.fr" } ], "require": { "php": ">=5.3.0", "symfony/process": ">=2.0,<3.0" }, + "require-dev": { + "phpspec/phpspec": "~2.0", + "phpspec/nyan-formatters": "1.*", + "composer/composer": "dev-master" + }, "autoload": { "psr-0": { "Yohang": "src/" } }, diff --git a/phpspec.yml.dist b/phpspec.yml.dist new file mode 100644 index 0000000..2cde5c0 --- /dev/null +++ b/phpspec.yml.dist @@ -0,0 +1,2 @@ +extensions: + - PhpSpec\NyanFormattersExtension\Extension diff --git a/spec/Yohang/DependencyToolsSpec.php b/spec/Yohang/DependencyToolsSpec.php new file mode 100644 index 0000000..f4d32b8 --- /dev/null +++ b/spec/Yohang/DependencyToolsSpec.php @@ -0,0 +1,14 @@ +shouldHaveType('Yohang\DependencyTools'); + } +} diff --git a/src/Yohang/DependencyTools.php b/src/Yohang/DependencyTools.php index 6161b08..0a9d26e 100644 --- a/src/Yohang/DependencyTools.php +++ b/src/Yohang/DependencyTools.php @@ -10,6 +10,7 @@ * Simple static class that installs non-composer dependencies * * @author Yohan Giarelli + * @author Maxime Veber */ class DependencyTools { @@ -32,8 +33,8 @@ public static function updateDeps(Event $event) } /** - * @param Event $event - * @param string type + * @param Event $event + * @param string $type * @throws \RuntimeException */ protected static function setup(Event $event, $type) From 25b8823d6780b9c4cb2a6be4df0f616f09afae2a Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Tue, 17 Jun 2014 21:16:03 +0200 Subject: [PATCH 5/7] Udpated doc --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index b0dc71a..1a9da14 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ This simple tools allows you to run `npm install` and/or `bower install` each ti Usage ----- +### Basic usage + Add this lines to your composer.json file (only works with root file) : ```json @@ -35,3 +37,22 @@ Add this lines to your composer.json file (only works with root file) : ``` And that's all, your NPM and Bower dependencies will be installed just after your Composer dependencies. + +### Advanced usage + +If you don't have a global install of bower, you would maybe like to specify a path to bower. If you uses npm to install +bower directly in your project here is an example of how you can configure composer: + +```json +{ + "extra": { + "dependency-tools": { + "npm": true, + "bower": { + "path": "node_modules/.bin/bower" + } + } + } +} +``` + From 06db89edd2980f5722f6873297e6be9d669dd775 Mon Sep 17 00:00:00 2001 From: Maxime Veber Date: Fri, 1 May 2015 20:30:29 +0200 Subject: [PATCH 6/7] Added a section known issue to README --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 1a9da14..cdd6d73 100644 --- a/README.md +++ b/README.md @@ -56,3 +56,11 @@ bower directly in your project here is an example of how you can configure compo } ``` +Known issue +----------- + +Bower executable is searching for `node`, if you installed nodejs on ubuntu, the executable is `nodejs`, an easy fix is to execute the following command to make a shortcut named `node` to `nodejs`. + +```bash +sudo ln -vs /usr/bin/nodejs /usr/bin/node +``` From 11b2c81b08932c4ab5babacc8526f2e469c1156e Mon Sep 17 00:00:00 2001 From: Maxime Veber Date: Mon, 6 Mar 2017 13:00:28 +0100 Subject: [PATCH 7/7] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a9269d4..f242485 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ ], "require": { "php": ">=5.3.0", - "symfony/process": ">=2.0,<3.0" + "symfony/process": "~2.0|~3.0" }, "require-dev": { "phpspec/phpspec": "~2.0",