factoriomod-debug 2.0.11 → 2.0.13
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/CHANGELOG.md +9 -0
- package/dist/{chunk-VB5SSWJG.js → chunk-S7WJEOJD.js} +23 -23
- package/dist/fmtk-cli.js +2 -2
- package/dist/fmtk-vscode.js +9 -9
- package/package.json +19 -1
package/dist/fmtk-cli.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import {createRequire} from 'module'
|
|
4
4
|
const require = createRequire(import.meta.url)
|
|
5
5
|
|
|
6
|
-
import{A as mf,B as gf,C as Io,D as ft,E as ka,F as qy,G as vr,H as Ta,J as Ny,K as My,M as By,O as jy,P as Uy,a as B,b as II,c as x,d as Oy,e as ct,f as LI,g as Iy,h as Ly,i as Py,j as Ao,k as He,l as Nt,m as xr,n as Oo,o as Ae,p as Cy,q as yn,t as PI,u as Sa,v as oe,w as Ea,x as Cn,y as mi,z as Fy}from"./chunk-
|
|
6
|
+
import{A as mf,B as gf,C as Io,D as ft,E as ka,F as qy,G as vr,H as Ta,J as Ny,K as My,M as By,O as jy,P as Uy,a as B,b as II,c as x,d as Oy,e as ct,f as LI,g as Iy,h as Ly,i as Py,j as Ao,k as He,l as Nt,m as xr,n as Oo,o as Ae,p as Cy,q as yn,t as PI,u as Sa,v as oe,w as Ea,x as Cn,y as mi,z as Fy}from"./chunk-S7WJEOJD.js";var Lo=x(bf=>{"use strict";var Da=class extends Error{constructor(e,n,r){super(r),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=n,this.exitCode=e,this.nestedError=void 0}},yf=class extends Da{constructor(e){super(1,"commander.invalidArgument",e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};bf.CommanderError=Da;bf.InvalidArgumentError=yf});var Ra=x(_f=>{"use strict";var{InvalidArgumentError:CI}=Lo(),wf=class{constructor(e,n){switch(this.description=n||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,e[0]){case"<":this.required=!0,this._name=e.slice(1,-1);break;case"[":this.required=!1,this._name=e.slice(1,-1);break;default:this.required=!0,this._name=e;break}this._name.endsWith("...")&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(e,n){return n===this.defaultValue||!Array.isArray(n)?[e]:(n.push(e),n)}default(e,n){return this.defaultValue=e,this.defaultValueDescription=n,this}argParser(e){return this.parseArg=e,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(n,r)=>{if(!this.argChoices.includes(n))throw new CI(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(n,r):n},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function FI(t){let e=t.name()+(t.variadic===!0?"...":"");return t.required?"<"+e+">":"["+e+"]"}_f.Argument=wf;_f.humanReadableArgName=FI});var Sf=x(vf=>{"use strict";var{humanReadableArgName:qI}=Ra(),xf=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(e){this.helpWidth=this.helpWidth??e.helpWidth??80}visibleCommands(e){let n=e.commands.filter(i=>!i._hidden),r=e._getHelpCommand();return r&&!r._hidden&&n.push(r),this.sortSubcommands&&n.sort((i,o)=>i.name().localeCompare(o.name())),n}compareOptions(e,n){let r=i=>i.short?i.short.replace(/^-/,""):i.long.replace(/^--/,"");return r(e).localeCompare(r(n))}visibleOptions(e){let n=e.options.filter(i=>!i.hidden),r=e._getHelpOption();if(r&&!r.hidden){let i=r.short&&e._findOption(r.short),o=r.long&&e._findOption(r.long);!i&&!o?n.push(r):r.long&&!o?n.push(e.createOption(r.long,r.description)):r.short&&!i&&n.push(e.createOption(r.short,r.description))}return this.sortOptions&&n.sort(this.compareOptions),n}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];let n=[];for(let r=e.parent;r;r=r.parent){let i=r.options.filter(o=>!o.hidden);n.push(...i)}return this.sortOptions&&n.sort(this.compareOptions),n}visibleArguments(e){return e._argsDescription&&e.registeredArguments.forEach(n=>{n.description=n.description||e._argsDescription[n.name()]||""}),e.registeredArguments.find(n=>n.description)?e.registeredArguments:[]}subcommandTerm(e){let n=e.registeredArguments.map(r=>qI(r)).join(" ");return e._name+(e._aliases[0]?"|"+e._aliases[0]:"")+(e.options.length?" [options]":"")+(n?" "+n:"")}optionTerm(e){return e.flags}argumentTerm(e){return e.name()}longestSubcommandTermLength(e,n){return n.visibleCommands(e).reduce((r,i)=>Math.max(r,this.displayWidth(n.styleSubcommandTerm(n.subcommandTerm(i)))),0)}longestOptionTermLength(e,n){return n.visibleOptions(e).reduce((r,i)=>Math.max(r,this.displayWidth(n.styleOptionTerm(n.optionTerm(i)))),0)}longestGlobalOptionTermLength(e,n){return n.visibleGlobalOptions(e).reduce((r,i)=>Math.max(r,this.displayWidth(n.styleOptionTerm(n.optionTerm(i)))),0)}longestArgumentTermLength(e,n){return n.visibleArguments(e).reduce((r,i)=>Math.max(r,this.displayWidth(n.styleArgumentTerm(n.argumentTerm(i)))),0)}commandUsage(e){let n=e._name;e._aliases[0]&&(n=n+"|"+e._aliases[0]);let r="";for(let i=e.parent;i;i=i.parent)r=i.name()+" "+r;return r+n+" "+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){let n=[];if(e.argChoices&&n.push(`choices: ${e.argChoices.map(r=>JSON.stringify(r)).join(", ")}`),e.defaultValue!==void 0&&(e.required||e.optional||e.isBoolean()&&typeof e.defaultValue=="boolean")&&n.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),e.presetArg!==void 0&&e.optional&&n.push(`preset: ${JSON.stringify(e.presetArg)}`),e.envVar!==void 0&&n.push(`env: ${e.envVar}`),n.length>0){let r=`(${n.join(", ")})`;return e.description?`${e.description} ${r}`:r}return e.description}argumentDescription(e){let n=[];if(e.argChoices&&n.push(`choices: ${e.argChoices.map(r=>JSON.stringify(r)).join(", ")}`),e.defaultValue!==void 0&&n.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),n.length>0){let r=`(${n.join(", ")})`;return e.description?`${e.description} ${r}`:r}return e.description}formatItemList(e,n,r){return n.length===0?[]:[r.styleTitle(e),...n,""]}groupItems(e,n,r){let i=new Map;return e.forEach(o=>{let s=r(o);i.has(s)||i.set(s,[])}),n.forEach(o=>{let s=r(o);i.has(s)||i.set(s,[]),i.get(s).push(o)}),i}formatHelp(e,n){let r=n.padWidth(e,n),i=n.helpWidth??80;function o(f,h){return n.formatItem(f,r,h,n)}let s=[`${n.styleTitle("Usage:")} ${n.styleUsage(n.commandUsage(e))}`,""],a=n.commandDescription(e);a.length>0&&(s=s.concat([n.boxWrap(n.styleCommandDescription(a),i),""]));let l=n.visibleArguments(e).map(f=>o(n.styleArgumentTerm(n.argumentTerm(f)),n.styleArgumentDescription(n.argumentDescription(f))));if(s=s.concat(this.formatItemList("Arguments:",l,n)),this.groupItems(e.options,n.visibleOptions(e),f=>f.helpGroupHeading??"Options:").forEach((f,h)=>{let p=f.map(b=>o(n.styleOptionTerm(n.optionTerm(b)),n.styleOptionDescription(n.optionDescription(b))));s=s.concat(this.formatItemList(h,p,n))}),n.showGlobalOptions){let f=n.visibleGlobalOptions(e).map(h=>o(n.styleOptionTerm(n.optionTerm(h)),n.styleOptionDescription(n.optionDescription(h))));s=s.concat(this.formatItemList("Global Options:",f,n))}return this.groupItems(e.commands,n.visibleCommands(e),f=>f.helpGroup()||"Commands:").forEach((f,h)=>{let p=f.map(b=>o(n.styleSubcommandTerm(n.subcommandTerm(b)),n.styleSubcommandDescription(n.subcommandDescription(b))));s=s.concat(this.formatItemList(h,p,n))}),s.join(`
|
|
7
7
|
`)}displayWidth(e){return Wy(e).length}styleTitle(e){return e}styleUsage(e){return e.split(" ").map(n=>n==="[options]"?this.styleOptionText(n):n==="[command]"?this.styleSubcommandText(n):n[0]==="["||n[0]==="<"?this.styleArgumentText(n):this.styleCommandText(n)).join(" ")}styleCommandDescription(e){return this.styleDescriptionText(e)}styleOptionDescription(e){return this.styleDescriptionText(e)}styleSubcommandDescription(e){return this.styleDescriptionText(e)}styleArgumentDescription(e){return this.styleDescriptionText(e)}styleDescriptionText(e){return e}styleOptionTerm(e){return this.styleOptionText(e)}styleSubcommandTerm(e){return e.split(" ").map(n=>n==="[options]"?this.styleOptionText(n):n[0]==="["||n[0]==="<"?this.styleArgumentText(n):this.styleSubcommandText(n)).join(" ")}styleArgumentTerm(e){return this.styleArgumentText(e)}styleOptionText(e){return e}styleArgumentText(e){return e}styleSubcommandText(e){return e}styleCommandText(e){return e}padWidth(e,n){return Math.max(n.longestOptionTermLength(e,n),n.longestGlobalOptionTermLength(e,n),n.longestSubcommandTermLength(e,n),n.longestArgumentTermLength(e,n))}preformatted(e){return/\n[^\S\r\n]/.test(e)}formatItem(e,n,r,i){let s=" ".repeat(2);if(!r)return s+e;let a=e.padEnd(n+e.length-i.displayWidth(e)),l=2,c=(this.helpWidth??80)-n-l-2,f;return c<this.minWidthToWrap||i.preformatted(r)?f=r:f=i.boxWrap(r,c).replace(/\n/g,`
|
|
8
8
|
`+" ".repeat(n+l)),s+a+" ".repeat(l)+f.replace(/\n/g,`
|
|
9
9
|
${s}`)}boxWrap(e,n){if(n<this.minWidthToWrap)return e;let r=e.split(/\r\n|\n/),i=/[\s]*[^\s]+/g,o=[];return r.forEach(s=>{let a=s.match(i);if(a===null){o.push("");return}let l=[a.shift()],u=this.displayWidth(l[0]);a.forEach(c=>{let f=this.displayWidth(c);if(u+f<=n){l.push(c),u+=f;return}o.push(l.join(""));let h=c.trimStart();l=[h],u=this.displayWidth(h)}),o.push(l.join(""))}),o.join(`
|
|
@@ -109,7 +109,7 @@ ${i}
|
|
|
109
109
|
`)}}async function tI(t,e){let n=new FormData;return n.append("mod",t),(await _a(n,e)).upload_url}async function of(t,e){console.log("Uploading to mod portal...");let n=await tI(t,"https://mods.factorio.com/api/v2/mods/releases/init_upload"),r=new FormData;r.append("file",new Blob([Uint8Array.from(e)],{type:"application/x-zip-compressed"}),`${t}.zip`),await _a(r,n),console.log(`Published ${t}`)}async function PG(t,e,n){let r=await tI(t,"https://mods.factorio.com/api/v2/mods/images/add"),i=new FormData;return i.append("image",new Blob([Uint8Array.from(e)],{type:$b.getType(n)??void 0}),n),await _a(i,r)}async function CG(t,e){let n=new FormData;return n.append("mod",t),n.append("images",e.join(",")),(await _a(n,"https://mods.factorio.com/api/v2/mods/images/edit")).images}async function FG(t,e){let n=new FormData;n.append("mod",t),e.homepage!==void 0&&n.append("homepage",e.homepage),e.title!==void 0&&n.append("title",e.title),e.summary!==void 0&&n.append("summary",e.summary),e.description!==void 0&&n.append("description",e.description),e.faq!==void 0&&n.append("faq",e.faq),await _a(n,"https://mods.factorio.com/api/v2/mods/edit_details").then(()=>{console.log("Details updated")}).catch(r=>{console.log(`Details update failed: ${r}`)})}async function nI(t,e,n,r){let i=await fn.readFile(t).catch(()=>{});if(!i)return;let o=QO.createHash("sha1").update(i).digest("hex");r.add(o);let s=n.find(l=>l.id===o);if(s)return s;let a=await PG(e,i,ZO.basename(t));return n.push(a),a}async function YO(t,e,n,r,i){let o=new Date().toISOString(),s=await fn.readFile(t,"utf8").catch(()=>{});if(!s)return;let a=new RegExp(i?.url_match??/^((http(s?)|data):|#)/),l=i?.base_url;l&&!l.endsWith("/")&&(l+="/");let u=await cl().use(function(){return async function(c,f){if(i?.strip_first_header??!0){let p=c.children[0];p.type==="heading"&&p.depth===1&&c.children.splice(0,1)}let h=new Map;Et(c,"image",p=>{let b=h.get(p.url);b?b.push(p):h.set(p.url,[p])});for(let[p,b]of h)if(!p.match(a))switch(i?.images){case"gallery":default:let y=await nI(ZO.resolve(f.cwd,p),e,n,r);if(!y)continue;b.forEach(g=>{g.url=y.url});break;case"url":if(!l)continue;let T=l+p;b.forEach(g=>{g.url=T});break}l&&Et(c,"link",p=>{if(!p.url.match(a)){if(p.url==="$process_date"){p.url=o;return}p.url=l+p.url}})}}).process(s);return String(u)}async function sf(t,e){let n={title:t.title,homepage:t.homepage,summary:t.description},{images:r}=await Py(t.name,!0),i=new Set,o=t.package?.gallery;if(o)for(let l of o){let u=await new Promise((c,f)=>{let h=[],p=ai(process.cwd(),{pattern:l,nodir:!0});p.on("match",b=>{h.push(b.absolute)}),p.on("error",b=>f(b)),p.on("end",()=>c(h))});await Promise.all(u.sort().map(async c=>nI(c,t.name,r,i)))}let s=await YO(e?.readme??t.package?.readme??"readme.md",t.name,r,i,t?.package?.markdown);s&&(n.description=s);let a=await YO(e?.faq??t.package?.faq??"faq.md",t.name,r,i,t?.package?.markdown);if(a&&(n.faq=a),t.package?.gallery){if(t.package.prune_gallery===!1)for(let l of r)i.add(l.id);console.log("Sorting gallery ..."),await CG(t.name,Array.from(i))}console.log("Updating details ..."),await FG(t.name,n)}async function af(t,e){let n=eI.default.inc(t.version,"patch",{loose:!0}),r=bx(e,["version"],n,{});if(await fn.writeFile("info.json",wx(e,r)),t.version=n,await fn.readFile("changelog.txt","utf8").catch(()=>{}).then(async i=>{if(i){let s=i.indexOf(`\r
|
|
110
110
|
`)!==-1?`\r
|
|
111
111
|
`:`
|
|
112
|
-
`;await fn.writeFile("changelog.txt",`---------------------------------------------------------------------------------------------------${s}Version: ${n}${s}Date: ????${s} Changes:${s}`+i)}}),t.package?.scripts?.version){let i=await hn("version",t);i!==0&&process.exit(i)}return t}he.command("run <script> [args...]").description("Run a script from info.json#/package/scripts").action(async(t,e)=>{process.exit(await hn(t,await gr(),void 0,e))});he.command("datestamp").description("Datestamp the current changelog section").action(async()=>{let t=await gr();await nf(t)});import*as rI from"fs/promises";he.command("version").description("Increment the mod version").action(async()=>{let t=await rI.readFile("info.json","utf8"),e=JSON.parse(t);await af(e,t)});import{createWriteStream as qG}from"fs";he.command("package").description("Build a zip package").option("--outdir <outdir>","","").action(async t=>{let e=await gr(),n=Nt.resolvePath(He.file(process.cwd()),t.outdir,`${e.name}_${e.version}.zip`),r=qG(n.fsPath),i=await rf(e);i.pipe(r),await i.finalize(),console.log(`Built ${e.name}_${e.version}.zip ${i.pointer()} bytes`)});import NG from"path";import*as iI from"fs/promises";he.command("upload <zipname> [name]").description("Upload a zip package to the mod portal").action(async(t,e)=>{if(!e){let r=NG.basename(t,".zip").match(/^(.*?)(_(\d+\.){2}\d+)?$/);r&&(e=r[1])}if(!e){console.log("Unable to determine `name`");return}await of(e,await iI.readFile(t))});he.command("details").description("Update mod details").option("--readme <readme.md>").option("--faq <faq.md>").action(async t=>{let e=await gr();return sf(e,t)});import*as aI from"os";import*as ko from"fs/promises";import*as lI from"crypto";import jG from"path";import{exec as lf}from"child_process";import*as oI from"os";import*as li from"fs/promises";import MG from"path";var wy={async readFile(t){return li.readFile(t.fsPath)},async writeFile(t,e){return li.writeFile(t.fsPath,e)},async stat(t){let e=await li.stat(t.fsPath);return{size:e.size,type:(e.isFile()?1:0)|(e.isDirectory()?2:0)|(e.isSymbolicLink()?64:0),ctime:e.ctime.valueOf(),mtime:e.mtime.valueOf()}}};async function BG(t,e){let n=process.env.FMTK_CONFIG??MG.join(oI.homedir(),".fmtk","config.json");try{let r=JSON.parse(await li.readFile(n,"utf8"));if(typeof r!="object"||Array.isArray(r))return;let i={};for(let o in r)o.startsWith(`${t}.`)&&(i[o.substring(t.length+1)]=r[o]);return e||console.log(`Got config section ${t} from ${n}`),i}catch{}}async function sI(t,e,n){return Object.assign({},...await Promise.all([e,BG(t,n)]))}he.command("publish").description("Package and publish a mod to the mod portal").action(async()=>{let t=await ko.readFile("info.json","utf8"),e=JSON.parse(t);console.log(`Publishing: ${process.cwd()} ${e.version}`);let n=await sI("package",{preparingCommitMessage:"preparing release of version $VERSION",movedToCommitMessage:"moved to version $VERSION",autoCommitAuthor:"compilatron <compilatron@justarandomgeek.com>",tagName:"$VERSION",tagMessage:void 0}),r=await new Promise(u=>{lf("git status --porcelain",(c,f,h)=>{c&&c.code!==0&&u(void 0),f&&u("HasChanges"),u("OK")})}),i;if(r){if(r==="HasChanges"){console.log("Cannot Publish with uncommitted changes");return}i=await new Promise((c,f)=>{lf("git branch --show-current",(h,p)=>{h&&h.code!==0&&f(h),c(p.trim())})});let u=e.package?.git_publish_branch;switch(u){case null:break;case void 0:u=await new Promise((c,f)=>{lf("git config init.defaultBranch",(h,p)=>{h&&h.code!==0&&f(h),c(p.trim())})});default:u!==i&&(console.log(`Cannot Publish on branch other than '${u}', currently on '${i}'`),process.exit(1));break}}else console.log("No git repo found, skipping git subtasks...");if(e.package?.scripts?.prepublish){let u=await hn("prepublish",e);u!==0&&process.exit(u)}let o=await nf(e),s;if(r&&(o&&await yr("add changelog.txt"),await yr(`commit --author "${n.autoCommitAuthor}" --allow-empty -F -`,n.preparingCommitMessage.replace(/\$VERSION/g,e.version).replace(/\$MODNAME/g,e.name)),!e.package?.no_git_tag)){s=n.tagName.replace(/\$VERSION/g,e.version).replace(/\$MODNAME/g,e.name);let u=n.tagMessage?.replace(/\$VERSION/g,e.version).replace(/\$MODNAME/g,e.name);await yr(`tag -a ${s} -F -`,u??"")}let a=await new Promise((u,c)=>{rf(e).then(f=>{let h=[];f.on("data",p=>h.push(Buffer.from(p))),f.on("error",p=>c(p)),f.on("end",()=>u(Buffer.concat(h))),f.finalize()})});if(e.package?.scripts?.publish){let u=await hn("publish",e);u!==0&&process.exit(u)}if(e.package?.no_portal_upload||(await of(e.name,a),e.package?.sync_portal_details&&await sf(e)),e.package?.scripts?.postpublish){let u=jG.join(aI.tmpdir(),`${lI.randomBytes(16).toString("base64url")}.zip`);await ko.writeFile(u,a);let c=await hn("postpublish",e,{FACTORIO_MODPACKAGE:u});await ko.unlink(u),c!==0&&process.exit(c)}let l=await af(e,t);if(r&&(await yr("add info.json"),o&&await yr("add changelog.txt"),await yr(`commit --author "${n.autoCommitAuthor}" -F -`,n.movedToCommitMessage.replace(/\$VERSION/g,l.version).replace(/\$MODNAME/g,l.name)),!e.package?.no_git_push)){let u=await new Promise(c=>{lf(`git config branch.${i}.remote`,(f,h)=>{f&&f.code!==0&&c(void 0),c(h.trim())})});u?await yr(`push ${u} ${i} ${s??""}`):console.log(`no remote set as upstream on ${i}`)}});import*as ui from"fs/promises";import fI from"path";import{createWriteStream as UG}from"fs";import uI from"path";var uf=class{constructor(e,n,r){this.settingsdump=n;this.protosdump=r;if(this.docs=JSON.parse(e),this.docs.application!=="factorio")throw new Error(`Unknown application: ${this.docs.application}`);if(this.docs.api_version!==6)throw new Error(`Unsupported Prototype Docs JSON Version ${this.docs.api_version}`);if(this.docs.stage!=="prototype")throw new Error(`Wrong stage: ${this.docs.stage}`);this.concepts=new Map(this.docs.types.map(i=>[i.name,i])),this.simple_structs=new Set;for(let[i,o]of this.concepts)typeof o.type=="object"&&o.type.complex_type==="struct"&&this.simple_structs.add(i);this.prototypes=new Map(this.docs.prototypes.map(i=>[i.name,i]))}settingsdump;protosdump;docs;concepts;simple_structs;prototypes;type_prefix="data.";get api_version(){return this.docs.api_version}get stage(){return this.docs.stage}get application(){return this.docs.application}get application_version(){return this.docs.application_version}resolve_link(e,n){if(n=n?`#${n}`:"",["prototypes","types"].includes(e))return`/${e}.html${n}`;if(["libraries","storage","migrations","data-lifecycle","prototype-tree","noise-expressions","instrument","item-weight"].includes(e))return`/auxiliary/${e}.html${n}`;if(this.concepts.has(e))return`/types/${e}.html${n}`;if(this.prototypes.has(e))return`/prototypes/${e}.html${n}`;console.warn(`Invalid Link: prototype:${e}${n}`)}async generate_LuaLS_docs(e){return[...await this.generate_LuaLS_concepts(e),...await this.generate_LuaLS_prototypes(e),this.generate_LuaLS_data(e)]}async generate_LuaLS_concepts(e){let n=[];for(let[r,i]of this.concepts){let o=new Sa(`prototype-api/concepts/${i.name}`,this.application_version);if(i.type==="builtin")continue;let s=this.simple_structs.has(i.name),a=s?"":".struct";if(i.properties){let l=new Io(this.type_prefix+i.name+a);l.exact=!0,l.description=await e(i.description,{scope:"prototype",member:i.name}),i.parent&&(l.parents=[new oe(this.type_prefix+i.parent)]);for(let u of i.properties)l.add(new ft(u.name,this.lua_proto_type(u.type),await e(u.description,{scope:"prototype",member:i.name,part:u.name}),u.optional));o.add(l)}if(!s){let l=i.type;if(i.name==="AnyPrototype"&&typeof l=="object"&&l.complex_type==="union"){let u=["MapGenPresets","GuiStyle"];l={complex_type:"union",options:l.options.filter(f=>typeof f=="object"?!(f.complex_type==="type"&&typeof f.value=="string"&&u.includes(f.value)):!u.includes(f))}}if(this.protosdump){let u=i.description.match(/^The name of an? \[(.+)\]/);i.type==="string"&&i.name.endsWith("ID")&&u&&(l=i.name.replace(/ID$/,"Name"))}o.add(new gf(this.type_prefix+i.name,this.lua_proto_type(l,i),i.description))}n.push(o)}return n}generate_LuaLS_data(e){let n=new Sa("prototype-api/data",this.application_version),r=new Io("data");r.add(new ft("raw",new oe("data.raw"))),r.add(new ft("is_demo",new oe("boolean")));let i=new qy("extend",[new vr("otherdata",new mi(new oe("data.AnyPrototype")))]);i.add(new ka(void 0,[new vr("self",new oe("data")),new vr("otherdata",new mi(new oe("data.AnyPrototype")))])),i.add(new ka(void 0,[new vr("otherdata",new mi(new oe("data.AnyModSettingPrototype")))])),i.add(new ka(void 0,[new vr("self",new oe("data")),new vr("otherdata",new mi(new oe("data.AnyModSettingPrototype")))])),r.add(i),r.global_name="data",n.add(r);let o=new Io("data.raw");o.exact=!0,n.add(o);for(let[s,a]of this.prototypes)a.typename&&o.add(new ft(new Ea(a.typename),new Cn(new oe("string"),new oe(this.type_prefix+a.name))));return o.add(new ft("bool-setting",new Cn(new oe("string"),new oe("data.ModBoolSettingPrototype")),"In Settings Stage")),o.add(new ft("int-setting",new Cn(new oe("string"),new oe("data.ModIntSettingPrototype")),"In Settings Stage")),o.add(new ft("double-setting",new Cn(new oe("string"),new oe("data.ModDoubleSettingPrototype")),"In Settings Stage")),o.add(new ft("string-setting",new Cn(new oe("string"),new oe("data.ModStringSettingPrototype")),"In Settings Stage")),o.add(new ft("color-setting",new Cn(new oe("string"),new oe("data.ModColorSettingPrototype")),"In Settings Stage")),n}nameFor(e){let n=this.docs.prototypes.find(r=>r.typename===e);if(n)return new oe(this.type_prefix+n.name.replace(/(Prototype)?$/,"Name"));throw new Error(`no type for '${e}'`)}async generate_LuaLS_prototypes(e){let n=[];for(let[r,i]of this.prototypes){let o=new Sa(`prototype-api/prototypes/${i.name}`,this.application_version),s=new Io(this.type_prefix+i.name);s.exact=!0,s.description=await e(i.description,{scope:"prototype",member:i.name}),i.parent&&(s.parents=[new oe(this.type_prefix+i.parent)]);for(let a of i.properties)s.add(new ft(a.name,this.lua_proto_type(a.type),await e(a.description,{scope:"prototype",member:i.name,part:a.name}),a.optional)),a.alt_name&&s.add(new ft(a.alt_name,this.lua_proto_type(a.type),await e(a.description,{scope:"prototype",member:i.name,part:a.alt_name}),a.optional));if(i.custom_properties){let a=i.custom_properties;s.add(new ft(this.lua_proto_type(a.key_type),this.lua_proto_type(a.value_type),await e(a.description,{scope:"prototype",member:i.name,part:"custom_properties"})))}if(o.add(s),this.protosdump){let a=i.name.replace(/(Prototype)?$/,"Name"),l=[];if(this.prototypes.forEach(u=>{u.parent===i.name&&l.push(new oe(this.type_prefix+u.name.replace(/(Prototype)?$/,"Name")))}),i.typename){for(let u in this.protosdump[i.typename])l.push(new Ea(u));l.push(new oe("string"))}o.add(new gf(this.type_prefix+a,new mf(l)))}n.push(o)}return n}lua_proto_type(e,n){switch(typeof e){case"string":switch(e){case"bool":return new oe("boolean");case"table":case"number":case"nil":case"boolean":case"string":case"float":case"double":case"int8":case"uint8":case"int16":case"uint16":case"int32":case"uint32":case"int64":case"uint64":return new oe(e)}return e.match(/^defines\./)?new oe(e):new oe(this.type_prefix+e);case"object":switch(e.complex_type){case"struct":if(!n)throw new Error("struct without parent");return this.simple_structs.has(n.name)?new oe(this.type_prefix+n.name):new oe(this.type_prefix+n.name+".struct");case"array":return new mi(this.lua_proto_type(e.value,n));case"tuple":return new Fy(e.values.map(r=>this.lua_proto_type(r,n)));case"dictionary":return new Cn(this.lua_proto_type(e.key,n),this.lua_proto_type(e.value,n));case"union":return new mf(e.options.map(r=>this.lua_proto_type(r,n)));case"literal":return new Ea(e.value);case"type":return this.lua_proto_type(e.value,n);default:throw new Error("Invalid Type")}default:throw new Error("Invalid Type")}}};async function cI(t,e,n,r,i){let o=n&&JSON.parse(n),s=r&&JSON.parse(r),a=new uf(e,o,s),l=new Ta(t,a,o,s);console.log(`Loaded Prototype docs ${a.application_version}`),console.log(`Loaded Runtime docs ${l.application_version}`),o&&console.log("With Settings Dump"),s&&console.log("With Prototypes Dump");let u=b=>{let y=b.url.match(/^(runtime|prototype):(.+?)(?:::(.+))?$/);if(y)switch(y[1]){case"runtime":let T=l.resolve_link(y[2],y[3]);T&&(b.url="https://lua-api.factorio.com/latest"+T);break;case"prototype":let g=a.resolve_link(y[2],y[3]);g&&(b.url="https://lua-api.factorio.com/latest"+g);break}},c=cl().use(function(){return function(b,y){Et(b,"link",u)}}),f=async(b,y)=>{let T=y?`[View Documentation](${y.scope}:${y.member}${y.part?"::"+y.part:""})`:"";return String(await c.process(`${b??""}
|
|
112
|
+
`;await fn.writeFile("changelog.txt",`---------------------------------------------------------------------------------------------------${s}Version: ${n}${s}Date: ????${s} Changes:${s}`+i)}}),t.package?.scripts?.version){let i=await hn("version",t);i!==0&&process.exit(i)}return t}he.command("run <script> [args...]").description("Run a script from info.json#/package/scripts").action(async(t,e)=>{process.exit(await hn(t,await gr(),void 0,e))});he.command("datestamp").description("Datestamp the current changelog section").action(async()=>{let t=await gr();await nf(t)});import*as rI from"fs/promises";he.command("version").description("Increment the mod version").action(async()=>{let t=await rI.readFile("info.json","utf8"),e=JSON.parse(t);await af(e,t)});import{createWriteStream as qG}from"fs";he.command("package").description("Build a zip package").option("--outdir <outdir>","","").action(async t=>{let e=await gr(),n=Nt.resolvePath(He.file(process.cwd()),t.outdir,`${e.name}_${e.version}.zip`),r=qG(n.fsPath),i=await rf(e);i.pipe(r),await i.finalize(),console.log(`Built ${e.name}_${e.version}.zip ${i.pointer()} bytes`)});import NG from"path";import*as iI from"fs/promises";he.command("upload <zipname> [name]").description("Upload a zip package to the mod portal").action(async(t,e)=>{if(!e){let r=NG.basename(t,".zip").match(/^(.*?)(_(\d+\.){2}\d+)?$/);r&&(e=r[1])}if(!e){console.log("Unable to determine `name`");return}await of(e,await iI.readFile(t))});he.command("details").description("Update mod details").option("--readme <readme.md>").option("--faq <faq.md>").action(async t=>{let e=await gr();return sf(e,t)});import*as aI from"os";import*as ko from"fs/promises";import*as lI from"crypto";import jG from"path";import{exec as lf}from"child_process";import*as oI from"os";import*as li from"fs/promises";import MG from"path";var wy={async readFile(t){return li.readFile(t.fsPath)},async writeFile(t,e){return li.writeFile(t.fsPath,e)},async stat(t){let e=await li.stat(t.fsPath);return{size:e.size,type:(e.isFile()?1:0)|(e.isDirectory()?2:0)|(e.isSymbolicLink()?64:0),ctime:e.ctime.valueOf(),mtime:e.mtime.valueOf()}}};async function BG(t,e){let n=process.env.FMTK_CONFIG??MG.join(oI.homedir(),".fmtk","config.json");try{let r=JSON.parse(await li.readFile(n,"utf8"));if(typeof r!="object"||Array.isArray(r))return;let i={};for(let o in r)o.startsWith(`${t}.`)&&(i[o.substring(t.length+1)]=r[o]);return e||console.log(`Got config section ${t} from ${n}`),i}catch{}}async function sI(t,e,n){return Object.assign({},...await Promise.all([e,BG(t,n)]))}he.command("publish").description("Package and publish a mod to the mod portal").action(async()=>{let t=await ko.readFile("info.json","utf8"),e=JSON.parse(t);console.log(`Publishing: ${process.cwd()} ${e.version}`);let n=await sI("package",{preparingCommitMessage:"preparing release of version $VERSION",movedToCommitMessage:"moved to version $VERSION",autoCommitAuthor:"compilatron <compilatron@justarandomgeek.com>",tagName:"$VERSION",tagMessage:void 0}),r=await new Promise(u=>{lf("git status --porcelain",(c,f,h)=>{c&&c.code!==0&&u(void 0),f&&u("HasChanges"),u("OK")})}),i;if(r){if(r==="HasChanges"){console.log("Cannot Publish with uncommitted changes");return}i=await new Promise((c,f)=>{lf("git branch --show-current",(h,p)=>{h&&h.code!==0&&f(h),c(p.trim())})});let u=e.package?.git_publish_branch;switch(u){case null:break;case void 0:u=await new Promise((c,f)=>{lf("git config init.defaultBranch",(h,p)=>{h&&h.code!==0&&f(h),c(p.trim())})});default:u!==i&&(console.log(`Cannot Publish on branch other than '${u}', currently on '${i}'`),process.exit(1));break}}else console.log("No git repo found, skipping git subtasks...");if(e.package?.scripts?.prepublish){let u=await hn("prepublish",e);u!==0&&process.exit(u)}let o=await nf(e),s;if(r&&(o&&await yr("add changelog.txt"),await yr(`commit --author "${n.autoCommitAuthor}" --allow-empty -F -`,n.preparingCommitMessage.replace(/\$VERSION/g,e.version).replace(/\$MODNAME/g,e.name)),!e.package?.no_git_tag)){s=n.tagName.replace(/\$VERSION/g,e.version).replace(/\$MODNAME/g,e.name);let u=n.tagMessage?.replace(/\$VERSION/g,e.version).replace(/\$MODNAME/g,e.name);await yr(`tag -a ${s} -F -`,u??"")}let a=await new Promise((u,c)=>{rf(e).then(f=>{let h=[];f.on("data",p=>h.push(Buffer.from(p))),f.on("error",p=>c(p)),f.on("end",()=>u(Buffer.concat(h))),f.finalize()})});if(e.package?.scripts?.publish){let u=await hn("publish",e);u!==0&&process.exit(u)}if(e.package?.no_portal_upload||(await of(e.name,a),e.package?.sync_portal_details&&await sf(e)),e.package?.scripts?.postpublish){let u=jG.join(aI.tmpdir(),`${lI.randomBytes(16).toString("base64url")}.zip`);await ko.writeFile(u,a);let c=await hn("postpublish",e,{FACTORIO_MODPACKAGE:u});await ko.unlink(u),c!==0&&process.exit(c)}let l=await af(e,t);if(r&&(await yr("add info.json"),o&&await yr("add changelog.txt"),await yr(`commit --author "${n.autoCommitAuthor}" -F -`,n.movedToCommitMessage.replace(/\$VERSION/g,l.version).replace(/\$MODNAME/g,l.name)),!e.package?.no_git_push)){let u=await new Promise(c=>{lf(`git config branch.${i}.remote`,(f,h)=>{f&&f.code!==0&&c(void 0),c(h.trim())})});u?await yr(`push ${u} ${i} ${s??""}`):console.log(`no remote set as upstream on ${i}`)}});import*as ui from"fs/promises";import fI from"path";import{createWriteStream as UG}from"fs";import uI from"path";var uf=class{constructor(e,n,r){this.settingsdump=n;this.protosdump=r;if(this.docs=JSON.parse(e),this.docs.application!=="factorio")throw new Error(`Unknown application: ${this.docs.application}`);if(this.docs.api_version!==6)throw new Error(`Unsupported Prototype Docs JSON Version ${this.docs.api_version}`);if(this.docs.stage!=="prototype")throw new Error(`Wrong stage: ${this.docs.stage}`);this.concepts=new Map(this.docs.types.map(i=>[i.name,i])),this.simple_structs=new Set;for(let[i,o]of this.concepts)typeof o.type=="object"&&o.type.complex_type==="struct"&&this.simple_structs.add(i);this.prototypes=new Map(this.docs.prototypes.map(i=>[i.name,i]))}settingsdump;protosdump;docs;concepts;simple_structs;prototypes;type_prefix="data.";get api_version(){return this.docs.api_version}get stage(){return this.docs.stage}get application(){return this.docs.application}get application_version(){return this.docs.application_version}resolve_link(e,n){if(n=n?`#${n}`:"",["prototypes","types"].includes(e))return`/${e}.html${n}`;if(["libraries","storage","migrations","data-lifecycle","prototype-tree","noise-expressions","instrument","item-weight"].includes(e))return`/auxiliary/${e}.html${n}`;if(this.concepts.has(e))return`/types/${e}.html${n}`;if(this.prototypes.has(e))return`/prototypes/${e}.html${n}`;console.warn(`Invalid Link: prototype:${e}${n}`)}async generate_LuaLS_docs(e){return[...await this.generate_LuaLS_concepts(e),...await this.generate_LuaLS_prototypes(e),this.generate_LuaLS_data(e)]}async generate_LuaLS_concepts(e){let n=[];for(let[r,i]of this.concepts){let o=new Sa(`prototype-api/concepts/${i.name}`,this.application_version);if(i.type==="builtin")continue;let s=this.simple_structs.has(i.name),a=s?"":".struct";if(i.properties){let l=new Io(this.type_prefix+i.name+a);l.exact=!0,l.description=await e(i.description,{scope:"prototype",member:i.name}),i.parent&&(l.parents=[new oe(this.type_prefix+i.parent)]);for(let u of i.properties)l.add(new ft(u.name,this.lua_proto_type(u.type),await e(u.description,{scope:"prototype",member:i.name,part:u.name}),u.optional));o.add(l)}if(!s){let l=i.type;if(i.name==="AnyPrototype"&&typeof l=="object"&&l.complex_type==="union"){let u=["MapGenPresets","GuiStyle"];l={complex_type:"union",options:l.options.filter(f=>typeof f=="object"?!(f.complex_type==="type"&&typeof f.value=="string"&&u.includes(f.value)):!u.includes(f))}}if(this.protosdump){let u=i.description.match(/^The name of an? \[(.+)\]/);i.type==="string"&&i.name.endsWith("ID")&&u&&(l=i.name.replace(/ID$/,"Name"))}o.add(new gf(this.type_prefix+i.name,this.lua_proto_type(l,i),i.description))}n.push(o)}return n}generate_LuaLS_data(e){let n=new Sa("prototype-api/data",this.application_version),r=new Io("data");r.add(new ft("raw",new oe("data.raw"))),r.add(new ft("is_demo",new oe("boolean")));let i=new qy("extend",[new vr("otherdata",new mi(new oe("data.AnyPrototype")))]);i.add(new ka(void 0,[new vr("self",new oe("data")),new vr("otherdata",new mi(new oe("data.AnyPrototype")))])),i.add(new ka(void 0,[new vr("otherdata",new mi(new oe("data.AnyModSettingPrototype")))])),i.add(new ka(void 0,[new vr("self",new oe("data")),new vr("otherdata",new mi(new oe("data.AnyModSettingPrototype")))])),r.add(i),r.global_name="data",n.add(r);let o=new Io("data.raw");o.exact=!0,n.add(o);for(let[s,a]of this.prototypes)a.typename&&o.add(new ft(new Ea(a.typename),new Cn(new oe("string"),new oe(this.type_prefix+a.name))));return o.add(new ft("bool-setting",new Cn(new oe("string"),new oe("data.ModBoolSettingPrototype")),"In Settings Stage")),o.add(new ft("int-setting",new Cn(new oe("string"),new oe("data.ModIntSettingPrototype")),"In Settings Stage")),o.add(new ft("double-setting",new Cn(new oe("string"),new oe("data.ModDoubleSettingPrototype")),"In Settings Stage")),o.add(new ft("string-setting",new Cn(new oe("string"),new oe("data.ModStringSettingPrototype")),"In Settings Stage")),o.add(new ft("color-setting",new Cn(new oe("string"),new oe("data.ModColorSettingPrototype")),"In Settings Stage")),n}nameFor(e){let n=this.docs.prototypes.find(r=>r.typename===e);if(n)return new oe(this.type_prefix+n.name.replace(/(Prototype)?$/,"Name"));throw new Error(`no type for '${e}'`)}async generate_LuaLS_prototypes(e){let n=[];for(let[r,i]of this.prototypes){let o=new Sa(`prototype-api/prototypes/${i.name}`,this.application_version),s=new Io(this.type_prefix+i.name);s.exact=!0,s.description=await e(i.description,{scope:"prototype",member:i.name}),i.parent&&(s.parents=[new oe(this.type_prefix+i.parent)]);for(let u of i.properties)s.add(new ft(u.name,this.lua_proto_type(u.type),await e(u.description,{scope:"prototype",member:i.name,part:u.name}),u.optional)),u.alt_name&&s.add(new ft(u.alt_name,this.lua_proto_type(u.type),await e(u.description,{scope:"prototype",member:i.name,part:u.alt_name}),u.optional));if(i.custom_properties){let u=i.custom_properties;s.add(new ft(this.lua_proto_type(u.key_type),this.lua_proto_type(u.value_type),await e(u.description,{scope:"prototype",member:i.name,part:"custom_properties"})))}o.add(s);let a=i.name.replace(/(Prototype)?$/,"Name"),l=[];if(this.prototypes.forEach(u=>{u.parent===i.name&&l.push(new oe(this.type_prefix+u.name.replace(/(Prototype)?$/,"Name")))}),i.typename){if(this.protosdump)for(let u in this.protosdump[i.typename])l.push(new Ea(u));l.push(new oe("string"))}o.add(new gf(this.type_prefix+a,new mf(l))),n.push(o)}return n}lua_proto_type(e,n){switch(typeof e){case"string":switch(e){case"bool":return new oe("boolean");case"table":case"number":case"nil":case"boolean":case"string":case"float":case"double":case"int8":case"uint8":case"int16":case"uint16":case"int32":case"uint32":case"int64":case"uint64":return new oe(e)}return e.match(/^defines\./)?new oe(e):new oe(this.type_prefix+e);case"object":switch(e.complex_type){case"struct":if(!n)throw new Error("struct without parent");return this.simple_structs.has(n.name)?new oe(this.type_prefix+n.name):new oe(this.type_prefix+n.name+".struct");case"array":return new mi(this.lua_proto_type(e.value,n));case"tuple":return new Fy(e.values.map(r=>this.lua_proto_type(r,n)));case"dictionary":return new Cn(this.lua_proto_type(e.key,n),this.lua_proto_type(e.value,n));case"union":return new mf(e.options.map(r=>this.lua_proto_type(r,n)));case"literal":return new Ea(e.value);case"type":return this.lua_proto_type(e.value,n);default:throw new Error("Invalid Type")}default:throw new Error("Invalid Type")}}};async function cI(t,e,n,r,i){let o=n&&JSON.parse(n),s=r&&JSON.parse(r),a=new uf(e,o,s),l=new Ta(t,a,o,s);console.log(`Loaded Prototype docs ${a.application_version}`),console.log(`Loaded Runtime docs ${l.application_version}`),o&&console.log("With Settings Dump"),s&&console.log("With Prototypes Dump");let u=b=>{let y=b.url.match(/^(runtime|prototype):(.+?)(?:::(.+))?$/);if(y)switch(y[1]){case"runtime":let T=l.resolve_link(y[2],y[3]);T&&(b.url="https://lua-api.factorio.com/latest"+T);break;case"prototype":let g=a.resolve_link(y[2],y[3]);g&&(b.url="https://lua-api.factorio.com/latest"+g);break}},c=cl().use(function(){return function(b,y){Et(b,"link",u)}}),f=async(b,y)=>{let T=y?`[View Documentation](${y.scope}:${y.member}${y.part?"::"+y.part:""})`:"";return String(await c.process(`${b??""}
|
|
113
113
|
|
|
114
114
|
${T}`.trim())).trim()},h=uI.posix.join("factorio","library");await Promise.all([...await l.generate_LuaLS_docs(f),...await a.generate_LuaLS_docs(f)].map(async b=>{let y=await b;await i(uI.posix.join(h,y.name+".lua"),T=>y.write(T))})),await Promise.all(Ny().map(async b=>{await i(b.name,y=>{y.write(b.content)})}));let p=My(l.application_version);await i(p.name,b=>{b.write(p.content)})}async function hI(t){let e=await fetch(t);if(!e.ok)throw new Error(`Error fetching ${t} : ${e.statusText}`);return e.text()}he.command("luals-addon [outdir]").alias("sumneko-3rd").description("Generate a library bundle for LuaLS (sumneko.lua) LSP").option("-d, --docs <docsjson>","Runtime docs").option("-p, --protos <protosjson>","Prototype docs").option("-o, --online [version]","Use online docs").option("--sdump <mod-settings-dump.json>","Load Settings Prototype dump").option("--pdump <data-raw-dump.json>","Load Prototype dump").action(async(t,e)=>{let n,r;if(e.docs&&e.protos)n=await ui.readFile(e.docs,"utf8"),r=await ui.readFile(e.protos,"utf8");else{if(e.docs||e.protos)throw new Error("Using local json files must specify both files");{if(e.online==="throw")throw new Error("Test Error");let a=e.online??"latest";n=await hI(`https://lua-api.factorio.com/${a}/runtime-api.json`),r=await hI(`https://lua-api.factorio.com/${a}/prototype-api.json`)}}let i=e.sdump&&await ui.readFile(e.sdump,"utf8"),o=e.pdump&&await ui.readFile(e.pdump,"utf8"),s=0;await cI(n,r,i,o,async(a,l)=>{let u=fI.join(t??process.cwd(),a);await ui.mkdir(fI.dirname(u),{recursive:!0});let c=UG(u);await l(c),s++,c.close()}),console.log(`Generated bundle with ${s} files`)});var Ft=ct(cf(),1);import*as Ey from"fs/promises";var _t=ct(cf(),1);import WG from"assert";function ci(t,e,n){return Oe("text",t,e,n)}function zG(t,e,n){return WG(e.sticky),e.lastIndex=n,e.exec(t)}function xa(t,e,n){let r=t.value,i=t.range.start.line,o=t.range.start.character,s=[],a=0,l=-1;do l=r.indexOf(e,l+1),l>=0&&(n?n.find(u=>{let c=zG(r,u.pattern,l);if(!c)return!1;let f=u.parse(c,i,o);return f?(a<l&&s.push(ci(r.substring(a,l),i,o+a)),s.push(f),a=c.indices[0][1],l=a,!0):!1}):(s.push(ci(r.substring(a,l),i,o+a)),l+=e.length,a=l));while(l>=0);return a<=r.length-1&&s.push(ci(r.substring(a),i,o+a)),s}var $G=[{pattern:/\\n/dy,parse(t,e,n){let r=Oe("escape","\\n",e,n+t.index);return r.value=`
|
|
115
115
|
`,r}}];function HG(t){return xa(t,"|").map(e=>{let n=e.value.indexOf("="),r=ci(e.value.substring(0,n),e.range.start.line,e.range.start.character),i=ci(e.value.substring(n+1),e.range.start.line,e.range.start.character+n+1);return{type:"plural_option",range:e.range,selectionRange:e.selectionRange,children:[...xa(r,",").map(o=>{if(o.value==="rest")return{type:"plural_match",value:"rest",range:o.range,selectionRange:o.selectionRange};let s=o.value.match(/^(ends in )?(\d+)(?:-(\d+))?$/d);return s?{type:"plural_match",value:s[3]?[parseInt(s[2]),parseInt(s[3])]:parseInt(s[2]),ends_in:s[1]?!0:void 0,range:o.range,selectionRange:o.selectionRange}:{type:"error",value:o.value,range:o.range,selectionRange:o.selectionRange}}),...xa(i,"__",dI)]}})}var dI=[{pattern:/__([0-9]+)__/dy,parse(t,e,n){return{type:"parameter",value:parseInt(t[1]),range:we(e,n+t.index,t[0].length),selectionRange:we(e,n+t.indices[1][0],t[1].length)}}},{pattern:/__plural_for_parameter__([0-9]+)__\{(.*?)\}__/dy,parse(t,e,n){return{type:"plural",value:parseInt(t[1]),children:HG(ci(t[2],e,n+t.indices[2][0])),range:we(e,n+t.index,t[0].length),selectionRange:we(e,n+t.indices[1][0],t[1].length)}}},{pattern:/__(CONTROL_(?:MOVE|(?:LEFT|RIGHT)_CLICK|KEY_(?:SHIFT|CTRL)|STYLE_(?:BEGIN|END)))__/dy,parse(t,e,n){return{type:"macro",name:t[1],children:[],range:we(e,n+t.index,t[0].length),selectionRange:we(e,n+t.indices[1][0],t[1].length)}}},{pattern:/__(REMARK_COLOR_(?:BEGIN|END))__/dy,parse(t,e,n){return{type:"macro",name:t[1],children:[],range:we(e,n+t.index,t[0].length),selectionRange:we(e,n+t.indices[1][0],t[1].length)}}},{pattern:/__(CONTROL(?:_MODIFIER)?|ENTITY|ITEM|TILE|FLUID|PLANET|TECHNOLOGY|RECIPE)__(.+?)__/dy,parse(t,e,n){return{type:"macro",name:t[1],children:[Oe("macro_argument",t[2],e,n+t.indices[2][0])],range:we(e,n+t.index,t[0].length),selectionRange:we(e,n+t.indices[1][0],t[1].length)}}},{pattern:/__(ALT_CONTROL)__(.+?)__(.+?)__/dy,parse(t,e,n){return{type:"macro",name:t[1],children:[Oe("macro_argument",t[2],e,n+t.indices[2][0]),Oe("macro_argument",t[3],e,n+t.indices[3][0])],range:we(e,n+t.index,t[0].length),selectionRange:we(e,n+t.indices[1][0],t[1].length)}}},{pattern:/__(ALT_CONTROL_(?:LEFT|RIGHT)_CLICK)__(.+?)__/dy,parse(t,e,n){return{type:"macro",name:t[1],children:[Oe("macro_argument",t[2],e,n+t.indices[1][0])],range:we(e,n+t.index,t[0].length),selectionRange:we(e,n+t.indices[1][0],t[1].length)}}}];function _y(t){let e=t.open_comments;t.open_comments=[];let n=e[0],r=e[e.length-1];return{type:"comment_group",range:{start:n.range.start,end:r.range.end},selectionRange:n.selectionRange,children:e}}var VG=[{pattern:/^[\r\t ]*([#;].*)?$/d,parse(t,e,n){t[1]?n.open_comments.push(Oe("comment",t[1],e,t.indices[1][0])):n.open_comments.length>0&&(n.open_section??n.root).children.push(_y(n))}},{pattern:/^[\r\t ]*\[(.*?)\][\r\t ]*$/d,parse(t,e,n){n.open_section=Oe("section",t[1],e,t.indices[1][0],{children:[]}),n.open_comments.length>0&&n.open_section.children.push(_y(n)),n.open_section.range.start.character-=1,n.open_section.range.end.character+=1,n.root.children.push(n.open_section)}},{pattern:/^[\r\t ]*(.*?)=(.*)$/d,parse(t,e,n){let r=Oe("record",t[1],e,t.indices[1][0],{children:xa(ci(t[2],e,t.indices[2][0]),"\\",$G).flatMap(i=>i.type==="escape"?i:xa(i,"__",dI))});n.open_comments.length>0&&r.children.unshift(_y(n)),r.range.end.character=t[0].length,(n.open_section??n.root).children.push(r)}},{pattern:/^.*$/d,parse(t,e,n){n.root.children.push({type:"error",value:t[0],range:we(e,0,t[0].length),selectionRange:we(e,0,0)})}}];function mI(t){let e={root:{type:"root",children:[],range:{start:{line:0,character:0},end:{line:t.lineCount,character:0}},selectionRange:we(0,0,0)},open_comments:[]};for(let n=0;n<t.lineCount;n++){let r={start:{line:n,character:0},end:{line:n,character:1/0}},i=t.getText(r).replace(/((\r\n)|\r|\n)$/,"");for(let o of VG){let s=o.pattern.exec(i);if(s){o.parse(s,n,e);break}}}return e.root}var xy=new Map([["default",{red:1,green:.63,blue:.259,alpha:1}],["red",{red:1,green:.166,blue:.141,alpha:1}],["green",{red:.173,green:.824,blue:.25,alpha:1}],["blue",{red:.343,green:.683,blue:1,alpha:1}],["orange",{red:1,green:.63,blue:.259,alpha:1}],["yellow",{red:1,green:.828,blue:.231,alpha:1}],["pink",{red:1,green:.52,blue:.633,alpha:1}],["purple",{red:.821,green:.44,blue:.998,alpha:1}],["white",{red:.9,green:.9,blue:.9,alpha:1}],["black",{red:.5,green:.5,blue:.5,alpha:1}],["gray",{red:.7,green:.7,blue:.7,alpha:1}],["brown",{red:.757,green:.522,blue:.371,alpha:1}],["cyan",{red:.335,green:.918,blue:.866,alpha:1}],["acid",{red:.708,green:.996,blue:.134,alpha:1}]]);function gI(t){if(xy.has(t))return xy.get(t);if(t.startsWith("#")){let n=t.match(/#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})?/);if(n)return{red:parseInt(n[1],16)/255,green:parseInt(n[2],16)/255,blue:parseInt(n[3],16)/255,alpha:n[4]?parseInt(n[4],16)/255:1}}let e=t.match(/\s*(\d+(?:\.\d+)?)\s*,?\s*(\d+(?:\.\d+)?)\s*,?\s*(\d+(?:\.\d+)?)(?:\s*,?\s*(\d+(?:\.\d+)?))?\s*/);if(e){let n=parseFloat(e[1]),r=parseFloat(e[2]),i=parseFloat(e[3]),o=e[4]?parseFloat(e[4]):void 0;return(n>1||r>1||i>1||o&&o>1)&&(n=n/255,r=r/255,i=i/255,o&&(o=o/255)),o||(o=1),{red:n,green:r,blue:i,alpha:o}}}function fi(t){let e=Math.floor(t).toString(16);return e.length<2&&(e="0"+e),e}function hi(t,e){return Math.round(t*Math.pow(10,e))/Math.pow(10,e)}function yI(t){let e=[];for(let[n,r]of xy)if(Math.abs(r.red-t.red)<.004&&Math.abs(r.green-t.green)<.004&&Math.abs(r.blue-t.blue)<.004&&Math.abs(r.alpha-t.alpha)<.004){e.push(n);break}return t.alpha>.996?(e.push(`#${fi(t.red*255)}${fi(t.green*255)}${fi(t.blue*255)}`),e.push(`${Math.floor(t.red*255)}, ${Math.floor(t.green*255)}, ${Math.floor(t.blue*255)}`),e.push(`${hi(t.red,3)}, ${hi(t.green,3)}, ${hi(t.blue,3)}`)):(e.push(`#${fi(t.red*255)}${fi(t.green*255)}${fi(t.blue*255)}${fi(t.alpha*255)}`),e.push(`${Math.floor(t.red*255)}, ${Math.floor(t.green*255)}, ${Math.floor(t.blue*255)}, ${Math.floor(t.alpha*255)}`),e.push(`${hi(t.red,3)}, ${hi(t.green,3)}, ${hi(t.blue,3)}, ${hi(t.alpha,3)}`)),e}var bI=ct(ts(),1);var GG=[{message:"Duplicate Section",code:"section.duplicate",setup(t){let e=new Map;return{section:(n,r,i)=>{let o=e.get(n.value);if(o){let s=o.children.length>0?o.children[o.children.length-1].range.end:o.range.end,a=n.children.length>0?n.children[n.children.length-1].range.end:n.range.end;t.report({diag:{range:n.selectionRange,relatedInformation:[{message:"First defined here",location:{range:o.selectionRange,uri:t.uri}}]},fix:[{range:{start:n.range.start,end:a},newText:""},{range:{start:s,end:s},getText:{start:{line:n.range.end.line,character:n.range.end.character+1},end:a}}]})}else e.set(n.value,n)}}}},{message:"Section Name conflicts with Key in Root",code:"section.rootconflict",setup(t){let e;return{root:(n,r,i)=>{e=n},section:(n,r,i)=>{let o=e.children.find(s=>s.type==="record"&&s.value===n.value);o&&t.report({diag:{range:n.selectionRange,relatedInformation:[{location:{uri:t.uri,range:o.range},message:"First defined here"}]}})}}}},{message:"Duplicate Key",code:"key.duplicate",setup(t){let e=new Map;return{section:(n,r,i)=>{e.clear()},record:(n,r,i)=>{let o=e.get(n.value);o?t.report({diag:{range:n.selectionRange,relatedInformation:[{message:"First defined here",location:{range:o.selectionRange,uri:t.uri}}]}}):e.set(n.value,n)}}}},{message:"Key ends with whitespace",code:"key.whitespace-end",setup(t){return{record:(e,n,r)=>{e.value.match(/[\t ]+$/d)&&t.report({diag:{severity:bI.DiagnosticSeverity.Warning,range:e.selectionRange}})}}}},{message:"Empty Key",code:"key.empty",setup(t){return{record:(e,n,r)=>{e.value||t.report({diag:{range:e.range}})}}}},{message:"Invalid Line",code:"error.unknown",setup(t){return{error:(e,n,r)=>{t.report({diag:{range:e.range}})}}}}];function vy(t,e){let n=[],r={root:[],comment_group:[],comment:[],section:[],record:[],macro:[],macro_argument:[],parameter:[],plural:[],plural_match:[],plural_option:[],richtext:[],richtextopen:[],richtextclose:[],richtextformat:[],text:[],escape:[],error:[]};for(let i of GG){let o={uri:e,report(a){n.push({message:i.message,code:i.code,...a})}},s=i.setup(o);for(let a in r){let l=a;l in s&&s[l]&&r[l].push(s[l])}}return Et(t,(i,o,s)=>{let a=r[i.type];for(let l of a)l(i,o??-1,s)}),n}function KG(t,e){let n=[];return Mn(t,"record",(r,i)=>{let o=i.length>0?i[i.length-1]:void 0,s=o?.type==="section"?o.value:void 0;n.push({name:s?`${s}.${r.value}`:r.value,link:{targetUri:e,targetRange:r.range,targetSelectionRange:r.selectionRange},section:o?.type==="section"?o:void 0,record:r})}),n}function wI(t){return t!==void 0}var ff=class{hasDiagnosticRelatedInformationCapability=!1;definitions=new Map;documentTrees=new Map;loadDocument(e){let n=mI(e);this.documentTrees.set(e.uri,n),this.definitions.set(e.uri,KG(n,e.uri))}clearDocument(e){this.definitions.delete(e),this.documentTrees.delete(e)}clearFolder(e){for(let n of this.definitions.keys())n.startsWith(e)&&this.definitions.delete(n);for(let n of this.documentTrees.keys())n.startsWith(e)&&this.documentTrees.delete(n)}diagnose(e){let n=this.documentTrees.get(e);if(!n)return[];let r=vy(n,e),i=[];for(let o of r)i.push({message:o.message,code:o.code,source:"factorio-locale",severity:_t.DiagnosticSeverity.Error,...o.diag});return i}recordSymbol(e){return{name:e.value?e.value:"<empty>",detail:"",kind:e.value?_t.SymbolKind.String:_t.SymbolKind.Null,range:e.range,selectionRange:e.selectionRange,children:[]}}sectionSymbols(e){return{name:e.value?e.value:"[empty]",detail:"",tags:[],kind:_t.SymbolKind.Namespace,range:e.range,selectionRange:e.selectionRange,children:e.children.map(n=>{if(n.type==="record")return this.recordSymbol(n)}).filter(wI)}}documentSymbols(e){return e.children.map(n=>{switch(n.type){case"section":return this.sectionSymbols(n);case"record":return this.recordSymbol(n);default:return}}).filter(wI)}onDocumentSymbol(e){this.documentTrees.has(e.uri)||this.loadDocument(e);let n=this.documentTrees.get(e.uri);return n?this.documentSymbols(n):[]}findDefinitionLinks(e){return this.findDefinitions(e).map(r=>r.link)}findDefinitions(e){let n=[];for(let r of this.definitions.values())n.push(...r.filter(i=>i.name===e));return n}getKeyPlainText(e){let n=this.findDefinitions(e);return n.length===0?`Unknown key: ${e}`:this.getRecordPlainText(n[0].record)}getMacroPlainText(e){switch(e.name){case"ENTITY":return this.getKeyPlainText(`entity-name.${e.children[0].value}`);case"ITEM":return this.getKeyPlainText(`item-name.${e.children[0].value}`);case"TILE":return this.getKeyPlainText(`tile-name.${e.children[0].value}`);case"FLUID":return this.getKeyPlainText(`fluid-name.${e.children[0].value}`);case"PLANET":return this.getKeyPlainText(`space-location-name.${e.children[0].value}`);case"TECHNOLOGY":return this.getKeyPlainText(`technology-name.${e.children[0].value}`);case"RECIPE":return this.getKeyPlainText(`recipe-name.${e.children[0].value}`);case"CONTROL_KEY_SHIFT":return this.getKeyPlainText("control-keys.shift");case"CONTROL_KEY_CTRL":return this.getKeyPlainText("control-keys.control");case"CONTROL_MOVE":return"WASD";case"CONTROL":case"CONTROL_MODIFIER":return`__${e.name}__${e.children[0].value}__`;case"ALT_CONTROL":return`__${e.name}__${e.children[0].value}__${e.children[1].value}__`;case"CONTROL_LEFT_CLICK":return this.getKeyPlainText("control-keys.mouse-button-1");case"CONTROL_RIGHT_CLICK":return this.getKeyPlainText("control-keys.mouse-button-2");case"ALT_CONTROL_LEFT_CLICK":return this.getKeyPlainText(`control-keys.mouse-button-1-alt-${e.children[0].value}`);case"ALT_CONTROL_RIGHT_CLICK":return this.getKeyPlainText(`control-keys.mouse-button-2-alt-${e.children[0].value}`);case"CONTROL_STYLE_BEGIN":return"[font=default-semibold][color=128,206,240]";case"CONTROL_STYLE_END":return"[/color][/font]";case"REMARK_COLOR_BEGIN":return"[color=34,181,255]";case"REMARK_COLOR_END":return"[/color]";default:throw new Error("Unknown Macro Node Type")}}getPluralPlainTexts(e,n){return e.children.filter(r=>r.type==="plural_option").map(r=>{throw new Error("")})}getNodePlainText(e,n){switch(e.type){case"text":case"escape":return e.value;case"parameter":if(n.values&&e.value<n.values.length){let r=n.values[e.value];if(r!==void 0)return`${r}`}return`__${e.value}__`;case"plural":return this.getPluralPlainTexts(e,n);case"macro":return this.getMacroPlainText(e);default:throw new Error("Unknown Text Node Type")}}getRecordPlainText(e,n){let r={params:[]};return e.children.filter(i=>i.type!=="comment_group"&&i.type!=="error").map(i=>this.getNodePlainText(i,r)).join("")}onHover(e,n){return null}getCompletions(e){let n=[];for(let r of this.definitions.values())e?n.push(r.map(i=>i.name).filter(i=>i.startsWith(e))):n.push(r.map(i=>i.name).map(i=>{let o=i.indexOf(".");return o===-1?i:i.substring(0,o+1)}));return[...new Set(n.flat())]}onCodeAction(e,n,r){if(e.languageId!=="factorio-locale")return[];let i=this.documentTrees.get(e.uri);if(!i)return[];let o=vy(i,e.uri).filter(u=>!!u.fix),s=o.filter(u=>Wl(n,u.diag.range)),a=[],l=new Set;for(let u of s)if(a.push({title:`Fix this ${u.code}`,kind:_t.CodeActionKind.QuickFix+"."+u.code,diagnostics:[{message:u.message,code:u.code,source:"factorio-locale",severity:_t.DiagnosticSeverity.Error,...u.diag}],isPreferred:!0,edit:{changes:{[e.uri]:Vn(e,u.fix)}}}),!l.has(u.code)){l.add(u.code);let c=o.filter(f=>f.code===u.code);c.length>1&&a.push({title:`Fix all ${u.code} in file`,kind:_t.CodeActionKind.QuickFix+"."+u.code+".all",diagnostics:c.map(f=>({message:f.message,code:f.code,source:"factorio-locale",severity:_t.DiagnosticSeverity.Error,...f.diag})),edit:{changes:{[e.uri]:Vn(e,c.flatMap(f=>f.fix))}}})}return o.length>s.length&&a.push({title:"Fix all auto-fixable in file",kind:_t.CodeActionKind.QuickFix+".all",diagnostics:o.map(u=>({message:u.message,code:u.code,source:"factorio-locale",severity:_t.DiagnosticSeverity.Error,...u.diag})),edit:{changes:{[e.uri]:Vn(e,o.flatMap(u=>u.fix))}}}),a}onDocumentColor(e){let n=[];for(let r=0;r<e.lineCount;r++){let i={start:{line:r,character:0},end:{line:r,character:1/0}},o=e.getText(i).replace(/(\r\n)|\r|\n$/,"");i.end.character=o.length;let s=/\[color=([^\]]+)\]/g,a=s.exec(o);for(;a;){{let l=gI(a[1]);l&&n.push({color:l,range:{start:{line:r,character:a.index+7},end:{line:r,character:a.index+7+a[1].length}}})}a=s.exec(o)}}return n}onColorPresentation(e,n){return yI(e).map(r=>({label:r,textEdit:{range:n,newText:r}}))}};var Sy=ct(cf(),1),hf=class{constructor(e){this.Locale=e}Locale;onDefinition(e,n){let r=n.getText({start:{line:e.position.line,character:0},end:{line:e.position.line,character:Number.MAX_VALUE}});for(let i of r.matchAll(/(['"])((?:[^\\](?<!\1)|\\['"0abfnrtv\\]|\\\d{1,3}|\\x[0-9a-fA-F]{2})*)\1/g))if(i.index&&i.index<=e.position.character&&i.index+i[0].length>=e.position.character){let o=i[2],s={start:{line:e.position.line,character:i.index},end:{line:e.position.line,character:i.index+i[0].length}};return this.Locale.findDefinitionLinks(o).map(l=>Object.assign({originSelectionRange:s},l))}}onCompletion(e,n){let i=n.getText({start:{line:e.position.line,character:0},end:{line:e.position.line,character:e.position.character+1}}).match(/(['"])((?:[^\\](?<!\1)|\\['"0abfnrtv\\]|\\\d{1,3}|\\x[0-9a-fA-F]{2})*)\1$/);if(i){let o=i[2].lastIndexOf("."),s=o!==-1?i[2].substring(0,o+1):"";return this.Locale.getCompletions(s).map(a=>({label:a.endsWith(".")?a.substring(0,a.length-1):a,kind:a.endsWith(".")?Sy.CompletionItemKind.Enum:Sy.CompletionItemKind.EnumMember,commitCharacters:a.endsWith(".")?["."]:[],textEdit:{newText:a.endsWith(".")?a.substring(0,a.length-1):a,range:{start:{line:e.position.line,character:i.index+1},end:{line:e.position.line,character:e.position.character}}}}))}return[]}};async function _I(){let t=new $l,e=new ff,n=new hf(e),r=(0,Ft.createConnection)(Ft.ProposedFeatures.all),i=new Ft.TextDocuments(Pn);async function o(u){let c=i.get(u);if(c)return c;let f=He.parse(u);if(f.scheme==="file"){if(f.path.endsWith(".cfg"))return c=Pn.create(u,"factorio-locale",1,await Ey.readFile(f.fsPath,"utf8")),c;if(f.path.endsWith("changelog.txt"))return c=Pn.create(u,"factorio-changelog",1,await Ey.readFile(f.fsPath,"utf8")),c}}async function s(u){let c=await o(u);if(c)switch(c.languageId){case"factorio-locale":e.loadDocument(c);break;case"factorio-changelog":t.loadDocument(c);break}}async function a(u){let c=He.parse(u);if(c.scheme==="file"){let f=ai(c.fsPath,{pattern:["**/locale/*/*.cfg","**/changelog.txt"]});f.on("match",h=>{s(He.file(h.absolute).toString())}),f.on("error",h=>{throw h}),await new Promise(h=>{f.on("end",()=>{h()})})}}let l=!1;return r.onInitialize(async u=>{let c=u.capabilities;l=!!(c.workspace&&c.workspace.workspaceFolders),e.hasDiagnosticRelatedInformationCapability=!!(c.textDocument&&c.textDocument.publishDiagnostics&&c.textDocument.publishDiagnostics.relatedInformation);let f={capabilities:{textDocumentSync:Ft.TextDocumentSyncKind.Incremental,documentSymbolProvider:!0,codeActionProvider:!0,colorProvider:!0,definitionProvider:!0,completionProvider:{triggerCharacters:['"',"'","."],allCommitCharacters:["."]},hoverProvider:!0}};return l&&(f.capabilities.workspace={workspaceFolders:{supported:!0,changeNotifications:!0}},u.workspaceFolders&&await Promise.all(u.workspaceFolders.map(h=>a(h.uri)))),f}),r.onInitialized(()=>{l&&r.workspace.onDidChangeWorkspaceFolders(async u=>{for(let c of u.removed)e.clearFolder(c.uri),t.clearFolder(c.uri);for(let c of u.added)await a(c.uri)})}),i.onDidClose(u=>{switch(u.document.languageId){case"factorio-locale":r.sendDiagnostics({uri:u.document.uri,diagnostics:[]});break;case"factorio-changelog":r.sendDiagnostics({uri:u.document.uri,diagnostics:[]});break}}),i.onDidChangeContent(u=>{switch(u.document.languageId){case"factorio-locale":e.loadDocument(u.document),r.sendDiagnostics({uri:u.document.uri,diagnostics:e.diagnose(u.document.uri)});break;case"factorio-changelog":t.loadDocument(u.document),r.sendDiagnostics({uri:u.document.uri,diagnostics:t.diagnose(u.document.uri)});break}}),r.onDefinition(async u=>{let c=await o(u.textDocument.uri);return c&&c.languageId==="lua"?n.onDefinition(u,c):null}),r.onCompletion(async u=>{let c=await o(u.textDocument.uri);if(c&&c.languageId==="lua")return{isIncomplete:!0,items:n.onCompletion(u,c)}}),r.onDidChangeWatchedFiles(u=>{for(let c of u.changes)switch(c.type){case Ft.FileChangeType.Deleted:e.clearDocument(c.uri),t.clearDocument(c.uri);break;case Ft.FileChangeType.Changed:case Ft.FileChangeType.Created:o(c.uri).then(f=>{if(f)switch(f.languageId){case"factorio-locale":e.loadDocument(f);break;case"factorio-changelog":t.loadDocument(f);break}});break;default:break}}),r.onHover(u=>{let c=i.get(u.textDocument.uri);return c&&c.languageId==="factorio-locale"?e.onHover(u,c):null}),r.onDocumentSymbol(u=>{let c=i.get(u.textDocument.uri);if(c)switch(c.languageId){case"factorio-locale":return e.onDocumentSymbol(c);case"factorio-changelog":return t.onDocumentSymbol(c)}return null}),r.onCodeAction(u=>{let c=i.get(u.textDocument.uri);if(c)switch(c.languageId){case"factorio-locale":return e.onCodeAction(c,u.range,u.context);case"factorio-changelog":return t.onCodeAction(c,u.range,u.context)}return null}),r.onDocumentColor(u=>{let c=i.get(u.textDocument.uri);return c&&c.languageId==="factorio-locale"?e.onDocumentColor(c):null}),r.onColorPresentation(u=>{let c=i.get(u.textDocument.uri);return c&&c.languageId==="factorio-locale"?e.onColorPresentation(u.color,u.range):null}),i.listen(r),r.listen(),new Promise(u=>{r.onExit(u)})}he.command("lsp").description("Run LSP Server for Locale and Changelog features").allowUnknownOption(!0).allowExcessArguments(!0).action(async()=>{await _I()});import*as xI from"os";import*as vI from"fs/promises";he.command("debug <factorioPath>").description("Launch a DAP debug session").option("-d, --docs <docsPath>","path to runtime-api.json").option("-c, --config <configPath>","path to config.ini").option("-w, --workspace <workspacePath...>","path to workspace folders").action(async(t,e)=>{let n={name:"standalone",factorioPath:t,configPath:e.config,docsPath:e.docs},r=Nt.joinPath(He.file(t),n.docsPath?n.docsPath:xI.platform()==="darwin"?"../../doc-html/runtime-api.json":"../../../doc-html/runtime-api.json"),i=await vI.readFile(r.fsPath,"utf8"),o=new By(wy,n,new Ta(i)),s=new jy(o,wy,{async findWorkspaceFiles(a){let l=[];for(let u of e.workspace??[process.cwd()]){let c=ai(u,{pattern:a});c.on("match",f=>{l.push(He.file(f.absolute))}),c.on("error",f=>{throw f}),await new Promise(f=>{c.on("end",()=>{f()})})}return l}});process.on("SIGTERM",()=>{s.shutdown()}),s.start(process.stdin,process.stdout)});import*as SI from"fs/promises";he.command("scriptdat <file>").description("Dump script.dat").action(async t=>{let e=new Uy(new xr(await SI.readFile(t)));console.log(JSON.stringify({version:e.version.format(),data:e.data},void 0,2))});if(process.env.FMTK_TEST_ARGV)try{let t=JSON.parse(process.env.FMTK_TEST_ARGV);process.argv.push(...t),delete process.env.FMTK_TEST_ARGV}catch(t){console.log(`Error using extra args from FMTK_TEST_ARGV: ${t}`),process.exit(1)}await he.description(`${Iy} ${Ly}`).helpCommand("help").showHelpAfterError().showSuggestionAfterError().parseAsync(process.argv,{from:"node"}).catch(t=>{console.error(t),process.exit(1)}).then(()=>{process.disconnect?.()});
|