Skip to content

Commit

Permalink
Add ant build for executables
Browse files Browse the repository at this point in the history
  • Loading branch information
SMillerDev committed Sep 5, 2016
1 parent 9ac9bc0 commit 052a229
Show file tree
Hide file tree
Showing 10 changed files with 282 additions and 46 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/.idea/

# IntelliJ
/out/
/build/
/build/coverage
/build/logs
/build/phar
/build/*.phar

# JIRA plugin
atlassian-ide-plugin.xml
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ This is a parser for API Blueprint files in PHP.
## Usage
For direct usage you can run:
```bash
$ ./phpdraft.phar blueprint-file.apib > blueprint-webpage.html
$ ./phpdraft.phar -f blueprint-file.apib > blueprint-webpage.html
```
You can also install it first:
```bash
$ cp phpdraft.phar /usr/bin/phpdraft
$ chmod +x /usr/bin/phpdraft
$ phpdraft blueprint-file.apib > blueprint-webpage.html
$ phpdraft -f blueprint-file.apib > blueprint-webpage.html
```

## Including Files
Expand Down
113 changes: 113 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="phpdrafter" default="setup">
<target name="setup" depends="clean"/>

<target name="clean" unless="clean.done" description="Cleanup build artifacts">
<delete dir="${basedir}/bin"/>
<delete dir="${basedir}/build/documentation"/>
<delete dir="${basedir}/build/logfiles"/>
<delete dir="${basedir}/build/phar"/>
<delete>
<fileset dir="${basedir}/build">
<include name="**/phpdraft*.phar"/>
<include name="**/phpdraft*.phar.asc"/>
</fileset>
</delete>

<property name="clean.done" value="true"/>
</target>

<target name="signed-phar" depends="phar"
description="Create signed PHAR archive of PHPDraft and all its dependencies">
<exec executable="gpg" failonerror="true">
<arg value="--armor"/>
<arg value="--detach-sign"/>
<arg path="${basedir}/build/phpdraft-library-${version}.phar"/>
</exec>

<exec executable="gpg" failonerror="true">
<arg value="--armor"/>
<arg value="--detach-sign"/>
<arg path="${basedir}/build/phpdraft-${version}.phar"/>
</exec>
</target>

<target name="phar" depends="-phar-determine-version,-phar-prepare"
description="Create PHAR archive of PHPDraft and all its dependencies">
<antcall target="-phar-build">
<param name="type" value="release"/>
</antcall>
</target>

<target name="phar-nightly" depends="-phar-prepare"
description="Create PHAR archive of PHPDraft and all its dependencies (nightly)">
<antcall target="-phar-build">
<param name="type" value="nightly"/>
</antcall>
</target>

<target name="-phar-prepare" depends="clean">
<mkdir dir="${basedir}/build/phar"/>
<copy file="${basedir}/LICENSE" tofile="${basedir}/build/phar/LICENSE"/>
<exec executable="${basedir}/build/phar-manifest.php" output="${basedir}/build/phar/manifest.txt"/>
</target>

<target name="-phar-build" depends="-phar-determine-version">
<copy todir="${basedir}/build/phar/phpdraft/src">
<fileset dir="${basedir}/src/">
<exclude name="**/*Test.php*"/>
<include name="**/*.php"/>
<include name="**/*.js*"/>
<include name="**/*.css*"/>
</fileset>
</copy>
<copy todir="${basedir}/build/phar/phpdraft">
<fileset dir="${basedir}">
<include name="**/*.json*"/>
<include name="**/index.php"/>
</fileset>
</copy>

<exec executable="${basedir}/build/phar-version.php" outputproperty="_version">
<arg value="${version}"/>
<arg value="${type}"/>
</exec>

<exec executable="phpab" taskname="phpab">
<arg value="--all"/>
<arg value="--static"/>
<arg value="--once"/>
<arg value="--phar"/>
<arg value="--hash"/>
<arg value="SHA-1"/>
<arg value="--output"/>
<arg path="${basedir}/build/phpdraft-library-${_version}.phar"/>
<arg value="--template"/>
<arg path="${basedir}/build/library-phar-autoload.php.in"/>
<arg path="${basedir}/build/phar"/>
</exec>

<exec executable="phpab" taskname="phpab">
<arg value="--all"/>
<arg value="--nolower"/>
<arg value="--static"/>
<arg value="--phar"/>
<arg value="--hash"/>
<arg value="SHA-1"/>
<arg value="--output"/>
<arg path="${basedir}/build/phpdraft-${_version}.phar"/>
<arg value="--template"/>
<arg path="${basedir}/build/binary-phar-autoload.php.in"/>
<arg path="${basedir}/build/phar"/>
</exec>

<chmod file="${basedir}/build/phpdraft-${_version}.phar" perm="ugo+rx"/>
</target>

<target name="-phar-determine-version">
<exec executable="bash" outputproperty="version">
<arg value="-c"/>
<arg value="php ${basedir}/index.php -v | grep -ohE '([0-9]{1,}\.)+[0-9]{1,}'"/>
</exec>
</target>
</project>
34 changes: 34 additions & 0 deletions build/binary-phar-autoload.php.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env php
<?php
if (version_compare('5.6.0', PHP_VERSION, '>')) {
fwrite(
STDERR,
'This version of PHPDraft requires PHP 5.6; using the latest version of PHP is highly recommended.' . PHP_EOL
);

die(1);
}

if (__FILE__ == realpath($GLOBALS['_SERVER']['SCRIPT_NAME'])) {
$execute = true;
} else {
$execute = false;
}

