Skip to content

Commit

Permalink
Merge pull request #1 from seatsio/morten/move-types
Browse files Browse the repository at this point in the history
Add seats.io types
  • Loading branch information
mortendevold authored Dec 11, 2023
2 parents bb05463 + 7759423 commit e646534
Show file tree
Hide file tree
Showing 10 changed files with 1,918 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: 'Build'

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- run: yarn install
- run: yarn test
- run: yarn build
59 changes: 59 additions & 0 deletions .github/workflows/publishTypes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Very important!
# Make sure that the github token has read AND WRITE access on github.
# 1. hit https://github.com/seatsio/[REPO]/settings/actions
# 2. under "Workflow permissions", make sure "Read and write permissions" is checked instead of the (default?) read only.

name: 'Update and publish @seatsio/seatsio-types'

on:
workflow_dispatch:
inputs:
version:
description: 'Bump version or release current version without changing package.json. Major for incompatible API changes, minor for adding backwards compatible features, patch for bugfixes.'
required: true
default: 'patch'
type: choice
options:
- current
- patch
- minor
- major

jobs:
updateVersionAndPublish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: fregante/setup-git-user@v2
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/

- name: Checkout latest master
run: |
git checkout master
git pull origin master
- name: Build types
run: |
yarn install
yarn build
- name: Update package version
env:
VERSION: ${{ inputs.version }}
run: |
yarn bump-version --v $VERSION
- name: Commit updated package.json
run: |
git add package.json
git commit -m "Update @seatsio/seatsio-types"
git push origin master
- name: Publish new version to NPM
uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_TOKEN }}
package: './package.json'
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_STORE
node_modules
dist
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
TypeScript definitions for the renderer, event manager and chart designer of [Seats.io](https://www.seats.io/).

This replaces the legacy package [@types/seatsio](https://www.npmjs.com/package/@types/seatsio).
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@seatsio/seatsio-types",
"description": "Type definitions for Seats.io",
"version": "2.4.0",
"license": "MIT",
"types": "dist/index.d.ts",
"files": [
"dist/index.d.ts"
],
"devDependencies": {
"@actions/core": "1.10.1",
"cli-select-2": "2.0.0",
"typescript": "5.2.2",
"yargs": "17.7.2"
},
"scripts": {
"build": "tsc",
"test": "yarn tsc --noEmit src/index.test.ts",
"test:watch": "tsc --watch src/index.test.ts",
"bump-version": "node scripts/bumpVersion.mjs"
}
}
70 changes: 70 additions & 0 deletions scripts/bumpVersion.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import core from '@actions/core'
import { execSync } from 'child_process'
import cliSelect from 'cli-select-2'
import fs from 'fs'
import { hideBin } from 'yargs/helpers'
import yargs from 'yargs/yargs'

const argv = yargs(hideBin(process.argv))
.option('versionChange', {
alias: 'v',
type: 'string',
description: 'Version change type. Possible values are patch, minor, major.'
}).parse()

const validArgs = ['current', 'minor', 'major', 'patch']

const execute = cmd => {
execSync(cmd, { stdio: 'inherit' })
}

const bumpVersion = async (versionType) => {
if (versionType !== 'current') {
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf-8'))
const currentVersion = packageJson.version
let [major, minor, patch] = currentVersion.split('.').map(v => parseInt(v, 10))

switch (versionType) {
case 'major':
major += 1
minor = patch = 0
break
case 'minor':
minor += 1
patch = 0
break
case 'patch':
patch += 1
break
}

const newVersion = `${major}.${minor}.${patch}`
packageJson.version = newVersion
core.setOutput('newVersion', newVersion)
fs.writeFileSync('package.json', JSON.stringify(packageJson, undefined, 4))
console.log(`\nDone! Package file updated to ${newVersion}.`)
}
}

const onSelect = (selection) => {
if (selection.value && typeof selection.value === 'string') {
bumpVersion(selection.value.toLowerCase())
}
}

const versionBump = argv.v
if (validArgs.indexOf(versionBump) !== -1) {
bumpVersion(versionBump)
} else {
const options = {
values: {
'Keep current version': 'current',
'Patch': 'patch',
'Minor': 'minor',
'Major': 'major',
},
defautValue: 0
}

cliSelect(options, onSelect)
}
Loading

0 comments on commit e646534

Please sign in to comment.