diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..7171c65 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,35 @@ +# adopted from https://github.com/archilogic-com/actions/blob/main/.github/workflows/publish-npm-package.yml +name: Publish NPM package +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+*' +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + registry-url: https://registry.npmjs.org/ + - run: npm ci + env: + NODE_AUTH_TOKEN: ${{ secrets.CI_NPM_TOKEN_READONLY }} + + - run: npm run typecheck && npm run test + - id: get-dist-tag + uses: actions/github-script@v6 + with: + script: | + const { parse } = require('semver') + const { version } = require('./package.json') + + const [numberOrTag] = parse(version).prerelease + const isTag = typeof numberOrTag === 'string' + const distTag = isTag ? numberOrTag : 'latest' + + core.setOutput('dist-tag', distTag) + - run: npm run build && npm publish --tag ${{steps.get-dist-tag.outputs.dist-tag}} + env: + NODE_AUTH_TOKEN: ${{ secrets.CI_NPM_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/tests.js.yml b/.github/workflows/tests.js.yml new file mode 100644 index 0000000..b9aaa0c --- /dev/null +++ b/.github/workflows/tests.js.yml @@ -0,0 +1,27 @@ +# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Type check and tests + +on: + push: + branches: + - main + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + - name: Setup npmrc + run: npm config set //registry.npmjs.org/:_authToken=${{secrets.CI_NPM_TOKEN_READONLY}} + - run: npm ci + - run: npm run typecheck + - run: npm run build && npm run test diff --git a/.gitignore b/.gitignore index adce4fc..bc52912 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ node_modules +dist *.sublime-project -*.sublime-workspace -bundle.js \ No newline at end of file +*.sublime-workspace \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index a04bfe5..8054780 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "2d-visibility-demo-typescript", + "name": "@archilogic/2d-visibility", "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "2d-visibility-demo-typescript", + "name": "@archilogic/2d-visibility", "version": "1.0.0", "license": "MIT", "devDependencies": { diff --git a/package.json b/package.json index 2f8287c..af9a39d 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "2d-visibility-demo-typescript", + "name": "@archilogic/2d-visibility", "version": "1.0.0", "description": "", "keywords": [], @@ -9,6 +9,9 @@ }, { "name": "David Neilsen" + }, + { + "name": "Frederic Schwarz" } ], "license": "MIT", @@ -31,6 +34,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "lint": "tslint --project tsconfig.json" + "test": "vitest --run", + "typecheck": "vue-tsc --noEmit" } } diff --git a/src/__tests__/visibility.test.ts b/src/__tests__/visibility.test.ts new file mode 100644 index 0000000..35aa103 --- /dev/null +++ b/src/__tests__/visibility.test.ts @@ -0,0 +1,29 @@ +import { loadMap } from "../load-map"; +import { Point, PolygonWithHoles } from "../types"; +import { calculateVisibility } from "../visibility"; + +describe("when computing visibility in an L shaped polygon", () => { + const polygon: PolygonWithHoles = [ + [ + [0, 0], + [200, 0], + [200, 200], + [400, 200], + [400, 300], + [0, 300], + ], + ]; + + const point = new Point(100, 100); + const { endPoints } = loadMap(polygon, point); + const visibility = calculateVisibility(point, endPoints); + it("creates creates a cut off shape", () => { + expect(visibility).toMatchObject([ + [new Point(0, 300), new Point(0, 0)], + [new Point(0, 0), new Point(200, 0)], + [new Point(200, 0), new Point(200, 200)], + [new Point(200, 200), new Point(200, 200)], + [new Point(300, 300), new Point(0, 300)], + ]); + }); +}); diff --git a/tsconfig.json b/tsconfig.json index a7463ef..620c5c2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,11 @@ "module": "ESNext", "moduleResolution": "node", "target": "ESNext", - "noEmitHelpers": true + "noEmitHelpers": true, + "types": [ + "vitest/globals" + ], + "skipLibCheck": true, }, "include": [ "./src/**/*.ts" diff --git a/vite.config.ts b/vite.config.ts index b8b52f0..b65e507 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,7 +3,6 @@ import dts from "vite-plugin-dts"; export default defineConfig({ test: { - environment: "jsdom", globals: true, }, plugins: [dts({ rollupTypes: true })],