Skip to content
Merged
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
2 changes: 1 addition & 1 deletion website/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function createAposConfig() {
'global-data': {},

// Shared constants module
'shared-constants': {},
'@apostrophecms/shared-constants': {},

// Configure page types
'@apostrophecms/rich-text-widget': {},
Expand Down
16 changes: 14 additions & 2 deletions website/scripts/generate_constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ try {
);
}

// Helper function to safely stringify object with single quotes
const stringifyWithSingleQuotes = (obj, indent = 2) => {
const spaces = ' '.repeat(indent);
const entries = Object.entries(obj)
.map(
([key, value]) =>
`${spaces}${key}: '${String(value).replace(/\\/gu, '\\\\').replace(/'/gu, "\\'")}'`,
)
.join(',\n');
return `{\n${entries},\n${' '.repeat(indent - 2)}}`;
};

// Generate client-side constants file content
const clientFileContent = `/*
* Client-side access to shared constants.
Expand All @@ -44,12 +56,12 @@ try {
*/

// Direct export of constants for import { STANDARD_FORM_FIELD_NAMES } from '...'
export const STANDARD_FORM_FIELD_NAMES = ${JSON.stringify(STANDARD_FORM_FIELD_NAMES, null, 2)};
export const STANDARD_FORM_FIELD_NAMES = ${stringifyWithSingleQuotes(STANDARD_FORM_FIELD_NAMES)};

// Default export function for backwards compatibility
export default () => {
return {
STANDARD_FORM_FIELD_NAMES
STANDARD_FORM_FIELD_NAMES,
};
};
`;
Expand Down
Loading