Skip to content

Commit 011b509

Browse files
Fix EDUPLICATEWORKSPACE error by dynamically updating package.json name field for Node.js services
1 parent 7afc35a commit 011b509

File tree

10 files changed

+22
-263
lines changed

10 files changed

+22
-263
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,13 @@ my-org/
212212
package.json
213213
turbo.json / nx.json (if preset chosen)
214214
scripts/
215-
dev-basic.cjs
215+
npx create-polyglot dev
216216
```
217217

218218
### Presets
219219
- **Turborepo**: Generates `turbo.json`, sets root `dev` & `build` scripts for pipeline caching.
220220
- **Nx**: Generates `nx.json` and adjusts scripts accordingly.
221-
- **Basic**: Minimal setup + `scripts/dev-basic.cjs` for simple concurrency.
221+
- **Basic**: Minimal setup + `npx create-polyglot dev` for simple concurrency.
222222

223223
## Development Workflow
224224
1. Scaffold with `init`.
@@ -228,7 +228,7 @@ my-org/
228228
5. Extend infra / databases inside `compose.yaml`.
229229

230230
### Basic Dev Runner
231-
When no preset is chosen, `npm run dev` uses `scripts/dev-basic.cjs`:
231+
When no preset is chosen, `npm run dev` uses `npx create-polyglot dev`:
232232
1. Detects package manager (pnpm > yarn > bun > npm fallback)
233233
2. Scans `services/` for Node services
234234
3. Runs those with a `dev` script
@@ -402,16 +402,16 @@ my-org/
402402
package.json
403403
turbo.json / nx.json (if preset chosen)
404404
scripts/
405-
dev-basic.cjs
405+
npx create-polyglot dev
406406
```
407407

408408
### Presets
409409
- Turborepo: Generates `turbo.json`, sets root `dev` & `build` scripts to leverage Turborepo pipelines.
410410
- Nx: Generates `nx.json` and adjusts scripts accordingly.
411-
- Basic: Provides a minimal setup plus `scripts/dev-basic.cjs` for simple concurrency.
411+
- Basic: Provides a minimal setup plus `npx create-polyglot dev` for simple concurrency.
412412

413413
### Basic Dev Runner
414-
When no preset is chosen, `npm run dev` uses `scripts/dev-basic.cjs`:
414+
When no preset is chosen, `npm run dev` uses `npx create-polyglot dev`:
415415
1. Detects package manager (pnpm > yarn > bun > npm fallback)
416416
2. Scans `services/` for Node services
417417
3. Runs those with a `dev` script

bin/lib/scaffold.js

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ export async function scaffoldMonorepo(projectNameArg, options) {
2929
interactiveQuestions.push({
3030
type: 'select',
3131
name: 'preset',
32-
message: 'Preset (optional):',
32+
message: 'Preset:',
3333
choices: [
34-
{ title: 'None', value: '' },
34+
{ title: 'None (basic)', value: '' },
3535
{ title: 'Turborepo', value: 'turborepo' },
3636
{ title: 'Nx', value: 'nx' }
3737
],
@@ -310,7 +310,7 @@ export async function scaffoldMonorepo(projectNameArg, options) {
310310
], { cwd: dest, stdio: 'inherit' });
311311
usedGenerator = true;
312312
} catch (e) {
313-
console.log(chalk.yellow('⚠️ create-next-app failed, falling back to internal template. Error:'), e.shortMessage || e.message);
313+
console.log(chalk.yellow(`⚠️ create-next-app failed: ${e.message}. Using template.`));
314314
}
315315
}
316316
if (!usedGenerator) {
@@ -327,10 +327,10 @@ export async function scaffoldMonorepo(projectNameArg, options) {
327327
await fs.writeFile(path.join(dest, 'README.md'), `# ${svcName} service\n\nScaffolded by create-polyglot.`);
328328
}
329329
}
330-
330+
331331
// Initialize logging for the service
332332
initializeServiceLogs(dest);
333-
333+
334334
console.log(chalk.green(`✅ Created ${svcName} (${svcType}) service on port ${svcPort}`));
335335
}
336336

