# Development

## Linking

In the `packages/generator` directory, run the command:

```shell
npm link
```

output:

```shell
added 1 package, ...
```

Now you can check that the command was successfully linked by running:

```shell
npm ls --global
```

output:

```shell
/path/to/npm/
├── @hex-insights/generator@1.2.3 -> path/to/packages/generator
└── ... other global npm commands
```

Now you can make a test directory on your desktop, and run

```shell
generator --help
```

to make sure the linking was successful.

## Note:

the actual command `generator` is determined by the `"bin"` or binary
field of `package.json`, not the name of the package. However, it is best
practice for the package and binary names to be the same.


## Main Development

Now that the command is linked, all you need to do for development is to run:

```shell
npm run build
```

from the `/packages/generator` directory (or `npm run build`
at the top level).

Since the command is linked, you don't need to relink to run the command!

## Unlinking

If you want to unlink, run:

```shell
npm rm --global @hex-insights/generator
```

output:

```shell
removed 1 package, ...
```

You might want to do this if the command or package name changes, you switch to
a branch without JS Generator, or just for tidiness.

## Note:

There is an npm command `unlink`, but this does something else. The `npm link`
command has other uses for which the `unlink` command is useful, but this is not
one of them.

## Debugging

Occasionally you might encounter a situation where the linking looks correct,
you run `npm run build`, and the you run the `generator` command, and
then you are hit with this error: (with zsh)

```shell
zsh: permission denied: generator
```

This is usually caused when you completely delete the `dist` folder or otherwise
change the build settings.

To solve this, just unlink and relink. This will point the command to the right
file.
