-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from moufmouf/commands
Adding commands
- Loading branch information
Showing
32 changed files
with
1,170 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,7 @@ humbuglog.txt | |
humbuglog.json | ||
template/ | ||
.couscous/ | ||
/tests/fixtures/copy/ | ||
/npm-debug.log | ||
/template | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
--- | ||
title: Command line interface | ||
subTitle: | ||
currentMenu: cli | ||
--- | ||
|
||
Discovery comes with a CLI (command line interface). | ||
|
||
You can use the CLI commands to: | ||
|
||
- debug what is happening | ||
- modify your local `discovery.json` | ||
- hook third party tools (like Gulp or Webpack) | ||
|
||
Actually, *discovery* is adding a set of commands to composer. | ||
|
||
## Listing asset types | ||
|
||
```bash | ||
$ composer discovery:list | ||
``` | ||
|
||
will output the list of asset types and the list of assets in each asset-type: | ||
|
||
``` | ||
my-asset-type-1: | ||
assetA | ||
assetB | ||
assetC | ||
my-asset-type-2: | ||
assetD | ||
``` | ||
|
||
You can also ask for the assets of a given asset-type: | ||
|
||
```bash | ||
$ composer discovery:list my-asset-type-2 | ||
``` | ||
|
||
will output: | ||
|
||
``` | ||
my-asset-type-2: | ||
assetD | ||
``` | ||
|
||
Finally, if you need more data, you can use the JSON output (maybe you want to output the metadata associated to each asset or you want to integrate the output with a third party tool). | ||
|
||
```bash | ||
$ composer discovery:list --format=json | ||
``` | ||
|
||
## Dumping the Discovery files | ||
|
||
Discovery is "dumping" a set of files that enable extremely quick access to the assets. **If you change manually a `discovery.json` file in your project, you will need to regenerate those files.** You can do this with the `discovery:dump` command: | ||
|
||
```bash | ||
$ composer discovery:dump | ||
``` | ||
|
||
## Adding an asset | ||
|
||
You can add an asset to an asset type using the `discovery:add` command: | ||
|
||
```bash | ||
$ composer discovery:add "my-asset-type" "my-asset-value" | ||
``` | ||
|
||
The asset is added to the `discovery.json` file at the root of your project. | ||
|
||
You can also set the priority while adding an asset: | ||
|
||
```bash | ||
$ composer discovery:add "my-asset-type" "my-asset-value" --priority=42 | ||
``` | ||
|
||
Note: currently, discovery does not support adding metadata via the command line. You will need to edit the `discovery.json` file manually to add metadata to an asset. | ||
|
||
## Removing an asset | ||
|
||
You can remove an asset from a project using the `discovery:remove` command: | ||
|
||
```bash | ||
$ composer discovery:remove "my-asset-type" "my-asset-value" | ||
``` | ||
|
||
The asset is removed from the `discovery.json` file at the root of your project or a "remove" action is added in the `discovery.json` file at the root of your project (if the asset is defined in a dependency). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
|
||
namespace TheCodingMachine\Discovery\Commands; | ||
|
||
|
||
use Composer\Command\BaseCommand; | ||
use Composer\Factory; | ||
use Composer\Repository\CompositeRepository; | ||
use Composer\Repository\InstalledArrayRepository; | ||
use TheCodingMachine\Discovery\AssetsBuilder; | ||
|
||
abstract class AbstractDiscoveryCommand extends BaseCommand | ||
{ | ||
/** | ||
* @return AssetType[] | ||
*/ | ||
protected function getAssetTypes() : array | ||
{ | ||
$installationManager = $this->getComposer()->getInstallationManager(); | ||
$rootDir = dirname(Factory::getComposerFile()); | ||
$assetBuilder = new AssetsBuilder($installationManager, $this->getIO(), $rootDir); | ||
|
||
$localRepos = $this->getComposer()->getRepositoryManager()->getLocalRepository(); | ||
|
||
$repos = array( | ||
$localRepos, | ||
new InstalledArrayRepository([$this->getComposer()->getPackage()]), | ||
); | ||
$compositeRepos = new CompositeRepository($repos); | ||
return $assetBuilder->findAssetTypes($compositeRepos); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
|
||
namespace TheCodingMachine\Discovery\Commands; | ||
|
||
|
||
use Composer\Command\BaseCommand; | ||
use Composer\Factory; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use TheCodingMachine\Discovery\Asset; | ||
use TheCodingMachine\Discovery\AssetOperation; | ||
use TheCodingMachine\Discovery\AssetsBuilder; | ||
use TheCodingMachine\Discovery\AssetType; | ||
use TheCodingMachine\Discovery\DiscoveryFileLoader; | ||
use TheCodingMachine\Discovery\Dumper; | ||
|
||
class AddAssetCommand extends BaseCommand | ||
{ | ||
protected function configure() | ||
{ | ||
$this->setName('discovery:add') | ||
->setDescription('Add an asset') | ||
->addArgument('asset-type', InputArgument::REQUIRED, 'The asset type') | ||
->addArgument('value', InputArgument::REQUIRED, 'The asset to add') | ||
->addOption('priority', 'p', InputOption::VALUE_REQUIRED, 'The priority', 0.0); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$assetTypeName = $input->getArgument('asset-type'); | ||
$assetValue = $input->getArgument('value'); | ||
|
||
$priority = $input->getOption('priority'); | ||
|
||
if (!is_numeric($priority)) { | ||
$output->writeln('<error>The priority must be a numeric value.</error>'); | ||
return; | ||
} | ||
|
||
$loader = new DiscoveryFileLoader(); | ||
|
||
if (file_exists('discovery.json')) { | ||
$assetOperationTypes = $loader->loadDiscoveryFile(new \SplFileInfo('discovery.json'), '', ''); | ||
} else { | ||
$assetOperationTypes = []; | ||
} | ||
|
||
$assetOperationTypes[$assetTypeName][] = new AssetOperation(AssetOperation::ADD, new Asset($assetValue, '', '', $priority, null)); | ||
|
||
$loader->saveDiscoveryFile($assetOperationTypes, new \SplFileObject('discovery.json', 'w+')); | ||
|
||
$dumper = new Dumper($this->getComposer(), $this->getIO()); | ||
$dumper->dumpDiscoveryFiles(); | ||
|
||
$output->writeln('discovery.json file successfully modified.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
|
||
namespace TheCodingMachine\Discovery\Commands; | ||
|
||
use Composer\Plugin\Capability\CommandProvider as CommandProviderCapability; | ||
|
||
/** | ||
* List of all commands provided by this package. | ||
*/ | ||
class CommandProvider implements CommandProviderCapability | ||
{ | ||
|
||
/** | ||
* Retrieves an array of commands | ||
* | ||
* @return \Composer\Command\BaseCommand[] | ||
*/ | ||
public function getCommands() | ||
{ | ||
return [ | ||
new ListAssetTypesCommand(), | ||
new DumpCommand(), | ||
new AddAssetCommand(), | ||
new RemoveAssetCommand(), | ||
]; | ||
} | ||
} |
Oops, something went wrong.