create apple-app-site-association during build

This commit is contained in:
Bruno Windels 2020-12-03 12:35:21 +01:00
parent e8e2f04f01
commit 604dda7380
4 changed files with 54 additions and 24 deletions

View File

@ -1,5 +1,9 @@
{ {
"version": "0.0.1", "version": "0.0.1",
"type": "module",
"engines": {
"node": ">= 14.0.0"
},
"scripts": { "scripts": {
"start": "node scripts/serve-local.js", "start": "node scripts/serve-local.js",
"build": "node scripts/build.js" "build": "node scripts/build.js"

View File

@ -15,32 +15,34 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
const cheerio = require("cheerio"); import cheerio from "cheerio";
const fsRoot = require("fs"); import fs from "fs/promises";
const fs = fsRoot.promises; import path from "path";
const path = require("path"); import xxhash from 'xxhashjs';
const xxhash = require('xxhashjs'); import { rollup } from 'rollup';
const { rollup } = require('rollup'); import postcss from "postcss";
const postcss = require("postcss"); import postcssImport from "postcss-import";
const postcssImport = require("postcss-import");
// needed for legacy bundle // 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 // 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 // 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 // multi-entry plugin so we can add polyfill file to main
const multi = require('@rollup/plugin-multi-entry'); import multi from '@rollup/plugin-multi-entry';
const { terser } = require("rollup-plugin-terser"); import { terser } from "rollup-plugin-terser";
const replace = require("@rollup/plugin-replace"); import replace from "@rollup/plugin-replace";
// replace urls of asset names with content hashed version // 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"); import {createClients} from "../src/open/clients/index.js";
const autoprefixer = require("autoprefixer");
const flexbugsFixes = require("postcss-flexbugs-fixes");
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() { async function build() {
// get version number // 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-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-legacy.js`, await buildJsLegacy("src/main.js", assets, ["src/polyfill.js"]));
await assets.write(`bundle.css`, await buildCss("css/main.css", assets)); await assets.write(`bundle.css`, await buildCss("css/main.css", assets));
await assets.writeUnhashed("apple-app-site-association", buildAppleAssociatedAppsFile(createClients()));
const globalHash = assets.hashForAll(); const globalHash = assets.hashForAll();
await buildHtml(assets); await buildHtml(assets);
@ -132,6 +136,24 @@ async function buildJsLegacy(mainFile, assets, extraFiles = []) {
return code; 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) { async function buildCss(entryPath, assets) {
entryPath = path.join(projectDir, entryPath); entryPath = path.join(projectDir, entryPath);
const assetUrlMapper = ({absolutePath}) => { const assetUrlMapper = ({absolutePath}) => {

View File

@ -14,14 +14,16 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
const finalhandler = require('finalhandler') import finalhandler from "finalhandler"
const http = require('http') import http from "http"
const serveStatic = require('serve-static') import serveStatic from "serve-static"
const path = require('path'); 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 // Serve up parent directory with cache disabled
const serve = serveStatic( const serve = serveStatic(
path.resolve(__dirname, "../"), projectDir,
{ {
etag: false, etag: false,
setHeaders: res => { setHeaders: res => {

View File

@ -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 description() { return 'Fully-featured Matrix client, used by millions.'; }
get homepage() { return "https://element.io"; } get homepage() { return "https://element.io"; }