CONNECT-platform / codedoc

Create beautiful modern documentation websites.

Home Page:https://codedoc.cc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Help with plugin development and publishing on NPM

danielsitnik opened this issue · comments

Hi guys.
This a followup to my earlier issue #115.

I have managed to develop the plugin and its working like a charm when the source files are placed inside the .codedoc folder.

However, I'm having errors when I bundle it into an NPM package and then install it into a fresh new project.

I have followed the same pattern of the coding-blog-plugin, so the package.json and the Typescript configurations are exactly the same.

Right now I'm testing locally, so I do an npm link inside the .codedoc folder to reference what would be the NPM package.

Here's the output of the codedoc serve command:

# Serving ...
# Fetching project configuration ...
[INFO] 13:13:31 ts-node-dev ver. 1.1.6 (using ts-node ver. 9.1.1, typescript ver. 3.9.10)
# Serving docs on http://localhost:3000
# building ........ docs/md/index.md
# BUILD FAILED!!
# ERROR in index.md
Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.

There is nothing special inside index.md, it fails even if there's just plain text there.

And this is the output of codedoc build:

# Building ...
# Fetching project configuration ...
# building ........ docs/md/index.md
(node:87550) UnhandledPromiseRejectionWarning: Error: # ERROR in index.md
Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
    at /Users/daniel.sitnik/Dev/mermaid-test/.codedoc/node_modules/@codedoc/core/src/build/index.ts:54:19
    at Object.error (/Users/daniel.sitnik/Dev/mermaid-test/.codedoc/node_modules/rxline/src/line/handle-error.ts:18:13)
    at SafeSubscriber.__tryOrUnsub (/Users/daniel.sitnik/Dev/mermaid-test/.codedoc/node_modules/rxjs/src/internal/Subscriber.ts:265:10)
    at SafeSubscriber.error (/Users/daniel.sitnik/Dev/mermaid-test/.codedoc/node_modules/rxjs/src/internal/Subscriber.ts:220:16)
    at Subscriber._error (/Users/daniel.sitnik/Dev/mermaid-test/.codedoc/node_modules/rxjs/src/internal/Subscriber.ts:143:22)
    at Subscriber.error (/Users/daniel.sitnik/Dev/mermaid-test/.codedoc/node_modules/rxjs/src/internal/Subscriber.ts:113:12)
    at MergeMapSubscriber.SimpleOuterSubscriber.notifyError (/Users/daniel.sitnik/Dev/mermaid-test/.codedoc/node_modules/rxjs/src/internal/innerSubscribe.ts:70:22)
    at SimpleInnerSubscriber._error (/Users/daniel.sitnik/Dev/mermaid-test/.codedoc/node_modules/rxjs/src/internal/innerSubscribe.ts:34:17)
    at SimpleInnerSubscriber.Subscriber.error (/Users/daniel.sitnik/Dev/mermaid-test/.codedoc/node_modules/rxjs/src/internal/Subscriber.ts:113:12)
    at /Users/daniel.sitnik/Dev/mermaid-test/.codedoc/node_modules/rxjs/src/internal/util/subscribeToPromise.ts:12:30
(node:87550) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:87550) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The code can be cloned from my repo: https://github.com/danielsitnik/codedoc-mermaid-plugin/tree/develop

Appreciate it if @loreanvictor could please take a look at this.
Thanks!

this looks pretty strange ... will take a look over the weekend.

@loreanvictor I managed to make it work!

The problem was that I was testing the package with npm link and I think somehow it messes up the module resolution.

I tried a different approach, doing npm pack and then npm install pointing directly to the generated tgz file, and this did the trick!

The plugin has been published to NPM and is ready to use!
https://www.npmjs.com/package/codedoc-mermaid-plugin

Have you automated this process? Is so, I would to look at it.

Have you automated this process? Is so, I would to look at it.

Which process do you mean?

I mean the process of publishing the NPM package.

For example, I am the maintainer of Elmish.WPF. To publish a new NuGet package, I follow these steps. Essentially, I change the version and push to master. Then this workflow creates a NuGet package with that version and publishes it to nuget.org.

Do you have a GitHub workflow that automatically publishes a new NPM package for you?

Ahhh yes yes! There are some Github actions for publishing to NPM.
I did add one but it was being triggered on new releases, I just need to tweak it to publish when I merge to the main branch.

@danielsitnik something like this?

If you need to run some tests before publishing, this might be a good example as well.

Note that these will only publish to NPM when the version specified in package.json is increased and that change is pushed to either main or master branches, but I suspect you can configure the action even further.