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

Make outdir current working dir #196

Merged
merged 2 commits into from
Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*gitignore.*
.vscode/launch.json
node_modules
**/dist
output-actual
experiment
debug
31 changes: 31 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Experiment",
"program": "${workspaceFolder}/bin/index.js",
"runtimeArgs": [
"--preserve-symlinks",
"--preserve-symlinks-main",
],
"runtimeVersion": "16.0.0",
"args": [
"--config",
"./experiment/glossarify-md.conf.json"
]
},
{
"type": "node",
"request": "attach",
"name": "Debug External",
"address": "127.0.0.1",
"port": 9229,
"localRoot": "${workspaceFolder}"
}
]
}
189 changes: 100 additions & 89 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
- [Preparing for Contributions](#preparing-for-contributions)
- [Installing](#installing)
- [Running a particular configuration](#running-a-particular-configuration)
- [Experiments](#experiments)
- [Debugging](#debugging)
- [Testing](#testing)
- [Directory Structure](#directory-structure)
- [Running the Test Suite](#running-the-test-suite)
- [Extending the Test Suite](#extending-the-test-suite)
- [Implement and Review](#implement-and-review)
- [Debugging](#debugging)

## Preparing for Contributions

Expand Down Expand Up @@ -44,13 +45,109 @@ npm install
npm run config ./path/to/glossarify-md.conf.json
```

Remote-debug a particular configuration with
There's an equivalent for running a debug session with a config

```
npm run dconfig ./path/to/glossarify-md.conf.json
```

More notes on debugging see [Debugging](#debugging).
Since these commands can become cumbersome to write over and over again continue reading on [Experiments](#experiments).

## Experiments

Should you need to try or debug changes to *glossarify-md source code* then never change the test suite for this. Instead set up an *experiment* with a configuration like this:

```
${workspace}/
|- bin
|- doc
|- experiment/ <-- create
| |- input/
| | |- document.md
| | |- glossary.md
| |- output/
| |- glossarify-md.conf.json
|- ...
`- package.json
```

*glossarify-md.conf.json*

```json
{
"$schema": "../conf/v5/schema.json",
"baseDir": "./input",
"outDir": "../output",
"dev": {
"termsFile": "../output/terms.json"
}
}
```

Then to run the experiment use the shortcut

```
npm run experiment
```

> **☛ Note**: If you need to create files outside the `experiment/` folder, consider using a \*.gitignore.\* pattern. Those files will be excluded from revision control and may not be accidentally committed.

## Debugging

```
npm run dconfig ./path/to/glossarify-md.conf.json
```

starts a "remote" debug session at `127.0.0.1:9229`. Remote debugging allows any debugger frontend speaking the Remote Debug Protocol to connect to the process. For example you can connect with

- *Chrome Browser* ⇨ URL-Bar: `chrome://inspect`
- *VSCode* by attaching as a remote debugger
- others

If you are coding in [VSCode](https://code.visualstudio.com) then you can use `Debug External` from our [Launch Configuration](./.vscode/launch.json) to debug *arbitrary* configurations after having issued `npm run dconfig ...` on a terminal.

**Debugging Experiments**:

In VSCode use the `Debug Experiment` launch configuration to debug experiments with the internal debugger (does not require `npm run debug`). Otherwise you may find

```
npm run debug
```

handy to launch a remote debug session for an experiment.

*VSCode Launch Configuration in ${workspace}/.vscode/launch.json*

```json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Experiment",
"program": "${workspaceFolder}/bin/index.js",
"runtimeArgs": [
"--preserve-symlinks",
"--preserve-symlinks-main",
],
"runtimeVersion": "16.0.0",
"args": [
"--config",
"./experiment/glossarify-md.conf.json"
]
},
{
"type": "node",
"request": "attach",
"name": "Debug External",
"address": "127.0.0.1",
"port": 9229,
"localRoot": "${workspaceFolder}"
}
]
}
```

## Testing

Expand Down Expand Up @@ -191,89 +288,3 @@ Tweak the implementation & rerun tests as necessary. Start careful reviewing aga
1. Push local history

1. Open a *Pull Request* in the origin repository (use dedicated pull requests for different fixes or features)

## Debugging

Should you need to analyse your implementation avoid changing the test suite for the sake of the analysis. Instead set up a *debug* folder and a configuration as follows:

```
${workspace}/
|- bin
|- debug/ <-- create
| |- input/
| | |- document.md
| | |- glossary.md
| |- output/
| |- glossarify-md.conf.json
|- doc
|- ...
`- package.json
```

*glossarify-md.conf.json*

```json
{
"$schema": "../conf/v5/schema.json",
"baseDir": "./input",
"outDir": "../output",
"dev": {
"termsFile": "../output/terms.json",
"printInputAst": true
}
}
```

To debug `${workspace}/debug/glossarify-md.conf.json` type

```
npm run debug
```

This starts a remote debug session at `127.0.0.1:9229`. To debug a configuration
in another directory type:

```
npm run dconfig ./path/to/glossarify-md.conf.json
```

You can now connect e.g. with

- *Chrome Browser* ⇨ URL-Bar: `chrome://inspect`
- *VSCode* (attaching as a remote debugger)

The launch configuration example for [VSCode](https://code.visualstudio.com) below offers two debug options:

1. VSCode connecting as a remote debugger
1. VSCode internal debugging

*${workspace}/.vscode/launch.json*

```json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug (internal)",
"program": "${workspaceFolder}/bin/index.js",
"args": [
"--config",
"./debug/glossarify-md.conf.json"
]
},
{
"type": "node",
"request": "attach",
"name": "Debug (remote)",
"address": "127.0.0.1",
"port": 9229,
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}/bin/index.js"
}
]
}
```

> **☛ Note**: If you need to create files outside the `debug/` folder, consider using a \*.gitignore.\* pattern. Those files will be excluded from revision control and may not be accidentally committed.
5 changes: 4 additions & 1 deletion lib/model/context.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import glob from "glob";
import path from "path";
import path from "node:path";
import proc from "node:process";
import { relativeFromTo, toForwardSlash } from "../path/tools.js";
import { init as initCollator } from "../text/collator.js";
import { Glossary } from "./glossary.js";


export function newContext(glossarifyMdConf) {
initCollator(glossarifyMdConf.i18n);
const context = new Context(glossarifyMdConf);
Expand Down Expand Up @@ -60,6 +62,7 @@ class Context {

setBaseDir(baseDir) {
this.conf.baseDir = toForwardSlash(baseDir);
proc.chdir(this.conf.baseDir);
}
}

Expand Down
Loading