Skip to content

Commit 1e67392

Browse files
authored
* typings: Make typings better * misc: Folder re-organization * fix: Wrong path in index.mjs * misc: More re-organization * misc: getFontHeight and fixed typos * misc: Fixed more typos * misc: Use ! instead of === for booleans * docs: Fixed getLineDash's description * misc: Refactored canvas size methods * ci: Make deploy only push to webpack on releases or master * lint: Disable TS checking in filters.js * docs: Updated all guides * docs: Removed extra underscore in ProfileCard.md * docs: Remove installation screenshot with plain text * src: Make addMultilineText not wrap lines * feat: Added wordWrap utility function * feat: Added Canvas#wrapText * misc: Renamed Canvas.fromCanvas to Canvas.from * misc: Rename Canvas.getCanvas() to Canvas.internalCanvas * fix: Canvas#wrapText's example calling the wrong method * docs: Fixed comment * typings: Updated for latest commit, return `unknown` on callbacks * docs: Changed score to client.points.get() for clarity Co-Authored-By: eslachance <[email protected]> * src: Fixed `addMultilineText` typings, added `addWrappedText`
1 parent 1ded1d9 commit 1e67392

File tree

16 files changed

+433
-221
lines changed

16 files changed

+433
-221
lines changed

.travis-deploy.sh

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,59 @@
33

44
set -e
55

