From 6acf0ff047af449ec38f242265805aed2310c1a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Sat, 10 Apr 2021 18:42:42 +0200 Subject: [PATCH 1/3] Creating a dedicated package for iframe API typings If users are willing to use Typescript to develop scripts for maps, they will need typings for the `WA` object. This commit creates a new package (@workadventure/iframe-api-typings) that contains only the `iframe_api.d.ts` file. The file is generated from the build of the front and isolated in this package. This is necessary because the iframe_api.js file is supposed to always be loaded from WorkAdventure directly (and there is no @workadventure/iframe-api package and there will never be one) --- .github/workflows/push-to-npm.yml | 55 +++++++++++++++++++ front/packages/iframe-api-typings/.gitignore | 1 + front/packages/iframe-api-typings/README.md | 27 +++++++++ .../packages/iframe-api-typings/iframe_api.js | 1 + .../packages/iframe-api-typings/package.json | 13 +++++ front/tsconfig.json | 1 + 6 files changed, 98 insertions(+) create mode 100644 .github/workflows/push-to-npm.yml create mode 100644 front/packages/iframe-api-typings/.gitignore create mode 100644 front/packages/iframe-api-typings/README.md create mode 100644 front/packages/iframe-api-typings/iframe_api.js create mode 100644 front/packages/iframe-api-typings/package.json diff --git a/.github/workflows/push-to-npm.yml b/.github/workflows/push-to-npm.yml new file mode 100644 index 00000000..18404dc0 --- /dev/null +++ b/.github/workflows/push-to-npm.yml @@ -0,0 +1,55 @@ +name: Push @workadventure/iframe-api-typings to NPM +on: + # TODO remove action on push + push: ~ + release: + types: [created] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + # Setup .npmrc file to publish to npm + - uses: actions/setup-node@v2 + with: + node-version: '14.x' + registry-url: 'https://registry.npmjs.org' + # TODO: replace version with RELEASE tag + # TODO: enable declaration flag in tsconfig dynamically + - name: Install Protoc + uses: arduino/setup-protoc@v1 + with: + version: '3.x' + + - name: "Install dependencies" + run: yarn install + working-directory: "front" + + - name: "Install messages dependencies" + run: yarn install + working-directory: "messages" + + - name: "Build proto messages" + run: yarn run proto && yarn run copy-to-front + working-directory: "messages" + + - name: "Create index.html" + run: ./templater.sh + working-directory: "front" + + - name: "Build" + run: yarn run build + env: + API_URL: "localhost:8080" + working-directory: "front" + # We build the front to generate the typings of iframe_api, then we copy those typings in a separate package. + - name: Copy typings to package dir + run: cp front/dist/src/iframe_api.d.ts front/packages/iframe-api-typings/iframe_api.d.ts + - name: Install dependencies in package + run: yarn install + working-directory: "front/packages/iframe-api-typings" + - name: Publish package + run: yarn publish + working-directory: "front/packages/iframe-api-typings" + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/front/packages/iframe-api-typings/.gitignore b/front/packages/iframe-api-typings/.gitignore new file mode 100644 index 00000000..f850ebdb --- /dev/null +++ b/front/packages/iframe-api-typings/.gitignore @@ -0,0 +1 @@ +iframe_api.d.ts diff --git a/front/packages/iframe-api-typings/README.md b/front/packages/iframe-api-typings/README.md new file mode 100644 index 00000000..c5c16ded --- /dev/null +++ b/front/packages/iframe-api-typings/README.md @@ -0,0 +1,27 @@ +

WorkAdventure - IFrame API typings for Typescript

+ +

This package contains Typescript typings for WorkAdventure's map scripting API

