-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from Siemienik/issue/2-typescript
Migrating from babel to typescript
- Loading branch information
Showing
50 changed files
with
932 additions
and
958 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,28 @@ | ||
name: lint-build-test | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [8.x, 10.x, 11.x, 12.x, 13.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: npm install, lint, build, and test | ||
run: | | ||
npm install | ||
npm list | ||
npm run lint | ||
npm run build | ||
npm run test | ||
env: | ||
CI: true |
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 |
---|---|---|
@@ -1,5 +1,10 @@ | ||
/lib | ||
/node_modules | ||
/.idea | ||
/src/example.js | ||
/coverage/ | ||
/.nyc_output/ | ||
/.idea/ | ||
|
||
|
||
/src/example.ts | ||
*.xlsx |
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,6 @@ | ||
{ | ||
"printWidth": 120, | ||
"trailingComma": "all", | ||
"singleQuote": true, | ||
"tabWidth": 4 | ||
} |
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 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Siemienik Paweł | ||
|
||
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 |
---|---|---|
@@ -1,13 +1,14 @@ | ||
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/siemienik/xlsx-renderer/lint-build-test)![NPM](https://img.shields.io/npm/l/xlsx-renderer)![npm](https://img.shields.io/npm/v/xlsx-renderer) | ||
![Snyk Vulnerabilities for GitHub Repo](https://img.shields.io/snyk/vulnerabilities/github/siemienik/xlsx-renderer)![GitHub top language](https://img.shields.io/github/languages/top/siemienik/xlsx-renderer)![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/siemienik/xlsx-renderer) | ||
|
||
# xlsx-renderer | ||
Render xlsx from a template (it uses another xlsx file with special commands like "#! FOR_EACH item items") | ||
# WIP current version of lib is under developing | ||
|
||
## Install: | ||
# Getting Started: | ||
|
||
1. install package | ||
|
||
package.json: | ||
``` | ||
"xls-renderer": "git+ssh://[email protected]/siemienik/xlsx-renderer.git#release/v1", | ||
npm i xlsx-renderer --save | ||
``` | ||
|
||
`npm install` | ||
|
@@ -29,7 +30,7 @@ package.json: | |
12. `#! DUMP_COLS arrayVar` write to next columns all array items (1 item = 1 column) | ||
|
||
|
||
## Sample code: | ||
## Sample code: (possible to be outdated yet - todo) | ||
|
||
```javascript | ||
import Renderer from './xls-renderer/Renderer' | ||
|
@@ -54,5 +55,6 @@ const viewModel = new MyAwesomeReportVm(); //or something else | |
|
||
await result.xlsx.writeFile('./my-awesome-raport.xlsx'); | ||
})(); | ||
|
||
``` | ||
|
||
[LICENSE](LICENSE) |
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 |
---|---|---|
@@ -1,25 +1,54 @@ | ||
{ | ||
"name": "xls-renderer", | ||
"version": "1.1.2", | ||
"name": "xlsx-renderer", | ||
"version": "1.1.2", | ||
"description": "Allows render xlsx files based on template supplied by viewModel.", | ||
"main": "index.js", | ||
"scripts": { | ||
"postinstall": "babel src --out-dir lib --copy-files", | ||
"example": "node lib/example.js", | ||
"build": "node_modules/.bin/babel -d lib -s true src ", | ||
"watch": "node_modules/.bin/babel -d lib -s true src --watch", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"main": "lib/Renderer.js", | ||
"types": "lib/Renderer.d.ts", | ||
"author": "Paweł Siemienik <[email protected]>", | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babel-preset-es2017-node7": "^0.5.2" | ||
}, | ||
"directories": { | ||
"lib": "lib/" | ||
}, | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Siemienik/xlsx-renderer" | ||
}, | ||
"keywords": [ | ||
"excel", | ||
"xlsx", | ||
"rendering xlsx", | ||
"generator", | ||
"template" | ||
], | ||
"scripts": { | ||
"build": "tsc", | ||
"format": "prettier --write \"src/**/*.ts\"", | ||
"lint": "tslint -p tsconfig.json", | ||
"lint:fix": "tslint -p tsconfig.json --fix", | ||
"test": "mocha -r ts-node/register tests/**/*.test.ts", | ||
"coverageRaport": "nyc -r lcov -e .ts -x \"*.test.ts\" mocha -r ts-node/register tests/**/*.test.ts && nyc report", | ||
"prepublishOnly": "npm test && npm run lint && npm run build", | ||
"preversion": "npm run lint", | ||
"version": "npm run format && git add -A src", | ||
"postversion": "git push && git push --tags" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.1.7", | ||
"@types/mocha": "^5.2.6", | ||
"chai": "^4.2.0", | ||
"mocha": "^6.1.4", | ||
"nyc": "^14.0.0", | ||
"prettier": "^1.17.0", | ||
"ts-node": "^8.1.0", | ||
"tslint": "^5.16.0", | ||
"tslint-config-prettier": "^1.18.0", | ||
"typescript": "^3.4.4" | ||
}, | ||
"dependencies": { | ||
"exceljs": "github:p3rio/exceljs#build" | ||
} | ||
"exceljs": "3.8.1" | ||
}, | ||
"files": [ | ||
"lib/**/*" | ||
] | ||
} | ||
|
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 @@ | ||
import { CellTemplatePool } from './CellTemplatePool'; | ||
import { Cell } from 'exceljs'; | ||
import { BaseCell } from './cell/BaseCell'; | ||
/* tslint:disable:no-console */ | ||
export class CellTemplateDebugPool extends CellTemplatePool { | ||
/** | ||
* do normal match and log in console result. | ||
*/ | ||
public match(cell: Cell): BaseCell { | ||
const result = super.match(cell); | ||
|
||
console.log(result, cell && cell.value); | ||
|
||
return result; | ||
} | ||
} |
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,56 @@ | ||
import { Cell } from 'exceljs'; | ||
|
||
import { BaseCell, CellType } from './cell/BaseCell'; | ||
import { NormalCell } from './cell/NormalCell'; | ||
import { VariableCell } from './cell/VariableCell'; | ||
import { FinishCell } from './cell/FinishCell'; | ||
import { ForEachCell } from './cell/ForEachCell'; | ||
import { ContinueCell } from './cell/ContinueCell'; | ||
import { EndLoopCell } from './cell/EndLoopCell'; | ||
import { EndRowCell } from './cell/EndRowCell'; | ||
import { SumCell } from './cell/SumCell'; | ||
import { AverageCell } from './cell/AverageCell'; | ||
import { DeleteCell } from './cell/DeleteCell'; | ||
import { DumpColsCell } from './cell/DumpColsCell'; | ||
import { WsNameCell } from './cell/WsNameCell'; | ||
import { HyperlinkCell } from './cell/HyperlinkCell'; | ||
import { FormulaCell } from './cell/FormulaCell'; | ||
|
||
export class CellTemplatePool { | ||
protected cells: CellType[] = [ | ||
NormalCell, | ||
EndRowCell, | ||
VariableCell, | ||
FormulaCell, | ||
HyperlinkCell, | ||
ForEachCell, | ||
FinishCell, | ||
EndLoopCell, | ||
ContinueCell, | ||
DumpColsCell, | ||
SumCell, | ||
AverageCell, | ||
WsNameCell, | ||
DeleteCell, | ||
]; | ||
|
||
protected instances: { [key: string]: BaseCell } = {}; | ||
|
||
public match(cell: Cell): BaseCell { | ||
const type = this.cells.find(x => x.match(cell)); | ||
|
||
return type ? this.getInstance(type) : this.getInstance(NormalCell); | ||
} | ||
|
||
private getInstance(type: CellType): BaseCell { | ||
if (!this.cells.includes(type)) { | ||
throw new TypeError(`parameter 'type' has to included in [${this.cells.map(x => x.name)}]`); | ||
} | ||
|
||
if (!this.instances[type.name]) { | ||
this.instances[type.name] = new type(); | ||
} | ||
|
||
return this.instances[type.name]; | ||
} | ||
} |
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 @@ | ||
export interface ICellCoord { | ||
r: number; | ||
c: number; | ||
ws: number; | ||
} |
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 { Workbook } from 'exceljs'; | ||
|
||
import { Scope } from './Scope'; | ||
import { CellTemplatePool } from './CellTemplatePool'; | ||
|
||
export class Renderer { | ||
constructor(private cellTemplatePool: CellTemplatePool = new CellTemplatePool()) { | ||
} | ||
|
||
public async render(templateFactory: () => Promise<Workbook>, vm: any): Promise<Workbook> { | ||
const template = await templateFactory(); | ||
const output = await templateFactory(); | ||
|
||
const scope = new Scope(template, output, vm); | ||
|
||
while (!scope.isFinished()) { | ||
this.cellTemplatePool.match(scope.getCurrentTemplateCell()).apply(scope); | ||
} | ||
|
||
return output; | ||
} | ||
} |
Oops, something went wrong.