@dezkareid/osddt 1.11.14 → 1.12.0
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.
- package/dist/commands/copy-env.d.ts +2 -0
- package/dist/index.js +95 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -254,13 +254,24 @@ ${npxCommand} start-worktree <feature-name> --dir <package-path>
|
|
|
254
254
|
|
|
255
255
|
4. Parse the command output to extract \`worktreePath\` and \`workingDir\`.
|
|
256
256
|
|
|
257
|
-
5.
|
|
257
|
+
5. Copy environment files into the new worktree. Read \`bare-path\` and \`mainBranch\` from \`.osddtrc\` to construct the source path:
|
|
258
|
+
- Single repo (\`repoType: "single"\`):
|
|
259
|
+
\`\`\`
|
|
260
|
+
${npxCommand} copy-env --source <bare-path>/<mainBranch> --target <worktreePath>
|
|
261
|
+
\`\`\`
|
|
262
|
+
- Monorepo (\`repoType: "monorepo"\`):
|
|
263
|
+
\`\`\`
|
|
264
|
+
${npxCommand} copy-env --source <bare-path>/<mainBranch>/<package-path> --target <worktreePath>/<package-path>
|
|
265
|
+
\`\`\`
|
|
266
|
+
If the command finds no files, it exits silently — this is not an error.
|
|
267
|
+
|
|
268
|
+
6. Navigate into the worktree directory to locate the project:
|
|
258
269
|
- Enter \`<worktreePath>\` — this is the isolated git worktree for this feature.
|
|
259
270
|
- If \`repoType\` is \`"single"\`: the project root is \`<worktreePath>\`.
|
|
260
271
|
- If \`repoType\` is \`"monorepo"\`: the project root is \`<worktreePath>/<package-path>\`.
|
|
261
272
|
- The planning files will live under \`<workingDir>\` (i.e. \`<project-root>/working-on/<feature-name>/\`).
|
|
262
273
|
|
|
263
|
-
|
|
274
|
+
7. Report the branch name, worktree path, project root, and working directory.
|
|
264
275
|
|
|
265
276
|
---
|
|
266
277
|
|
|
@@ -519,6 +530,17 @@ ${npxCommand} start-worktree <feature-name> --dir <package-path>
|
|
|
519
530
|
|
|
520
531
|
4. Parse the command output to extract \`worktreePath\` and \`workingDir\`. Navigate into \`<worktreePath>\` to locate the project root.
|
|
521
532
|
|
|
533
|
+
5. Copy environment files into the new worktree. Read \`bare-path\` and \`mainBranch\` from \`.osddtrc\` to construct the source path:
|
|
534
|
+
- Single repo (\`repoType: "single"\`):
|
|
535
|
+
\`\`\`
|
|
536
|
+
${npxCommand} copy-env --source <bare-path>/<mainBranch> --target <worktreePath>
|
|
537
|
+
\`\`\`
|
|
538
|
+
- Monorepo (\`repoType: "monorepo"\`):
|
|
539
|
+
\`\`\`
|
|
540
|
+
${npxCommand} copy-env --source <bare-path>/<mainBranch>/<package-path> --target <worktreePath>/<package-path>
|
|
541
|
+
\`\`\`
|
|
542
|
+
If the command finds no files, it exits silently — this is not an error.
|
|
543
|
+
|
|
522
544
|
#### If \`worktree-repository\` is **absent** — Standard workflow
|
|
523
545
|
|
|
524
546
|
3. Check whether the branch already exists locally or remotely:
|
|
@@ -1392,6 +1414,76 @@ function worktreeInfoCommand() {
|
|
|
1392
1414
|
return cmd;
|
|
1393
1415
|
}
|
|
1394
1416
|
|
|
1417
|
+
function matchesPatterns(filename, patterns) {
|
|
1418
|
+
return patterns.some((pattern) => {
|
|
1419
|
+
// Convert glob pattern to regex: only support leading/trailing * and literal chars
|
|
1420
|
+
const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
|
|
1421
|
+
return new RegExp(`^${escaped}$`).test(filename);
|
|
1422
|
+
});
|
|
1423
|
+
}
|
|
1424
|
+
async function readRc(cwd) {
|
|
1425
|
+
const rcPath = path.join(cwd, '.osddtrc');
|
|
1426
|
+
if (await fs.pathExists(rcPath)) {
|
|
1427
|
+
return await fs.readJson(rcPath);
|
|
1428
|
+
}
|
|
1429
|
+
return {};
|
|
1430
|
+
}
|
|
1431
|
+
async function copyFile(src, dest, force, dryRun) {
|
|
1432
|
+
if (dryRun) {
|
|
1433
|
+
console.log(`[dry-run] Would copy: ${src} → ${dest}`);
|
|
1434
|
+
return;
|
|
1435
|
+
}
|
|
1436
|
+
if ((await fs.pathExists(dest)) && !force) {
|
|
1437
|
+
console.log(`Skipped: ${dest} (already exists)`);
|
|
1438
|
+
return;
|
|
1439
|
+
}
|
|
1440
|
+
await fs.copy(src, dest, { overwrite: true });
|
|
1441
|
+
console.log(`Copied: ${src} → ${dest}`);
|
|
1442
|
+
}
|
|
1443
|
+
async function findMatchedFiles(source, patterns) {
|
|
1444
|
+
if (!(await fs.pathExists(source)))
|
|
1445
|
+
return [];
|
|
1446
|
+
const entries = await fs.readdir(source);
|
|
1447
|
+
return entries.filter(entry => matchesPatterns(entry, patterns));
|
|
1448
|
+
}
|
|
1449
|
+
async function runCopyEnv(options) {
|
|
1450
|
+
const cwd = process.cwd();
|
|
1451
|
+
if (!options.target)
|
|
1452
|
+
return;
|
|
1453
|
+
const rc = await readRc(cwd);
|
|
1454
|
+
const source = options.source ?? rc['copy-env']?.source;
|
|
1455
|
+
if (!source)
|
|
1456
|
+
return;
|
|
1457
|
+
const rawPattern = options.pattern ?? rc['copy-env']?.pattern ?? '.env*';
|
|
1458
|
+
const patterns = rawPattern.split(',').map(p => p.trim()).filter(Boolean);
|
|
1459
|
+
const matched = await findMatchedFiles(source, patterns);
|
|
1460
|
+
if (matched.length === 0)
|
|
1461
|
+
return;
|
|
1462
|
+
await fs.ensureDir(options.target);
|
|
1463
|
+
for (const filename of matched) {
|
|
1464
|
+
await copyFile(path.join(source, filename), path.join(options.target, filename), options.force ?? false, options.dryRun ?? false);
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
function copyEnvCommand() {
|
|
1468
|
+
const cmd = new Command('copy-env');
|
|
1469
|
+
cmd
|
|
1470
|
+
.description('Copy environment files from a source directory to a target directory')
|
|
1471
|
+
.option('--source <path>', 'source directory to copy env files from')
|
|
1472
|
+
.option('--target <path>', 'target directory to copy env files into')
|
|
1473
|
+
.option('--pattern <globs>', 'comma-separated glob patterns (default: .env*)')
|
|
1474
|
+
.option('--force', 'overwrite existing files in target')
|
|
1475
|
+
.option('--dry-run', 'print what would be copied without writing')
|
|
1476
|
+
.action(async (options) => {
|
|
1477
|
+
try {
|
|
1478
|
+
await runCopyEnv(options);
|
|
1479
|
+
}
|
|
1480
|
+
catch {
|
|
1481
|
+
// fail silently
|
|
1482
|
+
}
|
|
1483
|
+
});
|
|
1484
|
+
return cmd;
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1395
1487
|
const __filename$1 = fileURLToPath(import.meta.url);
|
|
1396
1488
|
const __dirname$1 = path.dirname(__filename$1);
|
|
1397
1489
|
const pkgPath = path.join(__dirname$1, '..', 'package.json');
|
|
@@ -1408,4 +1500,5 @@ program.addCommand(updateCommand());
|
|
|
1408
1500
|
program.addCommand(contextCommand());
|
|
1409
1501
|
program.addCommand(startWorktreeCommand());
|
|
1410
1502
|
program.addCommand(worktreeInfoCommand());
|
|
1503
|
+
program.addCommand(copyEnvCommand());
|
|
1411
1504
|
program.parse(process.argv);
|