Skip to content

Commit d048237

Browse files
committed
2 parents 323f58f + 2cb52b8 commit d048237

File tree

7 files changed

+79
-32
lines changed

7 files changed

+79
-32
lines changed

cli.mjs

100644100755
File mode changed.

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "generator-bitloops",
3-
"version": "0.3.10",
3+
"version": "0.3.15",
44
"description": "Next.js with TypeScript, Tailwind, Storybook and Cypress generator by Bitloops",
55
"license": "MIT",
66
"author": "Bitloops S.A.",

setup/index.js

+51-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from 'fs';
2-
import { exec } from 'child_process';
2+
import { exec, execSync } from 'child_process';
33
import Generator from 'yeoman-generator';
44
import path from 'path';
55
import { fileURLToPath } from 'url';
@@ -8,11 +8,35 @@ import { fileURLToPath } from 'url';
88
const __filename = fileURLToPath(import.meta.url);
99
const __dirname = path.dirname(__filename);
1010

11+
function isKebabCase(str) {
12+
// Check if the string is empty
13+
if (!str || str.trim().length === 0) {
14+
return false;
15+
}
16+
17+
// Regular expression to check if a string is kebab-case,
18+
// ensuring it starts with a lowercase letter or digit, allowing for lowercase letters and digits in the middle or end,
19+
// and ensuring each new word starts with a lowercase letter or digit
20+
const kebabCaseRegex = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
21+
22+
return kebabCaseRegex.test(str);
23+
}
24+
1125
function toKebabCase(str) {
12-
return str
13-
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
14-
.toLowerCase()
15-
.replace(/\s+/g, '-');
26+
if (isKebabCase(str)) {
27+
return str;
28+
}
29+
30+
const words = str
31+
.trim()
32+
// Split by non-alphanumeric characters and the transition from lowercase to uppercase
33+
.split(/(?=[A-Z])|[^a-zA-Z0-9]+/)
34+
.filter((word) => word.length > 0);
35+
36+
return words
37+
.map((word) => word.toLowerCase())
38+
.filter((word) => word.length > 0) // Remove empty words
39+
.join('-');
1640
}
1741

1842
export default class extends Generator {
@@ -114,9 +138,30 @@ export default class extends Generator {
114138
// Conditionally initialize Storybook
115139
if (this.options.storybook) {
116140
this.log('Installing Storybook...');
141+
const versionsRaw = execSync('npm view storybook versions --json', {
142+
encoding: 'utf-8',
143+
});
144+
const versions = JSON.parse(versionsRaw);
145+
146+
// Filter for stable 8.4.x versions (exclude alpha/beta)
147+
const stableVersions = versions
148+
.filter(version => version.startsWith('8.4.'))
149+
.filter(version => !version.includes('-')); // Exclude pre-releases like -alpha or -beta
150+
151+
// Sort descending and get the latest
152+
const latest84 = stableVersions.sort((a, b) => (a > b ? -1 : 1))[0];
153+
154+
if (!latest84) {
155+
throw new Error('No stable 8.4.x versions found.');
156+
}
157+
158+
// Log the chosen version (optional)
159+
this.log(`Latest stable 8.4 version: ${latest84}`);
160+
161+
// Use `this.spawnCommandSync` with the selected version
117162
this.spawnCommandSync('npx', [
118163
'-y',
119-
'storybook@^8.4',
164+
`storybook@${latest84}`,
120165
'init',
121166
'--no-dev',
122167
]);

setup/templates/cypress.config.ts

+15-22
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
11
import { defineConfig } from 'cypress';
2-
import * as fs from 'fs';
3-
import * as path from 'path';
42

53
export default defineConfig({
64
e2e: {
75
specPattern: "**/*.cy.{ts,tsx}",
86
supportFile: false,
97
testIsolation: false,
10-
setupNodeEvents(on) {
11-
on('task', {
12-
saveTestResults(results) {
13-
const resultsPath = path.join(__dirname, '.', 'cypress', 'results', 'results.json');
14-
if (!fs.existsSync(resultsPath)) {
15-
fs.writeFileSync(resultsPath, '[]'); // Create file if it doesn't exist
16-
}
17-
const existingResults = JSON.parse(fs.readFileSync(resultsPath, 'utf8'));
18-
existingResults.push(JSON.parse(results));
19-
fs.writeFileSync(resultsPath, JSON.stringify(existingResults, null, 2));
20-
return null; // Indicate the task was successful
21-
}
22-
});
23-
},
248
},
259
reporter: "mochawesome",
26-
reporterOptions: {
27-
reportDir: "cypress/results",
28-
overwrite: true,
29-
html: true,
30-
json: true,
31-
},
10+
reporterOptions: {
11+
reportDir: "cypress/results",
12+
overwrite: true,
13+
html: true,
14+
json: true,
15+
reportTitle: "Component Testing",
16+
reportPageTitle: "Bitloops Component Testing",
17+
charts: true,
18+
reportFilename: "report",
19+
code: true,
20+
showPassed: true,
21+
showFailed: true,
22+
showSkipped: true,
23+
saveJson: true,
24+
},
3225
});

setup/templates/cypress/helpers/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ export const isOutOfBounds = (inRect: DOMRect, outRect: DOMRect): boolean => {
1111
return isOut;
1212
};
1313

14+
export const isOutOfHorizontalBounds = (inRect: DOMRect, outRect: DOMRect): boolean => {
15+
const isOut =
16+
inRect.left < outRect.left ||
17+
inRect.right > outRect.right;
18+
return isOut;
19+
};
20+
1421
export const hasHorizontalScroll = (document: Document): boolean => {
1522
const scrollingElement = document.scrollingElement;
1623
if (!scrollingElement) {

setup/templates/src/components/bitloops/unsupported/Unsupported.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ type UnsupportedType =
99
| 'LINE'
1010
| 'REGULAR_POLYGON'
1111
| 'SLICE'
12-
| 'IMAGE';
12+
| 'IMAGE'
13+
| 'INSTANCE'
14+
| 'COMPONENT';
1315

1416
export type UnsupportedElementProps = {
1517
type: UnsupportedType;

0 commit comments

Comments
 (0)