Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
23 changes: 12 additions & 11 deletions src/scripts/build-content-tree.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ function buildContentTree(source, output) {
dir: source,
});

fs.writeFileSync(
path.resolve(output),
JSON.stringify(content, null, 2),
(error) => {
if (error) {
console.log('scripts/build-content-tree', error);
} else {
console.log('Successfully built content tree file at ' + output);
}
}
);
// fs.writeFileSync does not accept a callback; wrap with try/catch and
// log a clear success or error instead.
try {
fs.writeFileSync(
path.resolve(output),
JSON.stringify(content, null, 2)
);
console.log('Successfully built content tree file at ' + output);
} catch (error) {
console.error('scripts/build-content-tree', error);
process.exitCode = 1;
}
}
6 changes: 4 additions & 2 deletions src/utilities/flatten-content-tree.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ export default (tree) => {
}

if ('children' in node) {
node.children.map(crawl);
node.children.forEach(crawl);
}
};

tree.children.map(crawl);
if (Array.isArray(tree.children)) {
tree.children.forEach(crawl);
}

return paths;
};
7 changes: 5 additions & 2 deletions src/utilities/is-client.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const isClient = window !== undefined && window.document !== undefined;
// Guard against ReferenceError in non-browser/SSR environments
// and use a consistent ESM default export.
const isClient =
typeof window !== 'undefined' && typeof window.document !== 'undefined';

module.exports = isClient;
export default isClient;
Loading