Skip to content

Commit e26db4a

Browse files
authored
fix: Accommodate nested folders (#13)
* fix: Support theme snippets in subfolders * Add other subfolders
1 parent dbcfe98 commit e26db4a

6 files changed

Lines changed: 19 additions & 4 deletions

File tree

src/utilities/nodes.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,14 @@ export async function generateLiquidNode(file: string, type: LiquidNode['type'],
7979
.filter(file => !fs.statSync(file).isDirectory())
8080
}
8181

82+
// For theme snippets, use just the filename (flatten subfolder structure)
83+
const name = path.basename(file)
84+
8285
return {
8386
assets,
8487
body,
8588
file,
86-
name: path.basename(file),
89+
name,
8790
setup,
8891
snippets,
8992
themeFolder,
@@ -117,12 +120,12 @@ export async function getCollectionNodes(collectionDir: string): Promise<LiquidN
117120
}
118121

119122
export async function getThemeNodes(themeDir: string): Promise<LiquidNode[]> {
120-
const entryNodes = globSync(path.join(themeDir, '{layout,sections,blocks,templates}', '*.liquid'), { absolute: true })
123+
const entryNodes = globSync(path.join(themeDir, '{layout,sections,blocks,templates}', '**/*.liquid'), { absolute: true })
121124
.map(file => {
122125
const parentFolderName = path.basename(path.dirname(file)) as LiquidNode['themeFolder']
123126
return generateLiquidNode(file, 'entry', parentFolderName)
124127
})
125-
const themeSnippets = globSync(path.join(themeDir, 'snippets', '*.liquid'), { absolute: true })
128+
const themeSnippets = globSync(path.join(themeDir, 'snippets', '**/*.liquid'), { absolute: true })
126129
.map(file => generateLiquidNode(file, 'snippet', 'snippets'))
127130
const themeAssets = globSync(path.join(themeDir, 'assets', '*'), { absolute: true })
128131
.map(file => generateLiquidNode(file, 'asset', 'assets'))

test/commands/theme/component/map.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ describe('theme component map', () => {
6363
const beforeData = JSON.parse(fs.readFileSync(path.join(testThemePath, 'component.manifest.json'), 'utf8'))
6464
expect(beforeData.files.assets['missing.css']).to.be.undefined
6565
expect(beforeData.files.snippets['missing.liquid']).to.be.undefined
66+
expect(beforeData.files.snippets['missing-subfolder.liquid']).to.be.undefined
6667

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

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

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

181184
// Check that removed files are present in map
182185
expect(beforeData.files.snippets['theme-component-removed.liquid']).to.equal('@theme')
183186
expect(beforeData.files.assets['theme-component-removed.css']).to.equal('@theme')
184187
expect(beforeData.files.snippets['other-collection-component-removed.liquid']).to.equal('@other/collection')
185188
expect(beforeData.files.assets['other-collection-component-removed.css']).to.equal('@other/collection')
189+
expect(beforeData.files.snippets['removed-subfolder.liquid']).to.equal('@theme')
186190

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

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

197202
// Check that removed files are no longer present in map
198203
expect(data.files.snippets['theme-component-removed.liquid']).to.be.undefined
199204
expect(data.files.assets['theme-component-removed.css']).to.be.undefined
200205
expect(data.files.snippets['other-collection-component-removed.liquid']).to.be.undefined
201206
expect(data.files.assets['other-collection-component-removed.css']).to.be.undefined
207+
expect(data.files.snippets['removed-subfolder.liquid']).to.be.undefined
202208
})
203209

204210
it('sorts the files and collections keys in the component.map.json file', async () => {

test/fixtures/theme/component.manifest.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"override.liquid": "@theme",
1515
"override-parent.liquid": "@theme",
1616
"to-be-copied.liquid": "@archetype-themes/test-collection",
17-
"to-be-copied-snippet.liquid": "@archetype-themes/test-collection"
17+
"to-be-copied-snippet.liquid": "@archetype-themes/test-collection",
18+
"existing-subfolder.liquid": "@theme",
19+
"removed-subfolder.liquid": "@theme"
1820
},
1921
"assets": {
2022
"other-collection-component.css": "@other/collection",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{% render 'existing-subfolder' %}
2+
{% render 'missing-subfolder' %}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% comment %} This file is included in the manifest.json {% endcomment %}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% comment %} This file is not included in the manifest.json {% endcomment %}

0 commit comments

Comments
 (0)