diff --git a/composer.json b/composer.json index 08970c4..b7e5d95 100644 --- a/composer.json +++ b/composer.json @@ -32,6 +32,16 @@ "issues": "http://drupal.org/project/issues/zurb_foundation", "source": "http://cgit.drupalcode.org/zurb_foundation" }, + "autoload": { + "classmap": [ + "src/ScriptHandler.php" + ] + }, + "scripts": { + "subtheme": [ + "Drupal\\foundation_sites\\ScriptHandler::subtheme" + ] + }, "require": { "drupal/stable": "^2.0" } diff --git a/src/ScriptHandler.php b/src/ScriptHandler.php new file mode 100644 index 0000000..ac421b3 --- /dev/null +++ b/src/ScriptHandler.php @@ -0,0 +1,66 @@ +getArguments(); + if (!empty($args)) { + $input = $args[0]; + $strip_chars = preg_replace('/[^a-zA-Z\_\s]*/', '', $input); + $strip_space = preg_replace('/\s+/', '_', $strip_chars); + $sub_name = strtolower($strip_space); + } + + // Copy STARTERKIT to parent dir. + $fs = new Filesystem(); + $fs->mirror(getcwd() . '/STARTER', '../' . $sub_name); + + // Rename STARTERKIT.* files + $finder = new Finder(); + $finder->files()->name('/STARTER/')->in('../' . $sub_name); + + foreach ($finder as $file) { + $location_segments = explode('/', $file->getRealPath()); + $old_filename = array_pop($location_segments); + $location = implode('/', $location_segments) . '/'; + + $new_filename = preg_replace('/STARTER/', $sub_name, $old_filename); + + $fs->rename($file->getRealPath(), $location . $new_filename); + } + + // Activate subtheme .info file. + $finder = new Finder(); + $finder->files()->name('*.yml.txt')->in('../' . $sub_name); + + foreach ($finder as $file) { + $location_segments = explode('/', $file->getRealPath()); + $old_filename = array_pop($location_segments); + $location = implode('/', $location_segments) . '/'; + + $new_filename = preg_replace('/yml.txt/', 'yml', $old_filename); + + $fs->rename($file->getRealPath(), $location . $new_filename); + } + + // Replace STARTERKIT in file contents. + $finder = new Finder(); + $finder->files()->contains('/STARTER/')->in('../' . $sub_name); + + foreach ($finder as $file) { + $old_contents = file_get_contents($file->getRealPath()); + + $new_contents = preg_replace('/STARTER/', $sub_name, $old_contents); + + file_put_contents($file->getRealPath(), $new_contents); + } + } +}