Skip to content

Commit

Permalink
feat: v1.0.0, add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
yisibl committed Oct 9, 2021
1 parent f3ca368 commit eeb479e
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI

env:
DEBUG: 'napi:*'
APP_NAME: 'package-template'
APP_NAME: 'resvgjs'
MACOSX_DEPLOYMENT_TARGET: '10.13'

on:
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY_URL
docker pull ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
docker tag ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine builder
build: docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/package-template -w /package-template builder sh -c "yarn build -- --target=aarch64-unknown-linux-musl"
build: docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/resvgjs -w /resvgjs builder sh -c "yarn build -- --target=aarch64-unknown-linux-musl"
- host: windows-latest
target: 'aarch64-pc-windows-msvc'
build: yarn build --target aarch64-pc-windows-msvc
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ Font './example/SourceHanSerifCN-Light-subset.ttf':0 found in 0.006ms.
✨ Done in 55.65491008758545 ms
```

| SVG | PNG |
| ------------------------------------------------------- | ------------------------------------------------------- |
| <img width="360" src="example/text.svg"> | <img width="360" src="example/text-out.png"> |
| SVG | PNG |
| ---------------------------------------- | -------------------------------------------- |
| <img width="360" src="example/text.svg"> | <img width="360" src="example/text-out.png"> |

## Support matrix

### Operating Systems
Expand All @@ -52,7 +53,9 @@ Font './example/SourceHanSerifCN-Light-subset.ttf':0 found in 0.006ms.

### Build

After `npm run build` command, you can see `package-template.[darwin|win32|linux].node` file in project root. This is the native addon built from [lib.rs](./src/lib.rs).
You can set the name of the generated `.node` file in `napi.name` of package.json.

After `npm run build` command, you can see `resvgjs.[darwin|win32|linux].node` file in project root. This is the native addon built from [lib.rs](./src/lib.rs).

### Test

Expand Down
28 changes: 27 additions & 1 deletion __test__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
import { promises } from 'fs'
import { join } from 'path'

import test from 'ava'
import probeImageSize from 'probe-image-size'

import { render } from '../index'

test('draw-svg', async (t) => {
const filePath = '../example/text.svg'
const svg = await promises.readFile(join(__dirname, filePath))
const svgString = svg.toString('utf-8')
const pngData = render(svgString, {
background: '#eeebe6',
fitTo: {
mode: 'width',
value: 1200,
},
font: {
fontFiles: ['./example/SourceHanSerifCN-Light-subset.ttf'], // Load custom fonts.
loadSystemFonts: false, // It will be faster to disable loading system fonts.
defaultFontFamily: 'Source Han Serif CN Light',
},
})
const result = probeImageSize.sync(pngData)

// TODO
t.is(result.width, 1200)
t.is(result.height, 623)
})
5 changes: 4 additions & 1 deletion example/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const { render } = require('../index')
const { promises } = require('fs')
const { join } = require('path')
const { performance } = require('perf_hooks')

const { render } = require('../index')

async function main() {
const svg = await promises.readFile(join(__dirname, './text.svg'))
const svgString = svg.toString('utf-8')
Expand All @@ -20,7 +21,9 @@ async function main() {
},
})
const t1 = performance.now()
// eslint-disable-next-line no-console
console.log('✨ Done in', t1 - t0, 'ms')

await promises.writeFile(join(__dirname, './text-out.png'), pngData)
}

Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ const { loadBinding } = require('@node-rs/helper')
* the first arguments was decided by `napi.name` field in `package.json`
* the second arguments was decided by `name` field in `package.json`
* loadBinding helper will load `resvg.[PLATFORM].node` from `__dirname` first
* If failed to load addon, it will fallback to load from `@resvg/resvg-[PLATFORM]`
* If failed to load addon, it will fallback to load from `@resvg/resvgjs-[PLATFORM]`
*/
module.exports = loadBinding(__dirname, 'resvg', '@resvg/resvg-js')
module.exports = loadBinding(__dirname, 'resvgjs', '@resvg/resvg-js')
4 changes: 2 additions & 2 deletions npm/android-arm64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"cpu": [
"arm64"
],
"main": "resvg.android-arm64.node",
"main": "resvgjs.android-arm64.node",
"files": [
"resvg.android-arm64.node"
"resvgjs.android-arm64.node"
],
"description": "A high-performance SVG renderer, powered by Rust based resvg and napi-rs",
"keywords": [
Expand Down
4 changes: 2 additions & 2 deletions npm/darwin-arm64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"cpu": [
"arm64"
],
"main": "resvg.darwin-arm64.node",
"main": "resvgjs.darwin-arm64.node",
"files": [
"resvg.darwin-arm64.node"
"resvgjs.darwin-arm64.node"
],
"description": "A high-performance SVG renderer, powered by Rust based resvg and napi-rs",
"keywords": [
Expand Down
4 changes: 2 additions & 2 deletions npm/darwin-x64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"cpu": [
"x64"
],
"main": "resvg.darwin-x64.node",
"main": "resvgjs.darwin-x64.node",
"files": [
"resvg.darwin-x64.node"
"resvgjs.darwin-x64.node"
],
"description": "A high-performance SVG renderer, powered by Rust based resvg and napi-rs",
"keywords": [
Expand Down
4 changes: 2 additions & 2 deletions npm/freebsd-x64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"cpu": [
"x64"
],
"main": "resvg.freebsd-x64.node",
"main": "resvgjs.freebsd-x64.node",
"files": [
"resvg.freebsd-x64.node"
"resvgjs.freebsd-x64.node"
],
"description": "A high-performance SVG renderer, powered by Rust based resvg and napi-rs",
"keywords": [
Expand Down
4 changes: 2 additions & 2 deletions npm/linux-arm-gnueabihf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"cpu": [
"arm"
],
"main": "resvg.linux-arm-gnueabihf.node",
"main": "resvgjs.linux-arm-gnueabihf.node",
"files": [
"resvg.linux-arm-gnueabihf.node"
"resvgjs.linux-arm-gnueabihf.node"
],
"description": "A high-performance SVG renderer, powered by Rust based resvg and napi-rs",
"keywords": [
Expand Down
4 changes: 2 additions & 2 deletions npm/linux-arm64-gnu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"cpu": [
"arm64"
],
"main": "resvg.linux-arm64-gnu.node",
"main": "resvgjs.linux-arm64-gnu.node",
"files": [
"resvg.linux-arm64-gnu.node"
"resvgjs.linux-arm64-gnu.node"
],
"description": "A high-performance SVG renderer, powered by Rust based resvg and napi-rs",
"keywords": [
Expand Down
4 changes: 2 additions & 2 deletions npm/linux-arm64-musl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"cpu": [
"arm64"
],
"main": "resvg.linux-arm64-musl.node",
"main": "resvgjs.linux-arm64-musl.node",
"files": [
"resvg.linux-arm64-musl.node"
"resvgjs.linux-arm64-musl.node"
],
"description": "A high-performance SVG renderer, powered by Rust based resvg and napi-rs",
"keywords": [
Expand Down
4 changes: 2 additions & 2 deletions npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"cpu": [
"x64"
],
"main": "resvg.linux-x64-gnu.node",
"main": "resvgjs.linux-x64-gnu.node",
"files": [
"resvg.linux-x64-gnu.node"
"resvgjs.linux-x64-gnu.node"
],
"description": "A high-performance SVG renderer, powered by Rust based resvg and napi-rs",
"keywords": [
Expand Down
4 changes: 2 additions & 2 deletions npm/linux-x64-musl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"cpu": [
"x64"
],
"main": "resvg.linux-x64-musl.node",
"main": "resvgjs.linux-x64-musl.node",
"files": [
"resvg.linux-x64-musl.node"
"resvgjs.linux-x64-musl.node"
],
"description": "A high-performance SVG renderer, powered by Rust based resvg and napi-rs",
"keywords": [
Expand Down
4 changes: 2 additions & 2 deletions npm/win32-arm64-msvc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"cpu": [
"arm64"
],
"main": "resvg.win32-arm64-msvc.node",
"main": "resvgjs.win32-arm64-msvc.node",
"files": [
"resvg.win32-arm64-msvc.node"
"resvgjs.win32-arm64-msvc.node"
],
"description": "A high-performance SVG renderer, powered by Rust based resvg and napi-rs",
"keywords": [
Expand Down
4 changes: 2 additions & 2 deletions npm/win32-ia32-msvc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"cpu": [
"ia32"
],
"main": "resvg.win32-ia32-msvc.node",
"main": "resvgjs.win32-ia32-msvc.node",
"files": [
"resvg.win32-ia32-msvc.node"
"resvgjs.win32-ia32-msvc.node"
],
"description": "A high-performance SVG renderer, powered by Rust based resvg and napi-rs",
"keywords": [
Expand Down
4 changes: 2 additions & 2 deletions npm/win32-x64-msvc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"cpu": [
"x64"
],
"main": "resvg.win32-x64-msvc.node",
"main": "resvgjs.win32-x64-msvc.node",
"files": [
"resvg.win32-x64-msvc.node"
"resvgjs.win32-x64-msvc.node"
],
"description": "A high-performance SVG renderer, powered by Rust based resvg and napi-rs",
"keywords": [
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"index.js"
],
"napi": {
"name": "resvg",
"name": "resvgjs",
"triples": {
"defaults": true,
"additional": [
Expand Down Expand Up @@ -53,6 +53,7 @@
"format:source": "prettier --config ./package.json --write './**/*.{js,ts}'",
"format:yaml": "prettier --parser yaml --write './**/*.{yml,yaml}'",
"lint": "eslint . -c ./.eslintrc.yml './**/*.{ts,tsx,js}'",
"lint:fix": "eslint . -c ./.eslintrc.yml './**/*.{ts,tsx,js}' --fix",
"prepublishOnly": "napi prepublish -t npm",
"test": "ava",
"version": "napi version"
Expand All @@ -74,6 +75,7 @@
"lint-staged": "^11.2.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.4.1",
"probe-image-size": "^7.2.1",
"typescript": "^4.4.3"
},
"dependencies": {
Expand Down

0 comments on commit eeb479e

Please sign in to comment.