Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
MAPSJS-3047, Split theme to stable and unstable parts
Browse files Browse the repository at this point in the history
Signed-off-by: Andrii Heonia <andrii.heonia@here.com>
  • Loading branch information
AndriiHeonia committed Nov 12, 2021
1 parent eb777fe commit fe4744f
Showing 1 changed file with 48 additions and 7 deletions.
55 changes: 48 additions & 7 deletions @here/harp-theme-tools/src/cli-build-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/* eslint-disable no-console */

import { FlatTheme } from "@here/harp-datasource-protocol";
import { ThemeLoader } from "@here/harp-mapview";
import * as program from "commander";
import * as fs from "fs";
Expand Down Expand Up @@ -40,25 +41,65 @@ if (typeof cliOptions.in !== "string" || cliOptions.in.length === 0) {

process.chdir(cliOptions.chdir);

const inputFiles = glob.sync(cliOptions.in);
const inFileNames = glob.sync(cliOptions.in);

if (inputFiles.length === 0) {
if (inFileNames.length === 0) {
console.error("No input files found");
program.outputHelp();
process.exit(1);
}

inputFiles.forEach(file => {
ThemeLoader.load(file, {
inFileNames.forEach(inFileName => {
ThemeLoader.load(inFileName, {
resolveResourceUris: false,
resolveIncludeUris: true
}).then(theme => {
theme.url = undefined;
const filename = `${cliOptions.out}/${path.basename(file)}`;
console.log(`Writing ${filename}`);
const json = cliOptions.minify
? JSON.stringify(theme)
: JSON.stringify(theme, undefined, 4);
fs.writeFileSync(filename, json);

const unifiedDefinitionsFileName =
path.dirname(inFileName) +
path.sep +
"unified-definitions" +
path.sep +
path.basename(inFileName);

// If unified definitions file exists then we split a theme to unified with native and
// non-unified with native parts. We need such split to explain users which parts of
// the theme will stay backward compatible and which ones will not:
if (fs.existsSync(unifiedDefinitionsFileName)) {
// Private (non-unified) part:
const outFileBaseNamePrivate = `${path.basename(inFileName, "json")}private.json`;
const outFileNamePrivate = cliOptions.out + path.sep + outFileBaseNamePrivate;
console.log(`Writing ${outFileNamePrivate}`);
fs.writeFileSync(outFileNamePrivate, json);

// Public (unified) part:
const themePublic: FlatTheme = {
extends: [outFileBaseNamePrivate],
definitions: {},
url: undefined
};
const unifiedDefinitions: string[] = JSON.parse(
fs.readFileSync(unifiedDefinitionsFileName, "utf8")
);
unifiedDefinitions.forEach(def => {
if (theme.definitions && themePublic.definitions) {
themePublic.definitions[def] = theme.definitions[def];
}
});
const jsonPublic = cliOptions.minify
? JSON.stringify(themePublic)
: JSON.stringify(themePublic, undefined, 4);
const outFileNamePublic = `${cliOptions.out}/${path.basename(inFileName)}`;
console.log(`Writing ${outFileNamePublic}`);
fs.writeFileSync(outFileNamePublic, jsonPublic);
} else {
const outFileName = `${cliOptions.out}/${path.basename(inFileName)}`;
console.log(`Writing ${outFileName}`);
fs.writeFileSync(outFileName, json);
}
});
});

0 comments on commit fe4744f

Please sign in to comment.