UNPKG

@yuebai008/cli

Version:

Command line interface for rapid qg-minigame development

1 lines 3.77 kB
import*as Common from"../../core/common/common.js";import{UISourceCode}from"./UISourceCode.js";export var projectTypes;!function(e){e.Debugger="debugger",e.Formatter="formatter",e.Network="network",e.FileSystem="filesystem",e.ContentScripts="contentscripts",e.Service="service"}(projectTypes||(projectTypes={}));export class ProjectStore{workspaceInternal;idInternal;typeInternal;displayNameInternal;#e;constructor(e,t,r,o){this.workspaceInternal=e,this.idInternal=t,this.typeInternal=r,this.displayNameInternal=o,this.#e=new Map}id(){return this.idInternal}type(){return this.typeInternal}displayName(){return this.displayNameInternal}workspace(){return this.workspaceInternal}createUISourceCode(e,t){return new UISourceCode(this,e,t)}addUISourceCode(e){const t=e.url();return!this.uiSourceCodeForURL(t)&&(this.#e.set(t,e),this.workspaceInternal.dispatchEventToListeners(Events.UISourceCodeAdded,e),!0)}removeUISourceCode(e){const t=this.#e.get(e);void 0!==t&&(this.#e.delete(e),this.workspaceInternal.dispatchEventToListeners(Events.UISourceCodeRemoved,t))}removeProject(){this.workspaceInternal.removeProject(this),this.#e.clear()}uiSourceCodeForURL(e){return this.#e.get(e)??null}uiSourceCodes(){return this.#e.values()}renameUISourceCode(e,t){const r=e.url(),o=e.parentURL()?Common.ParsedURL.ParsedURL.urlFromParentUrlAndName(e.parentURL(),t):Common.ParsedURL.ParsedURL.preEncodeSpecialCharactersInPath(t);this.#e.set(o,e),this.#e.delete(r)}rename(e,t,r){}excludeFolder(e){}deleteFile(e){}remove(){}indexContent(e){}}let workspaceInstance;export class WorkspaceImpl extends Common.ObjectWrapper.ObjectWrapper{projectsInternal;hasResourceContentTrackingExtensionsInternal;constructor(){super(),this.projectsInternal=new Map,this.hasResourceContentTrackingExtensionsInternal=!1}static instance(e={forceNew:null}){const{forceNew:t}=e;return workspaceInstance&&!t||(workspaceInstance=new WorkspaceImpl),workspaceInstance}static removeInstance(){workspaceInstance=void 0}uiSourceCode(e,t){const r=this.projectsInternal.get(e);return r?r.uiSourceCodeForURL(t):null}uiSourceCodeForURL(e){for(const t of this.projectsInternal.values()){const r=t.uiSourceCodeForURL(e);if(r)return r}return null}findCompatibleUISourceCodes(e){const t=e.url(),r=e.contentType(),o=[];for(const n of this.projectsInternal.values()){if(e.project().type()!==n.type())continue;const s=n.uiSourceCodeForURL(t);s&&s.url()===t&&s.contentType()===r&&o.push(s)}return o}uiSourceCodesForProjectType(e){const t=[];for(const r of this.projectsInternal.values())r.type()===e&&t.push(...r.uiSourceCodes());return t}addProject(e){console.assert(!this.projectsInternal.has(e.id()),`A project with id ${e.id()} already exists!`),this.projectsInternal.set(e.id(),e),this.dispatchEventToListeners(Events.ProjectAdded,e)}removeProject(e){this.projectsInternal.delete(e.id()),this.dispatchEventToListeners(Events.ProjectRemoved,e)}project(e){return this.projectsInternal.get(e)||null}projects(){return[...this.projectsInternal.values()]}projectsForType(e){return this.projects().filter((function(t){return t.type()===e}))}uiSourceCodes(){const e=[];for(const t of this.projectsInternal.values())e.push(...t.uiSourceCodes());return e}setHasResourceContentTrackingExtensions(e){this.hasResourceContentTrackingExtensionsInternal=e}hasResourceContentTrackingExtensions(){return this.hasResourceContentTrackingExtensionsInternal}}export var Events;!function(e){e.UISourceCodeAdded="UISourceCodeAdded",e.UISourceCodeRemoved="UISourceCodeRemoved",e.UISourceCodeRenamed="UISourceCodeRenamed",e.WorkingCopyChanged="WorkingCopyChanged",e.WorkingCopyCommitted="WorkingCopyCommitted",e.WorkingCopyCommittedByUser="WorkingCopyCommittedByUser",e.ProjectAdded="ProjectAdded",e.ProjectRemoved="ProjectRemoved"}(Events||(Events={}));