Initial
This commit is contained in:
1
resources/app/dist/packages/_module.mjs
vendored
Normal file
1
resources/app/dist/packages/_module.mjs
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export{default as ServerPackageMixin}from"./package.mjs";import{default as PackageWarnings}from"./warnings.mjs";import{default as PackageBackups}from"./package-backups.mjs";import Module from"./module.mjs";import System from"./system.mjs";import World from"./world.mjs";import HotReload from"./hot-reload.mjs";export{Module,System,World,HotReload};export{default as PreviewCompatibility}from"./preview-compatibility.mjs";export const PACKAGE_TYPE_MAPPING={module:Module,system:System,world:World};export const warnings=new PackageWarnings;export const backups=new PackageBackups;
|
||||
1
resources/app/dist/packages/hot-reload.mjs
vendored
Normal file
1
resources/app/dist/packages/hot-reload.mjs
vendored
Normal file
@@ -0,0 +1 @@
|
||||
import path from"node:path";import fs from"node:fs";import*as chokidar from"chokidar";import Files from"../files/files.mjs";export default class HotReload{static#a=new Map;static async watchForHotReload(a,t){if(await HotReload.stopWatching(),global.config.options.hotReload){global.express.debug&&await HotReload.#t({id:"core"}),a.system.flags.hotReload&&await HotReload.#t(a.system);for(const o of a.modules.filter((a=>a.flags.hotReload&&t[a.id])))await HotReload.#t(o)}}static async stopWatching(){for(let a of HotReload.#a.values())await a.close();HotReload.#a.clear()}static async#t(a){const t=new Set([".js",".mjs",".css",".html",".hbs",".json"]);let o="core"===a.id?t:new Set(a.flags.hotReload.extensions);if(o=new Set([...o].map((a=>a.startsWith(".")?a:`.${a}`))),!o.size)return void console.warn(`Hot Reload disabled for "${a.id}" because it has no extensions defined.`);const e="core"===a.id?global.paths.public:a.path;let s=[];if("core"!==a.id&&a.flags.hotReload.paths)for(const t of a.flags.hotReload.paths){const o=Files.standardizePath(path.join(e,t));Files.isPathContained(o,e)?s.push(o):console.warn(`Hot Reload skipped for "${a.id}" path "${o}" because it is not contained within the package directory.`)}0===s.length&&(s=[e]);const i=chokidar.watch(s);console.log(`Watching for changes to ${a.id} in ${s.join(", ")}`),i.on("change",(async t=>{const e=path.extname(t);if(!o.has(e))return;const s=fs.readFileSync(t,{encoding:"utf8"}),i=t.replace(path.normalize(global.paths.data),"").replace(path.normalize(global.paths.public),""),n=Files.standardizePath(i),l={packageType:a.type,packageId:a.id,content:s,path:n.startsWith("/")?n.slice(1):n,extension:e.replace(".","")};express.io.emit("hotReload",l)})),HotReload.#a.set(a.id,i)}}
|
||||
1
resources/app/dist/packages/installer.mjs
vendored
Normal file
1
resources/app/dist/packages/installer.mjs
vendored
Normal file
@@ -0,0 +1 @@
|
||||
import EventEmitter from"node:events";import path from"node:path";import fs from"node:fs";import Files from"../files/files.mjs";import{PACKAGE_TYPE_MAPPING}from"./_module.mjs";export default class PackageInstaller extends EventEmitter{constructor(t,s,i,e,a){super(),this._type=t,this._baseDir=s,this._id=i,this._localZip=e,this._auth=a}_id;_localZip;_auth;_type;_baseDir;#t={step:null,pct:0};async install(){this.#t={step:null,pct:0};try{return(await this.#s()).vend()}catch(t){this.emit("error",t)}finally{fs.unlinkSync(this._localZip)}}async#s(){if(this._id.startsWith(".."))throw new Error("You are not allowed to install packages outside of the designated directory path");const t=path.join(this._baseDir,this._id);let s="",i=await Files.summarizeArchive(this._localZip,{manifestPath:`${this._type}.json`});if(null===i.manifest){const t=i.contents.find((t=>t.endsWith(`${this._type}.json`)));s=`${path.dirname(t)}/`,i=await Files.summarizeArchive(this._localZip,{manifestPath:`${s}${this._type}.json`})}if(!i.manifest)throw fs.unlinkSync(this._localZip),new Error(`The downloaded package ${this._id} did not contain the expected ${this._type}.json manifest file.`);const e=new(0,PACKAGE_TYPE_MAPPING[this._type])(JSON.parse(i.manifest),{installed:!1});if(e.persistentStorage&&fs.existsSync(path.join(t,"storage"))){const s=fs.readdirSync(t);for(let i of s){if("storage"===i)continue;const s=path.join(t,i);await fs.promises.rm(s,{recursive:!0})}}else await fs.promises.rm(t,{force:!0,recursive:!0});if(await Files.extractArchive(this._localZip,t,{removeRoot:s,onProgress:this.#i.bind(this)}),e.persistentStorage){const s=path.join(t,"storage");fs.existsSync(s)||fs.mkdirSync(s)}if(this._auth){const s=path.join(t,"signature.json"),i="signatureV2"in this._auth?{key:this._auth.key,package:this._id,signature:this._auth.signatureV2}:{key:this._auth.key,signature:this._auth.signature};fs.writeFileSync(s,JSON.stringify(i,null,2))}return e}#i(t,s,i){return this.emit("progress",CONST.SETUP_PACKAGE_PROGRESS.STEPS.INSTALL,s,i)}}
|
||||
1
resources/app/dist/packages/module.mjs
vendored
Normal file
1
resources/app/dist/packages/module.mjs
vendored
Normal file
@@ -0,0 +1 @@
|
||||
import path from"node:path";import fs from"node:fs";import{BaseModule}from"../../common/packages/module.mjs";import ServerPackageMixin from"./package.mjs";import Collection from"../../common/utils/collection.mjs";import Files from"../files/files.mjs";export default class Module extends(ServerPackageMixin(BaseModule)){static#e;static getPackages({system:e,coreTranslation:t=!1,enforceCompatibility:s=!1}={}){return super.getPackages({enforceCompatibility:s}).reduce(((s,i)=>(t&&!i.providesCoreTranslation||e&&!i.supportsSystem(e)||s.set(i.id,i),s)),new Collection)}static getCoreTranslationOptions(){const e=this.getPackages({coreTranslation:!0}).reduce(((e,t)=>{if(t.incompatibleWithCoreVersion)return e;let s=new Set;for(let i of t.languages){const a=e[i.lang]=e[i.lang]||{id:i.lang,label:"",modules:[]};a.label||(a.label=i.name),s.has(i.lang)||a.modules.push({id:t.id,label:t.title,path:i.path}),s.add(i.lang)}return e}),{en:{id:"en",label:"English",modules:[{id:"core",label:"Default",path:"lang/en.json"}]}});let t=[e.en];return e.en.modules=e.en.modules.slice(0,1),delete e.en,t.concat(Object.values(e))}static getCoreTranslationStyles(){if(!this.#e){const e=(config.options.language??"en.core").split(".")[1],t=this.getPackages({coreTranslation:!0}).get(e);this.#e=t?.styles||[]}return this.#e}get providesCoreTranslation(){return this.coreTranslation&&this.languages.size}isCompatibleWithSystem(e){if(!this.relationships?.systems?.size)return!0;const t=this.relationships.systems.find((t=>t.id===e.id));return!!t&&this.constructor.testDependencyCompatibility(t.compatibility,e)}supportsSystem(e){return!this.relationships?.systems?.size||!!this.relationships.systems.find((t=>t.id===e.id))}static create(e){if(e.id=e.id.slugify({strict:!0}),e.id.startsWith(".."))throw new Error("You are not allowed to create a Module outside of the modules directory path.");const t=path.join(this.baseDir,e.id);if(fs.existsSync(t))throw new Error(`A Module already exists in the requested directory ${e.id}.`);const s=new Module(e,{installed:!0});return fs.mkdirSync(t),s.save(),Files.writeFileSyncSafe(path.join(t,".gitattributes"),"packs/** binary\n"),globalThis.logger.info(`Created Module "${s.id}"`),this.packages&&this.packages.set(s.id,s),s.vend()}updateManifest(e){return this.updateSource(e),this.save(),this.vend()}static createOrUpdate(e){const t=this.get(e.id);return t?t.updateManifest(e):this.create(e)}}
|
||||
1
resources/app/dist/packages/package-backups.mjs
vendored
Normal file
1
resources/app/dist/packages/package-backups.mjs
vendored
Normal file
File diff suppressed because one or more lines are too long
1
resources/app/dist/packages/package.mjs
vendored
Normal file
1
resources/app/dist/packages/package.mjs
vendored
Normal file
File diff suppressed because one or more lines are too long
1
resources/app/dist/packages/preview-compatibility.mjs
vendored
Normal file
1
resources/app/dist/packages/preview-compatibility.mjs
vendored
Normal file
@@ -0,0 +1 @@
|
||||
import Module from"./module.mjs";import System from"./system.mjs";import World from"./world.mjs";import{ReleaseData}from"../../common/config.mjs";import Collection from"../../common/utils/collection.mjs";import{PACKAGE_AVAILABILITY_CODES}from"../../common/constants.mjs";export default class PreviewCompatibility{constructor(e){if(!(e instanceof ReleaseData))throw new Error("You must provide an instance of ReleaseData to the PreviewCompatibility constructor.");if(e.version===globalThis.release.version)throw new Error("You may not preview compatibility for the current software release.");this.release=e,this.release.maxGeneration=globalThis.release.maxGeneration,this.release.maxStableGeneration=globalThis.release.maxStableGeneration}release;modules=new Collection;systems=new Collection;worlds=new Collection;async evaluate(){await this.getRepositoryPackages(),await this.testCompatibility();for(const e of this.modules.keys())Module.packages.has(e)||this.modules.delete(e)}async getRepositoryPackages(){await this.#e(System,this.systems,{installedOnly:!0}),await this.#e(Module,this.modules,{installedOnly:!1}),this.worlds=packages.World.packages.reduce(((e,s)=>{const t=s.clone();return t.system=this.systems.get(s._source.system),t.compatibility.maximum=t._source.compatibility.maximum,e.set(t.id,t)}),new Collection)}async testCompatibility(){const e=PACKAGE_AVAILABILITY_CODES,{release:s,modules:t,systems:a,worlds:i}=this;for(const e of t.values())e.availability=Module.testAvailability(e,{release:s});for(const e of a.values())e.availability=System.testAvailability(e,{release:s});for(const o of i.values())o.availability=World.testAvailability(o,{release:s,modules:t,systems:a,systemAvailabilityThreshold:e.UNVERIFIED_GENERATION});for(const s of System.packages.keys()){const i=a.get(s);await i._testRequiredDependencies(t)||(i.availability=e.MISSING_DEPENDENCY)}for(const s of Module.packages.keys()){const i=t.get(s);await i._testRequiredDependencies(t)||(i.availability=e.MISSING_DEPENDENCY);await i._testSupportedSystems(a)||(i.availability=e.UNVERIFIED_SYSTEM)}for(const s of World.packages.keys()){const a=i.get(s);await a._testRequiredDependencies(t)||(a.availability=e.MISSING_DEPENDENCY)}}async#e(e,s,{installedOnly:t=!0}={}){s.clear();const a=e.getPackages(),i=await e.getRepositoryPackages(),o=await e.getRepositoryPackages({release:this.release});for(const e of o.packages.values())t&&!a.has(e.id)||s.set(e.id,e);for(const e of i.packages.values())t&&!a.has(e.id)||s.has(e.id)||s.set(e.id,e);let l=[];for(const t of a.values())s.has(t.id)||(l.length>=8&&(await Promise.all(l),l=[]),l.push(e.fromRemoteManifest(t.manifest).then((e=>{s.set(t.id,e)})).catch((()=>{s.set(t.id,t.clone())}))));await Promise.all(l)}vend(){return{version:this.release.version,world:this.worlds.map((e=>e.vend())),system:this.systems.map((e=>e.vend())),module:this.modules.map((e=>e.vend()))}}static async test(e={}){const s=new this(new ReleaseData({channel:"stable",node_version:16,...e}));return await s.evaluate(),s}}
|
||||
1
resources/app/dist/packages/system.mjs
vendored
Normal file
1
resources/app/dist/packages/system.mjs
vendored
Normal file
@@ -0,0 +1 @@
|
||||
import fs from"node:fs";import path from"node:path";import{BaseSystem}from"../../common/packages/module.mjs";import{ALL_DOCUMENT_TYPES,PACKAGE_AVAILABILITY_CODES}from"../../common/constants.mjs";import{isNewerVersion}from"../../common/utils/helpers.mjs";import ServerPackageMixin,{PackageAssetField}from"./package.mjs";export default class System extends(ServerPackageMixin(BaseSystem)){static defineSchema(){const e=super.defineSchema();return e.background=new PackageAssetField({relativeToPackage:!1,mustExist:!1,...e.background.options}),e}#e;#t=0;get template(){return this._template}_template;_initialize(e){super._initialize(e),this._initializeTemplateDocumentTypes()}_initializeTemplateDocumentTypes(){if(this.loadDataTemplate(),!this.installed||!this._template)return;const e=["htmlFields","filePathFields","gmOnlyFields"];for(const[t,s]of Object.entries(this._template))for(const a of s.types||[]){const i=this.documentTypes[t]||={};i[a]={};for(const t of e)t in s&&(i[a][t]=s[t])}}validate(e){return this.installed&&this.loadDataTemplate(this._source.id),super.validate(e)}updateSource(e={},t={}){return this._template=void 0,super.updateSource(e,t)}vend(){const e=super.vend();return e.strictDataCleaning=this._template?.strictDataCleaning,e}loadDataTemplate(e=this.id){return this._template||(this._template=System.#s(e)),this._template}static#s(e){const t=path.join(this.baseDir,e,"template.json");if(!fs.existsSync(t))return null;let s;try{s=JSON.parse(fs.readFileSync(t,"utf-8"))}catch(t){throw new Error(`Unable to parse system template for ${e}: ${t.message}`)}for(const t of ALL_DOCUMENT_TYPES){const a=s[t];if(!a)continue;const i=getDocumentClass(t);a.types=(a.types||[]).filter((a=>{try{return System.#a(e,i,a),a}catch(i){packages.warnings.add(e,{type:this.type,level:"warning",message:i.message}),console.warn(i.message),delete s[t][a]}}))}return s}static#a(e,t,s){const a=t.documentName;if(t.metadata.coreTypes.includes(s))throw new Error(`System "${e}" defines ${a} document sub-type "${s}" which is a reserved core type.`);if(s.includes("."))throw new Error(`System "${e}" defines ${a} document sub-type "${s}" which may not contain periods.`)}async getUpdateNotification(){const e=Date.now();if(!this.#e||e-this.#t>864e5){const e=await this.constructor.check(this.manifest,this);e.isUpgrade?globalThis.logger.info(`${this.title} update ${e.remote.version} is now available!`):globalThis.logger.info(`No system update for ${this.title} is currently available.`),this.#e={hasUpdate:e.isUpgrade,version:e.remote?.version||null}}return this.#e}async checkUpdateAvailable(){const e=await System.fromRemoteManifest(this.manifest);return isNewerVersion(e.version,this.version)&&e.availability<=PACKAGE_AVAILABILITY_CODES.UNVERIFIED_GENERATION?e.version:null}static async install(e,t,s,a,i){const n=await super.install(e,t,s,a,i);return packages.World.resetPackages(),n}static async uninstall(e){const t=await super.uninstall(e);return packages.World.resetPackages(),t}}
|
||||
1
resources/app/dist/packages/views.mjs
vendored
Normal file
1
resources/app/dist/packages/views.mjs
vendored
Normal file
File diff suppressed because one or more lines are too long
1
resources/app/dist/packages/warnings.mjs
vendored
Normal file
1
resources/app/dist/packages/warnings.mjs
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export default class PackageWarnings extends Map{add(r,{type:e,level:t="error",message:n=""}={}){this.has(r)||this.set(r,{id:r,type:e,warning:new Set,error:new Set});const s=this.get(r);e&&!s.type&&(s.type=e),s[t].add(n)}toJSON(){const r={};for(const[e,t]of this.entries())r[e]={...t,warning:Array.from(t.warning),error:Array.from(t.error)};return r}}
|
||||
1
resources/app/dist/packages/world.mjs
vendored
Normal file
1
resources/app/dist/packages/world.mjs
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user