API: workspace
Source:
platform/workspace.ts
Provides a wrapper for the platform's WorkspaceFacade to manage Workspaces, Projects, Folders, and Files.
Usage
import { workspace } from "sdk/platform";
import { response } from "sdk/http";
let workspacesNames = workspace.getWorkspacesNames();
response.println("Workspaces: " + workspacesNames);
response.flush();
response.close();Classes
Workspace
@class Workspace
@description Represents a logical container for projects, providing static methods for
high-level workspace management and instance methods for project management within the workspace.
Methods
createWorkspace
createWorkspace (name:string):WorkspaceCreates a new workspace with the given name.
@param {string} name The name of the workspace to create.
@returns {Workspace} The newly created Workspace instance.
getWorkspace
getWorkspace (name:string):WorkspaceRetrieves an existing workspace by name.
@param {string} name The name of the workspace to retrieve.
@returns {Workspace} The Workspace instance.
getWorkspacesNames
getWorkspacesNames ():string[]Retrieves the names of all existing workspaces.
@returns {string[]} An array of workspace names.
deleteWorkspace
deleteWorkspace (name:string):voidDeletes the workspace with the specified name.
@param {string} name The name of the workspace to delete.
getProjects
getProjects ():ProjectsGets a collection of all projects within this workspace.
@returns {Projects} A Projects collection instance.
createProject
createProject (name:string):ProjectCreates a new project within this workspace.
@param {string} name The name of the project to create.
@returns {Project} The newly created Project instance.
getProject
getProject (name:string):ProjectRetrieves an existing project by name from this workspace.
@param {string} name The name of the project to retrieve.
@returns {Project} The Project instance.
deleteProject
deleteProject (name:string):voidDeletes a project from this workspace by name.
@param {string} name The name of the project to delete.
exists
exists ():booleanChecks if the workspace currently exists.
@returns {boolean} True if the workspace exists, false otherwise.
existsFolder
existsFolder (path:string):booleanChecks if a specific folder path exists within the workspace's filesystem structure.
@param {string} path The relative path to the folder.
@returns {boolean} True if the folder exists.
existsFile
existsFile (path:string):booleanChecks if a specific file path exists within the workspace's filesystem structure.
@param {string} path The relative path to the file.
@returns {boolean} True if the file exists.
copyProject
copyProject (source:string, target:string):voidCopies a project from a source name to a target name within the workspace.
@param {string} source The name of the project to copy.
@param {string} target The name of the new project copy.
moveProject
moveProject (source:string, target:string):voidMoves a project from a source name to a target name (renaming it).
@param {string} source The current name of the project.
@param {string} target The new name/path of the project.
Projects
@class Projects
@description A collection/list of projects within a workspace.
Methods
size
size ():numberGets the number of projects in the collection.
@returns {number} The size of the collection.
get
get (index:number):ProjectGets a Project instance at the specified index.
@param {number} index The index of the project.
@returns {Project} The Project instance.
Project
@class Project
@description Represents a Project within a workspace. It provides methods for managing
folders and files within the project.
Methods
getName
getName ():stringGets the name of the project.
@returns {string} The project name.
getPath
getPath ():stringGets the path of the project.
@returns {string} The project path (relative to the repository/workspace root).
createFolder
createFolder (path:string):FolderCreates a new folder within the project.
@param {string} path The path of the folder to create (relative to the project root).
@returns {Folder} The newly created Folder instance.
exists
exists ():booleanChecks if the project itself exists.
@returns {boolean} True if the project exists.
existsFolder
existsFolder (path:string):booleanChecks if a specific folder path exists within the project.
@param {string} path The relative path to the folder.
@returns {boolean} True if the folder exists.
getFolder
getFolder (path:string):FolderRetrieves a folder by its path relative to the project root.
@param {string} path The relative path to the folder.
@returns {Folder} The Folder instance.
getFolders
getFolders (path:string):FoldersRetrieves a collection of folders at a specific path.
@param {string} path The path containing the folders to retrieve.
@returns {Folders} The Folders collection instance.
deleteFolder
deleteFolder (path:string):voidDeletes a folder from the project.
@param {string} path The path of the folder to delete (relative to the project root).
createFile
createFile (path:string, input:any[]=[]):FileCreates a new file within the project.
@param {string} path The path of the file to create (relative to the project root).
@param {any[]} [input=[]] Optional initial content as a byte array.
@returns {File} The newly created File instance.
existsFile
existsFile (path:string):booleanChecks if a specific file path exists within the project.
@param {string} path The relative path to the file.
@returns {boolean} True if the file exists.
getFile
getFile (path:string):FileRetrieves a file by its path relative to the project root.
@param {string} path The relative path to the file.
@returns {File} The File instance.
getFiles
getFiles (path:string):FilesRetrieves a collection of files at a specific path.
@param {string} path The path containing the files to retrieve.
@returns {Files} The Files collection instance.
deleteFile
deleteFile (path:string):voidDeletes a file from the project.
@param {string} path The path of the file to delete (relative to the project root).
Folders
@class Folders
@description A collection/list of folders.
Methods
size
size ():numberGets the number of folders in the collection.
@returns {number} The size of the collection.
get
get (index:number):FolderGets a Folder instance at the specified index.
@param {number} index The index of the folder.
@returns {Folder} The Folder instance.
Files
@class Files
@description A collection/list of files.
Methods
size
size ():numberGets the number of files in the collection.
@returns {number} The size of the collection.
get
get (index:number):FileGets a File instance at the specified index.
@param {number} index The index of the file.
@returns {File} The File instance.
Folder
@class Folder
@description Represents a directory or folder within a project, providing methods for
managing sub-folders and files.
Methods
getName
getName ():stringGets the name of the folder.
@returns {string} The folder name.
getPath
getPath ():stringGets the full path of the folder.
@returns {string} The folder path.
createFolder
createFolder (path:string):FolderCreates a new sub-folder within this folder.
@param {string} path The path of the sub-folder to create (relative to this folder).
@returns {Folder} The newly created Folder instance.
exists
exists ():booleanChecks if the folder itself exists.
@returns {boolean} True if the folder exists.
existsFolder
existsFolder (path:string):booleanChecks if a specific sub-folder path exists within this folder.
@param {string} path The relative path to the sub-folder.
@returns {boolean} True if the sub-folder exists.
getFolder
getFolder (path:string):FolderRetrieves a sub-folder by its path relative to this folder.
@param {string} path The relative path to the sub-folder.
@returns {Folder} The Folder instance.
getFolders
getFolders (path:string):FoldersRetrieves a collection of folders at a specific path relative to this folder.
@param {string} path The path containing the folders to retrieve.
@returns {Folders} The Folders collection instance.
deleteFolder
deleteFolder (path:string):voidDeletes a sub-folder from this folder.
@param {string} path The path of the sub-folder to delete (relative to this folder).
createFile
createFile (path:string, input:any[]=[]):FileCreates a new file within this folder.
@param {string} path The path of the file to create (relative to this folder).
@param {any[]} [input=[]] Optional initial content as a byte array.
@returns {File} The newly created File instance.
existsFile
existsFile (path:string):booleanChecks if a specific file path exists within this folder.
@param {string} path The relative path to the file.
@returns {boolean} True if the file exists.
getFile
getFile (path:string):FileRetrieves a file by its path relative to this folder.
@param {string} path The relative path to the file.
@returns {File} The File instance.
getFiles
getFiles (path:string):FilesRetrieves a collection of files at a specific path relative to this folder.
@param {string} path The path containing the files to retrieve.
@returns {Files} The Files collection instance.
deleteFile
deleteFile (path:string):voidDeletes a file from this folder.
@param {string} path The path of the file to delete (relative to this folder).
File
@class File
@description Represents a file (resource) within the workspace, providing methods for
content access and manipulation.
Methods
getName
getName ():stringGets the name of the file.
@returns {string} The file name.
getPath
getPath ():stringGets the full path of the file.
@returns {string} The file path.
getContentType
getContentType ():stringGets the content type (MIME type) of the file.
@returns {string} The content type string.
isBinary
isBinary ():booleanChecks if the file content is determined to be binary.
@returns {boolean} True if binary, false if text.
getContent
getContent ():any[]Gets the content of the file as a JavaScript-friendly byte array.
@returns {any[]} The content bytes.
getText
getText ():stringGets the content of the file as a text string.
@returns {string} The text content.
setContent
setContent (input:any[]):voidSets the content of the file using a byte array.
@param {any[]} input The new content bytes.
setText
setText (input:string):voidSets the content of the file using a text string.
The string is converted to a byte array before saving.
@param {string} input The new text content.
exists
exists ():booleanChecks if the file exists.
@returns {boolean} True if the file exists.