Skip to content

Commit

Permalink
fix projects loading (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcislo authored Mar 7, 2020
1 parent f594f1f commit 4914cac
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
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

0 comments on commit 4914cac

Please sign in to comment.