define('__PHPDRAFT_PHAR__', str_replace(DIRECTORY_SEPARATOR, '/', __FILE__));
define('__PHPDRAFT_PHAR_ROOT__', 'phar://___PHAR___');

Phar::mapPhar('___PHAR___');

___FILELIST___

if ($execute) {
if (isset($_SERVER['argv'][1]) && $_SERVER['argv'][1] == '--manifest') {
print file_get_contents(__PHPDRAFT_PHAR_ROOT__ . '/manifest.txt');
exit;
}

require_once __PHPDRAFT_PHAR_ROOT__.DIRECTORY_SEPARATOR.'phpdraft'.DIRECTORY_SEPARATOR.'index.php';
}

__HALT_COMPILER();
9 changes: 9 additions & 0 deletions build/library-phar-autoload.php.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
define('__PHPDRAFT_PHAR__', str_replace(DIRECTORY_SEPARATOR, '/', __FILE__));
define('__PHPDRAFT_PHAR_ROOT__', 'phar://___PHAR___');

Phar::mapPhar('___PHAR___');

___FILELIST___

__HALT_COMPILER();
15 changes: 15 additions & 0 deletions build/phar-manifest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env php
<?php
print 'phpdraft/phpdraft: ';

$tag = @exec('git describe --tags 2>&1');

if (strpos($tag, '-') === false && strpos($tag, 'No names found') === false) {
print $tag;
} else {
$branch = @exec('git rev-parse --abbrev-ref HEAD');
$hash = @exec('git log -1 --format="%H"');
print $branch . '@' . $hash;
}

print "\n";
20 changes: 20 additions & 0 deletions build/phar-version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env php
<?php
if (!isset($argv[1]) || !isset($argv[2])) {
exit(1);
}

file_put_contents(
__DIR__ . '/phar/phpdraft/index.php',
str_replace(
"define('VERSION', '');",
"define('VERSION', '" . $argv[1] . "');",
file_get_contents(__DIR__ . '/phar/phpdraft/index.php')
)
);

if ($argv[2] == 'release') {
print $argv[1];
} else {
print $argv[2];
}
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"tmpdir": "/tmp/drafter",
"logo": "/home/smillernl/Documents/5acf473a9e6a3deb8e98a2b6373d0a83.png"
"logo": "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"
}
47 changes: 6 additions & 41 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,18 @@
*/
require_once 'PHPDraft/Core/Autoloader.php';
use PHPDraft\In\ApibFileParser;
use PHPDraft\Out\UI;
use PHPDraft\Parse\ApibToJson;
use PHPDraft\Parse\JsonToHTML;

$options = getopt("f:t::i::h");
if(!isset($argv[1]))
{
file_put_contents('php://stderr', 'Not enough arguments'.PHP_EOL);
help();
exit(1);
}
define('VERSION', '0');

if (boolval(preg_match('/^\-/',$argv[1])))
{
if (isset($options['h']))
{
help();
exit(0);
}
elseif (isset($options['f']))
{
$file = $options['f'];
}
else
{
file_put_contents('php://stderr', 'No file to parse'.PHP_EOL);
exit(1);
}
}
else
{
$file = $argv[1];
}
$values = UI::main($argv);

$template = (isset($options['t']) && $options['t']) ? $options['t']: 'default';
$image = (isset($options['i']) && $options['i']) ? $options['i']: NULL;

$apib = new ApibFileParser($file);
$apib = new ApibFileParser($values['file']);
$json = new ApibToJson($apib);
$html = new JsonToHTML($json->parseToJson());
$html->get_html($template, $image);
$html->get_html($values['template'], $values['image']);


function help()
{
echo 'This is a parser for API Blueprint files in PHP.'.PHP_EOL.PHP_EOL;
echo "The following options can be used:.\n";
echo "\t-f\tSpecifies the file to parse.\n";
echo "\t-t\tSpecifies the template to use. (defaults to 'default')\n";
echo "\t-h\tDisplays this text.\n";
}
?>
78 changes: 78 additions & 0 deletions src/PHPDraft/Out/UI.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/**
* This file contains the UI.php
*
* @package php-drafter\SOMETHING
* @author Sean Molenaar<[email protected]>
*/

namespace PHPDraft\Out;


class UI
{
static function main($argv = [])
{
$options = getopt("f:t::i::hv");
if(!isset($argv[1]))
{
file_put_contents('php://stderr', 'Not enough arguments'.PHP_EOL);
self::help();
exit(1);
}

if (boolval(preg_match('/^\-/',$argv[1])))
{
if (isset($options['h']))
{
self::help();
exit(0);
}

if (isset($options['v']))
{
self::version();
exit(0);
}

elseif (isset($options['f']))
{
$file = $options['f'];
}
else
{
file_put_contents('php://stderr', 'No file to parse'.PHP_EOL);
exit(1);
}
}
else
{
$file = $argv[1];
}

$template = (isset($options['t']) && $options['t']) ? $options['t']: 'default';
$image = (isset($options['i']) && $options['i']) ? $options['i']: NULL;

return [
'file' => $file,
'template' => $template,
'image' => $image
];
}

static function help()
{
echo 'This is a parser for API Blueprint files in PHP.'.PHP_EOL.PHP_EOL;
echo "The following options can be used:.\n";
echo "\t-f\tSpecifies the file to parse.\n";
echo "\t-t\tSpecifies the template to use. (defaults to 'default')\n";
echo "\t-h\tDisplays this text.\n";
}

static function version()
{
$version = (VERSION === '0') ? @exec('git describe --tags 2>&1') : VERSION;
echo 'PHPDraft: '.$version;
}

}

0 comments on commit 052a229

Please sign in to comment.