{"_id":"@alu0101420868/espree-logging-solution","_rev":"1-a3a01c20bd6c9cbf3ddadb58c1779f64","name":"@alu0101420868/espree-logging-solution","dist-tags":{"latest":"0.4.0"},"versions":{"0.3.0":{"name":"@alu0101420868/espree-logging-solution","author":{"name":"Alicia G. Cruz Pérez","email":"alu0101420868@ull.edu.es","url":"https://crguezl.github.io/"},"description":"Adds logs to javascript code","type":"module","bin":{"funlog":"bin/log.js"},"scripts":{"test":"mocha test/test.mjs","cov":"c8 npm run test","clean":"rm -f test/data/out*.js; rm -f src/calc.js;"},"dependencies":{"acorn":"^8.8.2","commander":"^10.0.0","escodegen":"^2.0.0","espree":"^9.4.1","estraverse":"^5.2.0","underscore":"^1.12.0"},"version":"0.3.0","devDependencies":{"c8":"^7.13.0","chai":"^4.3.7","mocha":"^10.2.0"},"gitHead":"b414b21b04bee8f27bcadc16b0638409c24ab51c","_id":"@alu0101420868/espree-logging-solution@0.3.0","_nodeVersion":"17.5.0","_npmVersion":"8.4.1","dist":{"integrity":"sha512-qggyMb9Aov5WwN80lGcdaOvYxFRqJ31FSTPfR05Dj34G3x7JAf5fLEAf25D9IdAqjdEX2afrEy9sAkCzocTzfw==","shasum":"90eeaccd6c49893c0c5475553a31cf01ff82fe67","tarball":"https://registry.npmjs.org/@alu0101420868/espree-logging-solution/-/espree-logging-solution-0.3.0.tgz","fileCount":43,"unpackedSize":1020966,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDNV1pO9XPVq8tB83MKFWV1xh5332kQKQTquFY6ZQaeXAiA1VB8WIZpP96Ph9WFgVfUYrSpGq+s5bVURmuRli3Dc4g=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkAPfIACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqBJg//TBR37bSEpKgtxBKztxW2ojOAtBVnKH91jT7Y3K2ski5B0GJK\r\nRug7e5Nt7i9CurZ3/3paCumAZjsTa2dlgN5ppjW2YDR32RAKNNyblGN/9ovj\r\np0LUnXlvno3ba8KTr/JjnCbj89zZkc7Y9ClWDaKA/gBqYCGqAgiSF7ch/jvm\r\n7JuXQNkyHJqAIQq0LVSZ/8b7akm5j/YVe8rtktqj9IT5kA5+YCyjb3pAPlmC\r\nXjEdAhZbeXASpuZZipGTZZFYW2javFc0JuLrui/DUaOnNsqixhME2tMiWj1n\r\n5CzL5epnWPsY4KFw0BdHfAmb+vWGFDyQA3VWQ2sDbFnCG1W6sKiMGrjURpea\r\nkDV0+GuaDcvP6IEjOcF2gotZu9iVy/g4+6Nn16I2AQan6CwD6Enny+Cf9STs\r\n5K4uJ3JqXMYJ03MFKRUvXXCVOH/U9JGw1qDQuMTgg9VJYpSxm80gKSfO9Pu4\r\nP35NBRdGmyYJ7om79lY0DZX+nyojY3+l0hd0I5y9hC0IKUI2GCzDzy+ioHvI\r\nStvaMqdtyXpqkigXM4U/m0pdOc0NX7vIwhn5MMlUg5WhxHacNwbjUnzAQedw\r\n96j1W+Qn6jdxPugQV4LQTsV17CHeHMNHOaUh0Qpgd3oY0hzRY+s9K/S+uiKN\r\ncry1Ky/RCAYlKLi4ZuJGM2s/JOLzQpK0nUY=\r\n=as5X\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"alu0101420868","email":"alu0101420868@ull.edu.es"},"directories":{},"maintainers":[{"name":"alu0101420868","email":"alu0101420868@ull.edu.es"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/espree-logging-solution_0.3.0_1677785032096_0.11584235384896946"},"_hasShrinkwrap":false},"0.4.0":{"name":"@alu0101420868/espree-logging-solution","author":{"name":"Alicia G. Cruz Pérez","email":"alu0101420868@ull.edu.es","url":"https://crguezl.github.io/"},"description":"Adds logs to javascript code","type":"module","bin":{"funlog":"bin/log.js"},"scripts":{"test":"mocha test/test.mjs","cov":"c8 npm run test","clean":"rm -f test/data/out*.js; rm -f src/calc.js;"},"dependencies":{"acorn":"^8.8.2","commander":"^10.0.0","escodegen":"^2.0.0","espree":"^9.4.1","estraverse":"^5.2.0","underscore":"^1.12.0"},"version":"0.4.0","devDependencies":{"c8":"^7.13.0","chai":"^4.3.7","mocha":"^10.2.0"},"gitHead":"7cfb71ce3fd434619aa536dd2bbe7c896d97833a","_id":"@alu0101420868/espree-logging-solution@0.4.0","_nodeVersion":"17.5.0","_npmVersion":"8.4.1","dist":{"integrity":"sha512-E5X5sqoSjIEQjXhoxJZ4jUDNe/tdcKuAFbOp5713qEVbOtrr1bdZvssM7QhuUBYJM9CnKevehh3pN8rSSw/eaQ==","shasum":"98d1d38218d8914479b0f580f48cf3333e289c04","tarball":"https://registry.npmjs.org/@alu0101420868/espree-logging-solution/-/espree-logging-solution-0.4.0.tgz","fileCount":44,"unpackedSize":1181935,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCsSueDJPwQlcihFQymbdfuWGWoJcaEOIRl/y4SrhppQgIhAOWVLdc9jYPkStPFx6+UwIlZjpmj6WzoB7SJ2OYAuWyT"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkAQmOACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrQMQ/9E5hAoDjlP24IxIQBJV5V+RSTknyCICJ/M51L9OMosuxVNPJj\r\nfg+NiarINX9b9pQBC9MDnBeet+/sDvaQbcAwCVMll0eikcoJpD4O3CE+bb0f\r\nN8opwgeqwuFu0TWHXOXV+dJjoIW3ch6gPr/0FiiSo4vq2x90Oz6Y59WgHd/a\r\nj7h1KmBFyt0ckmz4M3VOl7/Stqd8LYlXuAlAoDO7X80CQF4/yevkWwhNLM6a\r\nsRbLo81lt/ciBVBgJ6S3G4NBYb3OnOlEyxHKQA7ojI8RyLz2dcVtGe8rTtWF\r\nngjChuOEOPNEqtdkNts09Sz5S3JbH4zON40EBBwRyuQt4P745QLT8959Yd17\r\nxpnRbCDTGL/VRfdcUmUOwEWv35kcb3oWfxtz/g4q02An+bMgYT6xkImaN4Pl\r\nnZmSBYTPZmhErCFfmA8E1B+RL8X1mIg9gZ8RY2J+lgVu9hz4FRDqPwr8N/0I\r\nbRB7JfuVw82+zaAZfbj8GDtQAGGiXwO2+Xeql9FEg2ySuFBEKllJfFCOq2sn\r\nOJmjH16S4qvv9EAIYOUUt573NRSmhS4geDW+G2AujJZkgbWeuUBKPV4cnJuP\r\nEK6WeFobEfcRI+PINwbPXUr1mU6ZBGsnmlMKgrlCSHYSRPpChy2teuzRQviz\r\n7Dl5zfBTpnJnIx+jn2Be3htfkTp/48deXk0=\r\n=2r6P\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"alu0101420868","email":"alu0101420868@ull.edu.es"},"directories":{},"maintainers":[{"name":"alu0101420868","email":"alu0101420868@ull.edu.es"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/espree-logging-solution_0.4.0_1677789582308_0.3384330363114487"},"_hasShrinkwrap":false}},"time":{"created":"2023-03-02T19:23:52.035Z","0.3.0":"2023-03-02T19:23:52.285Z","modified":"2023-03-02T20:39:42.622Z","0.4.0":"2023-03-02T20:39:42.520Z"},"maintainers":[{"name":"alu0101420868","email":"alu0101420868@ull.edu.es"}],"description":"Adds logs to javascript code","author":{"name":"Alicia G. Cruz Pérez","email":"alu0101420868@ull.edu.es","url":"https://crguezl.github.io/"},"readme":"[![Open in Codespaces](https://classroom.github.com/assets/launch-codespace-f4981d0f882b2a3f0472912d15f9806d57e124e0fc890972558857b51b24a6f9.svg)](https://classroom.github.com/open-in-codespaces?assignment_repo_id=10331479)\n# Práctica Espree logging\n\n## 1. Indicar los valores de los argumentos\n\nSe ha modificado el código de `logging-espree.js` para que el log también indique los valores de los argumentos que se pasaron a la función. \nEjemplo:\n\n```javascript\nfunction foo(a, b) {\n  var x = 'blah';\n  var y = (function (z) {\n    return z+3;\n  })(2);\n}\nfoo(1, 'wut', 3);\n```\n\n```javascript\nfunction foo(a, b) {\n    console.log(`Entering foo(${ a }, ${ b })`);\n    var x = 'blah';\n    var y = function (z) {\n        console.log(`Entering <anonymous function>(${ z })`);\n        return z + 3;\n    }(2);\n}\nfoo(1, 'wut', 3);\n```\n\n## 2. CLI con [Commander.js](https://www.npmjs.com/package/commander)\n\n- En `log.js`\n\n```javascript\nprogram\n  .version(version)\n  .argument(\"<filename>\", 'file with the original code')\n  .option(\"-o, --output <filename>\", \"file in which to write the output\")\n  .action((filename, options) => {\n    transpile(filename, options.output);\n  });\n```\n\n- El programa admite la introducción por línea de comandos\n\n![línea de comandos](./docs/comandos.png)\n\n## 3. Uso de scripts para ejecutar el programa\n\n- En `package.json`\n\n```json\n\"scripts\": {\n    \"test\": \"mocha test/test.mjs\",\n    \"cov\": \"c8 npm run test\",\n    \"clean\": \"rm -f test/data/out*.js; rm -f src/calc.js;\"\n},\n```\n\n## 4. Reto 1: Soportar funciones flecha\n\n- En `logging-espree.js` se ha añadido la función `ArrowFunctionExpression` que devuelve `true` si el nodo es una función flecha.\n\n```javascript\n/**\n * @desc Add logging to the code.\n * @param {*} code - The code to add logging to.\n * @returns {string} - The code with logging added.\n */\nexport function addLogging(code) {\n  const ast = espree.parse(code, { ecmaVersion: 12, loc: true });\n  estraverse.traverse(ast, {\n    enter: function (node, parent) {\n      if (node.type === 'FunctionDeclaration' ||\n          node.type === 'FunctionExpression' ||\n          node.type === 'ArrowFunctionExpression') {\n        addBeforeCode(node);\n      }\n    }\n  });\n  return escodegen.generate(ast);\n}\n```\n\n## 5. Reto 2: Añadir el número de línea\n\n- En `logging-espree.js` se ha modificado la función `addBeforeCode` para que indique el número de línea.\n\n```javascript\n/**\n * @desc Add logging code before the function.\n * @param {*} node - The function node.\n */\nfunction addBeforeCode(node) {\n  const name = node.id ? node.id.name : '<anonymous function>';\n  const params = node.params.map(p => '${ ' +  p.name + ' }').join(', ');\n  const beforeCode = 'console.log(\\`Entering ' + name + '(' + params + ') at line ' + node.loc.start.line + '\\`);';\n  const beforeNodes = espree.parse(beforeCode, { ecmaVersion: 12 }).body;\n  node.body.body = beforeNodes.concat(node.body.body);\n}\n```\n\n## 6. Tests and Covering\n\n- En `test-description.mjs` se han añadido test para comprobar la funcionalidad del programa\n\n```mjs\nexport default [\n  {\n    input: 'test1.js',\n    output: 'logged1.js',\n    correctLogged: 'correct-logged1.js',\n    correctOut: 'logged-out1.txt'\n  },\n  {\n    input: 'test2.js',\n    output: 'logged2.js',\n    correctLogged: 'correct-logged2.js',\n    correctOut: 'logged-out2.txt'\n  },\n  {\n    input: 'test3.js',\n    output: 'logged3.js',\n    correctLogged: 'correct-logged3.js',\n    correctOut: 'logged-out3.txt'\n  },\n  {\n    input: 'test4.js',\n    output: 'logged4.js',\n    correctLogged: 'correct-logged4.js',\n    correctOut: 'logged-out4.txt'\n  },\n  {\n    input: 'test5.js',\n    output: 'logged5.js',\n    correctLogged: 'correct-logged5.js',\n    correctOut: 'logged-out5.txt'\n  },\n]\n```\n\n- En `test.mjs` se ha añadido un fragmento de código para comprobra el correcto funcionamiento del programa\n\n```mjs\nfor (let i = 0; i < Test.length; i++) {\n  it ('Test ' + i, async function () {\n    const t = Test[i];\n    await transpile(t.input, t.output);\n    const correctLogged = await fs.readFile(t.correctLogged, 'utf-8');\n    assert.equal(removeSpaces(correctLogged), removeSpaces(await fs.readFile(t.output, 'utf-8')));\n\n    let outputs = [];\n    let oldLog = console.log;\n    console.log =\n        function(...args) {\n      outputs.push(args.join(' '));\n    }\n\n    await import(t.output);\n    console.log = oldLog;\n    const correctOut = await fs.readFile(t.correctOut, 'utf-8');\n    assert.equal(removeSpaces(outputs.join('\\n')), removeSpaces(correctOut));\n  });\n}\n```\n\n- Podemos comprobar que todos los test pasan correctamente\n\n![test](./docs/test.png)\n\n## 7. Se añade un estudio de cubrimiento de las pruebas (coverage) y se ha publicado en Github pages\n\n- Usando: \n\n```bash\nnpx c8 --reporter=html --reporter=text --report-dir docs mocha\n```\n\n![coverage](./docs/coverage.png)\n\n- En [Github pages](https://ull-esit-pl-2223.github.io/espree-logging-alicia_guadalupe-cruz-alu0101420868/)\n\n![github pages](./docs/github-pages.png)\n\n## 8. Se hace integración continua usando Github Actions\n\n- En `nodes.yml`\n\n```yml\n# Write your workflow for CI here\nname: CI\n\n# Controls when the workflow will run\non:\n  # Triggers the workflow on push or pull request events but only for the $default-branch branch\n  push:\n    branches: [ main ]\n  pull_request:\n    branches: [ main ]\n\n# A workflow run is made up of one or more jobs that can run sequentially or in parallel\njobs:\n  # This workflow contains a single job called \"build\"\n  test:\n    # The type of runner that the job will run on\n    runs-on: ubuntu-latest\n\n    # Steps represent a sequence of tasks that will be executed as part of the job\n    steps:\n      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it\n      - uses: actions/checkout@v2\n\n      # Test the code\n      - name: Test\n        run: npm ci && npm test\n```\n![github actions](./docs/github-actions.png)\n\n## 9. NPM\n\n- Se ha publicado el paquete en [NPM](https://www.npmjs.com/package/@alu0101420868/espree-logging-solution?activeTab=readme)\n\n- Para loquearnos en NPM usamos:\n\n```bash\nnpm login\n```\n\n- Para publicar el paquete usamos:\n\n```bash\nnpm publish --access=public\n```\n\n![npm](./docs/npm.png)\n","readmeFilename":"README.md"}