setName('generate:angular-directive')
->setDescription('Generates a template for an AngularJS directive')
->addOption('pluginname', null, InputOption::VALUE_REQUIRED, 'The name of an existing plugin')
->addOption('directive', null, InputOption::VALUE_REQUIRED, 'The name of the directive you want to create.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$pluginName = $this->getPluginName($input, $output);
$directive = $this->getConstructName($input, $output, $optionName = 'directive', $constructType = 'directive');
$pluginPath = $this->getPluginPath($pluginName);
$directiveLower = $this->getSnakeCaseName($directive);
$targetDir = $pluginPath . '/angularjs/' . $directiveLower;
if (is_dir($targetDir) || file_exists($targetDir)) {
throw new \Exception('The AngularJS directive ' . $directiveLower . ' already exists in plugin ' . $pluginName);
}
$exampleFolder = Manager::getPluginDirectory('ExamplePlugin');
$replace = array(
'ExamplePlugin' => $pluginName,
'directive-component' => $directiveLower,
'componentClass' => lcfirst($directive),
'componentAs' => lcfirst($directive),
'component' => $directiveLower,
'Component' => $directive
);
$componentPath = '/angularjs/directive-component';
$whitelistFiles = array(
'/angularjs',
$componentPath,
$componentPath . '/component.controller.js',
$componentPath . '/component.directive.html',
$componentPath . '/component.directive.js',
$componentPath . '/component.directive.less',
);
$this->copyTemplateToPlugin($exampleFolder, $pluginName, $replace, $whitelistFiles);
$replacedBasePath = '/angularjs/' . $directiveLower . '/' . $directiveLower;
$js1 = $replacedBasePath . '.controller.js';
$js2 = $replacedBasePath . '.directive.js';
$less1 = $replacedBasePath . '.directive.less';
$this->writeSuccessMessage($output, array(
sprintf('AngularJS directive "%s" for plugin "%s" in "%s" generated', $directive, $pluginName, $targetDir),
sprintf('In %1$s/%2$s.php you should now require the JS files', $pluginPath, $pluginName),
sprintf('%1$s%2$s, %1$s%3$s', $pluginPath, $js1, $js2),
sprintf('and the less file %1$s%2$s.', $pluginPath, $less1),
'If you are not familiar with this have a look at https://developer.matomo.org/guides/working-with-piwiks-ui'
));
}
}