Skip to content

Commit b9f39f6

Browse files
committed
Updated create-projec script.
1 parent c183645 commit b9f39f6

File tree

2 files changed

+15
-37
lines changed

2 files changed

+15
-37
lines changed

scripts/composer/ScriptHandler.php

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,12 @@
44

55
use Composer\Script\Event;
66
use Composer\Semver\Comparator;
7-
use DrupalFinder\DrupalFinder;
8-
use Drupal\Component\Utility\Crypt;
97

108
/**
119
* Project Create script.
1210
*/
1311
class ScriptHandler {
1412

15-
/**
16-
* Project setup event.
17-
*
18-
* @param \Composer\Script\Event $event
19-
* Composer event object.
20-
*/
21-
public static function setupProject(Event $event) {
22-
$io = $event->getIO();
23-
24-
$drupalFinder = new DrupalFinder();
25-
$drupalFinder->locateRoot(getcwd());
26-
27-
$current_dir = explode('/', $drupalFinder->getComposerRoot());
28-
$default_project = $current_dir[count($current_dir) - 1];
29-
$project = $io->ask("What's the project's name? [{$default_project}]: ", $default_project);
30-
$save_project = preg_replace('/\s+/', '-', strtolower(trim($project)));
31-
32-
exec(
33-
"sed -i \"s+drupal-composer+{$save_project}+g\" " . $drupalFinder->getComposerRoot() . "/.env.example"
34-
);
35-
exec(
36-
"sed -i \"s+drupal-composer+{$save_project}+g\" " . $drupalFinder->getComposerRoot() . "/.lando.yml"
37-
);
38-
39-
$hash = Crypt::randomBytesBase64(55);
40-
exec(
41-
"sed -i \"s+pleaseChangeThisToADifferentRandomString+{$hash}+g\" " . $drupalFinder->getComposerRoot() . "/.env.example"
42-
);
43-
}
44-
4513
/**
4614
* Checks if the installed version of Composer is compatible.
4715
*
@@ -55,6 +23,8 @@ public static function setupProject(Event $event) {
5523
* downloading the Composer dependencies.
5624
*
5725
* @see https://github.com/composer/composer/pull/5035
26+
*
27+
* @param \Composer\Script\Event $event
5828
*/
5929
public static function checkComposerVersion(Event $event) {
6030
$composer = $event->getComposer();

scripts/php/Tasks.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,36 @@ class Tasks extends RoboTasks {
1515
public function setup() {
1616
$drupalFinder = new DrupalFinder();
1717
$drupalFinder->locateRoot(getcwd());
18+
$composerRoot = $drupalFinder->getComposerRoot();
1819

19-
$current_dir = explode('/', $drupalFinder->getComposerRoot());
20+
// Get current dir name.
21+
$current_dir = explode('/', $composerRoot);
2022
$default_project = $current_dir[count($current_dir) - 1];
23+
24+
// Ask for the project name.
2125
$projectName = $this->askDefault("What's the project's name?", $default_project);
2226
$projectName = preg_replace('/\s+/', '-', strtolower(trim($projectName)));
23-
$this->say("Project: $projectName");
2427

25-
$this->taskReplaceInFile($drupalFinder->getComposerRoot() . '/.env.example')
28+
// Replace drupal-composer with the project name.
29+
$this->taskReplaceInFile($composerRoot . '/.env.example')
2630
->from('drupal-composer')
2731
->to($projectName)
2832
->run();
2933

30-
$this->taskReplaceInFile($drupalFinder->getComposerRoot() . '/.lando.yml')
34+
$this->taskReplaceInFile($composerRoot . '/.lando.yml')
3135
->from('drupal-composer')
3236
->to($projectName)
3337
->run();
3438

39+
// Generate a hash.
3540
$hash = Crypt::randomBytesBase64(55);
36-
$this->taskReplaceInFile($drupalFinder->getComposerRoot() . '/.env.example')
41+
$this->taskReplaceInFile($composerRoot . '/.env.example')
3742
->from('pleaseChangeThisToADifferentRandomString')
3843
->to($hash)
3944
->run();
45+
46+
// Copy env file.
47+
copy($composerRoot . '/.env.example', $composerRoot . '/.env');
4048
}
4149

4250
}

0 commit comments

Comments
 (0)