Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#16 - fix projects loading #17

Merged
merged 1 commit into from
Mar 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"configurations": [{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
Expand All @@ -16,7 +15,7 @@
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "npm: watch"
"preLaunchTask": "npm: compile"
},
{
"name": "Extension Tests",
Expand All @@ -33,4 +32,4 @@
"preLaunchTask": "npm: watch"
}
]
}
}
20 changes: 3 additions & 17 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import * as vscode from 'vscode';
import * as path from 'path';

import { TaskManager } from './taskManager';
import parseProject from './parseProject';


const xpath = require('xpath');
const dom = require('xmldom').DOMParser;
const fs = require("fs");
const axios = require('axios').default;
const exec = require('child_process').exec;
Expand All @@ -28,21 +28,7 @@ function loadProjects(panel: vscode.WebviewPanel) {
vscode.workspace.findFiles("**/*.csproj").then(files => {
let projects = Array();
files.map(x => x.fsPath).forEach(x => {
let document = new dom().parseFromString(fs.readFileSync(x, "utf8"));
let packagesReferences = xpath.select("//ItemGroup/PackageReference", document);
let project = {
path: x,
projectName: path.basename(x),
packages: Array()
};
packagesReferences.forEach((p: any) => {
let projectPackage = {

id: p.attributes.getNamedItem("Include").value,
version: p.attributes.getNamedItem("Version").value
};
project.packages.push(projectPackage);
});
let project = parseProject(x);
projects.push(project);
});
postMessage(panel, "setProjects", projects.sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
Expand Down
34 changes: 34 additions & 0 deletions src/parseProject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const xpath = require('xpath');
const dom = require('xmldom').DOMParser;
const fs = require("fs");
import * as path from 'path';

export default function (projectPath: string) {
let projectContent = fs.readFileSync(projectPath, "utf8");
let document = new dom().parseFromString(projectContent);
let packagesReferences = xpath.select("//ItemGroup/PackageReference", document);
let project = {
path: projectPath,
projectName: path.basename(projectPath),
packages: Array()
};
packagesReferences.forEach((p: any) => {
let version = p.attributes.getNamedItem("Version");
if (version) {
version = version.value;
}
else {
version = xpath.select("string(Version)", p);
if (!version) {
version = "not specifed";
}
}
let projectPackage = {

id: p.attributes.getNamedItem("Include").value,
version: version
};
project.packages.push(projectPackage);
});
return project;
}
1 change: 0 additions & 1 deletion web/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export default {
},
created() {
window.addEventListener("message", event => {
console.log("WEB: Received message", event);
switch (event.data.command) {
case "setProjects":
this.rawProjects = event.data.payload;
Expand Down