Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support keyword replacement for custom prompts when using the directory format #963

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/context/directory/handlers/prompts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import { ensureDirSync, readFileSync, writeFileSync } from 'fs-extra';
import { constants } from '../../../tools';
import { ensureDirSync, writeFileSync } from 'fs-extra';
import { constants, loadFileAndReplaceKeywords } from '../../../tools';
import { dumpJSON, existsMustBeDir, isFile, loadJSON } from '../../../utils';
import { DirectoryHandler } from '.';
import DirectoryContext from '..';
Expand Down Expand Up @@ -67,7 +67,10 @@ function parse(context: DirectoryContext): ParsedPrompts {
(insertionAcc, { name, template }) => {
const templateFilePath = path.join(promptsDirectory, template);
insertionAcc[name] = isFile(templateFilePath)
? readFileSync(templateFilePath, 'utf8').trim()
? loadFileAndReplaceKeywords(templateFilePath, {
mappings: context.mappings,
disableKeywordReplacement: context.disableKeywordReplacement,
}).trim()
: '';
return insertionAcc;
},
Expand Down
5 changes: 3 additions & 2 deletions test/context/directory/prompts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('#directory context prompts', () => {
},
signup: {
signup: {
'form-content-end.liquid': '<div>TEST AGAIN</div>',
'form-content-end.liquid': '<div>Hello, ##SOME_REPLACED_KEYWORD##!</div>',
kushalshit27 marked this conversation as resolved.
Show resolved Hide resolved
},
},
};
Expand All @@ -106,6 +106,7 @@ describe('#directory context prompts', () => {
AUTH0_KEYWORD_REPLACE_MAPPINGS: {
BUTTON_TEXT_FRENCH: 'French button text',
BUTTON_TEXT_ENGLISH: 'English button text',
SOME_REPLACED_KEYWORD: 'world',
},
};
const context = new Context(config, mockMgmtClient());
Expand All @@ -121,7 +122,7 @@ describe('#directory context prompts', () => {
},
signup: {
signup: {
'form-content-end': '<div>TEST AGAIN</div>',
'form-content-end': '<div>Hello, world!</div>',
},
},
},
Expand Down
13 changes: 10 additions & 3 deletions test/context/yaml/prompts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,20 @@ describe('#YAML context prompts', () => {
login-id:
login-id:
form-content-end: >-
<div>TEST</div>
<div>Hello, ##SOME_REPLACED_KEYWORD##!</div>
`;

const yamlFile = path.join(dir, 'config.yaml');
fs.writeFileSync(yamlFile, yaml);

const config = { AUTH0_INPUT_FILE: yamlFile };
const mappings = {
SOME_REPLACED_KEYWORD: 'world',
};

const config = {
AUTH0_INPUT_FILE: yamlFile,
AUTH0_KEYWORD_REPLACE_MAPPINGS: mappings,
};
kushalshit27 marked this conversation as resolved.
Show resolved Hide resolved
const context = new Context(config, mockMgmtClient());
await context.loadAssetsFromLocal();

Expand Down Expand Up @@ -147,7 +154,7 @@ describe('#YAML context prompts', () => {
},
'login-id': {
'login-id': {
'form-content-end': '<div>TEST</div>',
'form-content-end': '<div>Hello, world!</div>',
},
},
},
Expand Down
Loading