amxxpack 1.5.2 → 1.5.3

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/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var bt=Object.create;var Le=Object.defineProperty;var xt=Object.getOwnPropertyDescriptor;var Dt=Object.getOwnPropertyNames;var Pt=Object.getPrototypeOf,St=Object.prototype.hasOwnProperty;var Ft=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports);var Tt=(o,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Dt(e))!St.call(o,r)&&r!==t&&Le(o,r,{get:()=>e[r],enumerable:!(i=xt(e,r))||i.enumerable});return o};var p=(o,e,t)=>(t=o!=null?bt(Pt(o)):{},Tt(e||!o||!o.__esModule?Le(t,"default",{value:o,enumerable:!0}):t,o));var He=Ft((ci,Et)=>{Et.exports={name:"amxxpack",description:"AMXXPack",author:"Hedgehog Fog",version:"1.5.2",license:"MIT",scripts:{test:"jest",build:"tsc && tsup",lint:"eslint",prepare:"npm run build"},main:"lib/index.js",bin:{amxxpack:"./lib/index.js"},files:["lib/**/*","resources/**/*"],repository:{type:"git",url:"https://github.com/Hedgefog/node-amxxpack"},bugs:{url:"https://github.com/Hedgefog/node-amxxpack/issues"},homepage:"https://github.com/Hedgefog/node-amxxpack",keywords:["amx","amxx","amxmodx","sourcemod","smx","cli","pawn","compiler","build","watch"],dependencies:{chokidar:"^4.0.3",colors:"^1.4.0",commander:"^14.0.0",decompress:"^4.2.1",globule:"^1.3.4",lodash:"^4.17.21","node-cache":"^5.1.2","node-fetch":"^2.7.0","normalize-path":"^3.0.0","string-argv":"^0.3.2"},devDependencies:{"@eslint/js":"^9.34.0","@stylistic/eslint-plugin":"^5.3.1","@types/chance":"^1.1.7","@types/decompress":"^4.2.7","@types/glob":"^8.1.0","@types/globule":"^1.1.10","@types/jest":"^28.1.8","@types/lodash":"^4.17.20","@types/node":"^24.3.1","@types/node-fetch":"^2.6.13","@types/normalize-path":"^3.0.2",chance:"^1.1.13",eslint:"^9.34.0",jest:"^28.1.3","ts-jest":"^28.0.8","ts-node":"^10.9.2","tsconfig-paths":"^4.2.0",tsup:"^8.5.0","type-fest":"^4.41.0",typescript:"^4.9.5","typescript-eslint":"^8.41.0"}}});var jt=p(require("readline")),It=require("string-argv");var j=p(require("colors/safe"));var ve=class{constructor(e={}){this.debugMode=e.debug||process.env.NODE_ENV==="development"}debug(...e){this.out("debug",...e)}success(...e){this.out("success",...e)}info(...e){this.out("info",...e)}warn(...e){this.out("warning",...e)}error(...e){this.out("error",...e)}out(e,...t){if(e==="debug"&&!this.debugMode)return;let i=t.map(a=>a instanceof Object?JSON.stringify(a):String(a)).join(" "),r=this.getLevelLabel(e),s=this.colorifyMessageByLevel(e,i),c=new Date().toLocaleTimeString();console.log(`[${c}]`,r,s)}colorifyMessageByLevel(e,t){switch(e){case"debug":return j.default.grey(t);case"success":return j.default.white(t);case"info":return j.default.grey(t);case"warning":return j.default.white(t);case"error":return j.default.white(t)}return t}getLevelLabel(e){switch(e){case"debug":return j.default.grey("[DEBUG]");case"success":return j.default.green("[SUCCESS]");case"info":return j.default.cyan("[INFO]");case"warning":return j.default.yellow("[WARNING]");case"error":return j.default.red("[ERROR]")}return""}},n=new ve;var Be=require("commander");var h=class extends Error{constructor(e){super(e),this.name="CLIError"}};var N=p(require("path")),Me=p(require("os")),Ve=p(require("fs")),Ce=N.default.join(Me.default.tmpdir(),".amxxpack");Ve.default.mkdirSync(Ce,{recursive:!0});var ye=process.env.RESOURCES_DIR||N.default.resolve(require.main.path,"..","resources"),l={title:"AMXXPack",command:"amxxpack",downloadDir:N.default.join(Ce,"downloads"),cacheDir:N.default.join(Ce,"cache"),resourcesDir:ye,templatesDir:N.default.join(ye,"templates"),projectTypesDir:N.default.resolve(ye,"project-types"),version:He().version,project:{defaultVersion:"0.1.0",configFile:".amxxpack.json",defaultType:"amxmodx"}};function $t(o){switch(o.code){case"commander.help":return n.info(`Use '${l.command} --help' to see all available commands`),!0;case"commander.version":return n.info(`${l.title} CLI v${o.message}`),!0}return!1}function J(o,e=!1){if(o instanceof Be.CommanderError){if($t(o)){e||process.exit(0);return}n.error(o.message)}else o instanceof Error?n.error(o.message):n.error("Unknown error");if(!e&&process.env.NODE_ENV==="development")throw o;e||process.exit(1)}var yt=require("commander");var ft=require("commander");function w(o){return async(...e)=>{try{await o(...e)}catch(t){J(t)}}}var tt=require("commander");var S=p(require("path")),F=require("lodash");var g=require("lodash"),K=p(require("path")),q=p(require("fs"));var Rt=(o,e)=>({type:o,input:{scripts:"./src/scripts",include:"./src/include",assets:"./assets"},output:{base:"./dist",scripts:`./addons/${e.addonName}/scripting`,plugins:`./addons/${e.addonName}/plugins`,include:`./addons/${e.addonName}/scripting/include`,assets:"./"},compiler:{dir:"./.compiler",version:e.defaultVersion,dev:!1,addons:[],executable:e.executable},thirdparty:{dir:"./.thirdparty",dependencies:[]},include:[],rules:{flatCompilation:!0,rebuildDependents:!0},cli:{templates:{context:{PLUGIN_VERSION:"1.0.0",PLUGIN_AUTHOR:l.title}}}});function Nt(o){let e=K.default.resolve(l.projectTypesDir,`${o}.json`);if(!q.default.existsSync(e))throw new h(`Unsupported project type: ${o}`);return JSON.parse(q.default.readFileSync(e,"utf8"))}function je(o,e,t){var C;t=t?K.default.resolve(t):process.cwd();let i=Nt(o),r=Rt(o,i),s=(0,g.defaultsDeep)({},e,r),c=((C=e.rules)==null?void 0:C.flatCompilation)??!0,a=m=>K.default.resolve(t,m),d=(m,P,M)=>{var Ne,Oe,ke,Ae;let b=(0,g.isObject)(m)?m:{dir:m},V=(0,g.isObject)(P)?P:{dir:P};return(0,g.defaults)({src:a(b.dir),dest:K.default.resolve(t,s.output.base,V.dir,((Ne=b.output)==null?void 0:Ne.dir)||"."),prefix:[V.prefix,(Oe=b.output)==null?void 0:Oe.prefix].join(""),filter:b.filter?(0,g.castArray)(b.filter):[],flat:(0,g.isNil)((ke=b.output)==null?void 0:ke.flat)&&(0,g.isNil)(V.flat)?void 0:!!((Ae=b.output)!=null&&Ae.flat||V.flat)},M)},f=(m,P,M)=>{var b;return(0,g.isNull)((b=e.output)==null?void 0:b[m])?[]:(0,g.map)((0,g.castArray)(s.input[P]),V=>d(V,s.output[m],M))};return{type:o,path:t,defaults:{...(0,g.pick)(r,["type","input","output","thirdparty","include","cli"]),compiler:(0,g.pick)(r.compiler,["dir","version","addons","executable"])},cli:s.cli,targets:{assets:f("assets","assets",{flat:!1}),include:f("include","include",{flat:!0}),scripts:f("scripts","scripts",{flat:!0}),plugins:f("plugins","scripts",{flat:c})},include:(0,g.map)(s.include,a),compiler:{...s.compiler,dir:a(s.compiler.dir),config:i},thirdparty:{dir:a(s.thirdparty.dir),dependencies:(0,g.map)(s.thirdparty.dependencies,m=>({...m,strip:m.strip||0,filter:m.filter||[],type:m.type||null}))},rules:{flatCompilation:s.rules.flatCompilation,rebuildDependents:s.rules.rebuildDependents}}}function ne(o,e){if(!q.default.existsSync(o))throw new h(`Cannot find config file: ${o}`);try{let t=q.default.readFileSync(o,"utf8"),i=JSON.parse(t);return je(i.type||l.project.defaultType,i,e)}catch(t){throw new h(`Failed to read config file: ${o}! ${t instanceof Error?t.message:t}`)}}var Y=p(require("path")),be=p(require("fs")),xe=p(require("normalize-path")),Ge=p(require("decompress")),De=require("lodash"),Je=p(require("os"));var ze=p(require("path")),Ie=p(require("fs")),We=require("stream"),Ue=require("util"),_e=p(require("node-fetch"));async function Ot(o,e){await Ie.default.promises.mkdir(ze.default.dirname(e),{recursive:!0});let t=await(0,_e.default)(o);if(!t.ok)throw new Error(`Download failed: ${t.status} ${t.statusText}`);let i=Ie.default.createWriteStream(e,{flags:"w"});return await(0,Ue.promisify)(We.pipeline)(t.body,i),{url:o,path:e}}var X=Ot;var Z=class{constructor(e){this.projectConfig=e}async download(){let{compiler:e}=this.projectConfig,t=e.dir,i=[...e.addons],r=this.projectConfig.compiler.config.downloader.baseDist;i.includes(r)||i.unshift(r);let s=(0,De.map)(i,a=>this.resolveDist({type:this.projectConfig.type,name:a,version:e.version,dev:e.dev}));n.info("\u{1F53D} Downloading compiler...");let c=await Promise.all((0,De.map)(s,a=>this.downloadDist(a)));n.info("\u{1F4E4} Extracting compiler files...");for(let a of c)await this.extractDist(a.path,t)}async downloadDist(e){let t=await this.getDistFileName(e);if(!t)throw new h("Failed to fetch dist file meta!");let i=this.resolveDownloadDistOpts(t,e),r=await this.downloadFile(i);return{dist:e,path:r.path}}async extractDist(e,t){let{fileExtensions:i}=this.projectConfig.compiler.config;n.info(`\u{1F4E4} Extracting "${Y.default.parse(e).base}"...`),await be.default.promises.mkdir(t,{recursive:!0}),await(0,Ge.default)(e,t,{map:r=>{let s={...r};return(0,xe.default)(s.path).startsWith(this.projectConfig.compiler.config.downloader.compilerDir)&&(s.path=Y.default.relative(this.projectConfig.compiler.config.downloader.compilerDir,s.path)),s},filter:r=>(0,xe.default)(r.path).startsWith(this.projectConfig.compiler.config.downloader.compilerDir)?i.script!==Y.default.extname(r.path).slice(1):!1})}async getDistFileName(e){if(e.dev)return this.resolveFileName(e);if(!this.projectConfig.compiler.config.downloader.useMetaFile)return this.resolveFileName({...e,version:this.projectConfig.compiler.version});let t=this.resolveMetaFileName(e),i=this.resolveDownloadDistOpts(t,e),r=await this.downloadFile(i);return(await be.default.promises.readFile(r.path,"utf8")).trim()}resolveDist(e){let t=this.projectConfig.compiler.config.downloader.baseDist,{type:i,name:r=t,dev:s=!1}=e,c=s?e.version:this.resolveReleaseVersion(e.version||this.projectConfig.compiler.config.defaultVersion);e.version!==c&&r===t&&n.warn(`The "${e.version}" version format is redundant. Change the compiler version to "${c}" in the project configuration to remove this warning.`);let a=this.resolvePlatform();return{type:i,name:r,version:c,platform:a,dev:s}}resolveSource(e){let t=[this.projectConfig.compiler.config.downloader.distSource],i=this.resolveReleaseVersion(e.version);return t.push(i),t.join("/")}resolveDownloadDistOpts(e,t){let i=Y.default.join(l.downloadDir,e),r=this.resolveSource(t);return{url:this.resolveUrl(r,e),path:i}}resolveUrl(e,t){return`${this.projectConfig.compiler.config.downloader.downloadHost}/${e}/${t}`}resolveReleaseVersion(e){return e.split(".").slice(0,2).join(".")}resolveFileName({type:e,name:t,version:i,platform:r}){return[e,i,t,`${r}${r==="linux"?".tar.gz":".zip"}`].filter(Boolean).join("-")}resolveMetaFileName({type:e,name:t,platform:i}){return[e,"latest",t,`${i}`].filter(Boolean).join("-")}resolvePlatform(){let e=Je.default.platform();switch(e){case"win32":return"windows";case"linux":return"linux";case"darwin":return"mac"}throw new h(`Unable to resolve platform for ${e}`)}async downloadFile(e){return n.debug(`Downloading file from "${e.url}" to "${e.path}"`),await X(e.url,e.path)}};var k=p(require("path")),Ye=p(require("decompress")),Ze=p(require("globule")),Qe=p(require("fs")),et=require("url");var $=p(require("fs"));async function kt(o,e){await $.default.promises.access(o,$.default.constants.W_OK|$.default.constants.R_OK);try{await $.default.promises.access(e,$.default.constants.W_OK|$.default.constants.R_OK)}catch(t){if(t.code!=="ENOENT")throw t}await $.default.promises.copyFile(o,e)}var O=kt;var Ke=p(require("chokidar"));function At(o){let e=Ke.default.watch(o,{persistent:!0,ignoreInitial:!0,interval:300,awaitWriteFinish:{stabilityThreshold:50,pollInterval:10}});return process.on("SIGINT",async()=>{await e.close(),process.exit(0)}),e.on("error",t=>{console.error("Watcher failure",t),process.exit(1)}),e}var Pe=At;var qe=p(require("fs"));async function ae(o){let e=await qe.default.promises.readFile(o,"utf8"),t=/^\s*#(tryinclude|include)\s+(?:(?:"([^"]+)")|(?:<([^>]+)>))/gm,i=[],r;for(;r=t.exec(e);){let s=r[2]!=="tryinclude";r[2]?i.push({name:r[2],type:"relative",required:s}):r[3]&&i.push({name:r[3],type:"native",required:s})}return i}function Lt(){let o="";return e=>(o+=(e==null?void 0:e.toString())||"",o)}var Se=Lt;var Xe=["zip","tar","tar.gz","tar.bz2"];var Q=class{constructor(e){this.projectConfig=e}async download(){for(let e of this.projectConfig.thirdparty.dependencies)n.info(`\u{1F53D} Downloading "${e.name}" thirdparty...`),await this.downloadDependency(e)}async downloadDependency(e){let t=k.default.join(l.downloadDir,e.name),i=new et.URL(e.url).pathname,{base:r}=k.default.parse(i)||{},s=r||k.default.parse(t).base;await X(e.url,t);let c=k.default.join(this.projectConfig.thirdparty.dir,e.name);if(await Qe.default.promises.mkdir(c,{recursive:!0}),e.type==="archive"||Xe.includes(k.default.extname(s).slice(1))){n.info(`\u{1F4E4} Extracting "${e.name}" thirdparty...`),await(0,Ye.default)(t,c,{strip:e.strip,filter:e.filter&&e.filter.length&&(a=>Ze.default.isMatch(e.filter,a.path,{dot:!0,nocase:!0,matchBase:!0}))});return}n.info(`\u27A1\uFE0F Copying "${e.name}" thirdparty...`),await O(t,k.default.join(c,s))}};var ce=class{constructor(e){this.compilerDownloader=new Z(e),this.thirdpartyDownloader=new Q(e)}async downloadCompiler(){await this.compilerDownloader.download()}async downloadThirdparty(){await this.thirdpartyDownloader.download()}};var le=p(require("fs")),Fe=p(require("path")),x=require("lodash");var B=class{constructor(e,t,i){this.projectConfig=e;this.context=null;this.rawIncludes=null;this.context=(0,x.defaults)((0,x.merge)({},this.projectConfig.cli.templates.context,t),i)}async buildTemplate(e,t){let{templateDir:i}=this.projectConfig.compiler.config.cli,r=(0,x.get)(this.projectConfig.cli.templates.files,e,Fe.default.join(l.templatesDir,`${i}/${e}.txt`));return(await le.default.promises.readFile(r,"utf8")).replace(/\{\{([a-zA-Z0-9_]+)\}\}/gm,(a,...d)=>{let[f]=d;return(0,x.get)(t,f,(0,x.get)(this.context,f,a))})}async createFile(e,t,i){let{dir:r}=Fe.default.parse(e);await le.default.promises.mkdir(r,{recursive:!0});let s=(await Promise.all((0,x.map)(this.context.INCLUDES,c=>this.buildTemplate("include-directive",{FILE:c})))).join(`
2
+ "use strict";var bt=Object.create;var Le=Object.defineProperty;var xt=Object.getOwnPropertyDescriptor;var Dt=Object.getOwnPropertyNames;var Pt=Object.getPrototypeOf,St=Object.prototype.hasOwnProperty;var Ft=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports);var Tt=(o,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Dt(e))!St.call(o,r)&&r!==t&&Le(o,r,{get:()=>e[r],enumerable:!(i=xt(e,r))||i.enumerable});return o};var p=(o,e,t)=>(t=o!=null?bt(Pt(o)):{},Tt(e||!o||!o.__esModule?Le(t,"default",{value:o,enumerable:!0}):t,o));var He=Ft((ci,Et)=>{Et.exports={name:"amxxpack",description:"AMXXPack",author:"Hedgehog Fog",version:"1.5.3",license:"MIT",scripts:{test:"jest",build:"tsc && tsup",lint:"eslint",prepare:"npm run build"},main:"lib/index.js",bin:{amxxpack:"./lib/index.js"},files:["lib/**/*","resources/**/*"],repository:{type:"git",url:"https://github.com/Hedgefog/node-amxxpack"},bugs:{url:"https://github.com/Hedgefog/node-amxxpack/issues"},homepage:"https://github.com/Hedgefog/node-amxxpack",keywords:["amx","amxx","amxmodx","sourcemod","smx","cli","pawn","compiler","build","watch"],dependencies:{chokidar:"^4.0.3",colors:"^1.4.0",commander:"^14.0.0",decompress:"^4.2.1",globule:"^1.3.4",lodash:"^4.17.21","node-cache":"^5.1.2","node-fetch":"^2.7.0","normalize-path":"^3.0.0","string-argv":"^0.3.2"},devDependencies:{"@eslint/js":"^9.34.0","@stylistic/eslint-plugin":"^5.3.1","@types/chance":"^1.1.7","@types/decompress":"^4.2.7","@types/glob":"^8.1.0","@types/globule":"^1.1.10","@types/jest":"^28.1.8","@types/lodash":"^4.17.20","@types/node":"^24.3.1","@types/node-fetch":"^2.6.13","@types/normalize-path":"^3.0.2",chance:"^1.1.13",eslint:"^9.34.0",jest:"^28.1.3","ts-jest":"^28.0.8","ts-node":"^10.9.2","tsconfig-paths":"^4.2.0",tsup:"^8.5.0","type-fest":"^4.41.0",typescript:"^4.9.5","typescript-eslint":"^8.41.0"}}});var jt=p(require("readline")),It=require("string-argv");var j=p(require("colors/safe"));var ve=class{constructor(e={}){this.debugMode=e.debug||process.env.NODE_ENV==="development"}debug(...e){this.out("debug",...e)}success(...e){this.out("success",...e)}info(...e){this.out("info",...e)}warn(...e){this.out("warning",...e)}error(...e){this.out("error",...e)}out(e,...t){if(e==="debug"&&!this.debugMode)return;let i=t.map(a=>a instanceof Object?JSON.stringify(a):String(a)).join(" "),r=this.getLevelLabel(e),s=this.colorifyMessageByLevel(e,i),c=new Date().toLocaleTimeString();console.log(`[${c}]`,r,s)}colorifyMessageByLevel(e,t){switch(e){case"debug":return j.default.grey(t);case"success":return j.default.white(t);case"info":return j.default.grey(t);case"warning":return j.default.white(t);case"error":return j.default.white(t)}return t}getLevelLabel(e){switch(e){case"debug":return j.default.grey("[DEBUG]");case"success":return j.default.green("[SUCCESS]");case"info":return j.default.cyan("[INFO]");case"warning":return j.default.yellow("[WARNING]");case"error":return j.default.red("[ERROR]")}return""}},n=new ve;var Be=require("commander");var h=class extends Error{constructor(e){super(e),this.name="CLIError"}};var N=p(require("path")),Me=p(require("os")),Ve=p(require("fs")),Ce=N.default.join(Me.default.tmpdir(),".amxxpack");Ve.default.mkdirSync(Ce,{recursive:!0});var ye=process.env.RESOURCES_DIR||N.default.resolve(require.main.path,"..","resources"),l={title:"AMXXPack",command:"amxxpack",downloadDir:N.default.join(Ce,"downloads"),cacheDir:N.default.join(Ce,"cache"),resourcesDir:ye,templatesDir:N.default.join(ye,"templates"),projectTypesDir:N.default.resolve(ye,"project-types"),version:He().version,project:{defaultVersion:"0.1.0",configFile:".amxxpack.json",defaultType:"amxmodx"}};function $t(o){switch(o.code){case"commander.help":return n.info(`Use '${l.command} --help' to see all available commands`),!0;case"commander.version":return n.info(`${l.title} CLI v${o.message}`),!0}return!1}function J(o,e=!1){if(o instanceof Be.CommanderError){if($t(o)){e||process.exit(0);return}n.error(o.message)}else o instanceof Error?n.error(o.message):n.error("Unknown error");if(!e&&process.env.NODE_ENV==="development")throw o;e||process.exit(1)}var yt=require("commander");var ft=require("commander");function w(o){return async(...e)=>{try{await o(...e)}catch(t){J(t)}}}var tt=require("commander");var S=p(require("path")),F=require("lodash");var g=require("lodash"),K=p(require("path")),q=p(require("fs"));var Rt=(o,e)=>({type:o,input:{scripts:"./src/scripts",include:"./src/include",assets:"./assets"},output:{base:"./dist",scripts:`./addons/${e.addonName}/scripting`,plugins:`./addons/${e.addonName}/plugins`,include:`./addons/${e.addonName}/scripting/include`,assets:"./"},compiler:{dir:"./.compiler",version:e.defaultVersion,dev:!1,addons:[],executable:e.executable},thirdparty:{dir:"./.thirdparty",dependencies:[]},include:[],rules:{flatCompilation:!0,rebuildDependents:!0},cli:{templates:{context:{PLUGIN_VERSION:"1.0.0",PLUGIN_AUTHOR:l.title}}}});function Nt(o){let e=K.default.resolve(l.projectTypesDir,`${o}.json`);if(!q.default.existsSync(e))throw new h(`Unsupported project type: ${o}`);return JSON.parse(q.default.readFileSync(e,"utf8"))}function je(o,e,t){var C;t=t?K.default.resolve(t):process.cwd();let i=Nt(o),r=Rt(o,i),s=(0,g.defaultsDeep)({},e,r),c=((C=e.rules)==null?void 0:C.flatCompilation)??!0,a=m=>K.default.resolve(t,m),d=(m,P,M)=>{var Ne,Oe,ke,Ae;let b=(0,g.isObject)(m)?m:{dir:m},V=(0,g.isObject)(P)?P:{dir:P};return(0,g.defaults)({src:a(b.dir),dest:K.default.resolve(t,s.output.base,V.dir,((Ne=b.output)==null?void 0:Ne.dir)||"."),prefix:[V.prefix,(Oe=b.output)==null?void 0:Oe.prefix].join(""),filter:b.filter?(0,g.castArray)(b.filter):[],flat:(0,g.isNil)((ke=b.output)==null?void 0:ke.flat)&&(0,g.isNil)(V.flat)?void 0:!!((Ae=b.output)!=null&&Ae.flat||V.flat)},M)},f=(m,P,M)=>{var b;return(0,g.isNull)((b=e.output)==null?void 0:b[m])?[]:(0,g.map)((0,g.castArray)(s.input[P]),V=>d(V,s.output[m],M))};return{type:o,path:t,defaults:{...(0,g.pick)(r,["type","input","output","thirdparty","include","cli"]),compiler:(0,g.pick)(r.compiler,["dir","version","addons","executable"])},cli:s.cli,targets:{assets:f("assets","assets",{flat:!1}),include:f("include","include",{flat:!0}),scripts:f("scripts","scripts",{flat:!0}),plugins:f("plugins","scripts",{flat:c})},include:(0,g.map)(s.include,a),compiler:{...s.compiler,dir:a(s.compiler.dir),config:i},thirdparty:{dir:a(s.thirdparty.dir),dependencies:(0,g.map)(s.thirdparty.dependencies,m=>({...m,strip:m.strip||0,filter:m.filter||[],type:m.type||null}))},rules:{flatCompilation:s.rules.flatCompilation,rebuildDependents:s.rules.rebuildDependents}}}function ne(o,e){if(!q.default.existsSync(o))throw new h(`Cannot find config file: ${o}`);try{let t=q.default.readFileSync(o,"utf8"),i=JSON.parse(t);return je(i.type||l.project.defaultType,i,e)}catch(t){throw new h(`Failed to read config file: ${o}! ${t instanceof Error?t.message:t}`)}}var Y=p(require("path")),be=p(require("fs")),xe=p(require("normalize-path")),Ge=p(require("decompress")),De=require("lodash"),Je=p(require("os"));var ze=p(require("path")),Ie=p(require("fs")),We=require("stream"),Ue=require("util"),_e=p(require("node-fetch"));async function Ot(o,e){await Ie.default.promises.mkdir(ze.default.dirname(e),{recursive:!0});let t=await(0,_e.default)(o);if(!t.ok)throw new Error(`Download failed: ${t.status} ${t.statusText}`);let i=Ie.default.createWriteStream(e,{flags:"w"});return await(0,Ue.promisify)(We.pipeline)(t.body,i),{url:o,path:e}}var X=Ot;var Z=class{constructor(e){this.projectConfig=e}async download(){let{compiler:e}=this.projectConfig,t=e.dir,i=[...e.addons],r=this.projectConfig.compiler.config.downloader.baseDist;i.includes(r)||i.unshift(r);let s=(0,De.map)(i,a=>this.resolveDist({type:this.projectConfig.type,name:a,version:e.version,dev:e.dev}));n.info("\u{1F53D} Downloading compiler...");let c=await Promise.all((0,De.map)(s,a=>this.downloadDist(a)));n.info("\u{1F4E4} Extracting compiler files...");for(let a of c)await this.extractDist(a.path,t)}async downloadDist(e){let t=await this.getDistFileName(e);if(!t)throw new h("Failed to fetch dist file meta!");let i=this.resolveDownloadDistOpts(t,e),r=await this.downloadFile(i);return{dist:e,path:r.path}}async extractDist(e,t){let{fileExtensions:i}=this.projectConfig.compiler.config;n.info(`\u{1F4E4} Extracting "${Y.default.parse(e).base}"...`),await be.default.promises.mkdir(t,{recursive:!0}),await(0,Ge.default)(e,t,{map:r=>{let s={...r};return(0,xe.default)(s.path).startsWith(this.projectConfig.compiler.config.downloader.compilerDir)&&(s.path=Y.default.relative(this.projectConfig.compiler.config.downloader.compilerDir,s.path)),s},filter:r=>(0,xe.default)(r.path).startsWith(this.projectConfig.compiler.config.downloader.compilerDir)?i.script!==Y.default.extname(r.path).slice(1):!1})}async getDistFileName(e){if(e.dev)return this.resolveFileName(e);if(!this.projectConfig.compiler.config.downloader.useMetaFile)return this.resolveFileName({...e,version:this.projectConfig.compiler.version});let t=this.resolveMetaFileName(e),i=this.resolveDownloadDistOpts(t,e),r=await this.downloadFile(i);return(await be.default.promises.readFile(r.path,"utf8")).trim()}resolveDist(e){let t=this.projectConfig.compiler.config.downloader.baseDist,{type:i,name:r=t,dev:s=!1}=e,c=s?e.version:this.resolveReleaseVersion(e.version||this.projectConfig.compiler.config.defaultVersion);e.version!==c&&r===t&&n.warn(`The "${e.version}" version format is redundant. Change the compiler version to "${c}" in the project configuration to remove this warning.`);let a=this.resolvePlatform();return{type:i,name:r,version:c,platform:a,dev:s}}resolveSource(e){let t=[this.projectConfig.compiler.config.downloader.distSource],i=this.resolveReleaseVersion(e.version);return t.push(i),t.join("/")}resolveDownloadDistOpts(e,t){let i=Y.default.join(l.downloadDir,e),r=this.resolveSource(t);return{url:this.resolveUrl(r,e),path:i}}resolveUrl(e,t){return`${this.projectConfig.compiler.config.downloader.downloadHost}/${e}/${t}`}resolveReleaseVersion(e){return e.split(".").slice(0,2).join(".")}resolveFileName({type:e,name:t,version:i,platform:r}){return[e,i,t,`${r}${r==="linux"?".tar.gz":".zip"}`].filter(Boolean).join("-")}resolveMetaFileName({type:e,name:t,platform:i}){return[e,"latest",t,`${i}`].filter(Boolean).join("-")}resolvePlatform(){let e=Je.default.platform();switch(e){case"win32":return"windows";case"linux":return"linux";case"darwin":return"mac"}throw new h(`Unable to resolve platform for ${e}`)}async downloadFile(e){return n.debug(`Downloading file from "${e.url}" to "${e.path}"`),await X(e.url,e.path)}};var k=p(require("path")),Ye=p(require("decompress")),Ze=p(require("globule")),Qe=p(require("fs")),et=require("url");var $=p(require("fs"));async function kt(o,e){await $.default.promises.access(o,$.default.constants.W_OK|$.default.constants.R_OK);try{await $.default.promises.access(e,$.default.constants.W_OK|$.default.constants.R_OK)}catch(t){if(t.code!=="ENOENT")throw t}await $.default.promises.copyFile(o,e)}var O=kt;var Ke=p(require("chokidar"));function At(o){let e=Ke.default.watch(o,{persistent:!0,ignoreInitial:!0,interval:300,awaitWriteFinish:{stabilityThreshold:50,pollInterval:10}});return process.on("SIGINT",async()=>{await e.close(),process.exit(0)}),e.on("error",t=>{console.error("Watcher failure",t),process.exit(1)}),e}var Pe=At;var qe=p(require("fs"));async function ae(o){let e=await qe.default.promises.readFile(o,"utf8"),t=/^\s*#(tryinclude|include)\s+(?:(?:"([^"]+)")|(?:<([^>]+)>))/gm,i=[],r;for(;r=t.exec(e);){let s=r[2]!=="tryinclude";r[2]?i.push({name:r[2],type:"relative",required:s}):r[3]&&i.push({name:r[3],type:"native",required:s})}return i}function Lt(){let o="";return e=>(o+=(e==null?void 0:e.toString())||"",o)}var Se=Lt;var Xe=["zip","tar","tar.gz","tar.bz2"];var Q=class{constructor(e){this.projectConfig=e}async download(){for(let e of this.projectConfig.thirdparty.dependencies)n.info(`\u{1F53D} Downloading "${e.name}" thirdparty...`),await this.downloadDependency(e)}async downloadDependency(e){let t=k.default.join(l.downloadDir,e.name),i=new et.URL(e.url).pathname,{base:r}=k.default.parse(i)||{},s=r||k.default.parse(t).base;await X(e.url,t);let c=k.default.join(this.projectConfig.thirdparty.dir,e.name);if(await Qe.default.promises.mkdir(c,{recursive:!0}),e.type==="archive"||Xe.includes(k.default.extname(s).slice(1))){n.info(`\u{1F4E4} Extracting "${e.name}" thirdparty...`),await(0,Ye.default)(t,c,{strip:e.strip,filter:e.filter&&e.filter.length&&(a=>Ze.default.isMatch(e.filter,a.path,{dot:!0,nocase:!0,matchBase:!0}))});return}n.info(`\u27A1\uFE0F Copying "${e.name}" thirdparty...`),await O(t,k.default.join(c,s))}};var ce=class{constructor(e){this.compilerDownloader=new Z(e),this.thirdpartyDownloader=new Q(e)}async downloadCompiler(){await this.compilerDownloader.download()}async downloadThirdparty(){await this.thirdpartyDownloader.download()}};var le=p(require("fs")),Fe=p(require("path")),x=require("lodash");var B=class{constructor(e,t,i){this.projectConfig=e;this.context=null;this.rawIncludes=null;this.context=(0,x.defaults)((0,x.merge)({},this.projectConfig.cli.templates.context,t),i)}async buildTemplate(e,t){let{templateDir:i}=this.projectConfig.compiler.config.cli,r=(0,x.get)(this.projectConfig.cli.templates.files,e,Fe.default.join(l.templatesDir,`${i}/${e}.txt`));return(await le.default.promises.readFile(r,"utf8")).replace(/\{\{([a-zA-Z0-9_]+)\}\}/gm,(a,...d)=>{let[f]=d;return(0,x.get)(t,f,(0,x.get)(this.context,f,a))})}async createFile(e,t,i){let{dir:r}=Fe.default.parse(e);await le.default.promises.mkdir(r,{recursive:!0});let s=(await Promise.all((0,x.map)(this.context.INCLUDES,c=>this.buildTemplate("include-directive",{FILE:c})))).join(`
3
3
  `);await le.default.promises.writeFile(e,await this.buildTemplate(t,{INCLUDES:s}),{flag:i?"w":"wx"}),n.info("\u{1F4C4} New file created:",e)}};var T=class{constructor(e){this.projectConfig=ne(e)}async install(e){let t=new ce(this.projectConfig);e.compiler&&await t.downloadCompiler(),e.thirdparty&&await t.downloadThirdparty()}async createScript(e,t){let{config:{fileExtensions:i,cli:{defaultIncludes:r}}}=this.projectConfig.compiler,s=(0,F.first)(this.projectConfig.targets.scripts),{name:c,dir:a}=S.default.parse(e);await this.createTemplateService(e,{FILE_NAME:e,PLUGIN_NAME:t.title,PLUGIN_VERSION:t.version,PLUGIN_AUTHOR:t.author,INCLUDES:(0,F.uniq)([...r,...t.include||[]])}).createFile(S.default.join(s.src,a,`${c}.${i.script}`),"script",t.overwrite||!1)}async createInclude(e,t={}){let{config:{fileExtensions:i,cli:{defaultIncludes:r}}}=this.projectConfig.compiler,s=(0,F.first)(this.projectConfig.targets.include),{name:c,dir:a}=S.default.parse(e);await this.createTemplateService(e,{FILE_NAME:e,INCLUDES:(0,F.uniq)([...r,...t.include||[]])}).createFile(S.default.join(s.src,a,`${c}.${i.include}`),"include",t.overwrite||!1)}async createLibrary(e,t){let{config:{fileExtensions:i,cli:{defaultIncludes:r}}}=this.projectConfig.compiler,s=(0,F.first)(this.projectConfig.targets.scripts),c=(0,F.first)(this.projectConfig.targets.include),{name:a,dir:d}=S.default.parse(e),f=this.createTemplateService(e,{FILE_NAME:e,PLUGIN_NAME:t.title,PLUGIN_VERSION:t.version,PLUGIN_AUTHOR:t.author,LIBRARY_NAME:t.name||a.replace(/-/g,"_"),INCLUDES:(0,F.uniq)([...r,...t.include||[]]),INCLUDE_NAME:a});await f.createFile(S.default.join(s.src,d,`${a}.${i.script}`),"library-script",t.overwrite||!1),await f.createFile(S.default.join(c.src,`${a}.${i.include}`),"library-include",t.overwrite||!1)}createTemplateService(e,t){let{name:i}=S.default.parse(e);return new B(this.projectConfig,t,{PLUGIN_NAME:i})}};var pe=new tt.Command;pe.command("script").alias("s").arguments("<filename>").option("--title, -n <title>","Plugin title").option("--version, -v <version>","Plugin version").option("--author, -a <author>","Plugin author").option("--include, -i <include>","Add include",o=>o.split(/[\s|,]/),[]).option("--overwrite","Overwrite file if it already exists",!1).option("--config, -c <path>","Config file",l.project.configFile).action(w(async(o,e)=>{let{title:t,version:i,author:r,include:s,overwrite:c,config:a}=e;await new T(a).createScript(o,{title:t,version:i,author:r,include:s,overwrite:c})}));pe.command("include").alias("i").arguments("<filename>").option("--include, -i <include>","Add include",o=>o.split(/[\s|,]/),[]).option("--overwrite","Overwrite file if it already exists",!1).option("--config, -c <path>","Config file",l.project.configFile).action(w(async(o,e)=>{let{include:t,overwrite:i,config:r}=e;await new T(r).createInclude(o,{include:t,overwrite:i})}));pe.command("library").alias("lib").alias("l").arguments("<filename>").option("--title, -t <title>","Library title").option("--version, -v <version>","Library version").option("--author, -a <author>","Library author").option("--name, -n <name>","Library name").option("--include, -i <include>","Add include",o=>o.split(/[\s|,]/),[]).option("--overwrite","Overwrite file if it already exists",!1).option("--config, -c <path>","Config file",l.project.configFile).action(w(async(o,e)=>{let{name:t,title:i,version:r,author:s,include:c,overwrite:a,config:d}=e;await new T(d).createLibrary(o,{name:t,title:i,version:r,author:s,include:c,overwrite:a})}));var it=pe;var u=p(require("path")),ue=p(require("globule")),v=p(require("normalize-path")),A=require("lodash"),E=p(require("fs"));var de=p(require("path")),ot=p(require("child_process")),st=p(require("fs"));var nt=require("lodash");var rt={filename:/([a-zA-Z0-9.\-_/:\\\s]+)/,line:/\(([0-9]+)(?:\s--\s([0-9]+))?\)/,type:/((?:fatal\s)?error|warning)/,code:/([0-9]+)/,text:/(.*)/};function Vt(){let{filename:o,line:e,type:t,code:i,text:r}=rt,s=[o,e,/\s:\s/,t,/\s/,i,/:\s/,r].map(c=>c.toString().slice(1,-1)).join("");return new RegExp(s)}var Bt=Vt();function zt(o){let e=o.match(Bt);if(!e)return{type:"echo",text:o};let[,t,i,r,s,c,a]=e;return{filename:t,startLine:+i,endLine:r?+r:-1,type:s,code:+c,text:a}}function Wt(o){return o.startsWith("Compilation aborted.")||o.startsWith("Could not locate output file")}function Ut(o){let e={messages:[],aborted:!1,error:!1};return o.split(`
4
4
  `).forEach(t=>{let i=zt(t),{type:r}=i;r==="error"||r==="fatal error"?e.error=!0:r==="echo"&&Wt(t)&&(e.error=!0,e.aborted=!0),e.messages.push(i)}),e}function _t(o,e){return[o.path,`-o${e}`,...(0,nt.castArray)(o.includeDir).map(t=>`-i${t}`)]}function Gt(o){let e=o.dest,t=de.default.parse(e),i=de.default.parse(e).base;return st.default.mkdirSync(t.dir,{recursive:!0}),new Promise(r=>{let s=Se(),c=d=>{let f=s(),C=Ut(f),m=d&&d.message;!m&&C.error&&(m="Compilation error"),r({error:m,plugin:i,success:!m,output:C})},a=ot.default.spawn(o.compiler,_t(o,e),{env:process.env,cwd:de.default.parse(o.compiler).dir});a.on("error",c),a.on("close",c),a.stdout.on("data",s),a.stderr.on("data",d=>console.error(d))})}var Te=Gt;var W=p(require("fs")),ee=p(require("path")),ct=p(require("crypto")),lt=p(require("node-cache")),U=p(require("normalize-path")),pt=p(require("globule"));var Ee=(r=>(r.Hash="h",r.Dependencies="d",r.DependenciesHash="dh",r.Dependents="dt",r))(Ee||{});var at=p(require("crypto"));function z(o){let e=at.default.createHash("sha256");return e.update(o),e.digest("hex")}var te=class{constructor(e,t,i=[],r=3600*24*30){this.includeDirs=e;this.fileExtensions=t;this.ttl=r;this.changed=!1;this.cache=new lt.default,this.ignoredIncludesSet=new Set(i),this.filePathHashMap=new Map}clear(){this.cache.data={},this.changed=!0}save(e){this.changed&&(W.default.writeFileSync(e,JSON.stringify(this.cache.data)),this.changed=!1)}load(e){if(!W.default.existsSync(e))return;let t=W.default.readFileSync(e,"utf8");this.cache.data=JSON.parse(t),this.changed=!1}async isRelevantSrc(e){let t=this.getValue(e,"h");if(!t||await this.createFileHash(e)!==t)return!1;let r=this.getDependencies(e),s=await this.getFilesHash(r.items);return r.hash===s}async isRelevantFile(e){let t=await this.createFileHash(e);if(!t)return!1;let i=this.getValue(e,"h");return t===i}async updateSrc(e){let t=this.getValue(e,"h"),i=await this.updateFileHash(e),r=await this.updateDependencies(e);return t!==i||r}async updateFile(e){let t=this.getValue(e,"h"),i=await this.updateFileHash(e);return t!==i}async deleteFile(e){let t=this.getDependencies(e);for(let i of t.items)this.removeDependent(i,e);for(let i of Object.values(Ee))this.deleteValue(e,i)}isDependenciesInitialized(e){return this.hasValue(e,"d")}getDependencies(e){let t=this.getValue(e,"d"),i=this.getValue(e,"dh");return i?{items:t||[],hash:i}:{items:[],hash:null}}async updateDependencies(e){let t=this.hasValue(e,"d")?this.getValue(e,"d"):[],i=this.hasValue(e,"dh")?this.getValue(e,"dh"):null,r=new Set(await this.parseDependencies(e));for(let d of r.values()){this.isDependenciesInitialized(d)||await this.updateDependencies(d);for(let f of this.getDependencies(d).items)r.add(f)}let s=Array.from(r),c=await this.getFilesHash(s);if(i===c)return!1;this.setValue(e,"d",s),this.setValue(e,"dh",c);for(let d of t)r.has(d)||this.removeDependent(d,e);let a=this.getDependents(e);for(let d of s){this.addDependent(d,e);for(let f of a)this.addDependent(d,f)}return!0}getDependents(e){return this.hasValue(e,"dt")?this.getValue(e,"dt"):[]}addDependent(e,t){t=(0,U.default)(t);let i=this.hasValue(e,"dt")?this.getValue(e,"dt"):[],r=new Set(i);r.has(t)||(r.add(t),this.setValue(e,"dt",Array.from(r)),n.debug(`Added dependent: ${e} <- ${t}`))}removeDependent(e,t){if(!this.hasValue(e,"dt"))return;t=(0,U.default)(t);let i=this.getValue(e,"dt"),r=new Set(i);r.delete(t),this.setValue(e,"dt",Array.from(r)),n.debug(`Remove dependent: ${e} <- ${t}`)}async parseDependencies(e){let t=new Set,i=await ae(e);for(let r of i)if(r.type=="native"){if(this.ignoredIncludesSet.has(r.name))continue;for(let s of this.includeDirs){let c=`${r.name}.${this.fileExtensions.include}`,[a]=pt.default.find(ee.default.join(s,"**",`${c}`),{nodir:!0});if(a){t.add((0,U.default)(a));break}}}else{let c=ee.default.extname(r.name).slice(1)?r.name:`${r.name}.${this.fileExtensions.include}`,a=ee.default.resolve(ee.default.dirname(e),c);t.add((0,U.default)(a))}return Array.from(t)}async getFilesHash(e){let t=ct.default.createHash("sha256");for(let i of e){let r=this.hasValue(i,"h")?this.getValue(i,"h"):await this.updateFileHash(i);t.update(r)}return t.digest("hex")}async updateFileHash(e){let t=await this.createFileHash(e);return this.setValue(e,"h",t),t}async createFileHash(e){if(!W.default.existsSync(e))return null;let t=await W.default.promises.readFile(e);return z(t)}hasValue(e,t){let i=this.cache.get(this.getFileCacheKey(e));return i?!!i[t]:!1}getValue(e,t){let i=this.cache.get(this.getFileCacheKey(e));return i?i[t]:null}setValue(e,t,i){if(i===this.getValue(e,t))return;let r=this.getFileCacheKey(e);this.cache.set(r,{...this.cache.get(r),[t]:i},this.ttl),this.changed=!0}deleteValue(e,t){let i=this.getFileCacheKey(e);this.cache.set(i,{...this.cache.get(i),[t]:void 0},this.ttl),this.changed=!0}getFileCacheKey(e){let t=(0,U.default)(e);if(!this.filePathHashMap.has(t)){let i=z(t);this.filePathHashMap.set(t,i)}return this.filePathHashMap.get(t)}};var ie=class{constructor(e,t={}){this.projectConfig=e;this.options=t;this.cache=null;this.options.noCache||(this.cacheFile=u.default.join(l.cacheDir,`${z((0,v.default)(this.projectConfig.path))}.json`),this.initCache()),this.fileTargetsMap=new Map,this.watchingTargets=new Map,this.watcher=null,this.scriptsPathPattern=`**/*.${e.compiler.config.fileExtensions.script}`,this.includePathPattern=`**/*.${e.compiler.config.fileExtensions.include}`,this.assetsPathPattern="**/*.*"}async buildInclude(){for(let e of this.projectConfig.targets.include)await this.buildDir(e,this.includePathPattern,async t=>{await this.updateInclude(t),await this.updateDependents(t)})}async buildAssets(){for(let e of this.projectConfig.targets.assets)await this.buildDir(e,this.assetsPathPattern,t=>this.updateAsset(t))}async buildScripts(e={}){let{fileExtensions:t}=this.projectConfig.compiler.config,i=!0;for(let r of this.projectConfig.targets.scripts)await this.buildDir(r,e.pattern?u.default.join("**",e.pattern):this.scriptsPathPattern,async s=>{if(t.script===u.default.extname(s).slice(1)&&(e.skipCompilation?i=await this.updateScript(s)&&i:i=await this.updateScriptAndPlugin(s)&&i,!i&&!e.ignoreErrors))throw new h("Build failed!")});return i}async watchAssets(){for(let e of this.projectConfig.targets.assets)this.addTargetToWatcher(e,t=>this.updateAsset(t))}async watchInclude(){for(let e of this.projectConfig.targets.include)this.addTargetToWatcher(e,async t=>{await this.updateInclude(t)&&await this.rebuildDependents(t)})}async watchScripts(){for(let e of this.projectConfig.targets.scripts)this.addTargetToWatcher(e,t=>this.updateScriptAndPlugin(t))}async updateScript(e){let t=!0;this.cache&&(t=await this.cache.updateSrc(e));let i=this.getFileTarget(e);if(i.dest){let r=this.resolveDestPath(e,i);if(this.cache&&!t&&await this.cache.isRelevantFile(r))return!1;await E.default.promises.mkdir(u.default.dirname(r),{recursive:!0}),await O(e,r),this.cache&&await this.cache.updateFile(r),n.info("\u{1F4C4} Script updated:",(0,v.default)(r))}return!0}async updateAsset(e){let t=!0;this.cache&&(t=await this.cache.updateFile(e));let i=this.getFileTarget(e);if(i.dest){let r=this.resolveDestPath(e,i);if(this.cache&&!t&&await this.cache.isRelevantFile(r))return!1;await E.default.promises.mkdir(u.default.dirname(r),{recursive:!0}),await O(e,r),this.cache&&await this.cache.updateFile(r),n.info("\u{1F9F8} Asset updated:",(0,v.default)(r))}}async updateInclude(e){if(this.cache&&!await this.cache.updateSrc(e))return!1;let t=this.getFileTarget(e);if(t.dest){let i=this.resolveDestPath(e,t);await E.default.promises.mkdir(u.default.dirname(i),{recursive:!0}),await O(e,i),n.info("\u{1F4C4} Include updated:",(0,v.default)(i))}return!0}async updatePlugin(e){try{if(!await this.compileScript(e))return!1}catch(t){if(!this.options.ignoreErrors)throw t;return!1}return!0}async updateScriptAndPlugin(e){return await this.updatePlugin(e)?(await this.updateScript(e),!0):!1}async compileScript(e){let t=this.getPluginTarget(e);if(!t)return!0;let i=u.default.relative(process.cwd(),e),r=this.resolvePluginDestPath(e,t);if(this.cache){let a=await this.cache.isRelevantSrc(e),d=await this.cache.isRelevantFile(r);if(a&&d)return n.info("\u{1F4C4} Script is already up to date:",(0,v.default)(i),"Skipped!"),!0}let s=u.default.join(this.projectConfig.compiler.dir,this.projectConfig.compiler.executable);await E.default.promises.mkdir(u.default.dirname(r),{recursive:!0});let c=await Te({path:e,dest:r,compiler:s,includeDir:[u.default.join(this.projectConfig.compiler.dir,"include"),...this.projectConfig.include,...(0,A.map)(ue.default.find((0,A.map)(this.projectConfig.targets.include,a=>u.default.join(a.src,"**/"))),a=>u.default.resolve(a))]});return this.cache&&(c.error?await this.cache.deleteFile(r):await this.cache.updateFile(r)),c.output.messages.forEach(a=>{let{startLine:d,type:f,code:C,text:m,filename:P}=a,M=P?u.default.relative(process.cwd(),P):i;f==="error"||f==="fatal error"?n.error(`${(0,v.default)(M)}:${d}`,"-",f,C,":",m):f==="warning"?n.warn(`${(0,v.default)(M)}:${d}`,"-",f,C,":",m):f==="echo"&&n.debug(m)}),c.success?(n.success("Script compiled successfully:",(0,v.default)(i)),n.info("\u{1F9E9} Plugin updated:",(0,v.default)(r))):n.error(`Failed to compile ${(0,v.default)(i)} : "${c.error}"`),c.success}async rebuildDependents(e){if(!this.cache||!this.projectConfig.rules.rebuildDependents)return;let{fileExtensions:t}=this.projectConfig.compiler.config,i=this.cache.getDependents(e);for(let r of i)t.script===u.default.extname(r).slice(1)&&await this.updateScriptAndPlugin(r)}async buildDir(e,t,i){await ue.default.find(u.default.join(e.src,t),{nodir:!0}).reduce((s,c)=>s.then(async()=>{if(e.filter){let a=u.default.relative(e.src,c);if(!this.execPathFilter(a,e.filter))return}this.setFileTarget(c,e),await i(u.default.normalize(c)),this.cache&&this.cache.save(this.cacheFile)}),Promise.resolve())}addTargetToWatcher(e,t){this.watcher||this.setupWatcher(),this.watchingTargets.set(e,t),this.watcher.add(e.src),n.debug("New target added to the watcher:",e)}setupWatcher(){if(this.watcher)throw new h("Watcher already setup!");let e=async t=>{let i=this.getFileTarget(t);if(i){if(i.filter){let r=u.default.relative(i.src,t);if(!this.execPathFilter(r,i.filter))return}n.info("\u{1F539} File change detected. Starting incremental compilation..."),await this.watchingTargets.get(i)(u.default.normalize(t)).catch(r=>n.error(r.message)),n.info("\u{1F539} Compilation complete. Watching for file changes."),this.cache&&this.cache.save(this.cacheFile)}};this.watcher=Pe([]).on("change",e).on("add",async t=>{this.setFileTarget(t,this.findFileTarget(t)),await e(t)}).on("unlink",async t=>{this.cache&&(await this.cache.deleteFile(t),this.removeFileTarget(t))})}initCache(){E.default.mkdirSync(u.default.dirname(this.cacheFile),{recursive:!0});let e=this.getNativeIncludes();this.cache=new te((0,A.map)(this.projectConfig.targets.include,"src"),this.projectConfig.compiler.config.fileExtensions,e),this.cache.load(this.cacheFile)}getNativeIncludes(){let{fileExtensions:e}=this.projectConfig.compiler.config,t=[];for(let i of this.projectConfig.include)for(let r of E.default.readdirSync(i)){let{name:s,ext:c}=u.default.parse(r);c.slice(1)==e.include&&t.push(s)}return t}setFileTarget(e,t){this.fileTargetsMap.set((0,v.default)(e),t),n.debug("File target set:",e)}getFileTarget(e){let t=(0,v.default)(e);if(!this.fileTargetsMap.has(t)){let i=this.findFileTarget(e);i||n.debug("File target not found:",e),this.fileTargetsMap.set(t,i)}return this.fileTargetsMap.get(t)}removeFileTarget(e){n.debug("File target removed:",e),this.fileTargetsMap.delete((0,v.default)(e))}findFileTarget(e){return this.execPathFilter(e,this.scriptsPathPattern)?this.projectConfig.targets.scripts.find(t=>this.isPathMatchTarget(e,t)):this.execPathFilter(e,this.includePathPattern)?this.projectConfig.targets.include.find(t=>this.isPathMatchTarget(e,t)):this.execPathFilter(e,this.assetsPathPattern)?this.projectConfig.targets.assets.find(t=>this.isPathMatchTarget(e,t)):null}getPluginTarget(e){let t=(0,v.default)(e),i=`plugin:${t}`;if(!this.fileTargetsMap.has(i)){let r=this.getFileTarget(t);if(!r)throw new h(`Source file ${t} not found in any target`);this.fileTargetsMap.set(`plugin:${t}`,(0,A.find)(this.projectConfig.targets.plugins,{src:r.src}))}return this.fileTargetsMap.get(i)}isPathMatchTarget(e,t){return this.execPathFilter(e,u.default.join(t.src,"**"))}execPathFilter(e,t){return!t||Array.isArray(t)&&!t.length?!0:ue.default.isMatch(t,e,{dot:!0,nocase:!0,matchBase:!0})}resolveDestPath(e,t){let{dir:i,base:r}=u.default.parse(e),s=t.flat?".":u.default.relative(t.src,i);return u.default.join(t.dest,s,`${t.prefix}${r}`)}resolvePluginDestPath(e,t){let{fileExtensions:i}=this.projectConfig.compiler.config,r=this.getFileTarget(e),s=t.flat?".":u.default.relative(r.src,u.default.dirname(e)),{name:c}=u.default.parse(e);return u.default.join(t.dest,s,`${t.prefix}${c}.${i.plugin}`)}async updateDependents(e){if(!this.cache)return;let t=await Promise.all((0,A.map)(this.cache.getDependents(e),async i=>({path:i,exists:await E.default.promises.access(i,E.default.constants.F_OK).then(()=>!0).catch(()=>!1)})));for(let i of t)i.exists||this.cache.deleteFile(i.path)}};function dt(o,e){return new ie(o,e)}var _=class{constructor(e,t){this.projectConfig=ne(e),this.builder=dt(this.projectConfig,t)}async compile(e){await this.builder.buildScripts({pattern:e})}async build(e){let t=!0;return e.watch&&(e.assets&&await this.builder.watchAssets(),e.includes&&await this.builder.watchInclude(),e.scripts&&await this.builder.watchScripts()),e.assets&&await this.builder.buildAssets(),e.includes&&await this.builder.buildInclude(),(e.plugins||e.scripts)&&(t=await this.builder.buildScripts({skipCompilation:!e.plugins,ignoreErrors:e.ignoreErrors})),t}};var I=p(require("path")),y=p(require("fs")),ut=require("child_process"),R=require("lodash");var G=class{constructor(e){let t=e.cwd||process.cwd(),i=e.name||I.default.basename(t);this.isCurrentDir=!!e.name&&e.name===".",this.projectDir=this.isCurrentDir?t:I.default.join(t,i),this.options={...e,name:i,cwd:t},this.projectConfig=je(e.type,{},this.projectDir)}async createProject(){if(!this.isCurrentDir&&y.default.existsSync(this.projectDir))throw new h(`Project ${this.options.name} is already exists!`);if(this.isCurrentDir&&this.isInitialized())throw new h("Cannot create a project! The directory is not empty!");await this.createConfig(),await this.createDirectories(),this.options.npm&&await this.updatePackage(),this.options.git&&!this.isGitInitialized()&&await this.initGit(),this.isGitInitialized()&&await this.updateGitignore(),this.isNpmPackageInitialized()&&await this.installDependencies(),this.options.install&&await this.execCommand(`npx ${l.command} install`)}async updatePackage(){n.info("\u{1F4E6} Initializing npm package...");let e=I.default.join(this.projectDir,"package.json"),t={name:this.options.name,version:(0,R.get)(this.options,"version","0.1.0"),author:(0,R.get)(this.options,"author",l.title),description:(0,R.get)(this.options,"description",`This project was generated by ${l.title} CLI`)};y.default.existsSync(e)&&(0,R.merge)(t,JSON.parse(await y.default.promises.readFile(e,"utf8"))),(0,R.merge)(t,{scripts:{build:`${l.command} build`,watch:`${l.command} build --watch`,postinstall:`${l.command} install`}}),await y.default.promises.writeFile(e,JSON.stringify(t,null,2))}async createConfig(){n.info("\u{1F527} Creating project configuration file..."),await y.default.promises.mkdir(this.projectDir,{recursive:!0});let e=I.default.join(this.projectDir,l.project.configFile),t=(0,R.merge)({},this.projectConfig.defaults);await y.default.promises.writeFile(e,JSON.stringify(t,null,2))}async createDirectories(){n.info("\u{1F4C1} Creating project directories...");for(let e of this.projectConfig.targets.assets)await y.default.promises.mkdir(e.src,{recursive:!0});for(let e of this.projectConfig.targets.include)await y.default.promises.mkdir(e.src,{recursive:!0});for(let e of this.projectConfig.targets.scripts)await y.default.promises.mkdir(e.src,{recursive:!0})}async installDependencies(){n.info("\u{1F504} Installing dependencies..."),await this.execCommand(`npm install ${l.command}@${l.version} --save-dev`)}async initGit(){n.info("\u{1F33F} Initializing git..."),await this.execCommand("git init")}async updateGitignore(){n.info("\u2754 Updating .gitignore file...");let e=I.default.join(this.projectDir,".gitignore"),t=[`*.${this.projectConfig.compiler.config.fileExtensions.plugin}`],i=r=>!I.default.isAbsolute(r)&&t.push(`npx ${I.default.relative(this.projectDir,r)}/`);i("node_modules"),i(this.projectConfig.compiler.dir),i(this.projectConfig.thirdparty.dir);for(let r of this.projectConfig.targets.assets)i(r.src);y.default.existsSync(e)&&t.unshift(""),t.push(""),await y.default.promises.appendFile(e,t.join(`
5
5
  `))}isInitialized(){return y.default.existsSync(I.default.join(this.projectDir,l.project.configFile))}isGitInitialized(){return y.default.existsSync(I.default.join(this.projectDir,".git"))}isNpmPackageInitialized(){return y.default.existsSync(I.default.join(this.projectDir,"package.json"))}execCommand(e){return new Promise(t=>{let i=(0,ut.exec)(e,{cwd:this.projectDir});i.on("error",t),i.on("close",t)})}};var L=new ft.Command;L.command("config").option("--type, -t <type>","Project type",l.project.defaultType).action(w(async o=>{let{type:e}=o;await new G({type:e}).createConfig()}));L.command("create").argument("<name>","Project name").option("--type, -t <type>","Project type",l.project.defaultType).option("--version, -v <version>","Project version").option("--author, -a <author>","Project author").option("--description, -d <author>","Project description").option("--no-npm","Don't initialize npm package",!0).option("--no-install","Don't install dependencies",!0).option("--git","Initialize git",!1).action(w(async(o,e)=>{let{version:t,author:i,description:r,npm:s,install:c,git:a,type:d}=e;if(!o)throw new h("Project name cannot be empty!");await new G({name:o,version:t,author:i,description:r,npm:s,install:c,git:a,type:d}).createProject(),n.success(`Your project is ready! Thanks for using ${l.title} CLI! \u{1F917}`)}));L.command("install").alias("i").option("--config, -c <path>","Config file",l.project.configFile).option("--compiler","Install compiler").option("--thirdparty","Install thirdparty dependencies").action(w(async(o,e)=>{let{config:t,compiler:i,thirdparty:r}=e.opts(),s=!i&&!r;await new T(t).install({compiler:s||!!i,thirdparty:s||!!r})}));L.command("compile").alias("c").argument("<pattern>","Script path or glob").option("--config, -c <path>","Config file",l.project.configFile).option("--no-cache","Disable caching").action(w(async(o,e)=>{let{config:t,cache:i}=e;await new _(t,{noCache:!i}).compile(o)}));L.command("build").alias("b").option("--config, -c <path>","Config file",l.project.configFile).option("--watch, -w","Watch project").option("--ignore, -i","Ignore build errors").option("--no-cache","Disable caching").option("--assets","Build assets").option("--scripts","Build scripts").option("--plugins","Build plugins").option("--includes","Build includes").action(w(async(o,e)=>{let{config:t,watch:i,ignore:r,cache:s,assets:c,scripts:a,plugins:d,includes:f}=e.opts(),C=!c&&!a&&!d&&!f,m=new _(t,{noCache:!s});n.info("\u2692\uFE0F Building..."),await m.build({watch:i,ignoreErrors:r,noCache:!s,assets:C||c,scripts:C||a,plugins:C||d,includes:C||f})?n.success("\u2705 Build completed successfully!"):n.error("\u26A0\uFE0F Build completed with errors!")}));L.addCommand(it.name("generate").alias("new").alias("n").alias("g"));var mt=L;var ht=require("commander");var D=p(require("fs"));var $e=p(require("path")),re=class{getCacheSize(){let e=0;if(D.default.existsSync(l.cacheDir)){let t=D.default.readdirSync(l.cacheDir);for(let i of t)e+=D.default.statSync($e.default.join(l.cacheDir,i)).size}if(D.default.existsSync(l.downloadDir)){let t=D.default.readdirSync(l.downloadDir);for(let i of t)e+=D.default.statSync($e.default.join(l.downloadDir,i)).size}return e}clearCache(){D.default.existsSync(l.cacheDir)&&D.default.rmSync(l.cacheDir,{recursive:!0,force:!0}),D.default.rmSync(l.downloadDir,{recursive:!0,force:!0})}};var fe=new ht.Command,Re;fe.hook("preAction",()=>{Re=new re});fe.command("clean").action(w(()=>{Re.clearCache(),n.info("\u{1F9F9} Cache cleaned!")}));fe.command("size").action(w(()=>{let o=Re.getCacheSize();n.info(`\u{1F4BE} Cache size: ${o} bytes`)}));var gt=fe;var wt=require("commander");var me=p(require("fs")),he=require("lodash");var oe=class{async getDependencies(){return(await this.readProjectConfig()).thirdparty.dependencies}async addDependency(e,t,i,r){let s=await this.readProjectConfig();if((0,he.find)(s.thirdparty.dependencies,{name:e}))throw new h(`Dependency "${e}" already exists!`);s.thirdparty.dependencies.push({name:e,url:t,strip:i,filter:r}),await me.default.promises.writeFile(l.project.configFile,JSON.stringify(s,null,2))}async removeDependency(e){let t=await this.readProjectConfig(),i=(0,he.findIndex)(t.thirdparty.dependencies,{name:e});if(i===-1)throw new h(`Dependency "${e}" not found!`);t.thirdparty.dependencies.splice(i,1),await me.default.promises.writeFile(l.project.configFile,JSON.stringify(t,null,2))}async readProjectConfig(){try{return JSON.parse(await me.default.promises.readFile(l.project.configFile,"utf8"))}catch{throw new h(`Failed to read project config ${l.project.configFile}`)}}};var se=new wt.Command,ge;se.hook("preAction",()=>{ge=new oe});se.command("list").alias("l").action(w(async()=>{let o=await ge.getDependencies();if(!o.length){n.info("\u{1F50D} No thirdparty dependencies found!");return}n.info("\u{1F50D} Thirdparty dependencies:");for(let e of o)n.info(`- ${e.name} "${e.url}"`)}));se.command("add").alias("a").argument("<name>","Thirdparty name").argument("<url>","Thirdparty URL").option("--strip [strip]","Strip",o=>parseInt(o,10)).option("--filter [filter]","Filter",o=>o.split(",")).action(w(async(o,e,t)=>{let{strip:i,filter:r}=t;await ge.addDependency(o,e,i,r),n.success(`\u2795 Dependency "${o}" added successfully!`)}));se.command("remove").alias("r").argument("<name>","Thirdparty name").action(w(async o=>{await ge.removeDependency(o),n.success(`\u{1F5D1}\uFE0F Dependency "${o}" removed successfully!`)}));var vt=se;var H=new yt.Command;H.name(`${l.title} CLI`).description(`${l.title} CLI - Building tools for pawn projects`);H.version(l.version);H.command("exit",{hidden:!0}).alias("quit").alias("q").description("Exit the CLI").action(()=>{process.exit(0)});mt.commands.forEach(o=>H.addCommand(o));H.addCommand(gt.name("cache"));H.addCommand(vt.name("dependency").alias("dep").alias("d").alias("thirdparty").alias("t"));var Ct=H;async function we(o,e=!1){try{await Ct.exitOverride().parseAsync(o,{from:"user"})}catch(t){J(t,e)}}async function Kt(o){o.length>0&&await we(o,!0),n.info("\u{1F579}\uFE0F Interactive mode: Waiting for input...");let e=jt.default.createInterface({input:process.stdin,output:process.stdout});e.on("line",async t=>{e.pause(),await we((0,It.parseArgsStringToArgv)(t),!0),e.resume()}),process.on("SIGINT",()=>e.close()),process.on("uncaughtException",()=>e.close()),process.on("unhandledRejection",()=>e.close())}function qt(o){let e=[];for(let t of o){if(t[0]!=="-")break;e.push(t)}return e}function Xt(o){let e=new Set;for(let t of o)switch(t){case"-i":case"--interactive":case"--input":case"--shell":{e.add("interactive");break}}return e}async function Yt(){let o=qt(process.argv.slice(2)),e=Xt(o);if(e.size>0){let t=process.argv.slice(2+o.length);e.has("interactive")?await Kt(t):await we(t)}else await we(process.argv.slice(2))}process.env.NODE_ENV!=="development"&&process.on("warning",o=>{o.name!=="DeprecationWarning"&&console.warn(o)});Yt();
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "amxxpack",
3
3
  "description": "AMXXPack",
4
4
  "author": "Hedgehog Fog",
5
- "version": "1.5.2",
5
+ "version": "1.5.3",
6
6
  "license": "MIT",
7
7
  "scripts": {
8
8
  "test": "jest",
@@ -8,6 +8,6 @@ public plugin_init() {
8
8
  register_plugin("{{PLUGIN_NAME}}", "{{PLUGIN_VERSION}}", "{{PLUGIN_AUTHOR}}");
9
9
  }
10
10
 
11
- public plugin_native() {
11
+ public plugin_natives() {
12
12
  register_library("{{LIBRARY_NAME}}");
13
13
  }