ATL-58: Archive sketch.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta
2021-02-01 11:04:42 +01:00
committed by Akos Kitta
parent a8e60698a8
commit b65867d2f4
4 changed files with 86 additions and 1 deletions

View File

@@ -14,7 +14,7 @@ import { firstToLowerCase } from '../common/utils';
import { NotificationServiceServerImpl } from './notification-service-server';
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
import { CoreClientProvider } from './core-client-provider';
import { LoadSketchReq } from './cli-protocol/commands/commands_pb';
import { LoadSketchReq, ArchiveSketchReq } from './cli-protocol/commands/commands_pb';
const WIN32_DRIVE_REGEXP = /^[a-zA-Z]:\\/;
@@ -324,6 +324,29 @@ void loop() {
return FileUri.create(destination).toString();
}
async archive(sketch: Sketch, destinationUri: string): Promise<string> {
await this.loadSketch(sketch.uri); // sanity check
const { client } = await this.coreClient();
const archivePath = FileUri.fsPath(destinationUri);
// The CLI cannot override existing archives, so we have to wipe it manually: https://github.com/arduino/arduino-cli/issues/1160
if (await fs.exists(archivePath)) {
await fs.unlink(archivePath);
}
const req = new ArchiveSketchReq();
req.setSketchPath(FileUri.fsPath(sketch.uri));
req.setArchivePath(archivePath);
await new Promise<string>((resolve, reject) => {
client.archiveSketch(req, err => {
if (err) {
reject(err);
return;
}
resolve(destinationUri);
});
});
return destinationUri;
}
private async coreClient(): Promise<CoreClientProvider.Client> {
const coreClient = await new Promise<CoreClientProvider.Client>(async resolve => {
const client = await this.coreClientProvider.client();