Coder Social home page Coder Social logo

ionic-team / capacitor-docgen Goto Github PK

View Code? Open in Web Editor NEW
12.0 12.0 8.0 497 KB

Docs Readme Markdown and JSON Generator for Capacitor Plugins.

Home Page: https://capacitorjs.com/

License: Other

JavaScript 1.00% TypeScript 99.00%
capacitor capacitor-plugin docs-generator

capacitor-docgen's Introduction

@capacitor/docgen

Docs Readme Markdown and JSON Generator for Capacitor Plugins.

  • Designed specifically for generating docs for Capacitor plugins using TypeScript
  • Generates docs data pulled from JSDocs within source code
  • Replaces placeholders within existing README.md markdown files with the generated docs
  • Outputs a json file of the raw docs data
  • Ideal for formatted docs within Github and NPM readme landing pages
  • If you're looking for an entire docs site generator we recommend TypeDoc instead
npm i @capacitor/docgen --save-dev

Example Readme File

# My Capacitor Plugin ๐Ÿ”Œ

The readme file can be formatted however you'd like. Just insert
the docgen placeholder elements where the index of the API methods,
and the API docs should go.

Below is an index of all the methods available.

<docgen-index></docgen-index>

## Custom Readme Content

Manage your readme content however, and on every `docgen` rebuild
it will leave the original content as is, but update the inner text 
of the docgen placeholder elements with the updated generated docs.

<docgen-api></docgen-api>

## Commit Your Readme ๐Ÿš€

The benefit of this readme file is that is also acts as the landing 
page for the Github repo and NPM package, and the anchors within the 
docs can also be linked to and shared.

CLI

The easiest way to run docgen is to install @capacitor/docgen as a dev dependency and add the command to the package.json scripts. In the example below, HapticsPlugin is the primary interface:

docgen --api HapticsPlugin --output-readme README.md
Flag Alias Description
--api -a The name of the primary application programming interface. Required
--output-readme -r Path to the markdown file to update. Note that the file must already exist. Required
--output-json -j Path to write the raw docs data as a json file.
--project -p Path to the project's tsconfig.json file, same as the project flag for TypeScript's CLI. By default it'll attempt to find this file.

package.json script

{
  "scripts": {
    "docgen": "docgen --api HapticsPlugin --output-readme README.md"
  }
}

API

The same API that's available to the CLI can also be imported from @capacitor/docgen.

Related

capacitor-docgen's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

capacitor-docgen's Issues

Apple requires privacy descriptions to be specified in Info.plist for location information:

@capacitor/geolocation

https://capacitorjs.com/docs/apis/geolocation#ios

We need to add this manually to the info.plist file. I hope you'll add this to the Capacitor doc:

<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>$(PRODUCT_NAME) needs Location access for "some reason"!</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>$(PRODUCT_NAME) needs Location access for "some reason"!</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>$(PRODUCT_NAME) needs Location access for "some reason"!</string>

bug: wrong `reference types` in community plugins

The generated value in reference types always has the prefix @capacitor. However, community plugins have a different scope or no scope at all.

Example (see https://github.com/robingenz/capacitor-firebase/blob/main/packages/authentication/README.md#examples):

/// <reference types="@capacitor/firebase-authentication" />

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  plugins: {
    FirebaseAuthentication: {
      skipNativeAuth: false,
      providers: ["apple.com", "google.com"],
    },
  },
};

export default config;

/// <reference types="@capacitor/firebase-authentication" /> should be /// <reference types="@capacitor-firebase/authentication" />.

bug: Non-accessible APIs from external dependencies are part of the output

Hi,
thank you very much for this helpful generator.
I have the following problem since version 0.1.1:
APIs of external dependencies are included, which are not available via the plugin API (definitions.ts).

Here you can find an example: https://github.com/robingenz/capacitor-firebase-authentication/pull/122/files

In this project I have increased the version of docgen to 0.1.1 and updated the markdown. There are now many interfaces included (partly also twice), which are not available at all.

Use markdown link instead of <a> element

Currently we are busy refactoring the Capacitor Google Maps plugin. One of the improvements is better documentation. The fork (WIP) can be found here: https://github.com/DutchConcepts/capacitor-google-maps/tree/next

I use docsify to generate an organized documentation website based on the markdown documentation (can be found in the ./docs folder in that fork). The API reference is generated with this plugin. This works really well, for which I commend you ๐Ÿ‘.

The generated website (GitHub pages) can be found here.

As can be seen, the links generated by docgen are broken, because they are a <a> element instead of a markdown link.

It would be solved by changing:
<code><a href="#foobar">FooBar</a></code>
to
<code>[FooBar](#foobar)</code>

The docsify team said the following:

You need generate markdown syntax. Such as

[MyClass](#MyClass)

It will not be compiled if it is HTML.

Therefore I hope it can be solved in this plugin. As far as I can see now, I don't think this change does have any drawbacks, so it would make sense to implement it like this. But please do share your opinion about this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.