-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b344042
commit e4bf422
Showing
5 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# next-assetlinks | ||
|
||
Easily generate an `assetlinks.json` for Android app association in your Next.js | ||
project. This tool creates `.well-known/assetlinks.json`, allowing Android apps | ||
to handle URLs. | ||
|
||
## Installation | ||
|
||
Install via npm: | ||
|
||
```bash | ||
npm i next-assetlinks | ||
# or | ||
yarn add next-assetlinks | ||
``` | ||
|
||
## Setup | ||
|
||
1. **Create a Config File** | ||
Add `next-assetlinks.config.js` to your project root: | ||
|
||
```javascript | ||
// next-assetlinks.config.js | ||
module.exports = { | ||
packageName: "com.example.app", | ||
sha256Fingerprint: ["FINGERPRINT_1", "FINGERPRINT_2"], | ||
}; | ||
``` | ||
|
||
- **`packageName`**: Your Android app's package name. | ||
- **`sha256Fingerprint`**: Array of SHA-256 fingerprints for your app's | ||
signing certificates. | ||
|
||
2. **Add Script to `package.json`** | ||
Update package.json to add the generate-assetlinks script: | ||
|
||
```json | ||
"scripts": { | ||
"generate-assetlinks": "node ./node_modules/next-assetlinks/cli.js" | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
Run the command to generate `assetlinks.json`: | ||
|
||
```bash | ||
npm run generate-assetlinks | ||
# or | ||
yarn generate-assetlinks | ||
``` | ||
|
||
This will create or update `public/.well-known/assetlinks.json` with the | ||
configured package name and fingerprints. | ||
|
||
## Contributing | ||
|
||
Contributions are welcome! | ||
|
||
## Credits | ||
|
||
Package by [Reach Digital](https://www.reachdigital.nl/) | ||
|
||
## License | ||
|
||
Licensed under MIT. See [LICENSE](./LICENSE) for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env node | ||
|
||
const generateAssetLinks = require('./index.js') | ||
|
||
generateAssetLinks() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
function generateAssetLinks() { | ||
const configPath = path.join(process.cwd(), 'next-assetlinks.config.js') | ||
|
||
if (!fs.existsSync(configPath)) { | ||
console.warn("'next-assetlinks.config.js' not found. Skipping assetlinks.json generation.") | ||
return // Stop the function gracefully without crashing | ||
} | ||
|
||
const { packageName, sha256Fingerprint } = require(configPath) | ||
|
||
if (!packageName || !Array.isArray(sha256Fingerprint) || sha256Fingerprint.length === 0) { | ||
throw new Error( | ||
"Error: 'packageName' or 'sha256Fingerprint' array is missing or empty in 'next-assetlinks.config.js'. Please check your configuration.", | ||
) | ||
} | ||
|
||
const directoryPath = path.join(process.cwd(), 'public/.well-known') | ||
|
||
if (!fs.existsSync(directoryPath)) { | ||
fs.mkdirSync(directoryPath, { recursive: true }) | ||
} | ||
|
||
const assetLinksContent = [ | ||
{ | ||
relation: ['delegate_permission/common.handle_all_urls'], | ||
target: { | ||
namespace: 'android_app', | ||
package_name: packageName, | ||
sha256_cert_fingerprints: sha256Fingerprint, | ||
}, | ||
}, | ||
] | ||
|
||
fs.writeFileSync( | ||
path.join(directoryPath, 'assetlinks.json'), | ||
JSON.stringify(assetLinksContent, null, 2), | ||
) | ||
|
||
console.log('assetlinks.json file successfully created.') | ||
} | ||
|
||
module.exports = generateAssetLinks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
packageName: 'com.example.app', | ||
sha256Fingerprint: ['FINGERPRINT_1', 'FINGERPRINT_2'], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "next-assetlinks", | ||
"homepage": "https://www.reachdigital.nl/", | ||
"repository": "github:ho-nl/next-assetlinks", | ||
"version": "1.0.0", | ||
"description": "Generate an assetlinks.json file for Next.js projects", | ||
"main": "index.js", | ||
"bin": { | ||
"generate-assetlinks": "./cli.js" | ||
}, | ||
"dependencies": {}, | ||
"author": "Reach Digital", | ||
"license": "MIT" | ||
} |