twittwer / nx-tools

Workspace for Nx Plugins.
40 stars 7 forks source link

Watch mode for workspaceDocs. Server doesn't reload after changing source files. #44

Closed eulersson closed 2 years ago

eulersson commented 3 years ago

Hello,

Thanks for your time developing this plugin, it's very handy!

After following your recipe and configuring my builder as follows:

"configurations": {
    "serve": {
        "serve": true,
        "watch": true,
        "silent": false,
        "workspaceDocs": true,
        "port": 8081
    },
    ...
}

I can't seem to have the tool reload when I change fils under (for instance libs/shared/login/src/lib/components/login/login.component.ts).

It seems when using the workspace recipe it doesn't listen for file changes globally?

In the logs it says Watching sources in src folder.

I just wanted to know whether this is supported, or if you plan to have it in the future.

[14:51:55] 
Documentation generated in /Users/ramon/Watchity/frontend/dist/compodoc/tools/ in 8.543 seconds using gitbook theme
[14:51:55] Serving documentation from /Users/ramon/Watchity/frontend/dist/compodoc/tools/ at http://127.0.0.1:8081

[14:51:55] 
Watching sources in src folder
twittwer commented 2 years ago

The latest update (v1.6.4 🎉) should solve your issue.

During the testing of version 1.6.0 I discovered the cause of your problem. Compodoc's internal watcher cannot handle the includes of the workspaceDocs correctly, as the calculation of the highest common directory seems to fail.

Before 1.6.4 only the watch mode with json export was handled by the nodemon wrapper, now this wrapper is depending on the workspaceDocs setting to work around your issue for the moment.

eulersson commented 1 year ago

Thanks for your change @twittwer. I can see it works now if I edit the .ts files but not if I edit the README.md for each individual project of an Nx monorepo.

Prepare Compodoc...
 {
  disableCoverage: false,
  tsConfig: 'libs/tools/tsconfig.compodoc.json',
  outputPath: 'dist/compodoc/tools',
  workspaceDocs: true,
  assetsFolder: 'docs/',
  serve: true,
  watch: true,
  silent: false,
  port: 8080,
  debug: true,
  exportFormat: 'html',
  disableSourceCode: false,
  disableDomTree: false,
  disableTemplateTab: false,
  disableStyleTab: false,
  disableGraph: false,
  disablePrivate: true,
  disableProtected: false,
  disableInternal: true,
  disableLifeCycleHooks: true,
  disableRoutesGraph: false,
  disableSearch: false,
  disableDependencies: false,
  language: 'en-US',
  theme: 'gitbook',
  hideGenerator: false
}
Spawn Compodoc in nodemon... {
  command: 'yarn nodemon',
  arguments: [
    '--ignore dist',
    '--ext ts',
    '--exec "node_modules/.bin/compodoc --tsconfig="libs/tools/tsconfig.compodoc.json" --output="dist/compodoc/tools" --exportFormat="html" --name="watchity" --includes="../../../../var/folders/l4/dq9gl2r55gz1jxm0b5k0sppw0000gn/T/compodoc-includes-Bv4Xuy" --includesName="Projects" --assetsFolder="docs" --disablePrivate --disableInternal --disableLifeCycleHooks --language="en-US" --theme="gitbook" --serve --port="8080""'
  ],
  options: { cwd: '/Users/ramon/Watchity/frontend', shell: true }
}
$ /Users/ramon/Watchity/frontend/node_modules/.bin/nodemon --ignore dist --ext ts --exec 'node_modules/.bin/compodoc --tsconfig=libs/tools/tsconfig.compodoc.json --output=dist/compodoc/tools --exportFormat=html --name=watchity --includes=../../../../var/folders/l4/dq9gl2r55gz1jxm0b5k0sppw0000gn/T/compodoc-includes-Bv4Xuy --includesName=Projects --assetsFolder=docs --disablePrivate --disableInternal --disableLifeCycleHooks --language=en-US --theme=gitbook --serve --port=8080'

[nodemon] 2.0.20

[nodemon] to restart at any time, enter `rs`

[nodemon] watching path(s): *.*
[nodemon] watching extensions: ts

[nodemon] starting `node_modules/.bin/compodoc --tsconfig=libs/tools/tsconfig.compodoc.json --output=dist/compodoc/tools --exportFormat=html --name=watchity --includes=../../../../var/folders/l4/dq9gl2r55gz1jxm0b5k0sppw0000gn/T/compodoc-includes-Bv4Xuy --includesName=Projects --assetsFolder=docs --disablePrivate --disableInternal --disableLifeCycleHooks --language=en-US --theme=gitbook --serve --port=8080`

1.1.19

I can see the [nodemon] watching extensions: ts.

In your code I can see the nodemon process that it is spawned has the .ts extension filter.

    if (options.watch && options.workspaceDocs) {
      const _cmd = `${getPackageManagerCommand().exec} nodemon`;
      const _cmdArgs = [
        '--ignore dist',
        '--ext ts',
        `--exec "${cmd} ${cmdArgs
          .filter((arg) => !arg.startsWith('--watch'))
          .join(' ')}"`,
      ];

Is this done on purpose? Would it make sense to --ext the .md files too?

Thank you.

twittwer commented 1 year ago

@docwhite Do you want to rerun compodoc on .md file changes in general or the project readmes which are listed under the Projects menu? And could you provide a use case for this?

eulersson commented 1 year ago

Well, either way it would be fine.

Imagine if you are writing on the root README.md or any other project's README.md (e.g. libs/my-lib/README.md), if you want to see how—for instance—a markdown table looks like as you are writing it to make sure you don't break the table syntax then it would come handy, to iteratively see actual HTML results instead of believing the MarkDown file you are writing is valid.

Many times I had broken tables because of the MarkDown table syntax.

Now with your tool I have to kill the process and re-run it and it compiles so many files again.