Comparing version 0.1.0 to 0.2.0
{ | ||
"name": "fs-api-js", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"main": "src/main.js", | ||
@@ -13,2 +13,3 @@ "repository": "https://github.com/sourcelair/fs-api-js", | ||
"prettier": "^1.13.7", | ||
"prettier-check": "^2.0.0", | ||
"watchify": "^3.11.0" | ||
@@ -18,6 +19,7 @@ }, | ||
"test": "jest", | ||
"format": "prettier \"src/*.js\" --write", | ||
"format": "prettier src/*.js --write", | ||
"watch": "watchify src/main.js --verbose --standalone fsApi -o dist/fsapi.js", | ||
"start": "browser-sync start --server --watch --files 'dist/*' 'index.html' --port $PORT" | ||
"start": "browser-sync start --server --watch --files 'dist/*' 'index.html' --port $PORT", | ||
"lint": "prettier-check src/*.js" | ||
} | ||
} |
@@ -5,3 +5,10 @@ function convertItemsToUnorderedList(listItems) { | ||
const liElement = document.createElement("li"); | ||
liElement.textContent = item.name; | ||
liElement.classList.add("fs-api-entry", `fs-api-${item.type}`); | ||
const nameElement = document.createElement("span"); | ||
nameElement.textContent = item.name; | ||
nameElement.classList.add("fs-api-entry-name"); | ||
liElement.appendChild(nameElement); | ||
if (item.children) { | ||
renderInput(item.children, liElement); | ||
} | ||
ulElement.appendChild(liElement); | ||
@@ -20,3 +27,3 @@ }); | ||
const dirItems = input.filter(inputEl => inputEl.type === "directory"), | ||
fileItems = input.filter(inputEl => inputEl.type === "file"); | ||
fileItems = input.filter(inputEl => inputEl.type === "file"); | ||
dirItems.sort(alphabeticCompare); | ||
@@ -26,5 +33,6 @@ fileItems.sort(alphabeticCompare); | ||
ulElement = convertItemsToUnorderedList(listItems); | ||
ulElement.classList.add("fs-api-tree"); | ||
container.appendChild(ulElement); | ||
} | ||
module.exports.render = renderInput; | ||
module.exports.render = renderInput; |
@@ -39,3 +39,16 @@ const fsapi = require("./main"); | ||
type: "directory", | ||
children: null | ||
children: [ | ||
{ | ||
name: "yarn.lock", | ||
absolute_path: "/mnt/project/vendor/yarn.lock", | ||
type: "file", | ||
children: null | ||
}, | ||
{ | ||
name: "package.json", | ||
absolute_path: "/mnt/project/vendor/package.json", | ||
type: "file", | ||
children: null | ||
} | ||
] | ||
} | ||
@@ -46,13 +59,38 @@ ]; | ||
const ul = container.querySelector("ul"); | ||
for (const child of ul.children) { | ||
const trees = container.querySelectorAll("ul"); | ||
const rootTree = trees[0]; | ||
for (const child of rootTree.children) { | ||
expect(child).toBeInstanceOf(HTMLLIElement); | ||
} | ||
expect(ul.children[0].textContent).toBe("Dir"); | ||
expect(ul.children[1].textContent).toBe("FinalDir"); | ||
expect(ul.children[2].textContent).toBe("AnotherFile.html"); | ||
expect(ul.children[3].textContent).toBe("SFile.sth"); | ||
expect(ul.children[4].textContent).toBe("test.go"); | ||
expect(ul.children[5].textContent).toBe("Troll.go"); | ||
expect(rootTree.children[0].children[0].textContent).toBe("Dir"); | ||
expect(rootTree.children[1].children[0].textContent).toBe("FinalDir"); | ||
expect(rootTree.children[2].children[0].textContent).toBe("AnotherFile.html"); | ||
expect(rootTree.children[3].children[0].textContent).toBe("SFile.sth"); | ||
expect(rootTree.children[4].children[0].textContent).toBe("test.go"); | ||
expect(rootTree.children[5].children[0].textContent).toBe("Troll.go"); | ||
expect(trees[1].children[0].children[0].textContent).toBe("package.json"); | ||
expect(trees[1].children[1].children[0].textContent).toBe("yarn.lock"); | ||
for (const ulElement of trees) { | ||
expect(ulElement.classList.contains("fs-api-tree")).toBe(true); | ||
} | ||
expect(rootTree.children[0].classList.contains("fs-api-directory")).toBe( | ||
true | ||
); | ||
expect(rootTree.children[1].classList.contains("fs-api-directory")).toBe( | ||
true | ||
); | ||
expect(rootTree.children[2].classList.contains("fs-api-file")).toBe(true); | ||
expect(rootTree.children[3].classList.contains("fs-api-file")).toBe(true); | ||
expect(rootTree.children[4].classList.contains("fs-api-file")).toBe(true); | ||
expect(rootTree.children[5].classList.contains("fs-api-file")).toBe(true); | ||
for (const tree of trees) { | ||
for (const child of tree.children) { | ||
expect(child.children[0].classList.contains("fs-api-entry-name")).toBe( | ||
true | ||
); | ||
expect(child.classList.contains("fs-api-entry")).toBe(true); | ||
} | ||
} | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8227
122
6