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

For revision (md-links) Dianyela Maldonado este si, ya lo terminé :D -->burguer queen please #39

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
767bf73
implementation in code: The app must read a file app.js
DianyelaMaldonado May 28, 2020
5d6a4e7
Added function to check it is markdown file in app.js
DianyelaMaldonado Jun 2, 2020
26c2271
Merge pull request #6 from DianyelaMaldonado/feature/The-app-must-rea…
DianyelaMaldonado Jun 2, 2020
9eba2dc
Added read file function app.js and a cli.js file will be executed ma…
DianyelaMaldonado Jun 5, 2020
e3dfd1b
Merge pull request #8 from DianyelaMaldonado/feature/check-that-it-is…
DianyelaMaldonado Jun 5, 2020
f060acf
Changes were made in app.j. Getting links works, cli proofs of concep…
DianyelaMaldonado Jun 9, 2020
b6cb311
Merge pull request #10 from DianyelaMaldonado/feature/get-links-and-c…
DianyelaMaldonado Jun 9, 2020
35c787c
Correction of functions that were out of order in app.js. I turned th…
DianyelaMaldonado Jun 10, 2020
57df9e5
Merge pull request #13 from DianyelaMaldonado/hotfix/correction-in-th…
DianyelaMaldonado Jun 10, 2020
dd41a8d
Merge pull request #14 from DianyelaMaldonado/master
DianyelaMaldonado Jun 10, 2020
46bf402
Changes in file app.js functions. i changed informations of functions…
DianyelaMaldonado Jun 11, 2020
a213561
I install the colors library, so in app.js i do changes in function …
DianyelaMaldonado Jun 15, 2020
8684f69
Merge pull request #15 from DianyelaMaldonado/feature/getting-links-t…
DianyelaMaldonado Jun 15, 2020
4ddd5e9
I create folder called test, and i create a file called mdlink.spec f…
DianyelaMaldonado Jun 15, 2020
36453f8
Merge pull request #16 from DianyelaMaldonado/feature/getting-links-t…
DianyelaMaldonado Jun 15, 2020
7417c88
App.js was edited and a new statistics function was created
DianyelaMaldonado Jun 17, 2020
4870e5b
Merge pull request #18 from DianyelaMaldonado/feature/getting-links-t…
DianyelaMaldonado Jun 18, 2020
876187e
add new file tests.spec.js and i do the testing
DianyelaMaldonado Jun 18, 2020
94453c4
test ok finish
DianyelaMaldonado Jun 18, 2020
8a272c0
Merge pull request #20 from DianyelaMaldonado/feature/testing
DianyelaMaldonado Jun 18, 2020
dd73bb4
finish changes about test. All ok
DianyelaMaldonado Jun 18, 2020
aa9cbf0
Merge pull request #22 from DianyelaMaldonado/feature/testing
DianyelaMaldonado Jun 18, 2020
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,6 @@ si tienes dudas existenciales con respecto a estas decisiones. No existe una
- [Promise](https://javascript.info/promise-basics)
- [Comprendiendo Promesas en Js](https://hackernoon.com/understanding-promises-in-javascript-13d99df067c1)
- [Pill de recursión - video](https://www.youtube.com/watch?v=lPPgY3HLlhQ&t=916s)
- [Pill de recursión - repositorio](https://github.com/merunga/pildora-recursion)
- [Pill de recursión - repositorio](https://github.com/merunga/pildora-recursion)

![link]("https://github.com/DianyelaMaldonado/CDMX009-MdLinks")
90 changes: 90 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
const path = require('path');
const fs = require('fs');
const fetch = require('node-fetch');
const colors = require('colors/safe');

//make sure its a markdown file
const isMarkDown = uri => path.extname(uri) === '.md' ? true : false;

//The app must read a file
const readFile = () => {
let index = process.argv.indexOf("--file"); //flag--> --file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Súper bien! Por favor, solo borra el comentario.

if (index < 0) return console.log("no se encuentra el archivo");
let uri = process.argv[index + 1];
if (isMarkDown(uri)) {
let fileInformation = fs.readFileSync(uri, 'utf8');
showLinks(fileInformation);
}
}

//finding links
const showLinks = (fileInformation) => {
console.log("all the information contained in the md file", fileInformation);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elimina el console

let regEx = /\bhttps:\/\/([a-z0-9.a-z0-9\/]+)([-a-z0-9?=_&#\/]+)([.a-z0-9]+)/gi;
let result = fileInformation.match(regEx);
checkLinkStatus(result);
}

//check link status
const checkLinkStatus = (allLinks) => {
let promises = allLinks.map(link => fetch(link)
.then(res => {
let thrownAnswer = {
url: res.url,
status: res.status,
text: res.statusText
}
if (thrownAnswer.status === 200) {
console.log(colors.blue(res.status), colors.grey(res.statusText), ('url:', link))
} else {
console.log(colors.yellow(res.status), colors.green(res.statusText), ('url:', link))
}
return thrownAnswer
})
.catch(error => {
let bug = {
url: link,
status: 'error',
text: error.errno
}
if (bug.status === 'error') {
console.log(colors.yellow(bug.status), colors.red(bug.text), ('url:', link))
}
return bug
})
)

return Promise.all(promises)
.then(res => {
arrayCount(res)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Buenísimo!!!! lo conseguiste!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

siiiiii 💯

})

}

//Obtaining statistics
function arrayCount(res) {
console.log(colors.underline('The total Links: '), (res.length))
console.log(colors.magenta('Broken Links: ', res.reduce((accountant, element) => {
if (element.status !== 200) {
return accountant += 1
}
return accountant
}, 0)))
console.log(colors.green('Works links: ', res.reduce((accountant, element) => {
if (element.status === 200) {
return accountant += 1
}
return accountant
}, 0)))

return res
}

module.exports = {
readFile,
showLinks,
isMarkDown,
checkLinkStatus,
arrayCount
}
7 changes: 7 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin / env node

let {
readFile
} = require("./app.js")

readFile();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me parece que este archivo no lo veo necesario, para qué lo estás utilizando?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debo quitarlo 🧛 se me paso el borrarlo, muchas gracias adri.

50 changes: 50 additions & 0 deletions coverage/clover.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1592520227709" clover="3.2.0">
<project timestamp="1592520227710" name="All files">
<metrics statements="41" coveredstatements="16" conditionals="14" coveredconditionals="3" methods="11" coveredmethods="5" elements="66" coveredelements="24" complexity="0" loc="41" ncloc="41" packages="1" files="1" classes="1"/>
<file name="app.js" path="C:\Users\Danna\Documents\CDMX009-MdLinks\app.js">
<metrics statements="41" coveredstatements="16" conditionals="14" coveredconditionals="3" methods="11" coveredmethods="5"/>
<line num="1" count="1" type="stmt"/>
<line num="2" count="1" type="stmt"/>
<line num="3" count="1" type="stmt"/>
<line num="4" count="1" type="stmt"/>
<line num="7" count="2" type="cond" truecount="2" falsecount="0"/>
<line num="10" count="1" type="stmt"/>
<line num="11" count="1" type="stmt"/>
<line num="12" count="1" type="cond" truecount="1" falsecount="1"/>
<line num="13" count="0" type="stmt"/>
<line num="14" count="0" type="cond" truecount="0" falsecount="2"/>
<line num="15" count="0" type="stmt"/>
<line num="16" count="0" type="stmt"/>
<line num="21" count="1" type="stmt"/>
<line num="22" count="1" type="stmt"/>
<line num="23" count="1" type="stmt"/>
<line num="24" count="1" type="stmt"/>
<line num="25" count="0" type="stmt"/>
<line num="29" count="1" type="stmt"/>
<line num="30" count="1" type="stmt"/>
<line num="32" count="0" type="stmt"/>
<line num="37" count="0" type="cond" truecount="0" falsecount="2"/>
<line num="38" count="0" type="stmt"/>
<line num="40" count="0" type="stmt"/>
<line num="42" count="0" type="stmt"/>
<line num="45" count="0" type="stmt"/>
<line num="50" count="0" type="cond" truecount="0" falsecount="2"/>
<line num="51" count="0" type="stmt"/>
<line num="53" count="0" type="stmt"/>
<line num="57" count="0" type="stmt"/>
<line num="59" count="0" type="stmt"/>
<line num="67" count="1" type="stmt"/>
<line num="68" count="0" type="stmt"/>
<line num="69" count="0" type="cond" truecount="0" falsecount="2"/>
<line num="70" count="0" type="stmt"/>
<line num="72" count="0" type="stmt"/>
<line num="74" count="0" type="stmt"/>
<line num="75" count="0" type="cond" truecount="0" falsecount="2"/>
<line num="76" count="0" type="stmt"/>
<line num="78" count="0" type="stmt"/>
<line num="81" count="0" type="stmt"/>
<line num="84" count="1" type="stmt"/>
</file>
</project>
</coverage>
2 changes: 2 additions & 0 deletions coverage/coverage-final.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"C:\\Users\\Danna\\Documents\\CDMX009-MdLinks\\app.js": {"path":"C:\\Users\\Danna\\Documents\\CDMX009-MdLinks\\app.js","statementMap":{"0":{"start":{"line":1,"column":13},"end":{"line":1,"column":28}},"1":{"start":{"line":2,"column":11},"end":{"line":2,"column":24}},"2":{"start":{"line":3,"column":14},"end":{"line":3,"column":35}},"3":{"start":{"line":4,"column":15},"end":{"line":4,"column":37}},"4":{"start":{"line":7,"column":19},"end":{"line":7,"column":68}},"5":{"start":{"line":7,"column":26},"end":{"line":7,"column":68}},"6":{"start":{"line":10,"column":17},"end":{"line":18,"column":1}},"7":{"start":{"line":11,"column":16},"end":{"line":11,"column":46}},"8":{"start":{"line":12,"column":4},"end":{"line":12,"column":68}},"9":{"start":{"line":12,"column":19},"end":{"line":12,"column":68}},"10":{"start":{"line":13,"column":14},"end":{"line":13,"column":37}},"11":{"start":{"line":14,"column":4},"end":{"line":17,"column":5}},"12":{"start":{"line":15,"column":30},"end":{"line":15,"column":58}},"13":{"start":{"line":16,"column":8},"end":{"line":16,"column":35}},"14":{"start":{"line":21,"column":18},"end":{"line":26,"column":1}},"15":{"start":{"line":22,"column":4},"end":{"line":22,"column":81}},"16":{"start":{"line":23,"column":16},"end":{"line":23,"column":83}},"17":{"start":{"line":24,"column":17},"end":{"line":24,"column":45}},"18":{"start":{"line":25,"column":4},"end":{"line":25,"column":28}},"19":{"start":{"line":29,"column":24},"end":{"line":63,"column":1}},"20":{"start":{"line":30,"column":19},"end":{"line":55,"column":5}},"21":{"start":{"line":30,"column":40},"end":{"line":54,"column":10}},"22":{"start":{"line":32,"column":31},"end":{"line":36,"column":13}},"23":{"start":{"line":37,"column":12},"end":{"line":41,"column":13}},"24":{"start":{"line":38,"column":16},"end":{"line":38,"column":100}},"25":{"start":{"line":40,"column":16},"end":{"line":40,"column":100}},"26":{"start":{"line":42,"column":12},"end":{"line":42,"column":31}},"27":{"start":{"line":45,"column":22},"end":{"line":49,"column":13}},"28":{"start":{"line":50,"column":12},"end":{"line":52,"column":13}},"29":{"start":{"line":51,"column":16},"end":{"line":51,"column":94}},"30":{"start":{"line":53,"column":12},"end":{"line":53,"column":22}},"31":{"start":{"line":57,"column":4},"end":{"line":61,"column":10}},"32":{"start":{"line":59,"column":12},"end":{"line":59,"column":27}},"33":{"start":{"line":67,"column":4},"end":{"line":67,"column":68}},"34":{"start":{"line":68,"column":4},"end":{"line":73,"column":11}},"35":{"start":{"line":69,"column":8},"end":{"line":71,"column":9}},"36":{"start":{"line":70,"column":12},"end":{"line":70,"column":34}},"37":{"start":{"line":72,"column":8},"end":{"line":72,"column":25}},"38":{"start":{"line":74,"column":4},"end":{"line":79,"column":11}},"39":{"start":{"line":75,"column":8},"end":{"line":77,"column":9}},"40":{"start":{"line":76,"column":12},"end":{"line":76,"column":34}},"41":{"start":{"line":78,"column":8},"end":{"line":78,"column":25}},"42":{"start":{"line":81,"column":4},"end":{"line":81,"column":14}},"43":{"start":{"line":84,"column":0},"end":{"line":90,"column":1}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":7,"column":19},"end":{"line":7,"column":20}},"loc":{"start":{"line":7,"column":26},"end":{"line":7,"column":68}},"line":7},"1":{"name":"(anonymous_1)","decl":{"start":{"line":10,"column":17},"end":{"line":10,"column":18}},"loc":{"start":{"line":10,"column":23},"end":{"line":18,"column":1}},"line":10},"2":{"name":"(anonymous_2)","decl":{"start":{"line":21,"column":18},"end":{"line":21,"column":19}},"loc":{"start":{"line":21,"column":39},"end":{"line":26,"column":1}},"line":21},"3":{"name":"(anonymous_3)","decl":{"start":{"line":29,"column":24},"end":{"line":29,"column":25}},"loc":{"start":{"line":29,"column":38},"end":{"line":63,"column":1}},"line":29},"4":{"name":"(anonymous_4)","decl":{"start":{"line":30,"column":32},"end":{"line":30,"column":33}},"loc":{"start":{"line":30,"column":40},"end":{"line":54,"column":10}},"line":30},"5":{"name":"(anonymous_5)","decl":{"start":{"line":31,"column":14},"end":{"line":31,"column":15}},"loc":{"start":{"line":31,"column":21},"end":{"line":43,"column":9}},"line":31},"6":{"name":"(anonymous_6)","decl":{"start":{"line":44,"column":15},"end":{"line":44,"column":16}},"loc":{"start":{"line":44,"column":24},"end":{"line":54,"column":9}},"line":44},"7":{"name":"(anonymous_7)","decl":{"start":{"line":58,"column":14},"end":{"line":58,"column":15}},"loc":{"start":{"line":58,"column":21},"end":{"line":61,"column":9}},"line":58},"8":{"name":"arrayCount","decl":{"start":{"line":66,"column":9},"end":{"line":66,"column":19}},"loc":{"start":{"line":66,"column":25},"end":{"line":82,"column":1}},"line":66},"9":{"name":"(anonymous_9)","decl":{"start":{"line":68,"column":60},"end":{"line":68,"column":61}},"loc":{"start":{"line":68,"column":85},"end":{"line":73,"column":5}},"line":68},"10":{"name":"(anonymous_10)","decl":{"start":{"line":74,"column":57},"end":{"line":74,"column":58}},"loc":{"start":{"line":74,"column":82},"end":{"line":79,"column":5}},"line":74}},"branchMap":{"0":{"loc":{"start":{"line":7,"column":26},"end":{"line":7,"column":68}},"type":"cond-expr","locations":[{"start":{"line":7,"column":56},"end":{"line":7,"column":60}},{"start":{"line":7,"column":63},"end":{"line":7,"column":68}}],"line":7},"1":{"loc":{"start":{"line":12,"column":4},"end":{"line":12,"column":68}},"type":"if","locations":[{"start":{"line":12,"column":4},"end":{"line":12,"column":68}},{"start":{"line":12,"column":4},"end":{"line":12,"column":68}}],"line":12},"2":{"loc":{"start":{"line":14,"column":4},"end":{"line":17,"column":5}},"type":"if","locations":[{"start":{"line":14,"column":4},"end":{"line":17,"column":5}},{"start":{"line":14,"column":4},"end":{"line":17,"column":5}}],"line":14},"3":{"loc":{"start":{"line":37,"column":12},"end":{"line":41,"column":13}},"type":"if","locations":[{"start":{"line":37,"column":12},"end":{"line":41,"column":13}},{"start":{"line":37,"column":12},"end":{"line":41,"column":13}}],"line":37},"4":{"loc":{"start":{"line":50,"column":12},"end":{"line":52,"column":13}},"type":"if","locations":[{"start":{"line":50,"column":12},"end":{"line":52,"column":13}},{"start":{"line":50,"column":12},"end":{"line":52,"column":13}}],"line":50},"5":{"loc":{"start":{"line":69,"column":8},"end":{"line":71,"column":9}},"type":"if","locations":[{"start":{"line":69,"column":8},"end":{"line":71,"column":9}},{"start":{"line":69,"column":8},"end":{"line":71,"column":9}}],"line":69},"6":{"loc":{"start":{"line":75,"column":8},"end":{"line":77,"column":9}},"type":"if","locations":[{"start":{"line":75,"column":8},"end":{"line":77,"column":9}},{"start":{"line":75,"column":8},"end":{"line":77,"column":9}}],"line":75}},"s":{"0":1,"1":1,"2":1,"3":1,"4":1,"5":2,"6":1,"7":1,"8":1,"9":1,"10":0,"11":0,"12":0,"13":0,"14":1,"15":1,"16":1,"17":1,"18":0,"19":1,"20":1,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":1,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":1},"f":{"0":2,"1":1,"2":1,"3":1,"4":0,"5":0,"6":0,"7":0,"8":1,"9":0,"10":0},"b":{"0":[1,1],"1":[1,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0]},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"03996bb04d781225df0409b72f9b4411d3267655"}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me parece que estos archivos no deberían estar arriba

Loading