Skip to content

Commit 7187b46

Browse files
authored
Fixed export configuration not working (#23)
1 parent ea46cfc commit 7187b46

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,27 @@ NI DataPlugins: Create new Python-DataPlugin
2020

2121
# Settings
2222

23+
24+
25+
## Export Path
26+
Set the export path for all your plugins in Preferences -> Settings -> Extensions -> Vscode-NI-Python-DataPlugins -> Plugin Export Path. The path can be a folder or a *.uri file.
27+
28+
<details>
29+
<summary>Example</summary>
30+
<p>
31+
2332
```json
2433
{
25-
"NI-DataPlugins.PluginExportPath": ""
34+
"NI-DataPlugins.PluginExportPath": "C:\\Temp"
35+
}
36+
// OR
37+
{
38+
"NI-DataPlugins.PluginExportPath": "C:\\Temp\\MyPlugin.uri"
2639
}
2740
```
2841

29-
**Export-Path** Set the export path for all your plugins in Preferences -> Settings -> Extensions -> Vscode-NI-Python-DataPlugins -> Plugin Export Path
42+
</p>
43+
</details>
3044

3145
# Contribute
3246

src/commands.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export async function createDataPlugin(): Promise<DataPlugin | null> {
5252
}
5353

5454
export async function exportPluginFromContextMenu(uri: vscode.Uri) {
55+
let storeFileExtensionsAfterExport: boolean = false;
5556
const scriptPath: string = uri.fsPath;
5657
const pluginName: string = path.basename(path.dirname(scriptPath));
5758

@@ -70,8 +71,7 @@ export async function exportPluginFromContextMenu(uri: vscode.Uri) {
7071
return;
7172
}
7273

73-
// Store selected extensions so we don't have to ask again
74-
fileutils.storeFileExtensionConfig(path.dirname(scriptPath), extensions);
74+
storeFileExtensionsAfterExport = true;
7575
}
7676

7777
let exportPath: string = config.exportPath || '';
@@ -82,9 +82,20 @@ export async function exportPluginFromContextMenu(uri: vscode.Uri) {
8282
};
8383

8484
const fileInfos = await vscode.window.showSaveDialog({ ...options });
85-
exportPath = fileInfos?.fsPath || '';
85+
if (!fileInfos) {
86+
return;
87+
}
88+
89+
exportPath = fileInfos.fsPath;
90+
}
91+
92+
const isDirectory = path.extname(exportPath) === '';
93+
if (isDirectory) {
94+
exportPath = path.join(exportPath, `${pluginName}.uri`);
8695
}
8796

8897
await vscu.exportDataPlugin(scriptPath, extensions.toString(), `${exportPath}`);
8998

99+
// Store selected extensions so we don't have to ask again
100+
fileutils.storeFileExtensionConfig(path.dirname(scriptPath), extensions);
90101
}

src/file-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export async function readFileExtensionConfig(workspaceDir: string): Promise<str
3838
export function storeFileExtensionConfig(workspaceDir: string, fileExtensions: string): void {
3939
const filePath: string = path.join(workspaceDir, '.file-extensions');
4040
if (fs.existsSync(filePath)) {
41-
fs.writeFile(filePath, fileExtensions);
41+
fs.writeFileSync(filePath, fileExtensions);
4242
}
4343
}
4444

0 commit comments

Comments
 (0)