Skip to content

Commit 05850b5

Browse files
author
Akos Kitta
committed
Ensure default data and sketch dir existence.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent 21dedd4 commit 05850b5

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

arduino-ide-extension/src/node/config-service-impl.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import { injectable, inject } from 'inversify';
1+
import { mkdirpSync, existsSync } from 'fs-extra';
2+
import { injectable, inject, postConstruct } from 'inversify';
23
import URI from '@theia/core/lib/common/uri';
4+
import { FileUri } from '@theia/core/lib/node/file-uri';
5+
import { Deferred } from '@theia/core/lib/common/promise-util';
36
import { ConfigService, Config } from '../common/protocol/config-service';
47
import { ArduinoCli } from './arduino-cli';
58

@@ -8,9 +11,24 @@ export class ConfigServiceImpl implements ConfigService {
811

912
@inject(ArduinoCli)
1013
protected readonly cli: ArduinoCli;
14+
protected readonly config: Deferred<Config> = new Deferred();
15+
16+
@postConstruct()
17+
protected init(): void {
18+
this.cli.getDefaultConfig().then(config => {
19+
const { dataDirUri, sketchDirUri } = config;
20+
for (const uri of [dataDirUri, sketchDirUri]) {
21+
const path = FileUri.fsPath(uri);
22+
if (!existsSync(path)) {
23+
mkdirpSync(path);
24+
}
25+
}
26+
this.config.resolve(config);
27+
});
28+
}
1129

1230
async getConfiguration(): Promise<Config> {
13-
return this.cli.getDefaultConfig();
31+
return this.config.promise;
1432
}
1533

1634
async getVersion(): Promise<string> {

0 commit comments

Comments
 (0)