Skip to content

Commit 07cf849

Browse files
committed
wip
1 parent 6f93e84 commit 07cf849

File tree

5 files changed

+87
-64
lines changed

5 files changed

+87
-64
lines changed

README.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
# TailPress Installer
1+
<p align="center"><a href="https://tailpress.io" target="_blank"><img src="https://raw.githubusercontent.com/tailpress/art/main/logo.svg" width="200" alt="TailPress"></a></p>
22

3-
Installer to quickly get started with your next TailPress theme.
3+
<p align="center">
4+
<a href="https://github.com/tailpress/installer/releases/"><img src="https://img.shields.io/github/release/tailpress/installer?include_prereleases=&sort=semver" alt="GitHub release"></a>
5+
<a href="https://packagist.org/packages/installer/tailpress"><img src="https://img.shields.io/packagist/dt/tailpress/installer" alt="Total Downloads"></a>
6+
<a href="#license"><img src="https://img.shields.io/badge/License-MIT-blue" alt="License"></a>
7+
</p>
48

5-
The installer has not been tested on Windows yet, but it should work. Let me know if you run into issues.
9+
## About TailPress
10+
11+
> **Note:** This repository contains the code of the TailPress installer. If you want to build a theme using TailPress, go to the [TailPress repository](https://github.com/tailpress/tailpress).
12+
13+
[TailPress](https://tailpress.io) is your go-to starting point for your next [Tailwind CSS](https://tailwindcss.com) powered [WordPress](https://wordpress.org) theme.
14+
15+
To get started, have a look at the [documentation](https://tailpress.io/docs).
616

717
## Install WordPress
818

@@ -14,13 +24,11 @@ Note that this will setup WordPress, but you still need a local development envi
1424

1525
- Update version number in `bin/tailpress`.
1626

17-
## Thanks
18-
19-
This package is inspired by the [Laravel Installer](https://github.com/laravel/installer).
20-
2127
## Contributors
22-
* [Jeffrey van Rossum](https://github.com/jeffreyvr)
23-
* [All contributors](https://github.com/jeffreyvr/tailpress-installer/graphs/contributors)
28+
29+
- [Jeffrey van Rossum](https://github.com/jeffreyvr)
30+
- [All contributors](https://github.com/tailpress/installer/graphs/contributors)
2431

2532
## License
33+
2634
MIT. Please see the [License File](/LICENSE) for more information.

bin/tailpress

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if (file_exists(__DIR__.'/../../../autoload.php')) {
77
require __DIR__.'/../vendor/autoload.php';
88
}
99

10-
$app = new Symfony\Component\Console\Application('TailPress Installer', '4.0.0');
10+
$app = new Symfony\Component\Console\Application('TailPress Installer', '5.0.0');
1111

1212
$app->add(new \TailPress\Installer\Console\NewCommand);
1313

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
],
1111
"minimum-stability": "dev",
1212
"require": {
13-
"php": "^7.4|^8.0|^8.1",
14-
"symfony/console": "^4.0|^5.0|^6.0",
15-
"symfony/process": "^4.2|^5.0|^6.0"
13+
"php": ">=8.0.2",
14+
"symfony/console": "^6.0|^7.0",
15+
"symfony/process": "^6.0|^7.0"
1616
},
1717
"require-dev": {
1818
"phpunit/phpunit": "^8.0|^9.3",

src/Console/NewCommand.php

Lines changed: 59 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,21 @@ protected function configure()
1919
->setName('new')
2020
->setDescription('Create a new TailPress theme')
2121
->addArgument('folder', InputArgument::REQUIRED)
22-
->addOption('name', null, InputOption::VALUE_REQUIRED, 'The name of your theme', false)
22+
->addOption('name', null, InputOption::VALUE_REQUIRED, 'The name of your theme')
2323
->addOption('git', null, InputOption::VALUE_NONE, 'Initialize a Git repository')
2424
->addOption('branch', null, InputOption::VALUE_REQUIRED, 'The branch that should be created for a new repository', $this->defaultBranch())
25-
->addOption('wordpress', null, InputOption::VALUE_NONE, 'Install WordPress.')
26-
->addOption('dbname', null, InputOption::VALUE_OPTIONAL, 'The name of your database.')
27-
->addOption('dbuser', null, InputOption::VALUE_OPTIONAL, 'The name of your database user.', 'root')
28-
->addOption('dbpass', null, InputOption::VALUE_OPTIONAL, 'The password of your database.', 'root')
29-
->addOption('dbhost', null, InputOption::VALUE_OPTIONAL, 'The host of your database.', 'localhost');
25+
->addOption('dev', null, InputOption::VALUE_NONE, 'Use development version of your TailPress.')
26+
->addOption('wordpress', null, InputOption::VALUE_NONE, 'Install WordPress')
27+
->addOption('dbname', null, InputOption::VALUE_OPTIONAL, 'The name of your database')
28+
->addOption('dbuser', null, InputOption::VALUE_OPTIONAL, 'The name of your database user')
29+
->addOption('dbpass', null, InputOption::VALUE_OPTIONAL, 'The password of your database')
30+
->addOption('dbhost', null, InputOption::VALUE_OPTIONAL, 'The host of your database')
31+
->addOption('author-name', null, InputOption::VALUE_OPTIONAL, 'The name of the theme author')
32+
->addOption('author-email', null, InputOption::VALUE_OPTIONAL, 'The email of the theme author')
33+
->addOption('local-dev-url', null, InputOption::VALUE_OPTIONAL, 'The local development url of your site');
3034
}
3135

32-
protected function execute(InputInterface $input, OutputInterface $output)
36+
protected function execute(InputInterface $input, OutputInterface $output): int
3337
{
3438
$commands = [];
3539

@@ -40,15 +44,22 @@ protected function execute(InputInterface $input, OutputInterface $output)
4044
| | (_| | | | __/| | | __/\__ \__ \
4145
|_|\__,_|_|_|_| |_| \___||___/___/'</>".PHP_EOL.PHP_EOL);
4246

43-
$installWordPress = ($input->getOption('wordpress') || (new SymfonyStyle(
44-
$input,
45-
$output
46-
))->confirm(
47-
'Would you like to install WordPress as well?',
48-
false
49-
));
50-
5147
$folder = $input->getArgument('folder');
48+
49+
$name = $input->getOption('name') ?? (new SymfonyStyle($input, $output))->ask('What is the name of your theme?', $folder);
50+
$authorName = $input->getOption('author-name') ?? (new SymfonyStyle($input, $output))->ask('What is the theme author name?', 'Jeffrey van Rossum');
51+
$authorEmail = $input->getOption('author-email') ?? (new SymfonyStyle($input, $output))->ask('What is the theme author email?', 'jeffrey@vanrossum.dev');
52+
$localDevUrl = $input->getOption('local-dev-url') ?? (new SymfonyStyle($input, $output))->ask('What is the local development url of your site?', 'http://localhost:8000');
53+
54+
$installWordPress = ($input->getOption('wordpress') || (new SymfonyStyle($input, $output))->confirm('Would you like to install WordPress as well?', false));
55+
56+
if($installWordPress) {
57+
$dbName = $input->getOption('dbname') ?? (new SymfonyStyle($input, $output))->ask('What is the name of your database?', str_replace('-', '_', $folder));
58+
$dbUser = $input->getOption('dbuser') ?? (new SymfonyStyle($input, $output))->ask('What is the user of your database?', 'root');
59+
$dbPass = $input->getOption('dbpass') ?? (new SymfonyStyle($input, $output))->ask('What is the password of your database?', 'root');
60+
$dbHost = $input->getOption('dbhost') ?? (new SymfonyStyle($input, $output))->ask('What is the host of your database?', 'localhost');
61+
}
62+
5263
$slug = $this->determineSlug($folder);
5364
$prefix = $this->determineSlug($folder, true);
5465

@@ -64,42 +75,40 @@ protected function execute(InputInterface $input, OutputInterface $output)
6475
$commands[] = "mkdir \"$workingDirectory\"";
6576
}
6677

78+
$version = '';
79+
if($input->getOption('dev')) {
80+
$version = '5.x-dev';
81+
}
82+
83+
$commands[] = "composer create-project tailpress/tailpress \"$workingDirectory\" {$version} --remove-vcs --prefer-dist --no-scripts";
6784
$commands[] = "cd \"$workingDirectory\"";
68-
$commands[] = "git clone -b 4.x https://github.com/jeffreyvr/tailpress.git . --q";
6985

7086
if (($process = $this->runCommands($commands, $input, $output))->isSuccessful()) {
71-
if ($name = $input->getOption('name')) {
72-
$this->replaceInFile('TailPress', $name, $workingDirectory.'/style.css');
73-
$this->replaceInFile('tailpress', $prefix, $workingDirectory.'/style.css');
74-
75-
$this->replaceInFile('tailpress_', $prefix.'_', $workingDirectory.'/functions.php');
76-
$this->replaceInFile('tailpress_', $prefix.'_', $workingDirectory.'/header.php');
77-
$this->replaceInFile('tailpress_', $prefix.'_', $workingDirectory.'/footer.php');
78-
79-
$this->replacePackageJsonInfo($workingDirectory.'/package.json', 'name', $folder);
80-
$this->replacePackageJsonInfo($workingDirectory.'/package.json', 'text_domain', $folder);
87+
$this->replacePackageJsonInfo($workingDirectory.'/package.json', 'name', $prefix);
88+
$this->replacePackageJsonInfo($workingDirectory.'/package.json', 'text_domain', $prefix);
89+
$this->replacePackageJsonInfo($workingDirectory.'/package.json', 'version', '0.1.0');
90+
$this->replacePackageJsonInfo($workingDirectory.'/package.json', 'author', $authorName);
8191

82-
$this->replaceInFile('https://github.com/jeffreyvr/tailpress', 'https://github.com/username/' . $folder, $workingDirectory.'/package.json');
83-
$this->replaceInFile('tailpress.test', $folder . '.test', $workingDirectory.'/package.json');
92+
$this->replaceInFile('Jeffrey van Rossum', $authorName, $workingDirectory.'/composer.json');
93+
$this->replaceInFile('jeffrey@vanrossum.dev', $authorEmail, $workingDirectory.'/composer.json');
8494

85-
if (file_exists($workingDirectory.'/tailpress.json')) {
86-
rename($workingDirectory.'/tailpress.json', $workingDirectory.'/'.$slug.'.json');
87-
}
95+
if (file_exists($workingDirectory.'/vite.config.mjs')) {
96+
$this->replaceInFile('http://tailpress.test', $localDevUrl, $workingDirectory.'/vite.config.mjs');
97+
$this->replaceInFile('wp-content/themes/tailpress', "wp-content/themes/{$prefix}", $workingDirectory.'/vite.config.mjs');
8898
}
8999

100+
$this->replaceThemeHeader($workingDirectory.'/style.css', 'Theme Name', $name, $workingDirectory.'/style.css');
101+
$this->replaceThemeHeader($workingDirectory.'/style.css', 'Author', $authorName, $workingDirectory.'/style.css');
102+
$this->replaceThemeHeader($workingDirectory.'/style.css', 'Text Domain', $prefix, $workingDirectory.'/style.css');
103+
104+
$this->replaceThemeHeader($workingDirectory.'/style.css', 'Description', 'A WordPress theme made with TailPress.');
90105
$this->replaceThemeHeader($workingDirectory.'/style.css', 'Version', '0.1.0');
91-
$this->replaceThemeHeader(
92-
$workingDirectory.'/style.css',
93-
'Description',
94-
'A WordPress theme made with TailPress.'
95-
);
96-
$this->replacePackageJsonInfo($workingDirectory.'/package.json', 'version', '0.1.0');
97106

98107
if ($installWordPress) {
99-
$this->replaceInFile('database_name_here', $input->getOption('dbname') ?? $prefix, $workingDirectory.'/../../../wp-config.php');
100-
$this->replaceInFile('username_here', $input->getOption('dbuser'), $workingDirectory.'/../../../wp-config.php');
101-
$this->replaceInFile('password_here', $input->getOption('dbpass'), $workingDirectory.'/../../../wp-config.php');
102-
$this->replaceInFile('localhost', $input->getOption('dbhost'), $workingDirectory.'/../../../wp-config.php');
108+
$this->replaceInFile('database_name_here', $dbName, $workingDirectory.'/../../../wp-config.php');
109+
$this->replaceInFile('username_here', $dbUser, $workingDirectory.'/../../../wp-config.php');
110+
$this->replaceInFile('password_here', $dbPass, $workingDirectory.'/../../../wp-config.php');
111+
$this->replaceInFile('localhost', $dbHost, $workingDirectory.'/../../../wp-config.php');
103112
$this->replaceInFile("define( 'WP_DEBUG', false );", "define( 'WP_DEBUG', false );\ndefine( 'WP_ENVIRONMENT_TYPE', 'development' );", $workingDirectory.'/../../../wp-config.php');
104113
}
105114

@@ -111,17 +120,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
111120
$finalCommands[] = "rm -rf .git";
112121
}
113122

123+
if (file_exists($workingDirectory.'/composer.json')) {
124+
$finalCommands[] = 'composer install';
125+
}
126+
114127
$finalCommands[] = "npm install --q --no-progress";
115128

129+
$finalCommands[] = "npm run build";
130+
116131
$this->runCommands($finalCommands, $input, $output);
117132

118133
if ($input->getOption('git')) {
119134
$this->createRepository($workingDirectory, $input, $output);
120135
}
121136

122-
$output->writeln(PHP_EOL.'<info>Your theme is here: '.$workingDirectory.'</info>');
123-
124-
$output->writeln(PHP_EOL.'<comment>Your boilerplate is ready, go create something beautiful!</comment>');
137+
$output->writeln(PHP_EOL.'<comment>🌊 Your boilerplate is ready, go create something beautiful!</comment>');
138+
$output->writeln(PHP_EOL.'<info>🏗️ Your theme is here: '.$workingDirectory.'</info>');
139+
$output->writeln(PHP_EOL.'<comment>✨ If you like TailPress, please consider starring the repo at https://github.com/tailpress/tailpress</comment>');
125140
}
126141

127142
return $process->getExitCode();

tests/NewCommandTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ public function test_it_can_scaffold_a_new_tailpress_theme()
4040

4141
$tester = new CommandTester($app->find('new'));
4242

43-
$tester->execute(['folder' => $scaffoldDirectoryName, '--name' => 'Just TailPress']);
43+
$tester->execute(['folder' => $scaffoldDirectoryName, '--name' => 'Just TailPress', '--dev' => true]);
4444

4545
$this->assertDirectoryExists($scaffoldDirectory);
4646
$this->assertFileExists($scaffoldDirectory . '/functions.php');
47-
$this->assertStringContainsString('just_tailpress', file_get_contents($scaffoldDirectory . '/functions.php'));
47+
// $this->assertStringContainsString('just_tailpress', file_get_contents($scaffoldDirectory . '/functions.php'));
4848
}
4949

5050
public function test_it_can_scaffold_a_new_tailpress_theme_with_wordpress()
@@ -65,13 +65,13 @@ public function test_it_can_scaffold_a_new_tailpress_theme_with_wordpress()
6565

6666
$tester = new CommandTester($app->find('new'));
6767

68-
$tester->execute(['folder' => $scaffoldDirectoryName, '--name' => 'Just TailPress', '--wordpress' => true]);
68+
$tester->execute(['folder' => $scaffoldDirectoryName, '--name' => 'Just TailPress', '--wordpress' => true, '--dev' => true]);
6969

7070
$this->assertDirectoryExists($scaffoldDirectory);
7171
$this->assertFileExists($scaffoldDirectory . '/wp-content/themes/with-wordpress/functions.php');
72-
$this->assertStringContainsString(
73-
'with_wordpress',
74-
file_get_contents($scaffoldDirectory . '/wp-content/themes/with-wordpress/functions.php')
75-
);
72+
// $this->assertStringContainsString(
73+
// 'with_wordpress',
74+
// file_get_contents($scaffoldDirectory . '/wp-content/themes/with-wordpress/functions.php')
75+
// );
7676
}
7777
}

0 commit comments

Comments
 (0)