Skip to content
Open
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
48 changes: 35 additions & 13 deletions src/utilities/setup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as fs from 'node:fs'
import path from 'node:path'

import { copyFileIfChanged, writeFileIfChanged } from './files.js'
Expand All @@ -7,8 +8,8 @@ import { DeepObject, deepMerge } from './objects.js'
import { LiquidNode } from './types.js'

export async function copySetupComponentFiles(
collectionDir: string,
destination: string,
collectionDir: string,
destination: string,
componentSelector: string
): Promise<void> {
const collectionNodes = await getCollectionNodes(collectionDir)
Expand All @@ -18,6 +19,8 @@ export async function copySetupComponentFiles(

const settingsSchema: object[] = []
const settingsData: DeepObject = {}
let hasSchemaFiles = false
let hasDataFiles = false

// Process all files in parallel
await Promise.all(setupFiles.map(async (setupFile) => {
Expand All @@ -27,29 +30,48 @@ export async function copySetupComponentFiles(
if (node.name === 'settings_schema.json') {
const schemaItems = await processSettingsSchema(setupFile, node)
settingsSchema.push(...schemaItems)
hasSchemaFiles = true
} else if (node.name === 'settings_data.json') {
const dataItems = await processSettingsData(setupFile, node)
deepMerge(settingsData, dataItems)
hasDataFiles = true
} else {
copyFileIfChanged(node.file, path.join(destination, node.themeFolder, node.name))
}
}))

// Write combined settings schema
writeFileIfChanged(
JSON.stringify(settingsSchema),
path.join(destination, 'config', 'settings_schema.json')
)
// Only write combined settings files if we found setup files for them
if (hasSchemaFiles) {
writeFileIfChanged(
JSON.stringify(settingsSchema, null, 2),
path.join(destination, 'config', 'settings_schema.json')
)
} else {
// If no schema files found, copy existing file from theme if it exists
const existingSchemaPath = path.join(destination, 'config', 'settings_schema.json')
if (!fs.existsSync(existingSchemaPath)) {
// Only create an empty schema file if none exists
writeFileIfChanged('[]', existingSchemaPath)
}
}

// Write combined settings data
writeFileIfChanged(
JSON.stringify(settingsData),
path.join(destination, 'config', 'settings_data.json')
)
if (hasDataFiles) {
writeFileIfChanged(
JSON.stringify(settingsData, null, 2),
path.join(destination, 'config', 'settings_data.json')
)
} else {
// If no data files found, copy existing file from theme if it exists
const existingDataPath = path.join(destination, 'config', 'settings_data.json')
if (!fs.existsSync(existingDataPath)) {
// Only create an empty data file if none exists
writeFileIfChanged('{}', existingDataPath)
}
}
}

export async function processSettingsSchema(
setupFile: string,
setupFile: string,
node: LiquidNode
): Promise<object[]> {
if (node?.name !== 'settings_schema.json') {
Expand Down