UNPKG

@dx-box/common

Version:

(DX) by providing common configurations for TypeScript, ESLint, Prettier, and automated Git hooks for formatting and linting.

2 lines (1 loc) 830 B
import{askUserForGitRemote as f,detectGitPlatform as l}from"../utils/index.js";import{execSync as g}from"child_process";import e from"fs";import c from"path";const S=async(o,a)=>{let t;try{t=g("git remote get-url origin",{cwd:o,encoding:"utf8"}).trim()}catch{t=await f()}const n=l(t),p=`changeset-config.${n}.json`,i=c.join(a,p);if(!e.existsSync(i))throw new Error(`Config template not found: ${i}`);let r=e.readFileSync(i,"utf-8");const m=t.match(/[:/]([\w.-]+\/[\w.-]+)(\.git)?$/)?.[1]??"your-org/your-repo";n==="github"&&(r=r.replace(/"__REPO_PLACEHOLDER__"/g,`"${m}"`));const s=c.join(o,".changeset");e.existsSync(s)||g("npx changeset init",{cwd:o,stdio:"inherit"}),e.writeFileSync(c.join(s,"config.json"),r),console.log(`\u2705 Changeset setup completed (${n} repository, remote: ${t})`)};export{S as setupChangesetScripts};