Skip to content

Commit

Permalink
Merge pull request #554 from alejofernandez/ulx-430
Browse files Browse the repository at this point in the history
feat: add support for branding themes (no-code tool) [ULX-430]
  • Loading branch information
willvedd authored Jun 1, 2022
2 parents a58bfe5 + ac3aee4 commit 1d91472
Show file tree
Hide file tree
Showing 16 changed files with 1,218 additions and 6 deletions.
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@types/nconf": "^0.10.2",
"@types/winston": "^2.4.4",
"ajv": "^6.12.6",
"auth0": "^2.40.0",
"auth0": "^2.42.0",
"dot-prop": "^5.2.0",
"fs-extra": "^10.1.0",
"global-agent": "^2.1.12",
Expand All @@ -52,8 +52,8 @@
"devDependencies": {
"@types/expect": "^24.3.0",
"@types/mocha": "^9.1.0",
"chai": "^4.3.6",
"@typescript-eslint/parser": "^5.18.0",
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",
"cross-env": "^3.1.4",
"eslint": "^7.28.0",
Expand Down
2 changes: 2 additions & 0 deletions src/context/directory/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import branding from './branding';
import logStreams from './logStreams';
import prompts from './prompts';
import customDomains from './customDomains';
import themes from './themes';

import DirectoryContext from '..';
import { AssetTypes, Asset } from '../../../types';
Expand Down Expand Up @@ -66,6 +67,7 @@ const directoryHandlers: {
logStreams,
prompts,
customDomains,
themes,
};

export default directoryHandlers;
49 changes: 49 additions & 0 deletions src/context/directory/handlers/themes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import path from 'path';
import { ensureDirSync } from 'fs-extra';
import { getFiles, dumpJSON, loadJSON, existsMustBeDir } from '../../../utils';
import { DirectoryHandler } from '.';
import DirectoryContext from '..';
import { ParsedAsset } from '../../../types';
import { Theme } from '../../../tools/auth0/handlers/themes';
import { constants } from '../../../tools';

type ParsedThemes = ParsedAsset<'themes', Theme[]>;

function parse(context: DirectoryContext): ParsedThemes {
const baseFolder = path.join(context.filePath, constants.THEMES_DIRECTORY);
if (!existsMustBeDir(baseFolder)) {
return { themes: null };
}

const themeDefinitionsFiles = getFiles(baseFolder, ['.json']);
if (!themeDefinitionsFiles.length) {
return { themes: [] };
}

const themes = themeDefinitionsFiles.map(
(themeDefinitionsFile) => loadJSON(themeDefinitionsFile, context.mappings) as Theme
);

return { themes };
}

async function dump(context: DirectoryContext): Promise<void> {
const { themes } = context.assets;
if (!themes) {
return;
}

const baseFolder = path.join(context.filePath, constants.THEMES_DIRECTORY);
ensureDirSync(baseFolder);

themes.forEach((themeDefinition, i) => {
dumpJSON(path.join(baseFolder, `theme${i ? i : ''}.json`), themeDefinition);
});
}

const themesHandler: DirectoryHandler<ParsedThemes> = {
parse,
dump,
};

export default themesHandler;
2 changes: 2 additions & 0 deletions src/context/yaml/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import branding from './branding';
import logStreams from './logStreams';
import prompts from './prompts';
import customDomains from './customDomains';
import themes from './themes';

import YAMLContext from '..';
import { AssetTypes } from '../../../types';
Expand Down Expand Up @@ -64,6 +65,7 @@ const yamlHandlers: { [key in AssetTypes]: YAMLHandler<{ [key: string]: unknown
logStreams,
prompts,
customDomains,
themes,
};

export default yamlHandlers;
23 changes: 23 additions & 0 deletions src/context/yaml/handlers/themes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { YAMLHandler } from '.';
import YAMLContext from '..';
import { ParsedAsset } from '../../../types';
import { Theme } from '../../../tools/auth0/handlers/themes';

type ParsedThemes = ParsedAsset<'themes', Theme[]>;

async function parseAndDump(context: YAMLContext): Promise<ParsedThemes> {
const { themes } = context.assets;

if (!themes) return { themes: null };

return {
themes,
};
}

const themesHandler: YAMLHandler<ParsedThemes> = {
parse: parseAndDump,
dump: parseAndDump,
};

export default themesHandler;
2 changes: 2 additions & 0 deletions src/tools/auth0/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import * as organizations from './organizations';
import * as attackProtection from './attackProtection';
import * as logStreams from './logStreams';
import * as customDomains from './customDomains';
import * as themes from './themes';

import { AssetTypes } from '../../../types';
import APIHandler from './default';
Expand Down Expand Up @@ -61,6 +62,7 @@ const auth0ApiHandlers: { [key in AssetTypes]: any } = {
attackProtection,
logStreams,
customDomains,
themes,
};

export default auth0ApiHandlers as {
Expand Down
Loading

0 comments on commit 1d91472

Please sign in to comment.