{"_id":"@alu0101408903/espree-logging","_rev":"1-b4254208669bab7a920d93ff238e7312","name":"@alu0101408903/espree-logging","dist-tags":{"latest":"0.3.1"},"versions":{"0.3.0":{"name":"@alu0101408903/espree-logging","author":{"name":"Diego Herrera Mendoza"},"description":"Adds logs to javascript code","type":"module","bin":{"funlog":"bin/log.js"},"scripts":{"test":"mocha test/test.mjs","cov":"nyc npm test","test1":"./bin/calc2js.js test/data/test1.js","clean":"rm -rf test/data/out*"},"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":{"mocha":"^10.2.0"},"gitHead":"2baa8547dcfc8e041c146fab0fe70f2e1fe25b4d","_id":"@alu0101408903/espree-logging@0.3.0","_nodeVersion":"19.6.0","_npmVersion":"9.4.0","dist":{"integrity":"sha512-tAxVrCkZ/UVxkQvpDBD25zyYFkmkV2wioJjlHzsvqNPLcCKtzhst5B8WZyWSuWUGl72E+yQyx+VwxqbXJbiScg==","shasum":"9a219fa9438c39b1088c5509054cfc2de8f46f96","tarball":"https://registry.npmjs.org/@alu0101408903/espree-logging/-/espree-logging-0.3.0.tgz","fileCount":20,"unpackedSize":8374,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCrqYpLYTXozB//U6NViqs6HwYxWscI5XugPHzWFiYFfAIhAJQFFniJgFOfqoUEG1OQ/1vCl+CZ3SSIAgO1HkqbH5nm"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj/58yACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpotBAAl2biLmSt4CmFpWWYMboPr2EBmTu0R+nnDxCr8AargDdAOZrY\r\n3hTR8nl+hFeOXAVaXwI+AKIuV53paXBnSoUCT5q3WRQAufAuLRfUjCMXihk6\r\ncHVx0l27rYuO1jkdHq5h4CVZgi8db3g8En9wBpF8NofzvypVsd+WRZCyVXOe\r\nQt8XJgmpAD/imDpYelZ99me01H3DYElWOppR8iJ5RDhh2ewIZkhv95lkvsuq\r\n94XY8pxfvA20cWE0OYJ4yXA4Oyn8/XAV8bB/CcYtkz0fVfjwa4mKbsQBkdjX\r\ndH/byeZC7pdV91iVo9LfmFH5SKAtuh1M3mwxqzR7u9RS+ahovQHJ/2LvAYDA\r\n9QZuaeAPKeMVYemLR2dddVyOJXTczhbOV4ENaUk6rvihNNBZbT5A5erYp1hw\r\nTP0CKkyhkBmhH/EmkciSI6t1PefmTwzRsTbxBhMZ2SYFDGwI3H7w1LLFVVK7\r\nBcmPEksbkWXrtIi83ra59hfd/Okp9gGRRvGS+Rev17IOLkEXDFx40oLDDM1J\r\nUVWmxIkTs8NeI/aYKAiVJQqNOhBG9ODLli75YDVWItZZpvTy/2b3Zhn9ZE+4\r\nqUxlKBa0rodmbWNPkvMAyGFkNvc5dBu2564hemUytgk5yrusw6Hj86tdVyBZ\r\nfHK4MtctXzCUEGXUBBfSDEfymHOCa5rrlaM=\r\n=z4Qb\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"alu0101408903","email":"alu0101408903@ull.edu.es"},"directories":{},"maintainers":[{"name":"alu0101408903","email":"alu0101408903@ull.edu.es"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/espree-logging_0.3.0_1677696818362_0.45794013900897323"},"_hasShrinkwrap":false},"0.3.1":{"name":"@alu0101408903/espree-logging","author":{"name":"Diego Herrera Mendoza"},"description":"Adds logs to javascript code","type":"module","bin":{"funlog":"bin/log.js"},"scripts":{"test":"mocha test/test.mjs","cov":"nyc npm test","test1":"./bin/calc2js.js test/data/test1.js","clean":"rm -rf test/data/out*"},"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.1","devDependencies":{"mocha":"^10.2.0","nyc":"^15.1.0"},"gitHead":"3b2d394e3591268537c3e06299af61314880db2c","_id":"@alu0101408903/espree-logging@0.3.1","_nodeVersion":"19.6.0","_npmVersion":"9.4.0","dist":{"integrity":"sha512-DDLN51FJijFw9ZBRQ6jweqgy601FOwOfF0NNxqIj4HLr0LeqBuYFsoNhd4CI1oizyhRn/joD219J4NYN2LnJgQ==","shasum":"b23a61f190f32b5f4d12b5b0dc5d1db0bfb157f1","tarball":"https://registry.npmjs.org/@alu0101408903/espree-logging/-/espree-logging-0.3.1.tgz","fileCount":43,"unpackedSize":73772,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIF0IH0Me8q1LTMQ1Zgco7s6+J+WMKOMNlVGQdy9B4LDWAiBzMx7vwSsRv9/YWAfapyfo57jGvoGyW1zHEwVs5ffeEg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj/6UEACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpgMQ//Ss/twNGLHqXs23KKBkn8vj+uEdnioyh9G/yedBn+jsey4+/U\r\n6Rxlji3IPZik9lpFzOT/exnvd/w1Jv9uFYK5c9MasfOe4+jWTf8WP//lNZs8\r\nKWMobAVD329E+OYFKa//55Df7o98SIwmtRq1xBeQf8esuExp9SPsIGaWPa0D\r\nOfVTZj6kN1bJuJzzWMXwPpUsujepJmCja+J2nsJ9ziw0RR2ku2JRl+9HXOMP\r\nredrs3tIBqLaZTLkUUREH+b5Ky1Fg2XLvyhq7uI48SkQU/tJoqS/2r3fh+w3\r\n7IBrhmR4vx3qY0Nje0gt7rVZfxAUrBJzjXMoVKz/je0o9uVir93RIEWiY+ob\r\njNULwNM1EYYTkmNjgoertMpf1Ip/o7do/ss7EgZkBXnUfEKZlvi4XQ6FhLAj\r\n96vuvyQ7gGDKi/ncDikl4HXkyFF2RZ1RBYAS7UpbxUg5JGgB0EUbojup4oxx\r\n6Wmx/J8ArHyP4Hl1YTBheV0ODYEOVvkK+Yj/f/nyrdz9NDhI8bPJYzwTkOBt\r\njEugJ8Euu6ylEStd/EqYN1ntUacvIpCsW7F75bZaDBQfk73qgOp/v2XswVbO\r\nBqz+RYJQX4gkSwP/TEv16LeVwfVNNA0ciQux4hp7DY7mtvyrm3kLRWgL3JCm\r\ngNN5m8nireKURp2qjjmzI1+Fv4AHzIxl3yM=\r\n=CUl0\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"alu0101408903","email":"alu0101408903@ull.edu.es"},"directories":{},"maintainers":[{"name":"alu0101408903","email":"alu0101408903@ull.edu.es"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/espree-logging_0.3.1_1677698308640_0.35498223822323216"},"_hasShrinkwrap":false}},"time":{"created":"2023-03-01T18:53:38.268Z","0.3.0":"2023-03-01T18:53:38.519Z","modified":"2023-03-01T19:18:28.927Z","0.3.1":"2023-03-01T19:18:28.801Z"},"maintainers":[{"name":"alu0101408903","email":"alu0101408903@ull.edu.es"}],"description":"Adds logs to javascript code","author":{"name":"Diego Herrera Mendoza"},"readme":"[![Open in Codespaces](https://classroom.github.com/assets/launch-codespace-f4981d0f882b2a3f0472912d15f9806d57e124e0fc890972558857b51b24a6f9.svg)](https://classroom.github.com/open-in-codespaces?assignment_repo_id=10290036)\n# Práctica Espree logging\n\n## 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## CLI con [Commander.js](https://www.npmjs.com/package/commander)\n\nEl programa admite la introducción de parametros por linea de comandos\n\n![opciones](./docs/opciones.png)\n\n## Reto 1: Soportar funciones flecha\n\nSe ha modificado el código de `logging-espree.js` para que el log también se aplique a las funciones flecha.\n\n```javascript\n/**\n * @desc Adds logging to the input code.\n * @param {string} code The code to add logging to.\n * @returns The code with logging added.\n */\nexport function addLogging(code) {  \n  const ast = espree.parse(code, { ecmaVersion: 6 }, { loc: true });\n  estraverse.traverse(ast, {\n    enter: function (node, parent) {\n      if (node.type === 'FunctionDeclaration' ||\n        node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') {\n          addBeforeCode(node);\n      }\n    }\n  });\n  return escodegen.generate(ast);\n}\n```\n\n## Reto 2: Añadir el número de línea\n\nSe ha modificado el código de 'addBeforeCode' para que el log también indique el número de línea de la función.\n\n```javascript\n/**\n * @desc Adds a console.log statement before the function\n * @param {Object} node the function node\n */\nfunction addBeforeCode(node) {\n  let name = node.id ? node.id.name : '<anonymous function>';\n  let lineNum = node.loc.start.line;\n  let params = node.params.map(function (argumentos) {\n    if (argumentos.type === 'Identifier') {\n      return argumentos.name;\n    }\n    else if (argumentos.type === 'AssignmentPattern') {\n      return argumentos.left.name + \"=\" + argumentos.right.name;\n    }\n    else if (argumentos.type === 'RestElement') {\n      return \"...\" + argumentos.argument.name;\n    }\n  });\n  params = params.join(', ');\n  let beforeCode = `console.log(\\`Entering ${name}(${params}) at line ${lineNum}\\`);`;\n  let beforeNodes = espree.parse(beforeCode, { ecmaVersion: 6 }).body;\n  node.body.body = beforeNodes.concat(node.body.body);\n}\n```\n\n## Tests and Covering\n\nSe han añadido tests para comprobar que el programa funciona correctamente.\n\n```javascript\t\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\nSe ha añadido el siguiente fragmento de código a los test para comprobar tanto el código generado como la salida del programa.\n\n```javascript\nfor (let i = 0; i < Test.length; i++) {\n  it(`addLogging(${Tst[i].input}, ${Tst[i].output})`, async () => {\n    transpile(Test[i].input, Test[i].output);\n    const output = await fs.readFile(Test[i].output, 'utf-8');\n    const expected = await fs.readFile(Test[i].correctLogged, 'utf-8');\n    assert.equal(removeSpaces(output), removeSpaces(expected));\n    \n    // Run the output program and check the logged output is what expected\n    const logged = execSync(`node ${Test[i].output}`).toString();\n    const expectedLogged = await fs.readFile(Test[i].correctOut, 'utf-8');\n    assert.equal(removeSpaces(logged), removeSpaces(expectedLogged));\n  });\n}\n```\nAl ejecutar los test se obtiene el siguiente resultado:\n\n![test](./docs/test.png)\n\nDebido a que existe una incompatibilidad entre nyc y los módulos de ES6 no se puede realizar un correcto estudio de cobertura.\n\n![coverage](./docs/coverage.png)\n\n## GitHub Actions\n\nSe ha hecho uso de la integración continua de GitHub Actions para comprobar que el programa funciona correctamente.\n```yaml\n# Write your workflow for CI here\nname: CI\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  # Allows you to run this workflow manually from the Actions tab\n  workflow_dispatch:\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  build:\n    # The type of runner that the job will run on\n    runs-on: ubuntu-latest\n\n    name: Test\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      - name: Test\n        uses: actions/setup-node@v2\n      - run: npm ci; npm test\n```\n![github](./docs/actions.png)\n","readmeFilename":"README.md"}