Skip to content

Commit

Permalink
added option to set multiple output folders
Browse files Browse the repository at this point in the history
  • Loading branch information
wdiesveld committed May 29, 2019
1 parent 122191f commit 8534c95
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@ The folder from which the script is run should contain a file `tinyqueries.json`

## Optional settings

### compiler.lang

Possible values: `sql` | `php`

### compiler.output

`compiler.output` can be used as a dictionary as well, for example:

```json
{
"compiler": {
"output": {
"sql": "<output folder sql>",
"php": "<output folder php>"
}
}
}
```

### compiler.outputFieldNames

```json
Expand Down
24 changes: 14 additions & 10 deletions bin/tqc.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,15 @@ function standardizeConfig(StdClass &$config)
$config->compiler->input = pathAbs($config->compiler->input);
}
if (isset($config->compiler->output)) {
$config->compiler->output = pathAbs($config->compiler->output);
if (is_string($config->compiler->output)) {
$outputFolder = $config->compiler->output;
$defaultLang = $config->compiler->lang ?? 'sql';
$config->compiler->output = new StdClass();
$config->compiler->output->$defaultLang = $outputFolder;
}
foreach ($config->compiler->output as $lang => $folder) {
$config->compiler->output->$lang = pathAbs($folder);
}
}
// Add "v" to version if missing
if (isset($config->compiler->version)
Expand Down Expand Up @@ -265,15 +273,11 @@ function uploadFiles($config)
$filename = $zip->getNameIndex($i);
$content = $zip->getFromName($filename);
$path = explode('/', $filename);
if ($config->compiler->lang) {
if ($config->compiler->output
&& $path[0] == $config->compiler->lang
&& $path[1]) {
file_put_contents($config->compiler->output . DIRECTORY_SEPARATOR . $path[1], $content);
}
} elseif ($path[0] == 'sql') {
if ($path[1]) {
file_put_contents($config->compiler->output . DIRECTORY_SEPARATOR . $path[1], $content);
foreach ($config->compiler->output as $lang => $folder) {
if ($path[0] == $lang) {
if ($path[1]) {
file_put_contents($folder . DIRECTORY_SEPARATOR . $path[1], $content);
}
}
}
}
Expand Down

0 comments on commit 8534c95

Please sign in to comment.