Skip to content

Commit

Permalink
update gh pages on publish
Browse files Browse the repository at this point in the history
  • Loading branch information
piglovesyou committed Jan 3, 2024
1 parent 42e5df5 commit 13b5acc
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ jobs:
- run: yarn lint
- run: yarn build
- run: yarn test
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
6 changes: 2 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@ jobs:
with:
files: |
dist/merge-cells.js
dist/merge-cells.min.js
dist/merge-cells.min.js.map
dist/merge-cells.ts
dist/merge-cells.ts.map
dist/merge-cells.d.ts
dist/merge-cells.d.ts.map
43 changes: 34 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# merge-cells [![Node.js CI](https://github.com/piglovesyou/merge-cells/actions/workflows/node.js.yml/badge.svg)](https://github.com/piglovesyou/merge-cells/actions/workflows/node.js.yml)

Provide JavaScript/TypeScript functions to help you merge cells in a table.
Provide JavaScript/TypeScript functions to help you merge cells of an HTML `GROUP BY`-like table.

👉 Example: https://piglovesyou.github.io/merge-cells/

## Usage

Example usage in a browser:

```html
<script type="module" defer>
import { mergeCells } from 'https://cdn.jsdelivr.net/npm/merge-cells@latest/dist/merge-cells.min.js'
Expand All @@ -15,25 +17,50 @@ Provide JavaScript/TypeScript functions to help you merge cells in a table.
</script>
```

## `mergeCells`
Example usage in Node.js:

Apply the `rowspan` calculated by `calcRowspanFromObjectArray` to a table. Signature:
```shell
npm install merge-cells
```

```ts
function mergeCells(tableEl: HTMLTableElement, rowspan: Record<string, number>): void
import { calcRowspanFromObjectArray } from 'merge-cells'

calcRowspanFromObjectArray(
[
{ c_1: 'a', c_2: 'a' },
{ c_1: 'a', c_2: 'a' },
{ c_1: 'b', c_2: 'a' },
],
['c_1', 'c_2'],
)
// returns: [
// { c_1: 2, c_2: 2 },
// { c_1: 0, c_2: 0 },
// { c_1: 1, c_2: 1 }
// ]
```

### `mergeCells`

Apply `rowspan` to an HTML table, calculated by `calcRowspanFromObjectArray`. Signature:

```ts
function mergeCells(tableEl: HTMLTableElement, columnIndexes?: number[]): void
```

Example:

```ts
const tableEl = document.getElementById('table') as HTMLTableElement
applyRowspanToTable(tableEl)
mergeCells(tableEl)
```

## `calcRowspanFromObjectArray`
### `calcRowspanFromObjectArray`

Calculate the `rowspan` of each cell in JavaScript object rows. Signature:
Calculate the `rowspan` of each cell in JavaScript object rows. Useful for flexible usage such as in server-side
rendering. Signature:

```ts
function calcRowspanFromObjectArray<E extends Record<string, any>>(
Expand Down Expand Up @@ -63,8 +90,6 @@ expect(

## Publishing

Run this to build source, upgrade npm version, push to GitHub, and publish to npm.

```shell
yarn version --patch # or --minor or --major
```
15 changes: 6 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "merge-cells",
"version": "0.1.0",
"version": "0.1.2",
"main": "dist/merge-cells.js",
"files": [
"dist"
Expand All @@ -23,10 +23,8 @@
"prettier": "^3.1.1",
"prettier-plugin-organize-imports": "^3.2.4",
"pug": "^3.0.2",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"typescript": "^5.3.3",
"uglify-js": "^3.17.4"
"typescript": "^5.3.3"
},
"prettier": {
"semi": false,
Expand All @@ -35,7 +33,7 @@
"printWidth": 120
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"*.{js,ts,json,md,yml,yaml}": [
"prettier --write"
]
},
Expand All @@ -46,11 +44,10 @@
"fix": "prettier --write .",
"build:gh-pages": "ts-node ./scripts/gen-gh-pages-html.ts",
"build:dist": "tsc --project tsconfig.dist.json",
"minify": "uglifyjs --compress --mangle --output dist/merge-cells.min.js --source-map filename dist/merge-cells.js",
"build": "npm-run-all clean --parallel build:* --sequential minify",
"build": "npm-run-all clean --parallel build:*",
"test": "jest",
"gh-pages": "gh-pages -d dist",
"preversion": "npm-run-all lint test build",
"postversion": "git push --tags && yarn publish . --tag $npm_package_version",
"gh-pages": "gh-pages -d dist"
"postversion": "git push --tags && yarn publish . --tag $npm_package_version && yarn gh-pages"
}
}
2 changes: 2 additions & 0 deletions scripts/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ html(lang="en")

.container
h1= pageTitle
p Provide JavaScript/TypeScript functions to help you merge cells of an HTML #[code GROUP BY]-like table.
p Go to #[a(href="https://github.com/piglovesyou/merge-cells") github.com/piglovesyou/merge-cells] for usage and more.

table#table.table.table-bordered
thead
Expand Down

0 comments on commit 13b5acc

Please sign in to comment.