ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
BuildJsProcess.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of Component Installer.
5  *
6  * (c) Rob Loach (http://robloach.net)
7  *
8  * For the full copyright and license information, please view the LICENSE.md
9  * file that was distributed with this source code.
10  */
11 
13 
17 class BuildJsProcess extends Process
18 {
22  public function process()
23  {
24  return $this->compile($this->packages);
25  }
26 
34  public function compile($packages)
35  {
36  // Set up the initial require-build.js file.
37  $destination = $this->componentDir.DIRECTORY_SEPARATOR.'require-built.js';
38  $require = $this->componentDir.DIRECTORY_SEPARATOR.'require.js';
39  copy($require, $destination);
40 
41  // Cycle through each package and add it to the built require.js file.
42  foreach ($packages as $package) {
43  // Retrieve some information about the package
44  $name = isset($package['name']) ? $package['name'] : '__component__';
45  $extra = isset($package['extra']) ? $package['extra'] : array();
46  $componentName = $this->getComponentName($name, $extra);
47 
48  // Find where the source file is located.
49  $packageDir = $this->componentDir.DIRECTORY_SEPARATOR.$componentName;
50  $source = $packageDir.DIRECTORY_SEPARATOR.$componentName.'-built.js';
51 
52  // Make sure the source script is available.
53  if (file_exists($source)) {
54  // Build the compiled script.
55  $content = file_get_contents($source);
56  $output = $this->definePrefix($componentName) . $content . $this->definePostfix();
57 
58  // Append the module definition to the destination file.
59  file_put_contents($destination, $output, FILE_APPEND);
60  }
61  }
62 
63  return true;
64  }
65 
72  protected function definePrefix($componentName)
73  {
74  // Define the module using the simplified CommonJS wrapper.
75  return "\ndefine('$componentName', function (require, exports, module) {\n";
76  }
77 
83  protected function definePostfix()
84  {
85  return "\n});\n";
86  }
87 }
compile($packages)
Copy file assets from the given packages to the component directory.
Builds all JavaScript Components into one require-built.js.
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
getComponentName($prettyName, array $extra=array())
Retrieves the component name for the component.
Definition: Process.php:154
definePostfix()
Finish the module definition.
Create styles array
The data for the language used.
process()
{Called when running through the process.boolean True or false depending on whether the process was s...
definePrefix($componentName)
Provide the initial definition prefix.
The base Process type.
Definition: Process.php:26