Skip to content

Commit

Permalink
added build
Browse files Browse the repository at this point in the history
  • Loading branch information
Lawrence Cherone committed Mar 17, 2018
1 parent d5f4088 commit 12e95c8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
Binary file added package-generator.phar
Binary file not shown.
14 changes: 14 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: phppackage/my-package
title: 'My Package'
description: ''
type: library
keywords: { }
homepage: 'http://github.com/phppackage/my-package'
authors:
- { name: '', email: '', homepage: 'http://github.com/phppackage/my-package', role: Owner }
autoload:
psr-4: { phppackage\my-package\: src }
autoload-dev:
psr-4: { phppackage\my-package\Tests\: tests }
vendor: phppackage
package: my-package
50 changes: 29 additions & 21 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,44 @@ class App extends MagicClass
public function __construct()
{
parent::__construct();

$this->cli = new Cli($this);
$this->package = new Package($this);
$this->config = new Config($this);

$this->filesystem = new Filesystem($this);
}

public function run()
{
$this->cli->clear();
$this->cli->arguments();

$this->config->check_php_version(7);

if ($this->arguments['wizard']) {
$package = $this->package->wizard();
}

if ($this->arguments['init']) {
$package = $this->package->init();
}

// start building package
$this->filesystem->target_dir = $this->config->basepath().'/MY-PACKAGE';
// detect if has a composer (cloned)
if (file_exists($this->config->basepath().'/composer.json')) {
$this->filesystem->target_dir = $this->config->basepath().'/'.basename($package['name']);
}
// detect if no composer.json presume downloaded build
else {
$this->filesystem->target_dir = $this->config->basepath();
}

$this->filesystem->source_dir = __DIR__.'/setup';

$this->filesystem->create_directory('src');
$this->filesystem->create_directory('tests/fixtures');

/**
* Move unchanged files
*/
Expand All @@ -59,7 +67,7 @@ public function run()
/**
* Process/Create files which change
*/

// README.md
$authors = [];
foreach ($package['authors'] as $author) {
Expand All @@ -71,7 +79,7 @@ public function run()
'description' => $package['description'],
'authors' => implode(PHP_EOL, $authors)
]);

// composer.json
file_put_contents(
$this->filesystem->target_dir.'/composer.json',
Expand All @@ -98,16 +106,16 @@ public function run()
'minimum-stability' => 'stable'
], JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT)
);

// create placeholder class
$namespace = rtrim(array_search('src', $package['autoload']['psr-4']), '\\');
$testName = str_replace([' ', $package['vendor']], null, ucwords(str_replace('\\', ' ', $namespace)));

$authors = [];
foreach ($package['authors'] as $author) {
$authors[] = ' | '.sprintf('%s <%s>', $author['name'], $author['email']);
}

// create class
file_put_contents($this->filesystem->target_dir.'/src/'.$testName.'.php', '<?php
/*
Expand Down Expand Up @@ -176,21 +184,21 @@ public function testTrueIsTrue()
{
$this->assertTrue(true);
}
/**
* has class initialised?
*/
public function testObjectInstanceOf()
{
$this->assertInstanceOf(\'\\'.$namespace.'\\'.$testName.'\', $this->instance);
}
/**
* @covers \\'.$namespace.'\\'.$testName.'::exampleMetod()
*/
public function testExampleMethod()
{
$this->assertEquals(\'foobar\', $this->instance->exampleMethod());
$this->assertEquals(\'foobar\', $this->instance->exampleMethod());
}
}'.PHP_EOL);
Expand All @@ -206,10 +214,10 @@ public function testExampleMethod()
$response = readline($options['question']);
} while (!in_array($response, $options['expected']));
readline_add_history($response);

return $callback($response);
};

$yesno = ['y', 'yes', 'n', 'no'];

$ask([
Expand All @@ -221,7 +229,7 @@ public function testExampleMethod()
echo `composer test`;
}
});

echo 'Happy coding! - If you liked this, star it!'.PHP_EOL;
}

Expand Down

0 comments on commit 12e95c8

Please sign in to comment.