/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@weapp-core/init@6.0.6/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
import process$1 from"node:process";import logger from"@weapp-core/logger";import{defu,fs,get,set}from"@weapp-core/shared";import https from"node:https";let _match,_lazyMatch=()=>{var e=(()=>{var e=Object.defineProperty,t=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,i={};((t,n)=>{for(var o in n)e(t,o,{get:n[o],enumerable:!0})})(i,{default:()=>ae});var r,s=e=>Array.isArray(e),a=e=>"function"==typeof e,c=e=>"string"==typeof e,l=e=>void 0===e,p=(e,t)=>s(e)?u(e,t):c(e)?f(e,t):g(e,t),u=(e,t)=>{const n={};for(const t of e){if(1!==t.length)throw new Error(`Invalid character: "${t}"`);const e=t.charCodeAt(0);n[e]=!0}return e=>{const o=e.index,i=e.input;for(;e.index<i.length&&i.charCodeAt(e.index)in n;)e.index+=1;const r=e.index;if(r>o){if(!l(t)&&!e.options.silent){const n=e.input.slice(o,r),s=a(t)?t(n,i,String(o)):t;l(s)||e.output.push(s)}e.indexMax=Math.max(e.indexMax,e.index)}return!0}},g=(e,t)=>{const n=e.source,o=e.flags.replace(/y|$/,"y"),i=new RegExp(n,o);return E((e=>{i.lastIndex=e.index;const n=i.exec(e.input);if(n){if(!l(t)&&!e.options.silent){const o=a(t)?t(...n,e.input,String(e.index)):t;l(o)||e.output.push(o)}return e.index+=n[0].length,e.indexMax=Math.max(e.indexMax,e.index),!0}return!1}))},f=(e,t)=>n=>{if(n.input.startsWith(e,n.index)){if(!l(t)&&!n.options.silent){const o=a(t)?t(e,n.input,String(n.index)):t;l(o)||n.output.push(o)}return n.index+=e.length,n.indexMax=Math.max(n.indexMax,n.index),!0}return!1},d=(e,t,n,o)=>{const i=y(e);return E(w(v((e=>{let o=0;for(;o<n;){const t=e.index;if(!i(e)||(o+=1,e.index===t))break}return o>=t}))))},m=(e,t)=>d(e,0,1/0),h=(e,t)=>{const n=e.map(y);return E(w(v((e=>{for(let t=0,o=n.length;t<o;t++)if(!n[t](e))return!1;return!0}))))},x=(e,t)=>{const n=e.map(y);return E(w((e=>{for(let t=0,o=n.length;t<o;t++)if(n[t](e))return!0;return!1})))},v=(e,t=!1)=>{const n=y(e);return e=>{const o=e.index,i=e.output.length,r=n(e);return(!r||t)&&(e.index=o,e.output.length!==i&&(e.output.length=i)),r}},w=(e,t)=>y(e),E=(()=>{let e=0;return t=>{const n=y(t),o=e+=1;return e=>{var t;if(!1===e.options.memoization)return n(e);const i=e.index,r=(t=e.cache)[o]||(t[o]=new Map),s=r.get(i);if(!1===s)return!1;if((e=>"number"==typeof e)(s))return e.index=s,!0;if(s)return e.index=s.index,s.output?.length&&e.output.push(...s.output),!0;{const t=e.output.length;if(n(e)){const n=e.index,o=e.output.length;if(o>t){const s=e.output.slice(t,o);r.set(i,{index:n,output:s})}else r.set(i,n);return!0}return r.set(i,!1),!1}}}})(),_=e=>{let t;return n=>(t||(t=y(e())),t(n))},y=(e=>{const t=new Map;return n=>{const o=t.get(n);if(o)return o;const i=e(n);return t.set(n,i),i}})((e=>{if(a(e))return(e=>0===e.length)(e)?_(e):e;if(c(e)||(e=>e instanceof RegExp)(e))return p(e);if(s(e))return h(e);if((e=>"object"==typeof e&&null!==e)(e))return x(Object.values(e));throw new Error("Invalid rule")})),$="abcdefghijklmnopqrstuvwxyz",b=e=>{let t="";for(;e>0;)t=$[(e-1)%26]+t,e=Math.floor((e-1)/26);return t},R=e=>{let t=0;for(let n=0,o=e.length;n<o;n++)t=26*t+$.indexOf(e[n])+1;return t},j=(e,t)=>{if(t<e)return j(t,e);const n=[];for(;e<=t;)n.push(e++);return n},O=(e,t)=>j(R(e),R(t)).map(b),D=e=>e,A=e=>P((t=>((e,t,n={})=>{const o={cache:{},input:e,index:0,indexMax:0,options:n,output:[]};if(y(t)(o)&&o.index===e.length)return o.output;throw new Error(`Failed to parse at index ${o.indexMax}`)})(t,e,{memoization:!1}).join(""))),P=e=>{const t={};return n=>t[n]??(t[n]=e(n))},C=p(/^\*\*\/\*$/,".*"),T=p(/^\*\*\/(\*)?([ a-zA-Z0-9._-]+)$/,((e,t,n)=>`.*${t?"":"(?:^|/)"}${n.replaceAll(".","\\.")}`)),N=p(/^\*\*\/(\*)?([ a-zA-Z0-9._-]*)\{([ a-zA-Z0-9._-]+(?:,[ a-zA-Z0-9._-]+)*)\}$/,((e,t,n,o)=>`.*${t?"":"(?:^|/)"}${n.replaceAll(".","\\.")}(?:${o.replaceAll(",","|").replaceAll(".","\\.")})`)),k=p(/\\./,D),F=p(/[$.*+?^(){}[\]\|]/,(e=>`\\${e}`)),z=p(/./,D),S=x([p(/^(?:!!)*!(.*)$/,((e,t)=>`(?!^${ne(t)}$).*?`)),p(/^(!!)+/,"")]),J=x([p(/\/(\*\*\/)+/,"(?:/.+/|/)"),p(/^(\*\*\/)+/,"(?:^|.*/)"),p(/\/(\*\*)$/,"(?:/.*|$)"),p(/\*\*/,".*")]),L=x([p(/\*\/(?!\*\*\/)/,"[^/]*/"),p(/\*/,"[^/]*")]),I=p("?","[^/]"),M=p("[",D),V=p("]",D),W=p(/[!^]/,"^/"),U=p(/[a-z]-[a-z]|[0-9]-[0-9]/i,D),G=x([k,p(/[$.*+?^(){}[\|]/,(e=>`\\${e}`)),U,p(/[^\]]/,D)]),Z=h([M,(r=W,d(r,0,1)),m(G),V]),B=p("{","(?:"),X=p("}",")"),q=h([B,x([p(/(\d+)\.\.(\d+)/,((e,t,n)=>((e,t,n)=>j(e,t).map((e=>String(e).padStart(n,"0"))))(+t,+n,Math.min(t.length,n.length)).join("|"))),p(/([a-z]+)\.\.([a-z]+)/,((e,t,n)=>O(t,n).join("|"))),p(/([A-Z]+)\.\.([A-Z]+)/,((e,t,n)=>O(t.toLowerCase(),n.toLowerCase()).join("|").toUpperCase()))]),X]),H=p("{","(?:"),K=p("}",")"),Q=p(",","|"),Y=p(/[$.*+?^(){[\]\|]/,(e=>`\\${e}`)),ee=p(/[^}]/,D),te=h([H,m(x([J,L,I,Z,q,_((()=>te)),k,Y,Q,ee])),K]),ne=A(m(x([C,T,N,S,J,L,I,Z,q,te,k,F,z]))),oe=p(/\\./,D),ie=p(/./,D),re=A(m(x([oe,p(/\*\*\*+/,"*"),p(/([^/{[(!])\*\*/,((e,t)=>`${t}*`)),p(/(^|.)\*\*(?=[^*/)\]}])/,((e,t)=>`${t}*`)),ie]))),se=(e,t)=>{const n=Array.isArray(e)?e:[e];if(!n.length)return!1;const o=n.map(se.compile),i=n.every((e=>/(\/(?:\*\*)?|\[\/\])$/.test(e))),r=t.replace(/[\\\/]+/g,"/").replace(/\/$/,i?"/":"");return o.some((e=>e.test(r)))};se.compile=e=>new RegExp(`^${ne(re(e))}$`,"s");var ae=se;return(i=>((i,r,s,a)=>{if(r&&"object"==typeof r||"function"==typeof r)for(let c of n(r))!o.call(i,c)&&c!==s&&e(i,c,{get:()=>r[c],enumerable:!(a=t(r,c))||a.enumerable});return i})(e({},"__esModule",{value:!0}),i))(i)})();return e.default||e};const zeptomatch=(e,t)=>(_match||(_match=_lazyMatch(),_lazyMatch=null),_match(e,t)),_DRIVE_LETTER_START_RE=/^[A-Za-z]:\//;function normalizeWindowsPath(e=""){return e?e.replace(/\\/g,"/").replace(_DRIVE_LETTER_START_RE,(e=>e.toUpperCase())):e}const _UNC_REGEX=/^[/\\]{2}/,_IS_ABSOLUTE_RE=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/,_DRIVE_LETTER_RE=/^[A-Za-z]:$/,_ROOT_FOLDER_RE=/^\/([A-Za-z]:)?$/,_EXTNAME_RE=/.(\.[^./]+|\.)$/,_PATH_ROOT_RE=/^[/\\]|^[a-zA-Z]:[/\\]/,normalize=function(e){if(0===e.length)return".";const t=(e=normalizeWindowsPath(e)).match(_UNC_REGEX),n=isAbsolute(e),o="/"===e[e.length-1];return 0===(e=normalizeString(e,!n)).length?n?"/":o?"./":".":(o&&(e+="/"),_DRIVE_LETTER_RE.test(e)&&(e+="/"),t?n?`//${e}`:`//./${e}`:n&&!isAbsolute(e)?`/${e}`:e)},join=function(...e){let t="";for(const n of e)if(n)if(t.length>0){const e="/"===t[t.length-1],o="/"===n[0];t+=e&&o?n.slice(1):e||o?n:`/${n}`}else t+=n;return normalize(t)};function cwd(){return"undefined"!=typeof process&&"function"==typeof process.cwd?process.cwd().replace(/\\/g,"/"):"/"}const resolve=function(...e){let t="",n=!1;for(let o=(e=e.map((e=>normalizeWindowsPath(e)))).length-1;o>=-1&&!n;o--){const i=o>=0?e[o]:cwd();i&&0!==i.length&&(t=`${i}/${t}`,n=isAbsolute(i))}return t=normalizeString(t,!n),n&&!isAbsolute(t)?`/${t}`:t.length>0?t:"."};function normalizeString(e,t){let n="",o=0,i=-1,r=0,s=null;for(let a=0;a<=e.length;++a){if(a<e.length)s=e[a];else{if("/"===s)break;s="/"}if("/"===s){if(i===a-1||1===r);else if(2===r){if(n.length<2||2!==o||"."!==n[n.length-1]||"."!==n[n.length-2]){if(n.length>2){const e=n.lastIndexOf("/");-1===e?(n="",o=0):(n=n.slice(0,e),o=n.length-1-n.lastIndexOf("/")),i=a,r=0;continue}if(n.length>0){n="",o=0,i=a,r=0;continue}}t&&(n+=n.length>0?"/..":"..",o=2)}else n.length>0?n+=`/${e.slice(i+1,a)}`:n=e.slice(i+1,a),o=a-i-1;i=a,r=0}else"."===s&&-1!==r?++r:r=-1}return n}const isAbsolute=function(e){return _IS_ABSOLUTE_RE.test(e)},toNamespacedPath=function(e){return normalizeWindowsPath(e)},extname=function(e){if(".."===e)return"";const t=_EXTNAME_RE.exec(normalizeWindowsPath(e));return t&&t[1]||""},relative=function(e,t){const n=resolve(e).replace(_ROOT_FOLDER_RE,"$1").split("/"),o=resolve(t).replace(_ROOT_FOLDER_RE,"$1").split("/");if(":"===o[0][1]&&":"===n[0][1]&&n[0]!==o[0])return o.join("/");const i=[...n];for(const e of i){if(o[0]!==e)break;n.shift(),o.shift()}return[...n.map((()=>"..")),...o].join("/")},dirname=function(e){const t=normalizeWindowsPath(e).replace(/\/$/,"").split("/").slice(0,-1);return 1===t.length&&_DRIVE_LETTER_RE.test(t[0])&&(t[0]+="/"),t.join("/")||(isAbsolute(e)?"/":".")},format=function(e){const t=e.ext?e.ext.startsWith(".")?e.ext:`.${e.ext}`:"",n=[e.root,e.dir,e.base??(e.name??"")+t].filter(Boolean);return normalizeWindowsPath(e.root?resolve(...n):n.join("/"))},basename=function(e,t){const n=normalizeWindowsPath(e).split("/");let o="";for(let e=n.length-1;e>=0;e--){const t=n[e];if(t){o=t;break}}return t&&o.endsWith(t)?o.slice(0,-t.length):o},parse=function(e){const t=_PATH_ROOT_RE.exec(e)?.[0]?.replace(/\\/g,"/")||"",n=basename(e),o=extname(n);return{root:t,dir:dirname(e),base:n,ext:o,name:n.slice(0,n.length-o.length)}},matchesGlob=(e,t)=>zeptomatch(t,normalize(e)),_path={__proto__:null,basename:basename,dirname:dirname,extname:extname,format:format,isAbsolute:isAbsolute,join:join,matchesGlob:matchesGlob,normalize:normalize,normalizeString:normalizeString,parse:parse,relative:relative,resolve:resolve,sep:"/",toNamespacedPath:toNamespacedPath},delimiter="win32"===globalThis.process?.platform?";":":",_platforms={posix:void 0,win32:void 0},mix=(e=delimiter)=>new Proxy(_path,{get:(t,n)=>"delimiter"===n?e:"posix"===n?posix:"win32"===n?win32:_platforms[n]||_path[n]}),posix=mix(":"),win32=mix(";");function createDocument(){return{name:"",path:"",value:null}}function createContext(){return{projectConfig:createDocument(),packageJson:createDocument(),viteConfig:createDocument(),tsconfig:createDocument(),tsconfigApp:createDocument(),tsconfigServer:createDocument(),tsconfigNode:createDocument(),dts:createDocument()}}const ctx=createContext();function resetContext(){const e=createContext();Object.assign(ctx.projectConfig,e.projectConfig),Object.assign(ctx.packageJson,e.packageJson),Object.assign(ctx.viteConfig,e.viteConfig),Object.assign(ctx.tsconfig,e.tsconfig),Object.assign(ctx.tsconfigApp,e.tsconfigApp),Object.assign(ctx.tsconfigServer,e.tsconfigServer),Object.assign(ctx.tsconfigNode,e.tsconfigNode),Object.assign(ctx.dts,e.dts)}function getDefaultTsconfigJson(){return{references:[{path:"./.weapp-vite/tsconfig.app.json"},{path:"./.weapp-vite/tsconfig.server.json"},{path:"./.weapp-vite/tsconfig.node.json"},{path:"./.weapp-vite/tsconfig.shared.json"}],files:[]}}function getDefaultTsDts(){return'/// <reference types="weapp-vite/client" />\n'}var FsReadError=class extends Error{constructor(e,t){super(`Failed to read ${e}`),this.filepath=e,this.cause=t,this.name="FsReadError"}},FsWriteError=class extends Error{constructor(e,t){super(`Failed to write ${e}`),this.filepath=e,this.cause=t,this.name="FsWriteError"}};async function readJsonIfExists(e){try{return await fs.readJSON(e)}catch(t){if("ENOENT"===t?.code)return null;throw new FsReadError(e,t)}}async function readFileIfExists(e){try{return await fs.readFile(e,"utf8")}catch(t){if("ENOENT"===t?.code)return null;throw new FsReadError(e,t)}}async function writeJsonFile(e,t,n=2){try{await fs.outputJSON(e,t,{spaces:n})}catch(t){throw new FsWriteError(e,t)}}async function writeFile(e,t){try{await fs.outputFile(e,t,"utf8")}catch(t){throw new FsWriteError(e,t)}}function resolveOutputPath(e,t,n){return t?posix.isAbsolute(t)?t:posix.resolve(e,t):n}function getDefaultViteConfig(){return"import { defineConfig } from 'weapp-vite/config'\n\nexport default defineConfig({\n  weapp: {\n    // weapp-vite options\n  },\n})\n"}async function initViteConfigFile(e){const{root:t,dest:n,write:o=!0}=e,i=ctx.packageJson.value?.type??"module",r=ctx.viteConfig.name="module"===i?"vite.config.ts":"vite.config.mts",s=resolveOutputPath(t,n,ctx.viteConfig.path=posix.resolve(t,r)),a=getDefaultViteConfig();return ctx.viteConfig.value=a,o&&(await writeFile(s,a),logger.log(`✨ 写入 ${posix.relative(t,s)} 成功!`)),a}async function initTsDtsFile(e){const{root:t,dest:n,write:o=!0}=e,i=ctx.dts.name="vite-env.d.ts",r=resolveOutputPath(t,n,ctx.dts.path=posix.resolve(t,i)),s=getDefaultTsDts();return ctx.dts.value=s,o&&(await writeFile(r,s),logger.log(`✨ 写入 ${posix.relative(t,r)} 成功!`)),s}async function initTsJsonFiles(e){const{root:t,dest:n,write:o=!0}=e,i=ctx.tsconfig.name="tsconfig.json",r=ctx.tsconfig.path=posix.resolve(t,i);ctx.tsconfigApp.name=".weapp-vite/tsconfig.app.json",ctx.tsconfigApp.path=posix.resolve(t,ctx.tsconfigApp.name),ctx.tsconfigServer.name=".weapp-vite/tsconfig.server.json",ctx.tsconfigServer.path=posix.resolve(t,ctx.tsconfigServer.name),ctx.tsconfigNode.name=".weapp-vite/tsconfig.node.json",ctx.tsconfigNode.path=posix.resolve(t,ctx.tsconfigNode.name);const s=getDefaultTsconfigJson();if(ctx.tsconfig.value=s,ctx.tsconfigApp.value=null,ctx.tsconfigServer.value=null,ctx.tsconfigNode.value=null,o){const e=resolveOutputPath(t,n,r);await writeJsonFile(e,s),logger.log(`✨ 写入 ${posix.relative(t,e)} 成功!`)}return{tsconfig:s,tsconfigApp:null,tsconfigServer:null,tsconfigNode:null}}var version="6.13.4";function getLatestVersionFromNpm(e){return new Promise(((t,n)=>{const o=`https://registry.npmjs.org/${e}/latest`;https.get(o,(i=>{if(!i||i.statusCode&&i.statusCode>=400)return i?.resume(),void n(new Error(`Request to ${o} failed with status ${i?.statusCode??"unknown"}`));let r="";i.setEncoding("utf8"),i.on("data",(e=>r+=e)),i.on("end",(()=>{try{const o=JSON.parse(r);if(!o.version||"string"!=typeof o.version)return void n(new Error(`Unexpected response when fetching ${e}: missing version`));t(o.version)}catch(e){n(e)}})),i.on("error",n)})).on("error",n)}))}async function latestVersion(e,t="^",n=getLatestVersionFromNpm){try{const o=await n(e);return o?`${t}${o}`:null}catch{return null}}const FALLBACK_DEP_VERSIONS={"miniprogram-api-typings":"^4.1.0",typescript:"^5.9.2","weapp-tailwindcss":"^4.3.3"};function createDefaultPackageJson(){return{name:"weapp-vite-app",homepage:"https://vite.icebreaker.top/",type:"module",scripts:{},devDependencies:{}}}async function upsertDependencyVersion(e,t,n,o={}){const i=get(e,t),r=o.skipNetwork?null:await latestVersion(n);r?set(e,t,r):void 0===i&&set(e,t,FALLBACK_DEP_VERSIONS[n]??"latest")}async function createOrUpdatePackageJson(e){const{root:t,dest:n,command:o,cb:i,write:r,filename:s}=defu(e,{write:!0,filename:"package.json",command:"weapp-vite"}),a=ctx.packageJson.name=s,c=ctx.packageJson.path=posix.resolve(t,a),l=resolveOutputPath(t,n,c);try{let e=await readJsonIfExists(c);return e||(e=createDefaultPackageJson(),logger.info(`✨ 没有找到 ${a} 文件，正在创建默认 package.json ...`)),set(e,"scripts.dev",`${o} dev`),set(e,"scripts.dev:open",`${o} dev -o`),set(e,"scripts.build",`${o} build`),"weapp-vite"===o&&(set(e,"scripts.open",`${o} open`),set(e,"scripts.g",`${o} generate`),set(e,"devDependencies.weapp-vite",`^${version}`),await Promise.all([upsertDependencyVersion(e,"devDependencies.miniprogram-api-typings","miniprogram-api-typings",{skipNetwork:!r}),upsertDependencyVersion(e,"devDependencies.typescript","typescript",{skipNetwork:!r})])),i?.(((...t)=>{set(e,...t)})),ctx.packageJson.value=e,r&&(await writeJsonFile(l,e),logger.log(`✨ 写入 ${posix.relative(t,l)} 成功!`)),e}catch(e){throw logger.error(`⚠️ 设置 ${a} 配置文件失败`,e),e}}function applyProjectConfigDefaults(e){set(e,"miniprogramRoot","dist/"),set(e,"srcMiniprogramRoot","dist/"),set(e,"setting.packNpmManually",!0),"plugin"===get(e,"compileType")&&set(e,"pluginRoot","dist-plugin")}function ensurePackNpmRelationList(e){const t=get(e,"setting.packNpmRelationList"),n={packageJsonPath:"./package.json",miniprogramNpmDistDir:"./dist"};Array.isArray(t)?t.some((e=>e.packageJsonPath===n.packageJsonPath&&e.miniprogramNpmDistDir===n.miniprogramNpmDistDir))||t.push(n):set(e,"setting.packNpmRelationList",[n])}function createDefaultProjectConfig(){return{compileType:"miniprogram",libVersion:"trial",packOptions:{ignore:[],include:[]},setting:{coverView:!0,es6:!0,postcss:!0,minified:!0,enhance:!0,showShadowRootInWxmlPanel:!0,packNpmRelationList:[{packageJsonPath:"./package.json",miniprogramNpmDistDir:"./dist"}],babelSetting:{ignore:[],disablePlugins:[],outputPath:""},packNpmManually:!0},condition:{},editorSetting:{tabIndent:"auto",tabSize:2},appid:"",miniprogramRoot:"dist/",srcMiniprogramRoot:"dist/"}}async function createOrUpdateProjectConfig(e){const{root:t,dest:n,cb:o,write:i,filename:r}=defu(e,{write:!0,filename:"project.config.json"}),s=ctx.projectConfig.name=r,a=ctx.projectConfig.path=posix.resolve(t,s),c=resolveOutputPath(t,n,a);try{let e=await readJsonIfExists(a);return e?applyProjectConfigDefaults(e):(e=createDefaultProjectConfig(),logger.info(`✨ 没有找到 ${s} 文件，正在使用默认模板创建...`)),o?.(((...t)=>{set(e,...t)})),ensurePackNpmRelationList(e),ctx.projectConfig.value=e,i&&(await writeJsonFile(c,e),logger.log(`✨ 写入 ${posix.relative(t,c)} 成功!`)),e}catch(e){throw logger.error(`⚠️ 设置 ${s} 配置文件失败`,e),e}}const DEFAULT_GITIGNORE="# dependencies\nnode_modules\n.pnp\n.pnp.js\n\n# testing\ncoverage\n\n# next.js\n.next/\nout/\nbuild\n\n# misc\n.DS_Store\n*.pem\n\n# debug\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\n.pnpm-debug.log*\n\n# local env files\n.env.local\n.env.development.local\n.env.test.local\n.env.production.local\n\n# turbo\n.turbo\n\ndist\ndist-plugin\ndist-web\ndist/web\nvite.config.ts.timestamp-*.mjs",CRLF_RE=/\r\n/g;function normalizeLineEndings(e){return e.replace(CRLF_RE,"\n")}function trimTrailingBlankLines(e){let t=e.length;for(;t>0&&""===e[t-1];)t-=1;return e.slice(0,t)}function ensureTrailingNewline(e){return e.endsWith("\n")?e:`${e}\n`}function mergeGitignore(e){const t=normalizeLineEndings(e??""),n=[...t.length?t.split("\n"):[]];for(;n.length>0&&""===n.at(-1);)n.pop();const o=new Set(n);let i=!1;for(const e of DEFAULT_GITIGNORE.split("\n"))if(0!==e.length)o.has(e)||(!i&&n.length>0&&""!==n.at(-1)&&n.push(""),n.push(e),o.add(e),i=!0);else{if(0===n.length||""===n.at(-1))continue;n.push("")}return ensureTrailingNewline(trimTrailingBlankLines(n).join("\n"))}async function updateGitIgnore(e){const{root:t,dest:n,write:o=!0}=e,i=resolveOutputPath(t,n,posix.resolve(t,".gitignore")),r=await readFileIfExists(i),s=mergeGitignore(r);return o&&s!==(r??"")&&(await writeFile(i,s),logger.log(`✨ 更新 ${posix.relative(t,i)} 成功!`)),s}async function initConfig(e){const{root:t=process$1.cwd(),command:n}=e;return await createOrUpdateProjectConfig({root:t}),await createOrUpdatePackageJson({root:t,command:n}),await updateGitIgnore({root:t}),"weapp-vite"===n&&(await initViteConfigFile({root:t}),await initTsDtsFile({root:t}),await initTsJsonFiles({root:t})),ctx}export{createOrUpdatePackageJson,createOrUpdateProjectConfig,initConfig,initTsDtsFile,initTsJsonFiles,initViteConfigFile,resetContext};
//# sourceMappingURL=/sm/68f61a61b0fd5da12520cbfc4ab4f1c698bf481cad5623fcd4ce69279546bdf6.map