Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #14 from voorhoede/fix/missing-slash
Browse files Browse the repository at this point in the history
fix(index): add missing slash to default distfolder path fixes #11
  • Loading branch information
celinekurpershoek authored Jan 16, 2020
2 parents 46658de + cc62119 commit 526f118
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 34 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Add `nuxt-twa-module` to `modules` section of `nuxt.config.js`.
/* module options */
defaultUrl: 'https://your-url.com',
hostName: 'your-url.com',
sha256Fingerprints: [/* your SHA-256 keys */],
sha256Fingerprints: ['/* your SHA-256 keys */'],
applicationId: 'com.example.example',
launcherName: 'Your app name',
versionCode: 1,
Expand All @@ -51,11 +51,15 @@ Add `nuxt-twa-module` to `modules` section of `nuxt.config.js`.
/* optional */
/* overwrite default location for icon */
iconPath: '/static/icon.png'
/* Overwrite folder where to put .wellknown */
distFolder: '.nuxt/dist/client',
}],
]
}
```

the `sha256Fingerprints` by is an array with one SHA-256 key string. But if you have multiple you can add them to the array. More information about the website asociation: https://developer.android.com/training/app-links/verify-site-associations#web-assoc

## Time to build 🏗

When the configuration is done you can run your project like you are used to.
Expand All @@ -73,7 +77,7 @@ npm run generate
### Output

- An `android` folder in your project root, which you can open in Android Studio to [build your app](https://developer.android.com/studio/run/). When you've build and tested your app you can use [Generate Signed Bundle/APK](https://developer.android.com/studio/publish/app-signing). This will generate a .aab file that can be uploaded to the Google Play Store.
- You Nuxt app with an added `.well-known` folder which is needed to make your domain trusted with the app in the store.
- Your Nuxt app with an added `.well-known` folder which is needed to make your domain trusted with the app in the store.

## Debug

Expand Down
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fs = require('fs')
const rimraf = require('rimraf')
const consola = require('consola')
const ncp = require('ncp')
const tmp = require('tmp-promise')
const tmp = require('tmp-promise')
const asyncRimRaf = promisify(rimraf)
const asyncNcp = promisify(ncp)

Expand All @@ -13,7 +13,7 @@ const { generateAssetLinksFile } = require('./lib/generate-asset-links-file')

const moduleRoot = __dirname

module.exports = function nuxtTwa (options) {
module.exports = function nuxtTwa(options) {
const { rootDir } = this.nuxt.options
const pckg = require(rootDir + '/package.json')
const defaultOptions = {
Expand All @@ -22,26 +22,26 @@ module.exports = function nuxtTwa (options) {
versionCode: Number(String(pckg.version).replace(/\./g, '')),
versionName: pckg.version,
iconPath: '/static/icon.png',
distFolder: rootDir + '.nuxt/dist/client',
distFolder: rootDir + '/.nuxt/dist/client',
androidFolder: rootDir + '/android',
statusBarColor: options.statusBarColor || '#fff'
}

this.nuxt.hook('build:before', async () => {

options = {
...defaultOptions,
...options,
}

let tempDir
let tmpRes

try {
tmpRes = await tmp.dir()
tempDir = tmpRes.path + '/android'
} catch (err) {
throw('Temperary directory generation failed:', err)
throw ('Temperary directory generation failed:', err)
}

try {
Expand All @@ -63,7 +63,7 @@ module.exports = function nuxtTwa (options) {
await generateIcons(iconPath, androidIconsPath)
} catch (err) {
return consola.error('Generating icons failed', err)
}
}

try {
await asyncNcp(tempDir, options.androidFolder)
Expand Down
18 changes: 10 additions & 8 deletions test/example/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ module.exports = {
resourceHints: false
},
modules: [
{ handler: require('../../'), options: {
hostName: 'test.com',
defaultUrl: 'https://test.com',
sha256Fingerprints: '123',
iconPath: '/test/fixture/static/icon.png',
distFolder: '/test/example/.nuxt/dist/client',
androidFolder: './test/example/android/'
} }
{
handler: require('../../'), options: {
hostName: 'test.com',
defaultUrl: 'https://test.com',
sha256Fingerprints: ['123'],
iconPath: '/test/fixture/static/icon.png',
distFolder: '/test/example/.nuxt/dist/client',
androidFolder: './test/example/android/'
}
}
]
}
32 changes: 16 additions & 16 deletions test/module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ const { generateAssetLinksFile, generateConfig } = require('../lib/generate-asse

describe('Test TWA module', () => {
const iconPath = path.resolve(__dirname, 'fixture/static/icon.png')
const testFolder = path.resolve(__dirname, 'test-env')
const testFolder = path.resolve(__dirname, 'test-env')

beforeAll(() => {
// Redirect std and console to consola too
// Calling this once is sufficient
consola.wrapAll()
if(fs.existsSync(testFolder)){
if (fs.existsSync(testFolder)) {
rimraf(testFolder, (error) => console.log(error))
}
fs.mkdirSync(testFolder, { recursive: true })
})

beforeEach(() => {
beforeEach(() => {
// Re-mock consola before each test call to remove
// calls from before
consola.mockTypes(() => jest.fn())
consola.mockTypes(() => jest.fn())
})

afterAll( () => {
afterAll(() => {
return rimraf(testFolder, (error) => console.log(error))
})

describe('Test generate-icons', () => {
const destination = path.resolve(testFolder, 'res/')
const destination = path.resolve(testFolder, 'res/')

beforeAll( () => {
beforeAll(() => {
fs.mkdirSync(destination, { recursive: true })
})

Expand Down Expand Up @@ -82,7 +82,7 @@ describe('Test TWA module', () => {
})

describe('Test generate-build-file', () => {
const appDirectory = path.resolve(__dirname, 'test-env/app')
const appDirectory = path.resolve(__dirname, 'test-env/app')
const gradleFile = path.resolve(__dirname, 'test-env/app/build.gradle')
const buildOptions = {
defaultUrl: 'test',
Expand All @@ -103,7 +103,7 @@ describe('Test TWA module', () => {
beforeAll(() => {
prepareAppFolder(appDirectory)
})


test('Get error when gradle file is undefined', async () => {
expect.assertions(1)
Expand Down Expand Up @@ -156,19 +156,19 @@ describe('Test TWA module', () => {
}
})
})

describe('Test generate-asset-links-file', () => {
const options = {
applicationId: "test",
sha256Fingerprints: "123"
sha256Fingerprints: ["123"]
}

const mockdata = [{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "test",
"sha256_cert_fingerprints": "123"
"sha256_cert_fingerprints": ["123"]
},
}]

Expand All @@ -178,17 +178,17 @@ describe('Test TWA module', () => {
await generateAssetLinksFile({}, '')
} catch (error) {
expect(error)
.toMatch(/Missing SHA256/)
.toMatch(/Missing SHA256/)
}
})

test('Get error when destination path is invalid', async() => {
test('Get error when destination path is invalid', async () => {
expect.assertions(1)
try {
await generateAssetLinksFile(options, '')
} catch (error) {
expect(error)
.toMatch(/No destination path/)
.toMatch(/No destination path/)
}
})

Expand All @@ -209,5 +209,5 @@ describe('Test TWA module', () => {
})
})
})


0 comments on commit 526f118

Please sign in to comment.