private function publish_directories($directories)
    {
        $root = \get_template_directory();

        if (\is_child_theme()) {
            $root = \get_stylesheet_directory();
        }

        if (isset($this->root)) {
            $root = $this->root;
        }

        foreach ($directories as $source => $target) {
            $target_path = \trailingslashit($root) . \ltrim($target, '/\\');

            // Check if source exists.
            if (! \is_dir($source)) {
                $this->output->writeln("<error>The package source [$source] could not be found or is not readable. Skipping.</error>");
                continue;
            }

            // Check if target exists yet, create if not.
            if (! \is_dir($target_path)) {
                $this->mkdir($target_path);
            }

            // Now we know it exists, check we can write to it.
            if (! \is_writable($target_path)) {
                $this->output->writeln("<error>[$target_path] is not writable. Please check directory permissions.</error>");
                continue;
            }
            
            $this->deep_copy($source, $target_path);
        }
    }