protected function ensureBuildDir($path, OutputInterface $output)
    {
        $parts = explode(DIRECTORY_SEPARATOR, $this->getPath());

        foreach ($parts as $part) {
            if (!$part) continue;

            $path .= DIRECTORY_SEPARATOR . $part;

            if (!file_exists($path)) {
                $output->writeln(sprintf('<info>Creating namespace build directory: <comment>%s</comment></info>', $path));
                mkdir($path);
            }
        }

        return $path;
    }