@@ -341,7 +341,7 @@ export async function scaffoldMonorepo(projectNameArg, options) {
341341
version: '0.1.0',
342342
workspaces: ['services/*', 'packages/*'],
343343
scripts: {
344-
dev: 'node scripts/dev-basic.cjs',
344+
dev: 'npx create-polyglot dev',
345345
'list:services': 'node scripts/list-services.mjs',
346346
format: 'prettier --write .',
347347
lint: 'eslint "services/**/*.{js,jsx,ts,tsx}" --max-warnings 0 || true'
@@ -366,16 +366,6 @@ export async function scaffoldMonorepo(projectNameArg, options) {
366366
// Always ensure scripts dir exists (needed for list-services script)
367367
const scriptsDir = path.join(projectDir, 'scripts');
368368
await fs.mkdirp(scriptsDir);
369-
if (!options.preset) {
370-
const runnerSrc = path.join(__dirname, '../../scripts/dev-basic.cjs');
371-
try {
372-
if (await fs.pathExists(runnerSrc)) {
373-
await fs.copy(runnerSrc, path.join(scriptsDir, 'dev-basic.cjs'));
374-
}
375-
} catch (e) {
376-
console.log(chalk.yellow('⚠️ Failed to copy dev-basic runner:', e.message));
377-
}
378-
}
379369
// Create list-services script with runtime status detection
380370
const listScriptPath = path.join(scriptsDir, 'list-services.mjs');
381371
await fs.writeFile(listScriptPath, `#!/usr/bin/env node\nimport fs from 'fs';\nimport path from 'path';\nimport net from 'net';\nimport chalk from 'chalk';\nconst cwd = process.cwd();\nconst cfgPath = path.join(cwd, 'polyglot.json');\nif(!fs.existsSync(cfgPath)){ console.error(chalk.red('polyglot.json not found.')); process.exit(1);}\nconst cfg = JSON.parse(fs.readFileSync(cfgPath,'utf-8'));\n\nfunction strip(str){return str.replace(/\\x1B\\[[0-9;]*m/g,'');}\nfunction pad(str,w){const raw=strip(str);return str+' '.repeat(Math.max(0,w-raw.length));}\nfunction table(items){ if(!items.length){console.log(chalk.yellow('No services.'));return;} const cols=[{k:'name',h:'Name'},{k:'type',h:'Type'},{k:'port',h:'Port'},{k:'status',h:'Status'},{k:'path',h:'Path'}]; const widths=cols.map(c=>Math.max(c.h.length,...items.map(i=>strip(i[c.k]).length))+2); const top='┌'+widths.map(w=>'─'.repeat(w)).join('┬')+'┐'; const sep='├'+widths.map(w=>'─'.repeat(w)).join('┼')+'┤'; const bot='└'+widths.map(w=>'─'.repeat(w)).join('┴')+'┘'; console.log(top); console.log('│'+cols.map((c,i)=>pad(chalk.bold.white(c.h),widths[i])).join('│')+'│'); console.log(sep); for(const it of items){ console.log('│'+cols.map((c,i)=>pad(it[c.k],widths[i])).join('│')+'│'); } console.log(bot); console.log(chalk.gray('Total: '+items.length)); }\n\nasync function check(port){ return new Promise(res=>{ const sock=net.createConnection({port,host:'127.0.0.1'},()=>{sock.destroy();res(true);}); sock.setTimeout(350,()=>{sock.destroy();res(false);}); sock.on('error',()=>{res(false);});}); }\nconst promises = cfg.services.map(async s=>{ const up = await check(s.port); return { ...s, _up: up }; });\nconst results = await Promise.all(promises);\nconst rows = results.map(s=>({ name: chalk.cyan(s.name), type: colorType(s.type)(s.type), port: chalk.green(String(s.port)), status: s._up ? chalk.bgGreen.black(' UP ') : chalk.bgRed.white(' DOWN '), path: chalk.dim(s.path) }));\nfunction colorType(t){ switch(t){case 'node': return chalk.green; case 'python': return chalk.yellow; case 'go': return chalk.cyan; case 'java': return chalk.red; case 'frontend': return chalk.blue; default: return chalk.white;} }\nif(process.argv.includes('--json')) { console.log(JSON.stringify(results.map(r=>({name:r.name,type:r.type,port:r.port,up:r._up,path:r.path})),null,2)); } else { console.log(chalk.magentaBright('\nWorkspace Services (runtime status)')); table(rows); }\n`);
@@ -456,7 +446,7 @@ export async function scaffoldMonorepo(projectNameArg, options) {
456446
await execa('git', ['commit', '-m', 'chore: initial scaffold'], { cwd: projectDir });
457447
console.log(chalk.green('✅ Initialized git repository'));
458448
} catch (e) {
459-
console.log(chalk.yellow('⚠️ Git initialization failed (continuing).'));
449+
console.log(chalk.yellow('⚠️ Failed to initialize git repository:', e.message));
460450
}
461451
}
462452

@@ -468,7 +458,7 @@ export async function scaffoldMonorepo(projectNameArg, options) {
468458
try {
469459
await execa(pm, installCmd, { cwd: projectDir, stdio: 'inherit' });
470460
} catch (e) {
471-
console.log(chalk.yellow('⚠️ Installing dependencies failed, you can try manually.'));
461+
console.log(chalk.yellow('⚠️ Failed to install dependencies:', e.message));
472462
}
473463
}
474464

@@ -487,7 +477,7 @@ export async function scaffoldMonorepo(projectNameArg, options) {
487477
console.log(chalk.green('✅ Added GitHub Actions workflow (.github/workflows/ci.yml)'));
488478
}
489479
} catch (e) {
490-
console.log(chalk.yellow('⚠️ Failed to create GitHub Actions workflow:'), e.message);
480+
console.log(chalk.yellow('⚠️ Failed to create GitHub Actions workflow:', e.message));
491481
}
492482
}
493483

@@ -546,10 +536,10 @@ export async function addService(projectDir, { type, name, port }, options = {})
546536
} else {
547537
await fs.writeFile(path.join(dest, 'README.md'), `# ${name} (${type}) service\n`);
548538
}
549-
539+
550540
// Initialize logging for the service
551541
initializeServiceLogs(dest);
552-
542+
553543
console.log(chalk.green(`✅ Added service '${name}' (${type}) on port ${port}`));
554544
cfg.services.push({ name, type, port, path: `services/${name}` });
555545
await fs.writeJSON(configPath, cfg, { spaces: 2 });

docs/guide/presets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ You can select a preset via `--preset turborepo` or `--preset nx`.
44

55
| Preset | Effect |
66
| ------ | ------ |
7-
| (none) | Adds `scripts/dev-basic.cjs` and uses a simple concurrent runner |
7+
| (none) | Adds `scripts/npx create-polyglot dev` and uses a simple concurrent runner |
88
| turborepo | Adds `turbo.json` and sets `dev` script to `turbo run dev --parallel` |
99
| nx | Adds `nx.json` and sets `dev` script to `nx run-many -t dev --all` |
1010

scripts/dev-basic.cjs

Lines changed: 0 additions & 235 deletions
This file was deleted.
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
artifactId=spring-boot-service
2+
groupId=com.example
3+
version=0.0.1-SNAPSHOT

templates/spring-boot/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/Users/I528923/Desktop/create-polyglot/templates/spring-boot/src/main/java/com/example/DemoApplication.java
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)