Skip to content

Commit bb6c161

Browse files
Merge pull request #158 from emulsify-ds/develop
Release: Fix non-src based project from duplication components direction
2 parents bb7579d + 72ed37b commit bb6c161

3 files changed

Lines changed: 37 additions & 34 deletions

File tree

.github/workflows/semantic-release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- name: Checkout
11-
uses: actions/checkout@v2
11+
uses: actions/checkout@v3
1212
with:
1313
fetch-depth: 0
1414
- name: Install Node.js
15-
uses: actions/setup-node@v2
15+
uses: actions/setup-node@v3
1616
with:
17-
node-version: 24
17+
node-version: "24.x"
1818
- name: Install
1919
run: npm install
2020
- name: Release

.storybook/main.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,15 @@ const config = {
9393
},
9494

9595
/**
96-
* Custom styles injected into the Storybook manager (sidebar) head.
96+
* Custom styles injected into the Storybook manager (sidebar) head,
97+
* plus any external manager-head.html snippet.
9798
* @param {string} head - Existing head HTML.
98-
* @returns {string} Modified head HTML with custom styles.
99+
* @returns {string} Modified head HTML.
99100
*/
100-
managerHead: (head) =>
101-
`${head}
102-
<style>
101+
managerHead: (head) => {
102+
// inline theme styles
103+
const inlineStyles = `
104+
<style>
103105
:root {
104106
--colors-emulsify-blue-100: #e6f5fc;
105107
--colors-emulsify-blue-200: #CCECFA;
@@ -198,15 +200,29 @@ const config = {
198200
color: var(--colors-emulsify-blue-1000) !important;
199201
}
200202
</style>
201-
`,
203+
`;
204+
205+
// load external manager-head.html if present
206+
const externalManagerHeadPath = resolve(
207+
__dirname,
208+
'../../../../config/emulsify-core/storybook/manager-head.html'
209+
);
210+
let externalManagerHtml = '';
211+
if (fs.existsSync(externalManagerHeadPath)) {
212+
externalManagerHtml = fs.readFileSync(externalManagerHeadPath, 'utf8');
213+
}
214+
215+
return `${head}
216+
${inlineStyles}
217+
${externalManagerHtml}`;
218+
},
202219

203220
/**
204221
* Function to load and append an external preview-head.html into the preview iframe.
205222
* @param {string} head - Existing preview head HTML.
206223
* @returns {string} Combined head HTML including external snippet if present.
207224
*/
208225
previewHead: (head) => {
209-
// Resolve the external preview-head.html path
210226
const externalHeadPath = resolve(
211227
__dirname,
212228
'../../../../config/emulsify-core/storybook/preview-head.html'

config/webpack/webpack.common.js

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const projectDir = resolve(_dirname, '../../../../..');
3636
const srcPath = resolve(projectDir, 'src');
3737
const isSrcExists = fs.pathExistsSync(srcPath);
3838
const srcDir = isSrcExists ? srcPath : resolve(projectDir, 'components');
39+
const isDrupal = emulsifyConfig.project.platform === 'drupal';
3940

4041
// Glob pattern for SCSS files that ignore file names prefixed with underscore.
4142
const BaseScssPattern = fs.pathExistsSync(resolve(projectDir, 'src'))
@@ -131,18 +132,11 @@ function getEntries(
131132
// Component JS entries.
132133
globSync(jsMatcher).forEach((file) => {
133134
if (!file.includes('dist/')) {
134-
const filePath = file.split('components/')[1];
135-
const filePathDist = replaceLastSlash(filePath, '/js/');
136-
const distStructure = fs.pathExistsSync(resolve(projectDir, 'src'))
137-
? 'components'
138-
: 'js';
139-
const newFilePath =
140-
emulsifyConfig.project.platform === 'drupal' &&
141-
fs.pathExistsSync(resolve(projectDir, 'src'))
142-
? `components/${filePathDist.replace('.js', '')}`
143-
: `dist/${distStructure}/${
144-
distStructure === 'components' ? 'components' : 'js'
145-
}/${filePathDist.replace('.js', '')}`;
135+
const filePath = file.split(`${srcDir}/components/`)[1];
136+
const filePathDistRaw = replaceLastSlash(filePath, '/js/');
137+
const filePathDist = filePathDistRaw.replace(/\.js$/, '');
138+
const prefix = isDrupal && isSrcExists ? 'components' : 'dist/components';
139+
const newFilePath = `${prefix}/${filePathDist}`;
146140
addEntry(newFilePath, file);
147141
}
148142
});
@@ -162,18 +156,11 @@ function getEntries(
162156

163157
// Component SCSS entries.
164158
globSync(ComponentScssMatcher).forEach((file) => {
165-
const filePath = file.split('components/')[1];
166-
const filePathDist = replaceLastSlash(filePath, '/css/');
167-
const distStructure = fs.pathExistsSync(resolve(projectDir, 'src'))
168-
? 'components'
169-
: 'css';
170-
const newFilePath =
171-
emulsifyConfig.project.platform === 'drupal' &&
172-
fs.pathExistsSync(resolve(projectDir, 'src'))
173-
? `components/${filePathDist.replace('.scss', '')}`
174-
: `dist/${distStructure}/${
175-
distStructure === 'components' ? 'components' : 'css'
176-
}/${filePathDist.replace('.scss', '')}`;
159+
const filePath = file.split(`${srcDir}/components/`)[1];
160+
const filePathDistRaw = replaceLastSlash(filePath, '/css/');
161+
const filePathDist = filePathDistRaw.replace(/\.scss$/, '');
162+
const prefix = isDrupal && isSrcExists ? 'components' : 'dist/components';
163+
const newFilePath = `${prefix}/${filePathDist}`;
177164
addEntry(newFilePath, file);
178165
});
179166

0 commit comments

Comments
 (0)