Skip to content

Commit 7b3f522

Browse files
committed
address PR review feedback
Addressed review comments: - Suppressed the shared renderTemplate status line in render-template-browser.js so the CLI prints one JSON result. - Suppressed the shared renderTemplate status line in render-template-import-status.js so the CLI prints one JSON result. Copilot-Session: a9952624-0a25-4d6e-ae67-537c962a8a60
1 parent fef669f commit 7b3f522

5 files changed

Lines changed: 42 additions & 2 deletions

File tree

plugins/power-pages/scripts/lib/render-template.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ const path = require('path');
1818
* @param {Object} [options.dataObject] - Data object passed directly. If provided, takes precedence over dataPath.
1919
* @param {string[]} options.requiredKeys - Keys that must be present in the data
2020
* @param {boolean} [options.escapeStringValues=false] - Escape string values for HTML text contexts
21+
* @param {boolean} [options.emitStatus=true] - Print JSON status after writing the file
2122
*/
22-
function renderTemplate({ templatePath, outputPath, dataPath, dataObject, requiredKeys, escapeStringValues = false }) {
23+
function renderTemplate({ templatePath, outputPath, dataPath, dataObject, requiredKeys, escapeStringValues = false, emitStatus = true }) {
2324
// Validate inputs exist
2425
if (!fs.existsSync(templatePath)) {
2526
console.error(`Template not found: ${templatePath}`);
@@ -97,7 +98,9 @@ function renderTemplate({ templatePath, outputPath, dataPath, dataObject, requir
9798
// non-fatal
9899
}
99100

100-
console.log(JSON.stringify({ status: 'ok', output: outputPath }));
101+
if (emitStatus) {
102+
console.log(JSON.stringify({ status: 'ok', output: outputPath }));
103+
}
101104
}
102105

103106
function escapeHtml(value) {

plugins/power-pages/scripts/render-template-browser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ function renderTemplateBrowser({ templatesJsonPath, outputPath, open = false },
167167
TEMPLATE_SECTIONS_HTML: renderTemplateSectionsHtml(templates),
168168
},
169169
requiredKeys: ['TEMPLATE_COUNT', 'TEMPLATE_TABS_HTML', 'TEMPLATE_SECTIONS_HTML'],
170+
emitStatus: false,
170171
});
171172
const validation = validateRenderedTemplateBrowser({ templates, html: fsImpl.readFileSync(outputPath, 'utf8') });
172173
if (!validation.ok) {

plugins/power-pages/scripts/render-template-import-status.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ function renderTemplateImportStatus({ templateName, statusPath, outputPath, prev
7373
PREVIEW_IMAGES_JSON: localizePreviewImages(previewImages, outputPath),
7474
},
7575
requiredKeys: ['TEMPLATE_NAME', 'STATUS_URL_JSON', 'PREVIEW_IMAGES_JSON'],
76+
emitStatus: false,
7677
});
7778
if (open) {
7879
try {

plugins/power-pages/scripts/tests/render-template-browser.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,26 @@ test('renderTemplateBrowser renders static template details and preview images',
8686
assert.doesNotMatch(html, /templates\.map/);
8787
});
8888

89+
test('renderTemplateBrowser does not print the shared renderTemplate status line', (t) => {
90+
const dir = tempDir();
91+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
92+
const dataPath = path.join(dir, 'templates.json');
93+
const outputPath = path.join(dir, 'browser.html');
94+
fs.writeFileSync(dataPath, JSON.stringify({
95+
TEMPLATES_JSON: [
96+
{ displayName: 'Company Portal', description: 'Internal site', framework: 'react', previewImages: [] },
97+
],
98+
}));
99+
const originalLog = console.log;
100+
const logs = [];
101+
console.log = (value) => logs.push(value);
102+
t.after(() => { console.log = originalLog; });
103+
104+
renderTemplateBrowser({ templatesJsonPath: dataPath, outputPath, open: false });
105+
106+
assert.deepEqual(logs, []);
107+
});
108+
89109
test('renderTemplateBrowser renders one family with read-only framework variants', (t) => {
90110
const dir = tempDir();
91111
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));

plugins/power-pages/scripts/tests/render-template-import-status.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ test('renderTemplateImportStatus renders scaffold-style slideshow, progress, and
9191
assert.match(html, /Template import needs attention/);
9292
});
9393

94+
test('renderTemplateImportStatus does not print the shared renderTemplate status line', (t) => {
95+
const dir = tempDir();
96+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
97+
const outputPath = path.join(dir, 'import.html');
98+
const statusPath = path.join(dir, 'status.json');
99+
const originalLog = console.log;
100+
const logs = [];
101+
console.log = (value) => logs.push(value);
102+
t.after(() => { console.log = originalLog; });
103+
104+
renderTemplateImportStatus({ templateName: 'Supplier Portal', statusPath, outputPath });
105+
106+
assert.deepEqual(logs, []);
107+
});
108+
94109
test('localizePreviewImages copies local preview images beside the served page', (t) => {
95110
const dir = tempDir();
96111
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));

0 commit comments

Comments
 (0)