Skip to content

Commit

Permalink
feat(general): round Android icons and configuration of input icon
Browse files Browse the repository at this point in the history
release-npm
  • Loading branch information
tobua committed Jun 30, 2022
1 parent 19355c1 commit 3827938
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,18 @@ Numic automatically picks up the plugin once installed and adds the various icon
- app-icon.png
- asset/icon.png
- logo.png (also used as Avatar in SourceTree)

## Configuration

The icon can be configured in `package.json` under the `numic` property. This will override default icon paths from the file system as described above.

```json
{
"name": "my-app",
"numic": {
"icon-numic-plugin": {
"icon": "image/my-icon.png"
}
}
}
```
24 changes: 19 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { contentsWithLinks } from './ios'
// Alternative: https://github.com/silvia-odwyer/photon
// https://github.com/aeirola/react-native-svg-app-icon
// https://www.npmjs.com/package/app-icon (requires imagemagik)
// https://docs.expo.dev/guides/app-icons/

type Input = {
cwd?: string
log?: (message: string, type?: string) => void
options?: object
}

const iconSourcePaths = (cwd: string) => [
Expand All @@ -21,7 +21,15 @@ const iconSourcePaths = (cwd: string) => [
join(cwd, 'logo.png'),
]

const getInput = (cwd: string) => {
const getInput = (cwd: string, options: { icon?: string }) => {
if (
typeof options === 'object' &&
typeof options.icon === 'string' &&
existsSync(join(cwd, options.icon))
) {
return join(cwd, options.icon)
}

const paths = iconSourcePaths(cwd)
let match: string | undefined

Expand All @@ -40,7 +48,12 @@ const getAndroidFolders = () => [
{ path: 'android/app/src/main/res/mipmap-xhdpi/ic_launcher.png', size: 96 },
{ path: 'android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png', size: 144 },
{ path: 'android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png', size: 192 },
// TODO rounded icons
// Round icons.
{ path: 'android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png', size: 48, round: true },
{ path: 'android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png', size: 72, round: true },
{ path: 'android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png', size: 96, round: true },
{ path: 'android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png', size: 144, round: true },
{ path: 'android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png', size: 192, round: true },
]

const getIOSFolders = (iosImageDirectory: string) => {
Expand Down Expand Up @@ -84,9 +97,10 @@ export default async ({
cwd = process.cwd(),
// eslint-disable-next-line no-console
log = console.log,
options,
}: Input) => {
const inputFile = getInput(cwd)
const sizes = getSizes({ cwd, log })
const inputFile = getInput(cwd, options)
const sizes = getSizes({ cwd, log, options })

const androidPromises = sizes.android.map((icon) => {
const destinationFile = join(cwd, icon.path)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"sideEffects": false,
"main": "dist/index.js",
"exports": {
"default": "./dist/index.js"
"default": "./dist/index.js",
"package.json": "./package.json"
},
"types": "dist/index.d.ts",
"files": [
Expand Down
22 changes: 20 additions & 2 deletions test/logo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ global.afterEach = afterEach

environment('logo')

test('Properly configures empty project.', async () => {
test('Creates logos in various sizes.', async () => {
prepare([packageJson('logo')])

const logoPath = join(process.cwd(), 'logo.png')
Expand All @@ -29,8 +29,9 @@ test('Properly configures empty project.', async () => {

const files = listFilesMatching('**/*.png')

expect(files.length).toBe(15)
expect(files.length).toBe(20)
expect(files.includes('android/app/src/main/res/mipmap-mdpi/ic_launcher.png')).toBe(true)
expect(files.includes('android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png')).toBe(true)
expect(files.includes('ios/numic/Images.xcassets/AppIcon.appiconset/Icon-80.png')).toBe(true)

const iosContentsPath = join(
Expand All @@ -44,3 +45,20 @@ test('Properly configures empty project.', async () => {

expect(iconContentsSpecification.images[0].filename).toBe('Icon-40.png')
})

test('Icon path can be configured.', async () => {
prepare([packageJson('logo-configured')])

const logoPath = join(process.cwd(), 'icon/my-image.png')

cpSync(join(initialCwd, 'test/logo.png'), logoPath, { recursive: true })
mkdirSync(join(process.cwd(), 'ios/numic/Images.xcassets'), { recursive: true })

expect(existsSync(logoPath)).toBe(true)

await plugin({ options: { icon: 'icon/my-image.png' } })

const files = listFilesMatching('**/*.png')

expect(files.length).toBe(20)
})

0 comments on commit 3827938

Please sign in to comment.