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
9 changes: 6 additions & 3 deletions src/utilities/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,14 @@ export async function generateLiquidNode(file: string, type: LiquidNode['type'],
.filter(file => !fs.statSync(file).isDirectory())
}

// For theme snippets, use just the filename (flatten subfolder structure)
const name = path.basename(file)

return {
assets,
body,
file,
name: path.basename(file),
name,
setup,
snippets,
themeFolder,
Expand Down Expand Up @@ -117,12 +120,12 @@ export async function getCollectionNodes(collectionDir: string): Promise<LiquidN
}

export async function getThemeNodes(themeDir: string): Promise<LiquidNode[]> {
const entryNodes = globSync(path.join(themeDir, '{layout,sections,blocks,templates}', '*.liquid'), { absolute: true })
const entryNodes = globSync(path.join(themeDir, '{layout,sections,blocks,templates}', '**/*.liquid'), { absolute: true })
.map(file => {
const parentFolderName = path.basename(path.dirname(file)) as LiquidNode['themeFolder']
return generateLiquidNode(file, 'entry', parentFolderName)
})
const themeSnippets = globSync(path.join(themeDir, 'snippets', '*.liquid'), { absolute: true })
const themeSnippets = globSync(path.join(themeDir, 'snippets', '**/*.liquid'), { absolute: true })
.map(file => generateLiquidNode(file, 'snippet', 'snippets'))
const themeAssets = globSync(path.join(themeDir, 'assets', '*'), { absolute: true })
.map(file => generateLiquidNode(file, 'asset', 'assets'))
Expand Down
6 changes: 6 additions & 0 deletions test/commands/theme/component/map.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ describe('theme component map', () => {
const beforeData = JSON.parse(fs.readFileSync(path.join(testThemePath, 'component.manifest.json'), 'utf8'))
expect(beforeData.files.assets['missing.css']).to.be.undefined
expect(beforeData.files.snippets['missing.liquid']).to.be.undefined
expect(beforeData.files.snippets['missing-subfolder.liquid']).to.be.undefined

await runCommand(['theme', 'component', 'map', testThemePath])

// Check that missing entries are present in map
const data = JSON.parse(fs.readFileSync(path.join(testThemePath, 'component.manifest.json'), 'utf8'))
expect(data.files.assets['missing.css']).to.equal('@theme')
expect(data.files.snippets['missing.liquid']).to.equal('@theme')
expect(data.files.snippets['missing-subfolder.liquid']).to.equal('@theme')
})

it('adds entries for newly referenced components from current collection', async () => {
Expand Down Expand Up @@ -177,12 +179,14 @@ describe('theme component map', () => {
expect(beforeData.files.assets['theme-component.css']).to.equal('@theme')
expect(beforeData.files.snippets['other-collection-component.liquid']).to.equal('@other/collection')
expect(beforeData.files.assets['other-collection-component.css']).to.equal('@other/collection')
expect(beforeData.files.snippets['existing-subfolder.liquid']).to.equal('@theme')

// Check that removed files are present in map
expect(beforeData.files.snippets['theme-component-removed.liquid']).to.equal('@theme')
expect(beforeData.files.assets['theme-component-removed.css']).to.equal('@theme')
expect(beforeData.files.snippets['other-collection-component-removed.liquid']).to.equal('@other/collection')
expect(beforeData.files.assets['other-collection-component-removed.css']).to.equal('@other/collection')
expect(beforeData.files.snippets['removed-subfolder.liquid']).to.equal('@theme')

await runCommand(['theme', 'component', 'map', testThemePath])

Expand All @@ -193,12 +197,14 @@ describe('theme component map', () => {
expect(data.files.assets['theme-component.css']).to.equal('@theme')
expect(data.files.snippets['other-collection-component.liquid']).to.equal('@other/collection')
expect(data.files.assets['other-collection-component.css']).to.equal('@other/collection')
expect(data.files.snippets['existing-subfolder.liquid']).to.equal('@theme')

// Check that removed files are no longer present in map
expect(data.files.snippets['theme-component-removed.liquid']).to.be.undefined
expect(data.files.assets['theme-component-removed.css']).to.be.undefined
expect(data.files.snippets['other-collection-component-removed.liquid']).to.be.undefined
expect(data.files.assets['other-collection-component-removed.css']).to.be.undefined
expect(data.files.snippets['removed-subfolder.liquid']).to.be.undefined
})

it('sorts the files and collections keys in the component.map.json file', async () => {
Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/theme/component.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"override.liquid": "@theme",
"override-parent.liquid": "@theme",
"to-be-copied.liquid": "@archetype-themes/test-collection",
"to-be-copied-snippet.liquid": "@archetype-themes/test-collection"
"to-be-copied-snippet.liquid": "@archetype-themes/test-collection",
"existing-subfolder.liquid": "@theme",
"removed-subfolder.liquid": "@theme"
},
"assets": {
"other-collection-component.css": "@other/collection",
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/theme/sections/subfolder.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% render 'existing-subfolder' %}
{% render 'missing-subfolder' %}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% comment %} This file is included in the manifest.json {% endcomment %}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% comment %} This file is not included in the manifest.json {% endcomment %}