diff --git a/.vscode/debug-ts.js b/.vscode/debug-ts.js new file mode 100644 index 0000000..37f6354 --- /dev/null +++ b/.vscode/debug-ts.js @@ -0,0 +1,52 @@ +'use strict'; +const meow = require('meow'); +const path = require('path'); + +const tsFile = getTSFile(); +const jsFile = TS2JS(tsFile); + +replaceCLIArg(tsFile, jsFile); + +// Ava debugger +require('ava/profile'); + +/** + * get ts file path from CLI args + * + * @return string path + */ +function getTSFile() { + const cli = meow(); + return cli.input[0]; +} + +/** + * get associated compiled js file path + * + * @param tsFile path + * @return string path + */ +function TS2JS(tsFile) { + const srcFolder = path.join(__dirname, '..', 'src'); + const distFolder = path.join(__dirname, '..', 'build', 'main'); + + const tsPathObj = path.parse(tsFile); + + return path.format({ + dir: tsPathObj.dir.replace(srcFolder, distFolder), + ext: '.js', + name: tsPathObj.name, + root: tsPathObj.root + }); +} + +/** + * replace a value in CLI args + * + * @param search value to search + * @param replace value to replace + * @return void + */ +function replaceCLIArg(search, replace) { + process.argv[process.argv.indexOf(search)] = replace; +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 2e7ac5e..e2ef905 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,7 +1,6 @@ { "version": "0.2.0", - "configurations": [ - { + "configurations": [{ "type": "node", "request": "launch", "name": "Debug Project", @@ -26,22 +25,11 @@ "console": "externalTerminal" }, { - /// Usage: set appropriate breakpoints in a *.spec.ts file, then open the - // respective *.spec.js file to run this task. Once a breakpoint is hit, - // the debugger will open the source *.spec.ts file for debugging. "type": "node", "request": "launch", - "name": "Debug Visible Compiled Spec", - "program": "${workspaceFolder}/node_modules/ava/profile.js", - "args": [ - "${file}" - // TODO: VSCode's launch.json variable substitution - // (https://code.visualstudio.com/docs/editor/variables-reference) - // doesn't quite allow us to go from: - // `./src/path/to/file.ts` to `./build/main/path/to/file.js` - // so the user has to navigate to the compiled file manually. (Close:) - // "${workspaceFolder}/build/main/lib/${fileBasenameNoExtension}.js" - ], + "name": "Debug Spec", + "program": "${workspaceRoot}/.vscode/debug-ts.js", + "args": ["${file}"], "skipFiles": ["/**/*.js"], // Consider using `npm run watch` or `yarn watch` for faster debugging // "preLaunchTask": "npm: build", @@ -93,4 +81,4 @@ "runtimeArgs": ["--nolazy"] } ] -} +} \ No newline at end of file