+ +
+ +[WorkAdventure](https://workadventu.re) comes with a scripting API. Using this API, you can add some intelligence to your map. +You use this API by loading an external script directly from WorkAdventure (at https://play.workadventu.re/iframe_api.js), or this script is loaded +for you if you are using the "script" property of a map. + +This project contains Typescript typings for the `WA` object provided by this script. + +## Usage + +This package is only useful if you are using Typescript to script your WorkAdventure maps. + +## Download & Installation + +```shell +$ npm install @workadventure/iframe-api-typings +``` + +or + +```shell +$ yarn add @workadventure/iframe-api-typings +``` diff --git a/front/packages/iframe-api-typings/iframe_api.js b/front/packages/iframe-api-typings/iframe_api.js new file mode 100644 index 00000000..033bf208 --- /dev/null +++ b/front/packages/iframe-api-typings/iframe_api.js @@ -0,0 +1 @@ +// This file is voluntarily empty. diff --git a/front/packages/iframe-api-typings/package.json b/front/packages/iframe-api-typings/package.json new file mode 100644 index 00000000..61184c4e --- /dev/null +++ b/front/packages/iframe-api-typings/package.json @@ -0,0 +1,13 @@ +{ + "name": "@workadventure/iframe-api-typings", + "version": "1.2.0", + "description": "Typescript typings for WorkAdventure iFrame API", + "main": "iframe_api.js", + "types": "iframe_api.d.ts", + "repository": "https://github.com/thecodingmachine/workadventure/", + "author": "David NĂ©grier ", + "license": "MIT", + "publishConfig": { + "access": "public" + } +} diff --git a/front/tsconfig.json b/front/tsconfig.json index 3fce57ea..f6cb384a 100644 --- a/front/tsconfig.json +++ b/front/tsconfig.json @@ -5,6 +5,7 @@ "moduleResolution": "node", "module": "CommonJS", "target": "ES2015", + "declaration": true, "downlevelIteration": true, "jsx": "react", "allowJs": true, From 0f7ac7ba8b3a6ad3958244868f7f50e14e54578e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Sat, 10 Apr 2021 19:14:36 +0200 Subject: [PATCH 2/3] Added empty .npmignore to override .gitignore --- .github/workflows/push-to-npm.yml | 3 +++ front/packages/iframe-api-typings/.npmignore | 0 2 files changed, 3 insertions(+) create mode 100644 front/packages/iframe-api-typings/.npmignore diff --git a/.github/workflows/push-to-npm.yml b/.github/workflows/push-to-npm.yml index 18404dc0..354cb651 100644 --- a/.github/workflows/push-to-npm.yml +++ b/.github/workflows/push-to-npm.yml @@ -42,12 +42,15 @@ jobs: env: API_URL: "localhost:8080" working-directory: "front" + # We build the front to generate the typings of iframe_api, then we copy those typings in a separate package. - name: Copy typings to package dir run: cp front/dist/src/iframe_api.d.ts front/packages/iframe-api-typings/iframe_api.d.ts + - name: Install dependencies in package run: yarn install working-directory: "front/packages/iframe-api-typings" + - name: Publish package run: yarn publish working-directory: "front/packages/iframe-api-typings" diff --git a/front/packages/iframe-api-typings/.npmignore b/front/packages/iframe-api-typings/.npmignore new file mode 100644 index 00000000..e69de29b From 728fd4779c03b976b04f75f4c3278f13d4be60cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Sun, 11 Apr 2021 11:15:59 +0200 Subject: [PATCH 3/3] Dynamically fetching correct version and generating declarations only for npm lib --- .github/workflows/push-to-npm.yml | 17 +++++++++++++---- front/packages/iframe-api-typings/package.json | 2 +- front/tsconfig.json | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/push-to-npm.yml b/.github/workflows/push-to-npm.yml index 354cb651..798e2530 100644 --- a/.github/workflows/push-to-npm.yml +++ b/.github/workflows/push-to-npm.yml @@ -1,7 +1,5 @@ name: Push @workadventure/iframe-api-typings to NPM on: - # TODO remove action on push - push: ~ release: types: [created] jobs: @@ -14,8 +12,19 @@ jobs: with: node-version: '14.x' registry-url: 'https://registry.npmjs.org' - # TODO: replace version with RELEASE tag - # TODO: enable declaration flag in tsconfig dynamically + + - name: Edit tsconfig.json to add declarations + run: "sed -i 's/\"declaration\": false/\"declaration\": true/g' tsconfig.json" + working-directory: "front" + + - name: Replace version number + run: 'sed -i "s#VERSION_PLACEHOLDER#${GITHUB_REF/refs\/tags\//}#g" package.json' + working-directory: "front/packages/iframe-api-typings" + + - name: Debug package.json + run: cat package.json + working-directory: "front/packages/iframe-api-typings" + - name: Install Protoc uses: arduino/setup-protoc@v1 with: diff --git a/front/packages/iframe-api-typings/package.json b/front/packages/iframe-api-typings/package.json index 61184c4e..fa35851c 100644 --- a/front/packages/iframe-api-typings/package.json +++ b/front/packages/iframe-api-typings/package.json @@ -1,6 +1,6 @@ { "name": "@workadventure/iframe-api-typings", - "version": "1.2.0", + "version": "VERSION_PLACEHOLDER", "description": "Typescript typings for WorkAdventure iFrame API", "main": "iframe_api.js", "types": "iframe_api.d.ts", diff --git a/front/tsconfig.json b/front/tsconfig.json index f6cb384a..b5c8c74d 100644 --- a/front/tsconfig.json +++ b/front/tsconfig.json @@ -5,7 +5,7 @@ "moduleResolution": "node", "module": "CommonJS", "target": "ES2015", - "declaration": true, + "declaration": false, "downlevelIteration": true, "jsx": "react", "allowJs": true,