-
-
Notifications
You must be signed in to change notification settings - Fork 420
[RFC][WIP] add scaffolding system (make:scaffold
)
#1085
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kbond
wants to merge
21
commits into
symfony:1.x
Choose a base branch
from
kbond:scaffolding
base: 1.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,502
−1
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
3093a44
wip add scaffolding system
kbond 010a2fa
use php files for scaffold manifests
kbond 2e4b5c7
add scaffold configuration system to manipulate files
kbond 3fcdd30
add bootstrapcss scaffold
kbond 738c07c
add starter-kit that includes all current scaffolds and and applicati…
kbond 184f21a
move "forgot your password" link to reset-password scaffold
kbond df75091
auto install required js packages
kbond 263fd0b
break out required packs/aliases into actual packages
kbond c8ee93f
add `FileManager::manipulateYaml()`
kbond 5f7a732
cs fixes
kbond 00195cb
flatten directories
kbond 5a6e21a
simplify scaffold tests by using latest zenstruck/browser
kbond 9bc88b2
prune # of tests (slightly)
kbond c9d17da
convert scaffold files to .tpl
kbond 653dce3
fix scaffold file cs
kbond b1581ca
changes from review
kbond 062542a
adjustments from review
kbond 0ea3bae
confirm before overwriting files
kbond 69b8b90
add interactive menu
kbond 0fae83e
add deprecation notes to make:user/make:reset-password/make:registrat…
kbond c98e95e
cs fixes
kbond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony MakerBundle package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\MakerBundle; | ||
|
||
use Symfony\Component\Process\ExecutableFinder; | ||
use Symfony\Component\Process\Process; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
*/ | ||
final class JsPackageManager | ||
{ | ||
private $executableFinder; | ||
private $files; | ||
|
||
public function __construct(FileManager $fileManager) | ||
{ | ||
$this->executableFinder = new ExecutableFinder(); | ||
$this->files = $fileManager; | ||
} | ||
|
||
public function isInstalled(string $package): bool | ||
{ | ||
$packageJson = $this->packageJson(); | ||
$deps = array_merge($packageJson['dependencies'] ?? [], $packageJson['devDependencies'] ?? []); | ||
|
||
return \array_key_exists($package, $deps); | ||
} | ||
|
||
public function add(string $package, string $version): void | ||
{ | ||
$packageWithVersion = "{$package}@{$version}"; | ||
|
||
if ($yarn = $this->executableFinder->find('yarn')) { | ||
$command = [$yarn, 'add', $packageWithVersion, '--dev']; | ||
} elseif ($npm = $this->executableFinder->find('npm')) { | ||
$command = [$npm, 'install', $packageWithVersion, '--save-dev']; | ||
} else { | ||
$this->addToPackageJson($package, $version); | ||
|
||
return; | ||
} | ||
|
||
(new Process($command, $this->files->getRootDirectory()))->run(); | ||
} | ||
|
||
public function install(): void | ||
{ | ||
(new Process([$this->bin(), 'install'], $this->files->getRootDirectory()))->run(); | ||
} | ||
|
||
public function run(string $script): void | ||
{ | ||
(new Process([$this->bin(), 'run', $script], $this->files->getRootDirectory()))->run(); | ||
} | ||
|
||
public function isAvailable(): bool | ||
{ | ||
try { | ||
$this->bin(); | ||
|
||
return true; | ||
} catch (\RuntimeException $e) { | ||
return false; | ||
} | ||
} | ||
|
||
private function bin(): string | ||
{ | ||
if (!$bin = $this->executableFinder->find('yarn') ?? $this->executableFinder->find('npm')) { | ||
throw new \RuntimeException('Unable to find js package manager.'); | ||
} | ||
|
||
return $bin; | ||
} | ||
|
||
private function addToPackageJson(string $package, string $version): void | ||
{ | ||
$packageJson = $this->packageJson(); | ||
$devDeps = $packageJson['devDependencies'] ?? []; | ||
$devDeps[$package] = $version; | ||
|
||
ksort($devDeps); | ||
|
||
$packageJson['devDependencies'] = $devDeps; | ||
|
||
$this->files->dumpFile('package.json', json_encode($packageJson, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES)); | ||
} | ||
|
||
private function packageJson(): array | ||
{ | ||
return json_decode($this->files->getFileContents('package.json'), true); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
symfony/process
is only a dev requirement of MakerBundle at the moment. After installing a fresh Symfony project with this PR's MakerBundle, I get this error when runningmake:scaffold
: