import { createRequire as _createRequire } from 'node:module';
const require = _createRequire(import.meta.url);
import {
  authenticate
} from "./chunk-PTNF7QD5.js";
import {
  syncRevisionTypes
} from "./chunk-UC4R2FMF.js";
import {
  writeJson
} from "./chunk-AYCGCYN3.js";
import {
  CliError,
  CliErrorCode
} from "./chunk-WGV2XQSB.js";
import {
  init_esm_shims
} from "./chunk-EXLZF52D.js";

// ../cli-site-old/src/sync-types/index.ts
init_esm_shims();

// ../cli-site-old/src/sync-types/sync-types-with-auth.ts
init_esm_shims();
import { mkdir } from "node:fs/promises";
import { join } from "node:path";
async function syncTypesWithAuth(model, opts) {
  try {
    const accessToken = await opts.authState.getAccessToken();
    await syncRevisionTypes(model, { getAppToken: () => accessToken });
    await mkdir(join(model.projectFolder, ".vscode/"), { recursive: true });
    await writeJson(join(model.projectFolder, ".vscode/settings.json"), {
      "files.associations": {
        "*.jsw": "javascript"
      }
    });
  } catch (e) {
    throw new CliError({
      code: CliErrorCode.FailedToSyncToRevision({ revision: model.revision }),
      cause: e,
      info: { model }
    });
  }
}

// ../cli-site-old/src/sync-types/sync-types.ts
init_esm_shims();
async function syncTypes(model, { biLogger, errorReporter }) {
  const authState = await authenticate({
    metaSiteId: model.metaSiteId,
    biLogger,
    errorReporter
  });
  return syncTypesWithAuth(model, { authState });
}

export {
  syncTypesWithAuth,
  syncTypes
};
//# sourceMappingURL=chunk-COHHFWMS.js.map