Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
wdiesveld committed May 8, 2020
1 parent 34ce081 commit 4c29a48
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions app/tqc.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,18 @@ function readConfig() : array

function standardizeConfig(array &$config)
{
if (!isset($config['project']['label'])) {
$config['project']['label'] = '';
}
if (!isset($config['compiler']['server'])) {
$config['compiler']['server'] = DEFAULT_COMPILER;
}
if (!isset($config['compiler']['version'])) {
$config['compiler']['version'] = 'latest';
}
if (!isset($config['compiler']['input'])) {
$config['compiler']['input'] = 'tinyqueries';
}
}

function isFileToUpload($filename) : bool
Expand Down Expand Up @@ -105,6 +114,10 @@ function sendCompileRequest(array $config, string $apiKey)
throw new \Exception('Cannot compile queries - curl extension for PHP is not installed');
}

if (!file_exists($config['compiler']['input'])) {
throw new \Exception('Cannot find input folder ' . $config['compiler']['input']);
}

$ch = curl_init();

if (!$ch) {
Expand All @@ -121,18 +134,7 @@ function sendCompileRequest(array $config, string $apiKey)

$zip->addFile($config['fileName']);

$folderInput = $config['compiler']['input'] ?? (file_exists('tinyqueries') ? 'tinyqueries' : null);

if (!$folderInput) {
throw new \Exception('No input folder specified in config file');
}

if (!file_exists($folderInput)) {
throw new \Exception('Cannot find input folder ' . $folderInput);
}

echo "- input folder: $folderInput\n";
addFolderRecursivelyToZip($zip, $folderInput);
addFolderRecursivelyToZip($zip, $config['compiler']['input']);

$zip->close();

Expand Down Expand Up @@ -207,9 +209,10 @@ function sendCompileRequest(array $config, string $apiKey)
echo "\033[1;33mTiny\033[1;37mQueries\033[0m\n";
$apiKey = getApiKey();
$config = readConfig();
echo "- project: " . ($config['project']['label'] ?? 'unknown') . "\n";
echo "- server: " . ($config['compiler']['server'] ?? 'default') . "\n";
echo "- version: " . ($config['compiler']['version'] ?? 'default') . "\n";
echo "- project: " . $config['project']['label'] . "\n";
echo "- server: " . $config['compiler']['server'] . "\n";
echo "- version: " . $config['compiler']['version'] . "\n";
echo "- input folder: " . $config['compiler']['input'] . "\n";
sendCompileRequest($config, $apiKey);
echo "\033[1;37mReady\033[0m\n";
} catch (\Exception $e) {
Expand Down
Binary file modified bin/tqc.phar
Binary file not shown.

0 comments on commit 4c29a48

Please sign in to comment.