1<?php 2 3/* 4 * This file is part of the Fxp Composer Asset Plugin package. 5 * 6 * (c) François Pluchino <francois.pluchino@gmail.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Fxp\Composer\AssetPlugin\Converter; 13 14/** 15 * Converter for NPM package to composer package. 16 * 17 * @author François Pluchino <francois.pluchino@gmail.com> 18 */ 19class NpmPackageConverter extends AbstractPackageConverter 20{ 21 /** 22 * {@inheritdoc} 23 */ 24 protected function getMapKeys() 25 { 26 $assetType = $this->assetType; 27 28 return array( 29 'name' => array('name', function ($value) use ($assetType) { 30 return $assetType->formatComposerName(NpmPackageUtil::convertName($value)); 31 }), 32 'type' => array('type', function () use ($assetType) { 33 return $assetType->getComposerType(); 34 }), 35 'version' => array('version', function ($value) use ($assetType) { 36 return $assetType->getVersionConverter()->convertVersion($value); 37 }), 38 'version_normalized' => 'version_normalized', 39 'description' => 'description', 40 'keywords' => 'keywords', 41 'homepage' => 'homepage', 42 'license' => array('license', function ($value) { 43 return NpmPackageUtil::convertLicenses($value); 44 }), 45 'time' => 'time', 46 'author' => array('authors', function ($value) { 47 return NpmPackageUtil::convertAuthor($value); 48 }), 49 'contributors' => array('authors', function ($value, $prevValue) { 50 return NpmPackageUtil::convertContributors($value, $prevValue); 51 }), 52 'bin' => array('bin', function ($value) { 53 return (array) $value; 54 }), 55 'dist' => array('dist', function ($value) { 56 return NpmPackageUtil::convertDist($value); 57 }), 58 ); 59 } 60 61 /** 62 * {@inheritdoc} 63 */ 64 protected function getMapExtras() 65 { 66 return array( 67 'bugs' => 'npm-asset-bugs', 68 'files' => 'npm-asset-files', 69 'main' => 'npm-asset-main', 70 'man' => 'npm-asset-man', 71 'directories' => 'npm-asset-directories', 72 'repository' => 'npm-asset-repository', 73 'scripts' => 'npm-asset-scripts', 74 'config' => 'npm-asset-config', 75 'bundledDependencies' => 'npm-asset-bundled-dependencies', 76 'optionalDependencies' => 'npm-asset-optional-dependencies', 77 'engines' => 'npm-asset-engines', 78 'engineStrict' => 'npm-asset-engine-strict', 79 'os' => 'npm-asset-os', 80 'cpu' => 'npm-asset-cpu', 81 'preferGlobal' => 'npm-asset-prefer-global', 82 'private' => 'npm-asset-private', 83 'publishConfig' => 'npm-asset-publish-config', 84 ); 85 } 86 87 /** 88 * {@inheritdoc} 89 */ 90 protected function convertDependency($dependency, $version, array &$vcsRepos, array $composer) 91 { 92 $dependency = NpmPackageUtil::convertName($dependency); 93 94 return parent::convertDependency($dependency, $version, $vcsRepos, $composer); 95 } 96} 97