/**
  * tearDown
  *
  * @return  void
  */
 protected function tearDown()
 {
     parent::tearDown();
     if (is_dir(static::$dest)) {
         Folder::delete(static::$dest);
     }
 }
예제 #2
0
 /**
  * copy
  *
  * @param string $src
  * @param string $dest
  *
  * @return  void
  */
 protected function copyFolder($src, $dest)
 {
     $this->out('<info>Create</info>: ' . $dest);
     if (is_dir($dest)) {
         Folder::delete($dest);
     }
     Folder::copy($src, $dest);
 }
예제 #3
0
 /**
  * delete
  *
  * @param string $path
  *
  * @return  bool
  */
 public static function delete($path)
 {
     if (is_dir($path)) {
         Folder::delete($path);
     } elseif (is_file($path)) {
         File::delete($path);
     }
     return true;
 }
예제 #4
0
 /**
  * Method to test move().
  *
  * @return void
  *
  * @covers Windwalker\Filesystem\Folder::move
  */
 public function testMove()
 {
     $dest2 = __DIR__ . '/dest2';
     if (is_dir($dest2)) {
         Folder::delete($dest2);
     }
     Folder::move(static::$dest, $dest2);
     $this->assertTrue(is_dir($dest2));
     $this->assertFileExists($dest2 . '/folder1/level2/file3');
     Folder::delete($dest2);
 }
 /**
  * doExecute
  *
  * @return  mixed|void
  */
 public function doExecute()
 {
     // Flip replace array because we want to convert template.
     $replace = array_flip($this->replace);
     foreach ($replace as &$val) {
         $val = '{{' . $val . '}}';
     }
     // Flip src and dest because we want to convert template.
     $src = $this->config['dir.src'];
     $dest = $this->config['dir.dest'];
     // Remove dir first
     if (is_dir($dest)) {
         Folder::delete($dest);
     }
     $this->container->get('operator.convert')->copy($src, $dest, $replace);
 }
 /**
  * doExecute
  *
  * @return  mixed|void
  */
 public function doExecute()
 {
     // Flip replace array because we want to convert template.
     $replace = array_flip($this->replace);
     foreach ($replace as &$val) {
         $val = '{{' . $val . '}}';
     }
     // Flip src and dest because we want to convert template.
     $src = $this->config['dir.src'];
     $dest = $this->config['dir.dest'];
     if (!is_dir($src)) {
         throw new \RuntimeException(sprintf('Extension "%s" in %s not exists', $this->config['element'], $this->config['client']));
     }
     // Remove dir first
     Folder::delete($dest);
     $this->container->get('operator.convert')->copy($src, $dest, $replace);
 }
예제 #7
0
 /**
  * onBeforeRenderFiles
  *
  * @param Event $event
  *
  * @return  void
  */
 public function onBeforeRenderFiles(Event $event)
 {
     $this->data = array();
     $files = new \DirectoryIterator(__DIR__ . '/../../resources');
     $resources = new PriorityQueue();
     $menus = new PriorityQueue();
     /** @var \SplFileInfo $file */
     foreach ($files as $file) {
         if ($file->isDir()) {
             continue;
         }
         $data = new Registry();
         $data->loadFile($file->getPathname(), 'yaml');
         $resName = $file->getBasename('.yml');
         list($priority, $resName) = explode('-', $resName, 2);
         $data['alias'] = $resName;
         $resources->insert($data->toArray(), PHP_INT_MAX - $priority);
         $menus->insert(array('title' => $data['title'], 'alias' => $resName), PHP_INT_MAX - $priority);
     }
     // Store in cache
     $this->data['menus'] = $menus->toArray();
     foreach ($resources as $data) {
         $this->data['resources'][$data['alias']] = $data;
     }
     // Auto create pages
     $categoryFolder = new \SplFileInfo(__DIR__ . '/../../entries/type');
     if (is_dir($categoryFolder->getPathname())) {
         Folder::delete($categoryFolder->getPathname());
     }
     Folder::create($categoryFolder->getPathname());
     foreach ($this->data['resources'] as $catName => &$category) {
         File::copy(__DIR__ . '/../../layouts/tmpl/category.twig', __DIR__ . '/../../entries/type/' . $catName . '.twig');
         // Auto create items page
         $itemFolder = new \SplFileInfo(__DIR__ . '/../../entries/type/' . $catName);
         if (is_dir($itemFolder->getPathname())) {
             Folder::delete($itemFolder->getPathname());
         }
         Folder::create($itemFolder->getPathname());
         foreach ($category['data'] as $itemAlias => &$item) {
             File::copy(__DIR__ . '/../../layouts/tmpl/item.twig', __DIR__ . '/../../entries/type/' . $catName . '/' . $itemAlias . '.twig');
             $item['alias'] = $itemAlias;
         }
     }
 }
예제 #8
0
 /**
  * Do this execute.
  *
  * @return  mixed
  */
 protected function doExecute()
 {
     /** @var ConvertOperator $operator */
     $operator = $this->container->get('operator.factory')->getOperator('convert');
     $replace = ArrayHelper::flatten($this->replace);
     // Flip replace array because we want to convert template.
     $replace = array_flip($replace);
     foreach ($replace as &$val) {
         $val = StringHelper::quote($val, $operator->getTagVariable());
     }
     // Flip src and dest because we want to convert template.
     $src = $this->config['dir.src'];
     $dest = $this->config['dir.dest'];
     if (is_dir($dest)) {
         // Remove dir first
         Folder::delete($dest);
     }
     $operator->copy($src, $dest, $replace);
 }
예제 #9
0
    $task->writeln('Copying files over.');
    recursiveCopy('dev', $basepath, $distfolder);
    $task->writeln('Running composer');
    $task->exec(function ($process) {
        $basepath = realpath(__DIR__ . '/..');
        $distfolder = Path::clean($basepath . '/dist');
        $distfolder = str_replace(' ', '\\ ', $distfolder);
        $process->runLocally("cd " . $distfolder . '/dev' . " && composer install --prefer-dist --optimize-autoloader");
        $process->runLocally("cd .. && cd ..");
    });
    Folder::move($distfolder . '/dev', $distfolder . '/notify');
    $task->writeln('Zipping');
    $zippy = Zippy::load();
    $archive = $zippy->create('flarum-notify.zip', array('notify' => $distfolder . '/notify'));
    $task->writeln('Deleting copied folder');
    Folder::delete($distfolder . '/notify');
    File::move($basepath . '/flarum-notify.zip', $distfolder . '/flarum-notify.zip');
})->description("Builds a release ready package from the current project state and stores it in /dist.");
function recursiveCopy($filename, $initialfolder, $targetfolder)
{
    $badfiles = ['vendor', 'node_modules', '.DS_Store', 'sftp-config.json', '.git', '.gitignore', 'build.sh'];
    foreach (Folder::items($initialfolder . '/' . $filename, false, Folder::PATH_BASENAME) as $item) {
        if (!in_array($item, $badfiles)) {
            if (is_dir($initialfolder . '/' . $filename . '/' . $item)) {
                recursiveCopy($item, $initialfolder . '/' . $filename, $targetfolder . '/' . $filename);
            } else {
                File::copy($initialfolder . '/' . $filename . '/' . $item, $targetfolder . '/' . $filename . '/' . $item);
            }
        }
    }
}