@flydocs/cli 0.6.0-alpha.28 → 0.6.0-alpha.29

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/cli.js CHANGED
@@ -15,7 +15,7 @@ var CLI_VERSION, CLI_NAME, PACKAGE_NAME, POSTHOG_API_KEY;
15
15
  var init_constants = __esm({
16
16
  "src/lib/constants.ts"() {
17
17
  "use strict";
18
- CLI_VERSION = "0.6.0-alpha.28";
18
+ CLI_VERSION = "0.6.0-alpha.29";
19
19
  CLI_NAME = "flydocs";
20
20
  PACKAGE_NAME = "@flydocs/cli";
21
21
  POSTHOG_API_KEY = "phc_v1MSJTQDFkMS90CBh3mxIz3v8bYCCnKU6v1ir6bz0Xn";
@@ -3545,6 +3545,137 @@ async function checkGitFreshness(repoDir) {
3545
3545
  } catch {
3546
3546
  }
3547
3547
  }
3548
+ async function isEmptyOrNonRepo(dir) {
3549
+ const hasGit = await pathExists(join20(dir, ".git"));
3550
+ if (hasGit) return false;
3551
+ const siblings = await detectSiblingRepos(dir);
3552
+ if (Object.keys(siblings).length >= 2) return false;
3553
+ return true;
3554
+ }
3555
+ function repoShortName(fullName) {
3556
+ return fullName.includes("/") ? fullName.split("/").pop() : fullName;
3557
+ }
3558
+ async function runCloneAndInit(targetDir, keyArg, repos, apiKey, workspaceId) {
3559
+ if (repos.length === 1) {
3560
+ const repo = repos[0];
3561
+ const shortName = repoShortName(repo.name);
3562
+ printInfo(`Workspace has 1 repo: ${pc8.bold(shortName)}`);
3563
+ const shouldClone = await confirm3({
3564
+ message: `Clone ${shortName} and initialize?`
3565
+ });
3566
+ if (isCancel4(shouldClone) || !shouldClone) {
3567
+ cancel3("Init cancelled.");
3568
+ process.exit(0);
3569
+ }
3570
+ const cloneDir = join20(targetDir, shortName);
3571
+ printInfo(`Cloning ${shortName}...`);
3572
+ await execFileAsync("git", ["clone", repo.cloneUrl, cloneDir], {
3573
+ timeout: 6e4
3574
+ });
3575
+ printStatus(`Cloned ${shortName}`);
3576
+ const serverResponse = await pullServerConfig(
3577
+ apiKey,
3578
+ cloneDir,
3579
+ workspaceId
3580
+ );
3581
+ const { actions, skipped } = await initSingleRepo(
3582
+ cloneDir,
3583
+ apiKey,
3584
+ serverResponse
3585
+ );
3586
+ actions.unshift("Stored credential globally (~/.flydocs/credentials)");
3587
+ actions.unshift(`Cloned ${shortName}`);
3588
+ printInitReport(
3589
+ actions,
3590
+ skipped,
3591
+ serverResponse.warnings,
3592
+ !!serverResponse.context
3593
+ );
3594
+ } else {
3595
+ const repoNames = repos.map((r) => repoShortName(r.name));
3596
+ printInfo(`Workspace has ${repos.length} repos:`);
3597
+ for (const name of repoNames) {
3598
+ console.log(` ${pc8.cyan(name)}`);
3599
+ }
3600
+ console.log();
3601
+ const shouldClone = await confirm3({
3602
+ message: `Clone and initialize all ${repos.length} repos?`
3603
+ });
3604
+ if (isCancel4(shouldClone) || !shouldClone) {
3605
+ cancel3("Init cancelled.");
3606
+ process.exit(0);
3607
+ }
3608
+ const allActions = [
3609
+ "Stored credential globally (~/.flydocs/credentials)"
3610
+ ];
3611
+ const allSkipped = [];
3612
+ let allWarnings = [];
3613
+ let firstResponse;
3614
+ for (let i = 0; i < repos.length; i++) {
3615
+ const repo = repos[i];
3616
+ const shortName = repoNames[i];
3617
+ const cloneDir = join20(targetDir, shortName);
3618
+ console.log();
3619
+ if (await pathExists(join20(cloneDir, ".git"))) {
3620
+ printInfo(`${pc8.bold(shortName)} already cloned, initializing...`);
3621
+ await checkGitFreshness(cloneDir);
3622
+ } else {
3623
+ printInfo(`Cloning ${pc8.bold(shortName)}...`);
3624
+ await execFileAsync("git", ["clone", repo.cloneUrl, cloneDir], {
3625
+ timeout: 6e4
3626
+ });
3627
+ allActions.push(`Cloned ${shortName}`);
3628
+ }
3629
+ const serverResponse = await pullServerConfig(
3630
+ apiKey,
3631
+ cloneDir,
3632
+ workspaceId
3633
+ );
3634
+ if (!firstResponse) firstResponse = serverResponse;
3635
+ const { actions, skipped } = await initSingleRepo(
3636
+ cloneDir,
3637
+ apiKey,
3638
+ serverResponse
3639
+ );
3640
+ for (const action of actions) {
3641
+ allActions.push(`[${shortName}] ${action}`);
3642
+ }
3643
+ for (const skip of skipped) {
3644
+ allSkipped.push(`[${shortName}] ${skip}`);
3645
+ }
3646
+ allWarnings = [...allWarnings, ...serverResponse.warnings];
3647
+ printStatus(`${shortName} initialized`);
3648
+ }
3649
+ if (firstResponse) {
3650
+ const repoEntries = {};
3651
+ for (const name of repoNames) {
3652
+ repoEntries[name] = { path: `./${name}` };
3653
+ }
3654
+ const workspaceFile = buildWorkspaceFile(
3655
+ firstResponse.workspaceId,
3656
+ repoEntries
3657
+ );
3658
+ await writeWorkspaceFile(targetDir, workspaceFile);
3659
+ allActions.push(`.flydocs-workspace.json (${repos.length} repos)`);
3660
+ const contextDir = join20(targetDir, "flydocs", "context");
3661
+ const workspaceMdPath = join20(contextDir, "workspace.md");
3662
+ if (!await pathExists(workspaceMdPath)) {
3663
+ await mkdir9(contextDir, { recursive: true });
3664
+ const content = firstResponse.context?.workspaceMd ?? await generateWorkspaceMd(targetDir, workspaceFile);
3665
+ await writeFile13(workspaceMdPath, content, "utf-8");
3666
+ const source = firstResponse.context?.workspaceMd ? "from server" : "generated locally";
3667
+ allActions.push(`Wrote flydocs/context/workspace.md (${source})`);
3668
+ }
3669
+ }
3670
+ console.log();
3671
+ printInitReport(
3672
+ allActions,
3673
+ allSkipped,
3674
+ allWarnings,
3675
+ !!firstResponse?.context
3676
+ );
3677
+ }
3678
+ }
3548
3679
  async function isParentDirectory(dir) {
3549
3680
  const hasGit = await pathExists(join20(dir, ".git"));
3550
3681
  if (hasGit) return false;
@@ -3702,6 +3833,27 @@ var init_init = __esm({
3702
3833
  await runMultiRepoInit(targetDir, args.key);
3703
3834
  return;
3704
3835
  }
3836
+ if (await isEmptyOrNonRepo(targetDir)) {
3837
+ const { apiKey: apiKey2, workspaceId: workspaceId2 } = await resolveAndValidateKey(
3838
+ args.key,
3839
+ targetDir
3840
+ );
3841
+ const preflightResponse = await pullServerConfig(
3842
+ apiKey2,
3843
+ targetDir,
3844
+ workspaceId2
3845
+ );
3846
+ if (preflightResponse.repos && preflightResponse.repos.length > 0) {
3847
+ await runCloneAndInit(
3848
+ targetDir,
3849
+ args.key,
3850
+ preflightResponse.repos,
3851
+ apiKey2,
3852
+ workspaceId2
3853
+ );
3854
+ return;
3855
+ }
3856
+ }
3705
3857
  await checkGitFreshness(targetDir);
3706
3858
  const { apiKey, workspaceId } = await resolveAndValidateKey(
3707
3859
  args.key,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flydocs/cli",
3
- "version": "0.6.0-alpha.28",
3
+ "version": "0.6.0-alpha.29",
4
4
  "type": "module",
5
5
  "description": "FlyDocs AI CLI — install, setup, and manage FlyDocs projects",
6
6
  "bin": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.6.0-alpha.28",
2
+ "version": "0.6.0-alpha.29",
3
3
  "sourceRepo": "github.com/plastrlab/flydocs-core",
4
4
  "tier": "local",
5
5
  "setupComplete": false,
@@ -1 +1 @@
1
- 0.6.0-alpha.28
1
+ 0.6.0-alpha.29
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.6.0-alpha.28",
2
+ "version": "0.6.0-alpha.29",
3
3
  "description": "FlyDocs Core - Manifest of all managed files",
4
4
  "repository": "github.com/plastrlab/flydocs-core",
5
5