/** * * * @param object \InputInterface * @param object \OutputInterface * @return void */ private function readKernel(InputInterface $input, OutputInterface $output) { $dir = $this->config->get('base_dir'); $finder = new Finder(); $finder->in($dir)->name('AppKernel.js'); foreach ($finder as $i => $file) { $kernelFilepath = $file->getRealPath(); if ($i > 0) { break; } } // save kernel file path inside the config $this->config->set('kernel_file', $kernelFilepath); // build the pathes for pathes and shims into the Dependency class memory Dependency::getPathes($this->config, $kernelFilepath); Dependency::getShims($this->config, $kernelFilepath); return $this; }
/** * Read a start module file path and read all dependencies recursively in that file to * return a list of dependencies file(s) path(es) in the inversed order (leaf deps come out first) * * @param object \Config * @param string Kernel file path * @return array List of dependencies file pathes */ public static function getKernelDependencies(\Adadgio\Common\Config $config, $kernelFilepath) { $dependencies = array(); $pathes = Dependency::getPathes(); $shims = Dependency::getShims(); $contents = file_get_contents($kernelFilepath); // always add require js to the list of deps // @todo Move this in the config $dependencies['requirejs'] = $config->get('base_dir') . '/lib/require-2.1.16.min.js'; if (preg_match('~require\\(\\[(.+)\\],~sU', $contents, $matches)) { $string = $matches[1]; $modules = array_filter(array_map('trim', explode(',', $string))); // modules to import foreach ($modules as $module) { $module = self::unquote($module); if (Module::isGlobalModule($module)) { // now this global module might have dependcies in the shim config ! $shimDeps = self::getShimDependencies($config, $module); $dependencies = array_merge($dependencies, $shimDeps); } else { //$path = $this->jsPath.'/'.$module.'.js'; $path = $config->get('base_dir') . '/' . $module . '.js'; $depId = self::removeExtension($path); $dependencies[$depId] = $path; } } } return $dependencies; }