generator-bitloops 0.3.10 → 0.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/setup/index.js +50 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generator-bitloops",
3
- "version": "0.3.10",
3
+ "version": "0.3.12",
4
4
  "description": "Next.js with TypeScript, Tailwind, Storybook and Cypress generator by Bitloops",
5
5
  "license": "MIT",
6
6
  "author": "Bitloops S.A.",
package/setup/index.js CHANGED
@@ -8,11 +8,35 @@ import { fileURLToPath } from 'url';
8
8
  const __filename = fileURLToPath(import.meta.url);
9
9
  const __dirname = path.dirname(__filename);
10
10
 
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
+
11
25
  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('-');
16
40
  }
17
41
 
18
42
  export default class extends Generator {
@@ -114,9 +138,30 @@ export default class extends Generator {
114
138
  // Conditionally initialize Storybook
115
139
  if (this.options.storybook) {
116
140
  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
117
162
  this.spawnCommandSync('npx', [
118
163
  '-y',
119
- 'storybook@^8.4',
164
+ `storybook@${latest84}`,
120
165
  'init',
121
166
  '--no-dev',
122
167
  ]);