start work on documentation generator

This commit is contained in:
Amish Shah 2016-08-14 18:12:59 +01:00
parent 0224138dc9
commit 62856ff57a
6 changed files with 82 additions and 2 deletions

View file

@ -13,5 +13,6 @@ module.exports = {
"no-restricted-syntax": 0,
"no-param-reassign": 0,
"consistent-return": 0,
"import/no-extraneous-dependencies": 0,
}
};

View file

@ -0,0 +1,8 @@
module.exports = {
category: 'General',
name: 'Getting Started',
data:
`# Welcome!
discord.js is an easy-to-use and intuitive JavaScript library that wraps around the Discord API.
`,
};

14
docs/custom/index.js Normal file
View file

@ -0,0 +1,14 @@
const files = [
require('./getting_started'),
];
const categories = {};
for (const file of files) {
file.category = file.category.toLowerCase();
if (!categories[file.category]) {
categories[file.category] = {};
}
categories[file.category][file.name] = file.data;
}
module.exports = categories;

1
docs/docs.json Normal file
View file

@ -0,0 +1 @@
{"custom":{"general":{"Getting Started":"# Welcome!\ndiscord.js is an easy-to-use and intuitive JavaScript library that wraps around the Discord API.\n"}},"json":[{"id":"Client","longname":"Client","name":"Client","scope":"global","kind":"class","description":"Creates a new Discord Client\n```js\nconst Discord = require(\"discord.js\");\nconst client = new Discord.Client();\n```","meta":{"lineno":18,"filename":"Client.js","path":"src/client"},"order":0},{"id":"User","longname":"User","name":"User","scope":"global","kind":"class","description":"Represents a User on Discord.","meta":{"lineno":6,"filename":"User.js","path":"src/structures"},"order":3},{"id":"Client#user","longname":"Client#user","name":"user","scope":"instance","kind":"member","description":"The User of the logged in Client, only available after `READY` has been fired.","memberof":"Client","params":[],"returns":[{"type":{"names":["ClientUser"]},"description":"[description]"}],"meta":{"lineno":55,"filename":"Client.js","path":"src/client"},"order":2},{"id":"User#username","longname":"User#username","name":"username","scope":"instance","kind":"member","description":"The username of the User","memberof":"User","type":{"names":["String"]},"meta":{"lineno":19,"filename":"User.js","path":"src/structures"},"order":4},{"id":"User#id","longname":"User#id","name":"id","scope":"instance","kind":"member","description":"The ID of the User","memberof":"User","type":{"names":["String"]},"meta":{"lineno":24,"filename":"User.js","path":"src/structures"},"order":5},{"id":"User#discriminator","longname":"User#discriminator","name":"discriminator","scope":"instance","kind":"member","description":"A discriminator based on username for the User","memberof":"User","type":{"names":["String"]},"meta":{"lineno":29,"filename":"User.js","path":"src/structures"},"order":6},{"id":"User#avatar","longname":"User#avatar","name":"avatar","scope":"instance","kind":"member","description":"The ID of the user's avatar","memberof":"User","type":{"names":["String"]},"meta":{"lineno":34,"filename":"User.js","path":"src/structures"},"order":7},{"id":"User#bot","longname":"User#bot","name":"bot","scope":"instance","kind":"member","description":"Whether or not the User is a Bot.","memberof":"User","type":{"names":["Boolean"]},"meta":{"lineno":39,"filename":"User.js","path":"src/structures"},"order":8},{"id":"User#status","longname":"User#status","name":"status","scope":"instance","kind":"member","description":"The status of the user:\n\n* **`online`** - user is online\n* **`offline`** - user is offline\n* **`idle`** - user is AFK","memberof":"User","type":{"names":["String"]},"meta":{"lineno":48,"filename":"User.js","path":"src/structures"},"order":9},{"id":"Client#login","longname":"Client#login","name":"login","scope":"instance","kind":"function","description":"Logs the client in. If successful, resolves with the account's token.","memberof":"Client","params":[{"type":{"names":["string"]},"description":"The email or token used for the account. If it is an email, a password _must_ be\nprovided.","name":"emailOrToken"},{"type":{"names":["string"]},"optional":true,"description":"The password for the account, only needed if an email was provided.","name":"password"}],"examples":["client.login(\"token\");\n// or\nclient.login(\"email\", \"password\");"],"returns":[{"type":{"names":["Promise.<String>"]}}],"meta":{"lineno":42,"filename":"Client.js","path":"src/client"},"order":1},{"id":"User#deleteDM","longname":"User#deleteDM","name":"deleteDM","scope":"instance","kind":"function","description":"Deletes a DM Channel (if one exists) between the Client and the User. Resolves with the Channel if successful.","memberof":"User","params":[],"returns":[{"type":{"names":["Promise.<DMChannel>"]}}],"meta":{"lineno":60,"filename":"User.js","path":"src/structures"},"order":10}]}

53
docs/gen/index.js Normal file
View file

@ -0,0 +1,53 @@
let fs;
/* eslint no-console:0 no-return-assign:0 */
let parse;
const customDocs = require('../custom/index');
const GEN_VERSION = 1;
try {
fs = require('fs-extra');
parse = require('jsdoc-parse');
} catch (e) {
console.log('Error loading fs-extra or jsdoc-parse:');
console.log(e);
process.exit();
}
console.log('Starting...');
let json = '';
const stream = parse({
src: ['./src/*.js', './src/*/*.js'],
});
const cwd = (`${process.cwd()}\\`).replace(/\\/g, '/');
function cleanPaths() {
for (const item of json) {
if (item.meta && item.meta.path) {
item.meta.path = item.meta.path.replace(/\\/g, '/').replace(cwd, '');
}
}
}
function next() {
json = JSON.parse(json);
cleanPaths();
console.log('parsed inline code');
json = {
custom: customDocs,
json,
};
fs.writeFile('./docs/docs.json', JSON.stringify(json, null, 0), err => {
if (err) {
throw err;
}
console.log('done');
});
}
stream.on('data', chunk => json += chunk.toString('utf-8'));
stream.on('end', () => next());

View file

@ -4,7 +4,8 @@
"description": "A way to interface with the Discord API",
"main": "./src/index",
"scripts": {
"test": "node test/random"
"test": "node test/random",
"docs": "node docs/gen/index.js"
},
"repository": {
"type": "git",
@ -45,7 +46,9 @@
"grunt-contrib-uglify": "^0.11.0",
"grunt-jscs": "^2.8.0",
"jscs": "^2.11.0",
"load-grunt-tasks": "^3.3.0"
"load-grunt-tasks": "^3.3.0",
"fs-extra": "^0.30.0",
"jsdoc-parse": "^1.2.7"
},
"optionalDependencies": {
"node-opus": "^0.1.11"