Skip to content

Commit a01204a

Browse files
committed
Addded d8:component:libraries-yml command.
1 parent c4f3f51 commit a01204a

File tree

7 files changed

+119
-2
lines changed

7 files changed

+119
-2
lines changed

src/Commands/BaseGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ protected function defaultName() {
248248
* Returns default value for the machine name question.
249249
*/
250250
protected function defaultMachineName($vars) {
251-
return self::human2machine($vars['name']);
251+
return self::human2machine(isset($vars['name']) ? $vars['name'] : $this->directoryBaseName);
252252
}
253253

254254
/**
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace DrupalCodeGenerator\Commands\Drupal_8\Component\Yml;
4+
5+
use Symfony\Component\Console\Input\InputInterface;
6+
use Symfony\Component\Console\Output\OutputInterface;
7+
use DrupalCodeGenerator\Commands\BaseGenerator;
8+
9+
/**
10+
* Implements d8:component:libraries-yml command.
11+
*/
12+
class Libraries extends BaseGenerator {
13+
14+
protected $name = 'd8:component:yml:libraries';
15+
protected $description = 'Generates a libraries yml file';
16+
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
protected function interact(InputInterface $input, OutputInterface $output) {
21+
22+
$questions = [
23+
'machine_name' => ['Module machine name', [$this, 'defaultMachineName']],
24+
];
25+
$vars = $this->collectVars($input, $output, $questions);
26+
27+
$this->files[$vars['machine_name'] . '.libraries.yml'] = $this->render('d8/libraries.yml.twig', $vars);
28+
}
29+
30+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Third-party library.
2+
jquery-labelauty:
3+
remote: https://github.com/fntneves/jquery-labelauty
4+
version: 1.1.0
5+
license:
6+
name: MIT
7+
url: https://github.com/fntneves/jquery-labelauty/blob/v1.1.0/LICENSE
8+
gpl-compatible: true
9+
js:
10+
/libraries/jquery-labelauty/source/jquery-labelauty.js: {}
11+
css:
12+
component:
13+
/libraries/jquery-labelauty/source/jquery-labelauty.css: {}
14+
dependencies:
15+
- core/jquery
16+
17+
# Custom js for general purposes.
18+
{{ machine_name }}:
19+
js:
20+
js/{{ machine_name }}.js: {}
21+
dependencies:
22+
- core/drupalSettings
23+
- {{ machine_name }}/jquery-labelauty
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace DrupalCodeGenerator\Tests\Drupal_8\Component\Yml;
4+
5+
use DrupalCodeGenerator\Tests\GeneratorTestCase;
6+
7+
/**
8+
* Test for d8:component:yml:libraries command.
9+
*/
10+
class LIbraries extends GeneratorTestCase {
11+
12+
/**
13+
* {@inheritdoc}
14+
*/
15+
public function setUp() {
16+
$this->class = 'Drupal_8\Component\Yml\Libraries';
17+
$this->answers = [
18+
'example',
19+
];
20+
$this->target = 'example.libraries.yml';
21+
$this->fixture = __DIR__ . '/_' . $this->target;
22+
23+
parent::setUp();
24+
}
25+
26+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Third-party library.
2+
jquery-labelauty:
3+
remote: https://github.com/fntneves/jquery-labelauty
4+
version: 1.1.0
5+
license:
6+
name: MIT
7+
url: https://github.com/fntneves/jquery-labelauty/blob/v1.1.0/LICENSE
8+
gpl-compatible: true
9+
js:
10+
/libraries/jquery-labelauty/source/jquery-labelauty.js: {}
11+
css:
12+
component:
13+
/libraries/jquery-labelauty/source/jquery-labelauty.css: {}
14+
dependencies:
15+
- core/jquery
16+
17+
# Custom js for general purposes.
18+
example:
19+
js:
20+
js/example.js: {}
21+
dependencies:
22+
- core/drupalSettings
23+
- example/jquery-labelauty

src/Tests/GeneratorsDiscoveryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
class GeneratorsDiscoveryTest extends \PHPUnit_Framework_TestCase {
1414

15-
const TOTAL_GENERATORS = 25;
15+
const TOTAL_GENERATORS = 26;
1616

1717
/**
1818
* Test callback.

src/Tests/integration-fixtures.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,21 @@
328328
'- ExampleTest.php',
329329
],
330330
],
331+
[
332+
'answers' => [
333+
'<comment>Drupal 8</comment>',
334+
'<comment>Component</comment>',
335+
'<comment>Yml</comment>',
336+
'Libraries',
337+
'example',
338+
],
339+
'output' => [
340+
'Command: d8:component:yml:libraries',
341+
'-----------------------------------',
342+
'The following files have been created:',
343+
'- example.libraries.yml',
344+
],
345+
],
331346
[
332347
'answers' => [
333348
'<comment>Drupal 8</comment>',

0 commit comments

Comments
 (0)