6-
# For revert branches, do nothing
6+
# For revert or dependabot branches, do nothing
77
if [[ "$TRAVIS_BRANCH" == revert-* ]] || [[ "$TRAVIS_BRANCH" == dependabot/* ]]; then
88
echo -e "\e[36m\e[1mBuild triggered for reversion branch \"${TRAVIS_BRANCH}\" - doing nothing."
99
exit 0
1010
fi
1111

12-
# For tags or pull requests, do nothing
13-
if [ -n "$TRAVIS_TAG" ] || [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
12+
# For pull requests, do nothing
13+
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
1414
echo -e "Not building for a non branch push - building without deploying."
1515
yarn docs
1616
exit 0
1717
fi
1818

19-
echo -e "Building for a branch push - building and deploying."
20-
21-
SOURCE="${TRAVIS_BRANCH//\/|\./_/}"
22-
REPO=$(git config remote.origin.url)
23-
SHA=$(git rev-parse --verify HEAD)
24-
25-
# Docs
26-
TARGET_BRANCH="docs"
27-
git clone $REPO out -b $TARGET_BRANCH
28-
yarn docs
29-
mv docs/docs.json out/${SOURCE}.json
30-
31-
cd out
32-
git add --all .
33-
git config user.name "Travis CI"
34-
git config user.email "$COMMIT_AUTHOR_EMAIL"
35-
git commit -m "Docs build: ${SHA}" || true
36-
git push "https://${GH_TOKEN}@${GH_REF}" $TARGET_BRANCH
37-
38-
# Clean-up
39-
cd ..
40-
rm -rf out
41-
42-
# Do the thing once more for webpack
43-
TARGET_BRANCH="webpack"
44-
git clone $REPO out -b $TARGET_BRANCH
45-
yarn build:browser
46-
mv webpack/canvasconstructor.min.js out/canvasconstructor.$SOURCE.min.js
47-
48-
# Commit and push
49-
cd out
50-
git add --all .
51-
git config user.name "Travis CI"
52-
git config user.email "$COMMIT_AUTHOR_EMAIL"
53-
git commit -m "Webpack build: ${SHA}" || true
54-
git push "https://${GH_TOKEN}@${GH_REF}" $TARGET_BRANCH
19+
# If it's not a tag (and not a pull request push)
20+
if [ -z $TRAVIS_TAG ]; then
21+
echo -e "Building for a branch push - building and deploying."
22+
23+
SOURCE="${TRAVIS_BRANCH//\/|\./_/}"
24+
REPO=$(git config remote.origin.url)
25+
SHA=$(git rev-parse --verify HEAD)
26+
27+
# Docs
28+
TARGET_BRANCH="docs"
29+
git clone $REPO out -b $TARGET_BRANCH
30+
yarn docs
31+
mv docs/docs.json out/${SOURCE}.json
32+
33+
cd out
34+
git add --all .
35+
git config user.name "Travis CI"
36+
git config user.email "$COMMIT_AUTHOR_EMAIL"
37+
git commit -m "Docs build: ${SHA}" || true
38+
git push "https://${GH_TOKEN}@${GH_REF}" $TARGET_BRANCH
39+
fi
40+
41+
# Only push to webpack if it's a release or master branch
42+
if [ -n "$TRAVIS_TAG" ] || [ $TRAVIS_BRANCH == "master" ]; then
43+
# Clean-up
44+
cd ..
45+
rm -rf out
46+
47+
# Do the thing once more for webpack
48+
TARGET_BRANCH="webpack"
49+
if [ -n "$TRAVIS_TAG" ]; then IDENTIFIER="$TRAVIS_TAG"; else IDENTIFIER="$TRAVIS_BRANCH"; fi
50+
git clone $REPO out -b $TARGET_BRANCH
51+
yarn build:browser
52+
mv webpack/canvasconstructor.min.js out/canvasconstructor.$IDENTIFIER.min.js
53+
54+
# Commit and push
55+
cd out
56+
git add --all .
57+
git config user.name "Travis CI"
58+
git config user.email "$COMMIT_AUTHOR_EMAIL"
59+
git commit -m "Webpack build: ${SHA}" || true
60+
git push "https://${GH_TOKEN}@${GH_REF}" $TARGET_BRANCH
61+
fi

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ new Canvas(300, 300)
3636
<script type="text/javascript" src="canvasconstructor.master.min.js"></script>
3737
<script type="text/javascript">
3838
const canvasElement = document.getElementById('canvas');
39-
CanvasConstructor.Canvas.fromCanvas(canvasElement)
39+
CanvasConstructor.Canvas.from(canvasElement)
4040
.setColor('#AEFD54')
4141
.addRect(5, 5, 290, 290)
4242
.setColor('#FFAE23')

guides/Getting Started/GettingStarted.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Getting Started
22

3-
Please check {@tutorial InstallingCanvas} for the installation. You **must** have Canvas installed and working before using this package.
3+
Please check {@tutorial InstallingCanvas} for the installation. You **must** have Canvas installed and working before
4+
using this package.
45

56
---
67

@@ -26,7 +27,7 @@ new Canvas(300, 300)
2627
<script type="text/javascript" src="canvasconstructor.master.min.js"></script>
2728
<script type="text/javascript">
2829
const canvasElement = document.getElementById('canvas');
29-
CanvasConstructor.Canvas.fromCanvas(canvasElement)
30+
CanvasConstructor.Canvas.from(canvasElement)
3031
.setColor('#AEFD54')
3132
.addRect(5, 5, 290, 290)
3233
.setColor('#FFAE23')
@@ -45,7 +46,9 @@ CanvasConstructor.Canvas.fromCanvas(canvasElement)
4546

4647
![Hello World!](https://raw.githubusercontent.com/kyranet/canvasConstructor/master/guides/assets/getting-started-example-01.png)
4748

48-
Now, let's suppose we want to add images. I'd recommend [fs-nextra](https://github.com/bdistin/fs-nextra), by BDISTIN, it requires Node.js 8.5.0 to work (it promisifies the async fs methods with `Util.promisify()`), it's a dependency-free and lightweight package that provides support for **atomic operations**.
49+
Now, let's suppose we want to add images. I'd recommend [fs-nextra](https://github.com/bdistin/fs-nextra), by BDISTIN,
50+
it requires Node.js LTS to work, it is a dependency-free and lightweight package that provides support for
51+
**atomic operations**.
4952

5053
```js
5154
const { Canvas } = require('canvas-constructor');
@@ -76,4 +79,7 @@ async function createCanvas() {
7679

7780
And now, you have created an image with a kitten in the background and some centered text in the bottom of it.
7881

79-
If you experience issues with **Canvas** or want to install it, please refer to the [canvas](https://www.npmjs.com/package/canvas) repository, if you feel you found an issue in this package, feel free to file an issue [here](https://github.com/kyranet/canvasConstructor/issues), or make a [Pull Request](https://help.github.com/articles/about-pull-requests/) if you have the fix.
82+
If you experience issues with **Canvas** or want to install it, please refer to the
83+
[canvas](https://www.npmjs.com/package/canvas) repository, if you feel you found an issue in this package, feel free to
84+
file an issue [here](https://github.com/kyranet/canvasConstructor/issues), or make a
85+
[Pull Request](https://help.github.com/articles/about-pull-requests/) if you have the fix.
Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
# Installing Canvas
22

3-
Let's start off by introducing what canvas is. In HTML, the `<canvas>` element can be used to draw images via scripting with JavaScript. The canvas that we're talking about is a Cairo backed canvas implementation for **Node.js**. An example of something that can be done with canvas is this.
3+
> **NOTE**: This guide is for installing `canvas` for node.js, if you want to use `canvas-constructor` for web browsers,
4+
use the package link from unpkg or get the bundle from the
5+
[webpack branch](https://github.com/kyranet/canvasConstructor/tree/webpack)
6+
7+
Let's start off by introducing what canvas is. In HTML, the `<canvas>` element can be used to draw images via scripting
8+
with JavaScript. The canvas that we're talking about is a Cairo backed canvas implementation for **Node.js**. An example
9+
of something that can be done with canvas is this.
410

511
![Canvas Command](https://raw.githubusercontent.com/kyranet/canvasConstructor/master/guides/assets/canvas-example.png)
612

7-
Here, the bot is using canvas to edit a template and insert your avatar, and a random users avatar onto the template. So that's just an example of what Canvas can do, let's get down to installing it.
13+
Here, the bot is using canvas to edit a template and insert your avatar, and a random users avatar onto the template. So
14+
that's just an example of what Canvas can do, let's get down to installing it.
815

916
## Installation Steps
1017

@@ -22,39 +29,54 @@ Based on what OS you're on, there are different steps to install the required pr
2229

2330
### Step 1
2431

25-
First, you need to run `npm install --global --production windows-build-tools` from a PowerShell or command prompt run as an administrator. This will take a little while, so be prepared to do other stuff while it installs.
32+
You need to install [`windows-build-tools`](https://github.com/felixrieseberg/windows-build-tools) globally from
33+
PowerShell or cmd.exe run as an administrator, this will take a little while, as it will install C++ build tools
34+
necessary to be able to compile native modules like canvas.
35+
36+
```bash
37+
# Using npm
38+
$ npm install --global windows-build-tools
39+
40+
# Using yarn
41+
$ yarn global add windows-build-tools
42+
```
2643

2744
**>Notes:**
2845

29-
- While the npm page tells you to install GTK and libjpeg-turbo, those aren't needed! Both canvas and canvas-constructor function perfectly fine without them, so they're really just taking up space that could be used for something else.
46+
- While the npm page tells you to install `GTK` and `libjpeg-turbo`, those aren't needed! Both `canvas` and
47+
`canvas-constructor` function perfectly fine without them, so they're really just taking up space that could be used for
48+
something else.
3049

3150
### Step 2
3251

33-
The next and final step is simple.
34-
35-
You can either do...
52+
The next and final step is simple, install canvas and canvas-constructor
3653

3754
```bash
3855
# Using npm
39-
$ npm i canvas
56+
$ npm i canvas canvas-constructor
4057

4158
# Using yarn
42-
$ yarn add canvas
59+
$ yarn add canvas canvas-constructor
4360
```
4461

45-
> **Note**: You can install a development version of canvas by replacing `canvas` with `Automattic/node-canvas`,
46-
however, we do not guarantee it will work with latest `canvas-constructor`.
62+
> **Note**: You can install a development version of `canvas` by replacing `canvas` with `Automattic/node-canvas`,
63+
or `canvas-constructor` with `kyranet/canvasConstructor` for that matter. However, we do not guarantee stability in
64+
development branches.
4765

48-
Next, to install canvas-constructor, you just need to do
66+
If you followed the guide completely, your console should look something like this, and you're good to go!
4967

5068
```bash
51-
# Using npm
52-
$ npm i canvas-constructor
53-
54-
# Using yarn
55-
$ yarn add canvas-constructor
69+
$ yarn add canvas canvas-constructor
70+
yarn add v1.13.0
71+
[1/4] Resolving packages...
72+
[2/4] Fetching packages...
73+
[3/4] Linking dependencies...
74+
[4/4] Building fresh packages...
75+
success Saved lockfile.
76+
success Saved 64 new dependencies.
77+
info Direct dependencies
78+
79+
5680
```
5781

58-
If you followed the guide completely, your console should look something like this, and you're good to go!
59-
6082
![Install Screenshot](https://raw.githubusercontent.com/kyranet/canvasConstructor/master/guides/assets/installation-screenshot.png)

0 commit comments

Comments
 (0)