Merge pull request #9 from karashiiro/master

Add library documentation
This commit is contained in:
karashiiro 2021-05-28 11:24:35 -07:00 committed by GitHub
commit 6c7c28e44d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 3741 additions and 71 deletions

18
.github/workflows/documentation.yml vendored Normal file
View file

@ -0,0 +1,18 @@
name: Generate documentation
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 14.x
uses: actions/setup-node@v2
with:
node-version: 14.x
- run: npm run docs:deploy

2
.gitignore vendored
View file

@ -104,3 +104,5 @@ dist
.tern-port
diskcache/
docs/

View file

@ -1 +1,4 @@
index.js
docs/
gh-pages.js
.github/

View file

@ -78,10 +78,20 @@ const infoTextBigStartY = infoTextSmallStartY + 25;
const infoTextSpacing = 50;
class CardCreator {
/**
* Creates a new card creator.
* @constructor
*/
constructor() {
this.isInit = false;
}
/**
* Ensures that the instance is ready to generate character cards.
* This function must be resolved before using character card
* generation methods.
* @returns {Promise} A promise representing the initialization state of this generator.
*/
async ensureInit() {
if (this.isInit) {
return;
@ -236,6 +246,23 @@ class CardCreator {
return num;
}
/**
* Creates a character card for a character.
* @param {number | string} charaId The Lodestone ID of the character to generate a card for.
* @example
* const fs = require("fs");
*
* const card = new CardCreator();
* const lodestoneId = "13821878";
*
* await card.ensureInit();
* const png = await card.createCard(lodestoneId);
*
* fs.writeFile("./test.png", png, err => {
* if (err) console.error(err);
* });
* @returns {Promise<Buffer>} A promise representating the construction of the card's image data.
*/
async createCard(charaId) {
var response = await fetch(`https://xivapi.com/character/${charaId}?extended=1&data=FC,mimo`);
var data = await response.json();

6
gh-pages.js Normal file
View file

@ -0,0 +1,6 @@
const ghpages = require("gh-pages");
ghpages.publish("docs/", (err) => {
if (err) {
console.error(err);
}
});

3742
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -10,14 +10,20 @@
],
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js"
"dev": "nodemon index.js",
"docs:generate": "jsdoc create-card.js -d docs -R readme.md",
"docs:deploy": "npm run docs:generate && node gh-pages.js"
},
"dependencies": {
"cache-manager-fs": "^1.0.8",
"cache-manager-fs-binary": "^1.0.4",
"canvas": "^2.6.1",
"express": "^4.17.1",
"node-fetch": "^2.6.1",
"node-fetch": "^2.6.1"
},
"devDependencies": {
"gh-pages": "^3.2.0",
"jsdoc": "^3.6.7",
"nodemon": "^2.0.7"
}
}

View file

@ -1,4 +1,6 @@
# XIV Character Cards
![npm Version](https://img.shields.io/npm/v/xiv-character-cards)
[![Documentation](https://img.shields.io/badge/docs-JSDoc-orange)](https://xivapi.github.io/XIV-Character-Cards/)
API to create fancy cards for FFXIV characters based on their Lodestone data, hosted at https://ffxiv-character-cards.herokuapp.com.