-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a task provider, currently providing a sync task
- Loading branch information
1 parent
d2f1b86
commit 470e052
Showing
12 changed files
with
5,963 additions
and
415 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { WorkspaceFolder, TaskProvider, Task, TaskDefinition, ShellExecution, TaskScope } from "vscode"; | ||
import * as path from 'path'; | ||
import * as fs from 'fs'; | ||
|
||
/** | ||
* A task provider for eXist package directories, currently providing a task | ||
* to automatically sync directory content to a database collection. | ||
* | ||
* The task provider will only return tasks for directories containing a ´.existdb.json` | ||
* configuration file. | ||
* | ||
* @author Wolfgang Meier | ||
*/ | ||
export class ExistTaskProvider implements TaskProvider { | ||
|
||
private workspaceFolders: WorkspaceFolder[]; | ||
private syncScript: string; | ||
private taskPromise: Thenable<Task[]> | undefined = undefined; | ||
|
||
constructor(workspaceFolders: WorkspaceFolder[], syncScript: string) { | ||
this.workspaceFolders = workspaceFolders; | ||
this.syncScript = syncScript; | ||
} | ||
|
||
public provideTasks(): Thenable<Task[]> | undefined { | ||
if (!this.taskPromise) { | ||
this.taskPromise = this.getTasks(); | ||
} | ||
return this.taskPromise; | ||
} | ||
|
||
public resolveTask(_task: Task): Task | undefined { | ||
return undefined; | ||
} | ||
|
||
private async getTasks(): Promise<Task[]> { | ||
let result: Task[] = []; | ||
for (let folder of this.workspaceFolders) { | ||
const config = path.join(folder.uri.fsPath, '.existdb.json'); | ||
if (!fs.existsSync(config)) { | ||
return result; | ||
} | ||
const configData = fs.readFileSync(config, 'utf8'); | ||
const json = JSON.parse(configData); | ||
const sync = json.sync; | ||
if (!sync) { | ||
return result; | ||
} | ||
|
||
const serverDef = sync.server; | ||
if (!serverDef) { | ||
return result; | ||
} | ||
const server = json.servers[serverDef]; | ||
if (!server) { | ||
return result; | ||
} | ||
const collection = sync.root; | ||
const user = sync.user || server.user; | ||
const password = sync.password || server.password; | ||
const kind: ExistTaskDefinition = { | ||
type: 'sync', | ||
server: server.server, | ||
user: user, | ||
password: password, | ||
root: collection, | ||
dir: folder.uri.fsPath, | ||
ignore: sync.ignore | ||
}; | ||
let command = `node ${this.syncScript} -s ${server.server} -u ${user} -p ${password} `; | ||
command += `-c ${collection} ${folder.uri.fsPath} -i ${sync.ignore.map(p => `"${p}"`).join(' ')}`; | ||
const task = new Task(kind, TaskScope.Workspace, `sync-${folder.name}`, 'existdb', new ShellExecution(command)); | ||
result.push(task); | ||
} | ||
return result; | ||
} | ||
} | ||
|
||
interface ExistTaskDefinition extends TaskDefinition { | ||
server: string; | ||
user: string; | ||
password: string; | ||
root: string; | ||
dir: string; | ||
ignore: string[]; | ||
} | ||
|
Oops, something went wrong.