|
| 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 | +} |
0 commit comments