From 604dda73804ab626b29476336d98d13c00159a9a Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 3 Dec 2020 12:35:21 +0100 Subject: [PATCH] create apple-app-site-association during build --- package.json | 4 +++ scripts/build.js | 60 +++++++++++++++++++++++++------------ scripts/serve-local.js | 12 ++++---- src/open/clients/Element.js | 2 ++ 4 files changed, 54 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index f375573..28234a8 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,9 @@ { "version": "0.0.1", + "type": "module", + "engines": { + "node": ">= 14.0.0" + }, "scripts": { "start": "node scripts/serve-local.js", "build": "node scripts/build.js" diff --git a/scripts/build.js b/scripts/build.js index a12e368..4cd2f74 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -15,32 +15,34 @@ See the License for the specific language governing permissions and limitations under the License. */ -const cheerio = require("cheerio"); -const fsRoot = require("fs"); -const fs = fsRoot.promises; -const path = require("path"); -const xxhash = require('xxhashjs'); -const { rollup } = require('rollup'); -const postcss = require("postcss"); -const postcssImport = require("postcss-import"); +import cheerio from "cheerio"; +import fs from "fs/promises"; +import path from "path"; +import xxhash from 'xxhashjs'; +import { rollup } from 'rollup'; +import postcss from "postcss"; +import postcssImport from "postcss-import"; // needed for legacy bundle -const babel = require('@rollup/plugin-babel'); +import babel from '@rollup/plugin-babel'; // needed to find the polyfill modules in the main-legacy.js bundle -const { nodeResolve } = require('@rollup/plugin-node-resolve'); +import { nodeResolve } from '@rollup/plugin-node-resolve'; // needed because some of the polyfills are written as commonjs modules -const commonjs = require('@rollup/plugin-commonjs'); +import commonjs from '@rollup/plugin-commonjs'; // multi-entry plugin so we can add polyfill file to main -const multi = require('@rollup/plugin-multi-entry'); -const { terser } = require("rollup-plugin-terser"); -const replace = require("@rollup/plugin-replace"); +import multi from '@rollup/plugin-multi-entry'; +import { terser } from "rollup-plugin-terser"; +import replace from "@rollup/plugin-replace"; // replace urls of asset names with content hashed version -const postcssUrl = require("postcss-url"); +import postcssUrl from "postcss-url"; +import cssvariables from "postcss-css-variables"; +import autoprefixer from "autoprefixer"; +import flexbugsFixes from "postcss-flexbugs-fixes"; -const cssvariables = require("postcss-css-variables"); -const autoprefixer = require("autoprefixer"); -const flexbugsFixes = require("postcss-flexbugs-fixes"); +import {createClients} from "../src/open/clients/index.js"; -const projectDir = path.join(__dirname, "../"); +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; +const projectDir = path.join(dirname(fileURLToPath(import.meta.url)), "../"); async function build() { // get version number @@ -56,6 +58,8 @@ async function build() { await assets.write(`bundle-esm.js`, await buildJs("src/main.js", assets)); await assets.write(`bundle-legacy.js`, await buildJsLegacy("src/main.js", assets, ["src/polyfill.js"])); await assets.write(`bundle.css`, await buildCss("css/main.css", assets)); + await assets.writeUnhashed("apple-app-site-association", buildAppleAssociatedAppsFile(createClients())); + const globalHash = assets.hashForAll(); await buildHtml(assets); @@ -132,6 +136,24 @@ async function buildJsLegacy(mainFile, assets, extraFiles = []) { return code; } +function buildAppleAssociatedAppsFile(clients) { + const appIds = clients.map(c => c.appleAssociatedAppId).filter(id => !!id); + return JSON.stringify({ + "applinks": { + "apps": [], + "details": appIds.map(id => { + return { + "appID": id, + "paths": ["*"] + }; + }), + }, + "webcredentials": { + "apps": appIds + } + }); +} + async function buildCss(entryPath, assets) { entryPath = path.join(projectDir, entryPath); const assetUrlMapper = ({absolutePath}) => { diff --git a/scripts/serve-local.js b/scripts/serve-local.js index 671a842..02581f9 100644 --- a/scripts/serve-local.js +++ b/scripts/serve-local.js @@ -14,14 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. */ -const finalhandler = require('finalhandler') -const http = require('http') -const serveStatic = require('serve-static') -const path = require('path'); +import finalhandler from "finalhandler" +import http from "http" +import serveStatic from "serve-static" +import path from "path" +import { fileURLToPath } from "url"; +const projectDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../"); // Serve up parent directory with cache disabled const serve = serveStatic( - path.resolve(__dirname, "../"), + projectDir, { etag: false, setHeaders: res => { diff --git a/src/open/clients/Element.js b/src/open/clients/Element.js index 2f426a6..6faf89c 100644 --- a/src/open/clients/Element.js +++ b/src/open/clients/Element.js @@ -32,6 +32,8 @@ export class Element { ]; } + get appleAssociatedAppId() { return "7J4U792NQT.im.vector.app"; } + get description() { return 'Fully-featured Matrix client, used by millions.'; } get homepage() { return "https://element.io"; }