Skip to content

Commit 60cd5e6

Browse files
committed
v0.2.0
1 parent 10a12d7 commit 60cd5e6

File tree

5 files changed

+60
-5
lines changed

5 files changed

+60
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,4 @@ dist
128128
.yarn/build-state.yml
129129
.yarn/install-state.gz
130130
.pnp.*
131+
.DS_Store

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# generator-bitloops
22

3-
The Yeoman Bitloops Generator is used by the Bitloops Platform to setup your Bitloops projects.
3+
The Bitloops Generator is used by the Bitloops Platform to setup your Bitloops projects.
44

55
Nonetheless, you can use it independently to setup your next next.js project with TypeScript, Tailwind, Storybook and Cypress all ready to go!
66

77
## How to run it
88

9-
`npx yo bitloops:setup --project="Your Project Name" --nextjs --typescript --tailwind --storybook --cypress`
9+
`npx generator-bitloops setup --project="Your Project Name" --nextjs --typescript --tailwind --storybook --cypress`

cli.mjs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env node
2+
3+
import { createEnv } from 'yeoman-environment';
4+
import npm from './package.json' assert { type: 'json' };
5+
6+
console.log(`generator-bitloops v${npm.version}`);
7+
8+
// Capture the subgenerator and additional arguments
9+
const [, , subgenerator, ...args] = process.argv;
10+
11+
if (!subgenerator) {
12+
console.error('Please specify a subgenerator (e.g., "setup" or "init")');
13+
process.exit(1);
14+
}
15+
16+
// Initialize Yeoman environment
17+
const env = createEnv();
18+
19+
(async () => {
20+
// Dynamically import the subgenerator path
21+
const generatorPath = await import(`./${subgenerator}/index.js`);
22+
23+
// Register your generator
24+
env.register(generatorPath.default, `bitloops:${subgenerator}`);
25+
26+
// Convert arguments into a format suitable for Yeoman
27+
const options = args.reduce((acc, arg) => {
28+
const [key, value] = arg.split('=');
29+
acc[key.replace('--', '')] = value || true;
30+
return acc;
31+
}, {});
32+
33+
// Run the generator with the specified subgenerator and options
34+
env.run(`bitloops:${subgenerator}`, options, (err) => {
35+
if (err) {
36+
console.error('Error running generator:', err);
37+
process.exit(1);
38+
}
39+
});
40+
})();

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "generator-bitloops",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Bitloops Yeoman generator",
55
"license": "MIT",
66
"author": "Bitloops S.A.",
@@ -9,9 +9,13 @@
99
"url": "https://github.com/bitloops/generator-bitloops"
1010
},
1111
"type": "module",
12+
"bin": {
13+
"bitloops-generator": "./cli.mjs"
14+
},
1215
"files": [
1316
"app",
14-
"setup"
17+
"setup",
18+
"cli.js"
1519
],
1620
"keywords": [
1721
"bitloops",
@@ -23,6 +27,7 @@
2327
"yeoman-generator"
2428
],
2529
"dependencies": {
30+
"yeoman-environment": "^4.4.3",
2631
"yeoman-generator": "^7.3.3"
2732
}
2833
}

setup/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import fs from 'fs';
22
import { exec } from 'child_process';
33
import Generator from 'yeoman-generator';
4+
import path from 'path';
5+
import { fileURLToPath } from 'url';
6+
7+
// Convert `import.meta.url` to a path
8+
const __filename = fileURLToPath(import.meta.url);
9+
const __dirname = path.dirname(__filename);
10+
411

512
function toKebabCase(str) {
613
return str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase().replace(/\s+/g, '-');
@@ -9,6 +16,7 @@ function toKebabCase(str) {
916
export default class extends Generator {
1017
constructor(args, opts) {
1118
super(args, opts);
19+
this.sourceRoot(path.join(__dirname, 'templates'));
1220

1321
// Define options
1422
this.option('project', {
@@ -103,12 +111,13 @@ export default class extends Generator {
103111
}
104112

105113
this.patchFiles = async function() {
106-
// await new Promise((resolve, reject) => this.fs.commit((err) => (err ? reject(err) : resolve())));
107114
if (this.options.storybook) {
108115
if (this.options.typescript) {
109116
this.log('Replace Next.js\' TypeScript configuration file with JS...');
110117
// Remove TypeScript configuration files given they require Next.js 15
111118
fs.unlinkSync(this.destinationPath('next.config.ts'));
119+
console.log('Template Path:', this.templatePath('next.config.js'));
120+
console.log('Destination Path:', this.destinationPath('next.config.js'));
112121
this.fs.copyTpl(
113122
this.templatePath('next.config.js'),
114123
this.destinationPath('next.config.js'),

0 commit comments

Comments
 (0)