Skip to content

Commit

Permalink
[WIP] rewrite (kyranet#1)
Browse files Browse the repository at this point in the history
* [WIP] rewrite

* plugging in and docs

* docs corrections

* going to need this

* Add a bunch of stuff

* fix lint

* docs corrections

* another missing external

* oops

* more init stuff

* more externals

* tweak headers

* whoops

* whoops x2 + debug

* leTypo

* another!

* oops

* uh, try this

* and don't forget this

* fixes

* how about a diy http server?

* oops

* try this

* hmm?

* debug

* ?

* ah, got it

* more fixes

* need node v10+ for: for await of

although, that can be changed with the transfer command.

* some docs and index additions

* docs corrections

* bloody caps
  • Loading branch information
bdistin authored Jun 9, 2018
1 parent cb4919d commit 4dfe900
Show file tree
Hide file tree
Showing 44 changed files with 920 additions and 127 deletions.
3 changes: 3 additions & 0 deletions .eslintrcmd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "klasa/md"
}
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
25 changes: 25 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Contributing

**The issue tracker is only for issue reporting or proposals/suggestions. If you have a question, you can find us in our [Discord Server](https://discord.gg/FpEFSyY)**.

To contribute to this repository, feel free to create a new fork of the repository
submit a pull request. We highly suggest [ESLint](https://eslint.org/) to be installed
in your text editor or IDE of your choice to avoid fail builds from Travis.

1. Fork, clone, and select the **master** branch.
2. Create a new branch in your fork.
3. Commit your changes, and push them.
4. Submit a Pull Request [here](https://github.com/dirigeants/klasa/pulls)!

## Klasa Concept Guidelines

There are a number of guidelines considered when reviewing Pull Requests to be merged into core framework (further referred to as __core__). _This is by no means an exhaustive list, but here are some things to consider before/while submitting your ideas._

- Klasa should never change D.JS's default behavior in core. Klasa should only add to D.JS and be as consistent as possible with D.JS.
- Nothing in core should respond with embeds or be terribly "personalized". Instead everything should be an abstract working base that people can personalize themselves to their own needs.
- Everything in core should be generally useful for the majority of Klasa bots. (A reason why core doesn't implement any Music features.) Don't let that stop you if you've got a good concept though, as your idea still might be a great addition to [klasa-pieces](https://github.com/dirigeants/klasa-pieces) or as an optional addon package.
- As much of the framework as possible is meant to be customizable for any possible use-case, even if the use-case is niche. New features shouldn't break existing use-cases without a strong/well-thought-out reason (that doesn't conflict with any other guideline).
- Everything should be shard compliant. If something you are PRing would break when sharding, break other things from supporting sharding, or is incompatible with sharding; then you will need to think of a way to make it work with sharding in mind before it will be accepted/merged.
- Everything should be documented with [jsdocs](http://usejsdoc.org/), whether private or not. __If you see a mistake in the docs, please pr a fix.__
- Everything should follow OOP paradigms and generally rely on behavior over state where possible. This generally helps methods be predictable, keeps the codebase simple & understandable, reduces code duplication through abstraction, and leads to efficiency and therefore scalability.
- Everything should follow our ESLint rules as closely as possible, and should pass lint tests even if you must disable a rule for a single line.
24 changes: 24 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
### Describe the issue

### Code or steps to reproduce

```js

```

<!--
If your issue is a proposal, you can provide its use case showing code.
Make sure to explain everything well and comment the code, so we can
follow up.
-->

### Expected and actual behaviour


### Further details

- **discord.js version**:
- **node.js version**:
- **Klasa version**:
- [ ] I have modified core files.
- [ ] I have tested the issue on latest master. Commit hash:
13 changes: 13 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### Description of the PR


### Changes Proposed in this Pull Request (List new items in CHANGELOG.MD)

-

### Semver Classification

- [ ] This PR only includes documentation or non-code changes.
- [ ] This PR fixes a bug and does not change the (intended) framework interface.
- [ ] This PR adds methods or properties to the framework interface.
- [ ] This PR removes or renames methods or properties in the framework interface.
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ build/Release
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

Expand All @@ -57,5 +54,10 @@ typings/
# dotenv environment variables file
.env

.vscode
package-lock.json
docs

package-lock\.json
\.vscode/
\.idea/
desktop.ini
13 changes: 13 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"default": true,
"header-style": { "style": "atx" },
"ul-indent": { "indent": 4 },
"line-length": false,
"no-hard-tabs": false,
"first-line-h1": false,
"first-header-h1": false,
"no-trailing-punctuation": false,
"no-blanks-blockquote": false,
"no-trailing-spaces": false,
"no-inline-html": false
}
31 changes: 31 additions & 0 deletions .travis-deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# Based on https://github.com/discordjs/discord.js-site/blob/master/deploy/deploy.sh

set -e

if [ -n "$TRAVIS_TAG" -o "$TRAVIS_PULL_REQUEST" != "false" ]; then
echo -e "Not building for a non branch push - building without deploying."
npm run docs
exit 0
fi

echo -e "Building for a branch push - building and deploying."

REPO=$(git config remote.origin.url)
SHA=$(git rev-parse --verify HEAD)

#new docs

TARGET_BRANCH="docs"
git clone $REPO out -b $TARGET_BRANCH

npm run docs

mv docs/docs.json out/${TRAVIS_BRANCH//\//_}.json

cd out
git add --all .
git config user.name "Travis CI"
git config user.email "${COMMIT_EMAIL}"
git commit -m "Docs build: ${SHA}" || true
git push "https://${GH_TOKEN}@${GH_REF}" $TARGET_BRANCH
20 changes: 20 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
language: node_js
node_js:
- "8"
install: npm install
jobs:
include:
- stage: test
script: npm test
- stage: deploy
script: bash ./.travis-deploy.sh
cache:
directories:
- node_modules
#notifications:
# webhooks:
# urls:
# - https://webhooks.gitter.im/e/0926b82fc22ea0760ede
# on_success: always # options: [always|never|change] default: always
# on_failure: always # options: [always|never|change] default: always
# on_start: never # options: [always|never|change] default: always
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# klasa-dashboard-hooks

Simple plugin to expose an api from a klasa bot. Lets you build an external dashboard in one of several frameworks such as Vue.js.
19 changes: 19 additions & 0 deletions guides/.docconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[{
"name": "Getting Started",
"files": [{
"name": "Getting Started",
"path": "GettingStarted.md"
}]
},
{
"name": "Piece Basics",
"files": [
{
"name": "Creating Routes",
"path": "CreatingRoutes.md"
},
{
"name": "Creating Middlewares",
"path": "CreatingMiddlewares.md"
}]
}]
3 changes: 3 additions & 0 deletions guides/Getting Started/GettingStarted.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Getting Started

placeholder
1 change: 1 addition & 0 deletions guides/Piece Basics/CreatingMiddlewares.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
placeholder
1 change: 1 addition & 0 deletions guides/Piece Basics/CreatingRoutes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
placeholder
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"docs": "npx dg --source src --custom guides/.docconfig.json --output docs/docs.json --logging"
},
"dependencies": {
"polka": "^0.3.4"
"snekfetch": "^4.0.2"
},
"peerDependencies": {
"klasa": "github:dirigeants/klasa#master"
Expand All @@ -36,6 +36,6 @@
"typescript": "^2.6.2"
},
"engines": {
"node": ">=8.6.0"
"node": ">=10.0.0"
}
}
28 changes: 27 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
module.exports = { DashboardHooks: require('./lib/DashboardHooks') };
module.exports = {
Client: require('./lib/Client'),
Server: require('./lib/http/Server'),
Middleware: require('./lib/structures/Middleware'),
MiddlewareStore: require('./lib/structures/MiddlewareStore'),
Route: require('./lib/structures/Route'),
RouteStore: require('./lib/structures/RouteStore'),
constants: require('./lib/util/constants'),
util: require('./lib/util/Util')
};

/**
* @external KlasaClient
* @see {@link https://klasa.js.org/#/docs/main/master/class/KlasaClient}
*/
/**
* @external Piece
* @see {@link https://klasa.js.org/#/docs/main/master/class/Piece}
*/
/**
* @external Store
* @see {@link https://klasa.js.org/#/docs/main/master/class/Store}
*/
/**
* @external KlasaClientOptions
* @see {@link https://klasa.js.org/#/docs/main/master/typedef/KlasaClientOptions}
*/
76 changes: 76 additions & 0 deletions src/lib/Client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const { join } = require('path');

const { Client, util: { mergeDefault } } = require('klasa');

const Server = require('./http/Server');
const RouteStore = require('./structures/RouteStore');
const MiddlewareStore = require('./structures/MiddlewareStore');
const { OPTIONS } = require('./util/constants');

/**
* The client for handling everything. See {@tutorial GettingStarted} for more information how to get started using this class.
* @extends external:KlasaClient
* @tutorial GettingStarted
*/
class DashboardClient extends Client {


/**
* @typedef {external:KlasaClientOptions} DashboardClientOptions
* @property {KlasaDashboardHooksOptions} [dashboardHooks] The Klasa-Dashboard-Hooks specific options
*/

/**
* @typedef {Object} KlasaDashboardHooksOptions
* @property {string} [apiPrefix="api/"] The route prefix for the api
* @property {string} [origin="*"] The cross origin setting
* @property {number} [port=4000] The port the api runs on
*/

/**
* Constructs the klasa-dashboard-hooks client
* @since 0.0.1
* @param {DashboardClientOptions} config The config to pass to the new client
*/
constructor(config) {
super(config);
mergeDefault(OPTIONS, this.options);

/**
* The directory to the node_modules folder where Klasa-Dashboard-Hooks exists
* @since 0.0.1
* @type {string}
*/
this.hooksBaseDir = join(__dirname, '../');

/**
* The http server handler for the api
* @since 0.0.1
* @type {Server}
*/
this.server = new Server(this);

/**
* The cache where routes are stored
* @since 0.0.1
* @type {RouteStore}
*/
this.routes = new RouteStore(this);

/**
* The cache where middlewares are stored
* @since 0.0.1
* @type {MiddlewareStore}
*/
this.middlewares = new MiddlewareStore(this);

this
.registerStore(this.routes)
.registerStore(this.middlewares);

this.server.listen(this.options.dashboardHooks.port);
}

}

module.exports = DashboardClient;
Loading

0 comments on commit 4dfe900

Please sign in to comment.