Skip to content

Commit b1db19f

Browse files
Initial implementation
1 parent b08f4c1 commit b1db19f

File tree

10 files changed

+564
-5
lines changed

10 files changed

+564
-5
lines changed

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
composer.phar
22
/vendor/
3-
4-
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
5-
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
6-
# composer.lock
3+
composer.lock

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,42 @@
11
# node-composer
2-
composer plugin for a better frontend setup
2+
3+
> composer plugin for a better frontend setup
4+
5+
PHP projects mostly are Web-Applications. Many Web-Applications also need a frontend part which runs in the browser. In
6+
modern Web-Development there often a whole build-chain connected to the frontend, so you can compile e.g. your scss, build
7+
your JavaScript with webpack and optimize your images.
8+
9+
This plugin provides a way to automatically download the right version of node.js and npm as a package. The binaries are
10+
linked to the bin-directory specified in your composer.json.
11+
12+
After that your can use node and npm in your scripts.
13+
14+
## Setup
15+
16+
The setup is pretty easy. Simply install the plugin in specify the node-version in your composer.json extra configs.
17+
18+
Example composer.json
19+
20+
```json
21+
{
22+
"name": "my/project",
23+
"type": "project",
24+
"license": "MIT",
25+
"authors": [
26+
{
27+
"name": "Marius Büscher",
28+
"email": "[email protected]"
29+
}
30+
],
31+
"require": {
32+
"mariusbuescher/node-composer": "*"
33+
},
34+
"extra": {
35+
"mariusbuescher": {
36+
"node-composer": {
37+
"node-version": "4.8.3"
38+
}
39+
}
40+
}
41+
}
42+
```

composer.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "mariusbuescher/node-composer",
3+
"type": "composer-plugin",
4+
"license": "MIT",
5+
"authors": [
6+
{
7+
"name": "Marius Büscher",
8+
"email": "[email protected]"
9+
}
10+
],
11+
"autoload": {
12+
"psr-4": {
13+
"MariusBuescher\\NodeComposer\\": "src/"
14+
}
15+
},
16+
"require": {
17+
"composer/composer": "^1.4",
18+
"composer-plugin-api": "^1.1"
19+
},
20+
"extra": {
21+
"class": "MariusBuescher\\NodeComposer\\NodeComposerPlugin"
22+
}
23+
}

src/ArchitectureMap.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace MariusBuescher\NodeComposer;
4+
5+
class ArchitectureMap
6+
{
7+
/**
8+
* @var array
9+
*/
10+
private static $map = array(
11+
'x86_64' => 'x64'
12+
);
13+
14+
/**
15+
* @param string $phpArchitecture
16+
* @return string
17+
*/
18+
public static function getNodeArchitecture($phpArchitecture)
19+
{
20+
return isset(static::$map[$phpArchitecture]) ? static::$map[$phpArchitecture] : $phpArchitecture;
21+
}
22+
}

src/Config.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace MariusBuescher\NodeComposer;
4+
5+
use MariusBuescher\NodeComposer\Exception\NodeComposerConfigException;
6+
7+
class Config
8+
{
9+
/**
10+
* @var string
11+
*/
12+
private $nodeVersion;
13+
14+
/**
15+
* @var string
16+
*/
17+
private $yarnVersion;
18+
19+
/**
20+
* Config constructor.
21+
*/
22+
private function __construct()
23+
{
24+
}
25+
26+
/**
27+
* @param array $conf
28+
* @return Config
29+
*/
30+
public static function fromArray(array $conf)
31+
{
32+
$self = new self();
33+
34+
$self->nodeVersion = $conf['node-version'];
35+
$self->yarnVersion = isset($conf['yarn-version']) ? $conf['yarn-version'] : null;
36+
37+
if ($self->nodeVersion === null) {
38+
throw new NodeComposerConfigException('You must specify a node-version');
39+
}
40+
41+
42+
return $self;
43+
}
44+
45+
/**
46+
* @return string
47+
*/
48+
public function getNodeVersion()
49+
{
50+
return $this->nodeVersion;
51+
}
52+
53+
/**
54+
* @return string
55+
*/
56+
public function getYarnVersion()
57+
{
58+
return $this->yarnVersion;
59+
}
60+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace MariusBuescher\NodeComposer\Exception;
4+
5+
class NodeComposerConfigException extends \RuntimeException
6+
{
7+
8+
}

0 commit comments

Comments
 (0)