Skip to content

Commit b35f717

Browse files
committed
include references to assets if --files is passed
1 parent 2220742 commit b35f717

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/commands/theme/generate/component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,13 @@ export default class GenerateComponent extends BaseCommand {
9595
js: context.assets.js
9696
} : undefined
9797

98+
const externalAssets = context.assets.inline ? undefined : {
99+
css: context.assets.css,
100+
js: context.assets.js
101+
}
102+
98103
files.push({
99-
content: generateLiquidContent(context.component.fullName, hasJs, inlineAssets),
104+
content: generateLiquidContent(context.component.fullName, hasJs, inlineAssets, externalAssets),
100105
description: `${context.component.fullName}.liquid`,
101106
path: path.join(directories.componentDir, `${context.component.fullName}.liquid`),
102107
})

src/utilities/content-generation.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const COPYRIGHT_NOTICE = 'Copyright © 2025 Archetype Themes LP. All rights reserved.'
22

3-
export function generateLiquidContent(fullName: string, hasJs: boolean = false, inlineAssets?: { css: boolean; js: boolean }): string {
3+
export function generateLiquidContent(fullName: string, hasJs: boolean = false, inlineAssets?: { css: boolean; js: boolean }, externalAssets?: { css: boolean; js: boolean }): string {
44
const elementName = fullName.replace('.', '-')
55
const wrapper = hasJs ? elementName : `div class="${elementName}"`
66
const closingTag = hasJs ? elementName : 'div'
@@ -13,7 +13,16 @@ export function generateLiquidContent(fullName: string, hasJs: boolean = false,
1313
@example
1414
{% render '${fullName}' %}
1515
{%- enddoc -%}
16+
`
17+
18+
// Add external CSS reference right after enddoc
19+
if (externalAssets?.css) {
20+
content += `
21+
{{ '${fullName}.css' | asset_url | stylesheet_tag }}
22+
`
23+
}
1624

25+
content += `
1726
<${wrapper}>
1827
<!-- Component content goes here -->
1928
</${closingTag}>
@@ -50,6 +59,15 @@ export function generateLiquidContent(fullName: string, hasJs: boolean = false,
5059
`
5160
}
5261

62+
// Add external JS reference if requested
63+
if (externalAssets?.js) {
64+
content += `
65+
<script type="module">
66+
import '${fullName}'
67+
</script>
68+
`
69+
}
70+
5371
return content
5472
}
5573

0 commit comments

Comments
 (0)