Skip to content

Commit 6cb18d4

Browse files
rfontanarosagino-m
andauthored
Deployment of .well-known/assertLinks.json using the proper environment (#2201)
Co-authored-by: Gino Miceli <[email protected]>
1 parent 7a5afeb commit 6cb18d4

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

web/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"ci-all": "npm run ci-local-deps && npm ci",
77
"ci-local-deps": "npm ci --workspace=../proto --workspace=../lib",
88
"build-local-deps": "npm run build --workspace=../proto --workspace=../lib",
9-
"build": "npm run --prefix scripts copy-keys && ng build -c $npm_config_config",
9+
"prebuild": "npm run --prefix scripts copy-keys",
10+
"build": "ng build -c $npm_config_config",
11+
"postbuild": "npm run --prefix scripts copy-asset-links",
1012
"build-all": "npm run build-local-deps && npm run build",
1113
"build-and-test": "npm run build && npm run test",
1214
"build-all-and-test": "npm run build-all && npm run test",

web/scripts/copy-asset-links.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright 2025 The Ground Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the 'License');
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an 'AS IS' BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
18+
19+
// This script copies the assetLinks.json file from `web/keys/<project-id>/` to the local
20+
// `dist/.well-known` folder before build. This file is used for Digital Asset Links
21+
// to associate the web app with the Android app.
22+
23+
const project = process.env['npm_config_project'];
24+
25+
const assertLinksFilepath = `../keys/${project}/assetLinks.json`;
26+
27+
if (existsSync(assertLinksFilepath)) {
28+
const assertLinks = readFileSync(
29+
`../keys/${project}/assetLinks.json`,
30+
'utf8'
31+
);
32+
33+
const wellKnownDir = '../dist/.well-known';
34+
35+
if (!existsSync(wellKnownDir)) {
36+
mkdirSync(wellKnownDir, { recursive: true });
37+
}
38+
39+
writeFileSync(`${wellKnownDir}/assetLinks.json`, assertLinks);
40+
} else {
41+
console.warn('Missing asserLinks.json file');
42+
}

web/scripts/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "Ground web app custom build scripts",
55
"type": "module",
66
"scripts": {
7-
"copy-keys": "node copy-keys.js"
7+
"copy-keys": "node copy-keys.js",
8+
"copy-asset-links": "node copy-asset-links.js"
89
},
910
"keywords": [],
1011
"author": "",

0 commit comments

Comments
 (0)