Completed
Push — master ( c58e43...03865c )
by Andrii
02:55
created

Npm::setDestination()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
/*
4
 * Composer plugin for bower/npm assets
5
 *
6
 * @link      https://github.com/hiqdev/composer-asset-plugin
7
 * @package   composer-asset-plugin
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hiqdev\composerassetplugin;
13
14
/**
15
 * NPM package manager class.
16
 *
17
 * @author Andrii Vasyliev <[email protected]>
18
 */
19
class Npm extends PackageManager
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    protected $name = 'npm';
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public $file = 'package.json';
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public $rcfile = '.npmrc';
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public $phpPackage = 'non existent npmphp';
40
41
    public $args = [];
42
43
    /**
44
     * {@inheritdoc}
45
     * Not really sure if peer, bundled and optional dependencies are really needed.
46
     * Remove them if not.
47
     */
48
    protected $dependencies = [
49
        'dependencies', 'devDependencies',
50
        'peerDependencies', 'bundledDependencies', 'optionalDependencies',
51
    ];
52
53
    /**
54
     * @var array Minimal NPM config
55
     */
56
    protected $config = [
57
        'name'        => 'composer-asset-plugin',
58
        'description' => "This file is auto-generated with 'hiqdev/composer-asset-plugin'.",
59
        'readme'      => ' ',
60
        'repository'  => ['type' => 'git'],
61
    ];
62
63
    public function setDestination($dir)
64
    {
65
        if (substr($dir, 0, 7) === 'vendor/') {
66
            $dir = substr($dir, 7);
67
        }
68
        $this->rc['prefix'] = $dir;
69
    }
70
71
    public function writeRc($path, $data) {
72
        $str = '';
73
        foreach ($data as $key => $value) {
74
            $str .= "$key = $value\n";
75
        }
76
        file_put_contents($path, $str);
77
    }
78
79
}
80