Skip to content

Commit

Permalink
Merge pull request #152 from geographika/raw-output
Browse files Browse the repository at this point in the history
Allow raw GeoStyler output option
  • Loading branch information
jansule committed Nov 29, 2021
2 parents b2e1651 + b5a10c5 commit 4ec5fb9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
7 changes: 3 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async function collectPaths(basePath: string, isFile: boolean): Promise<string[]

async function writeFile(
sourceFile: string, sourceParser: StyleParser,
targetFile: string, targetParser: StyleParser,
targetFile: string, targetParser: StyleParser | undefined,
oraIndicator: Ora
) {
const inputFileData = await promises.readFile(sourceFile, 'utf-8');
Expand All @@ -146,7 +146,7 @@ async function writeFile(
indicator.text = `Reading from ${sourceFile}`;
const geostylerStyle = await sourceParser.readStyle(inputFileData);
indicator.text = `Writing to ${targetFile}`;
const targetStyle = await targetParser.writeStyle(geostylerStyle);
const targetStyle = targetParser ? await targetParser.writeStyle(geostylerStyle) : JSON.stringify(geostylerStyle);
if (targetFile) {
await promises.writeFile(targetFile, targetStyle, 'utf-8');
indicator.succeed(`File "${sourceFile}" translated successfully. Output written to ${targetFile}`);
Expand Down Expand Up @@ -229,8 +229,7 @@ async function main() {
return;
}
if (!targetParser) {
indicator.fail('No targetparser was specified.');
return;
indicator.info('No targetparser was specified. Output will be a GeoStyler object.');
}

// Get source(s) path(s).
Expand Down
13 changes: 8 additions & 5 deletions src/logHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ export const logHelp = () :void => {
Options:
-h / --help : Display this help.
-o / --output : Output filename or directory. Required. [string]
-o / --output : Output filename or directory. Mandatory if the target
is a directory. If not provided for a single file then output
will be written to stdout. [string]
-s / --source : SourceParser, either "mapbox", "mapfile" or "map", "sld",
"qgis" or "qml". If not given, it will be guessed from the
extension of the output file. Mandatory if the the target
is a directory.
-t / --target : Target parser, either "mapbox", "mapfile" or "map", "sld",
"qgis" or "qml". If not given, it will be guessed from the
extension of the output file. Mandatory if the the target
is a directory. Mapfiles are currently not supported as target.
-t / --target : Target parser, either "mapbox", "sld", "qgis" or "qml".
Mapfiles are currently not supported as target.
Mandatory if the the target is a directory. If not given and cannot
be guessed from the extension of the output file, the output will
default to GeoStyler objects represented as JSON.
-v / --version: Display the version of the program.
`);
};
Expand Down

0 comments on commit 4ec5fb9

Please sign in to comment.