-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(resolver-pixi): initial implementation for pixi resolver
- Loading branch information
Showing
9 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
!/bin/**/* | ||
!/dist/**/* | ||
/src/ | ||
tsconfig.json | ||
tslint.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2018 Ihor Chulinda | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# BaseT React resolver | ||
> Pixi resolver for [BaseT](https://github.com/Igmat/baset) project. | ||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
|
||
|
||
- [Installation and usage](#installation-and-usage) | ||
|
||
<!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
|
||
## Installation and usage | ||
Run: | ||
``` | ||
npm install --save-dev baset-resolver-pixi | ||
``` | ||
and adding next line to `baset.plugins` section in your `package.json` or `plugins` section in your `.basetrc`/`.basetrc.json`: | ||
```JSON | ||
".spec.js$": ["baset-resolver-pixi", "baset-baseliner-json"] | ||
``` | ||
No additional options available for this plugin for now. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"name": "baset-resolver-pixi", | ||
"version": "0.8.0", | ||
"description": "Pixi resolver plugin for BaseT project.", | ||
"keywords": [ | ||
"baset-resolver-pixi", | ||
"pixi", | ||
"pixi.js", | ||
"baseline", | ||
"unit-test", | ||
"test", | ||
"testing", | ||
"e2e-test" | ||
], | ||
"author": "Ihor Chulinda <[email protected]>", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "[email protected]:Igmat/baset.git" | ||
}, | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"build": "npm run tslint && tsc", | ||
"watch": "npm run tslint && tsc -w", | ||
"tslint": "tslint -c tslint.json -p tsconfig.json", | ||
"test": "baset", | ||
"accept": "baset accept", | ||
"doctoc": "doctoc README.md", | ||
"prepublish": "npm run doctoc" | ||
}, | ||
"devDependencies": { | ||
"@types/pixi.js": "^4.7.1", | ||
"@types/node": "^9.3.0", | ||
"baset": "^0.8.0", | ||
"doctoc": "^1.3.0", | ||
"tslint": "^5.9.1", | ||
"typescript": "next" | ||
}, | ||
"dependencies": { | ||
"baset-core": "^0.8.0", | ||
"baset-vm": "^0.7.3", | ||
"pixi.js": "^4.7.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { AbstractResolver, utils } from 'baset-core'; | ||
import { NodeVM } from 'baset-vm'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { promisify } from 'util'; | ||
|
||
const readFile = promisify(fs.readFile); | ||
const renderInContextScript = readFile(path.resolve(__dirname, 'renderInContext.js'), { encoding: 'utf8' }); | ||
const matchInContextScript = readFile(path.resolve(__dirname, 'matchInContext.js'), { encoding: 'utf8'}); | ||
|
||
export default class PixiResolver extends AbstractResolver { | ||
match = async (obj: any, context: NodeVM, sandbox: utils.IDictionary<any>) => { | ||
sandbox.basetResolverPixi__ObjectToMatch = obj; | ||
|
||
return context.run(await matchInContextScript, 'PixiResolver.js').matchResult; | ||
} | ||
resolve = async (obj: any, context: NodeVM, sandbox: utils.IDictionary<any>) => { | ||
sandbox.basetResolverPixi__ObjectToRender = obj; | ||
|
||
return await context.run(await renderInContextScript, 'PixiResolver.js').renderedResult; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import 'pixi.js'; | ||
declare const basetSandbox: { basetResolverPixi__ObjectToMatch: any; }; | ||
|
||
export const matchResult = basetSandbox.basetResolverPixi__ObjectToMatch instanceof PIXI.DisplayObject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import 'pixi.js'; | ||
declare const basetSandbox: { basetResolverPixi__ObjectToRender: PIXI.DisplayObject }; | ||
|
||
const objectToRender = basetSandbox.basetResolverPixi__ObjectToRender; | ||
const bounds = objectToRender.getBounds(); | ||
const app = new PIXI.Application(bounds.width, bounds.height); | ||
const canvas = document.body.appendChild(app.view); | ||
|
||
app.stage.addChild(objectToRender); | ||
app.render(); | ||
|
||
export const renderedResult = new Promise((resolve, reject) => | ||
app.ticker.addOnce(() => | ||
resolve(canvas.toDataURL('image/png')))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"baseUrl": ".", | ||
"paths": { | ||
"*": [ | ||
"node_modules/*", | ||
"src/types/*" | ||
] | ||
} | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": [ | ||
"../../tslint.json" | ||
], | ||
"rules": { | ||
"no-default-export": false | ||
} | ||
} |