Skip to content

Commit 0105712

Browse files
committed
feat: unify appName logic and extract to utils
1 parent f42aa4a commit 0105712

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

src/commands/icons.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
import { Args, Command, Flags } from '@oclif/core'
1010
import Listr from 'listr'
11-
import { readFileSync } from 'node:fs'
1211
import { writeFile } from 'node:fs/promises'
1312
import { join } from 'node:path'
1413
import sharp from 'sharp'
1514
import { cyan, green, red } from 'yoctocolors'
1615

16+
import { extractAppName } from '../utils/app.utils.js'
1717
import { checkAssetFile, mkdirp } from '../utils/file-utils.js'
1818

1919
interface ContentJsonImage {
@@ -105,14 +105,7 @@ The base icon file should be at least 1024x1024px.
105105
static override flags = {
106106
appName: Flags.string({
107107
char: 'a',
108-
default() {
109-
try {
110-
const { name } = JSON.parse(readFileSync('./app.json', 'utf8'))
111-
return name
112-
} catch {
113-
return null
114-
}
115-
},
108+
default: extractAppName,
116109
description: "the appName used to build output assets path. Default is retrieved from 'app.json' file.",
117110
}),
118111
help: Flags.help({ char: 'h' }),

src/commands/splash.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
import { Args, Command, Flags } from '@oclif/core'
1010
import Listr from 'listr'
11-
import { readFileSync } from 'node:fs'
1211
import { writeFile } from 'node:fs/promises'
1312
import { join } from 'node:path'
1413
import sharp from 'sharp'
1514
import { cyan, green, red } from 'yoctocolors'
1615

16+
import { extractAppName } from '../utils/app.utils.js'
1717
import { checkAssetFile, mkdirp } from '../utils/file-utils.js'
1818

1919
interface ContentJsonImage {
@@ -97,14 +97,7 @@ The base splashscreen file should be at least 1242x2208px.
9797
static override flags = {
9898
appName: Flags.string({
9999
char: 'a',
100-
default() {
101-
try {
102-
const { name } = JSON.parse(readFileSync('./app.json', 'utf8'))
103-
return name
104-
} catch {
105-
return null
106-
}
107-
},
100+
default: extractAppName,
108101
description: "the appName used to build output assets path. Default is retrieved from 'app.json' file.",
109102
}),
110103
help: Flags.help({ char: 'h' }),

src/utils/app.utils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2025 ForWarD Software (https://forwardsoftware.solutions/)
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7+
*/
8+
9+
import { readFileSync } from 'node:fs'
10+
11+
export function extractAppName() {
12+
try {
13+
const { name } = JSON.parse(readFileSync('./app.json', 'utf8'))
14+
return name
15+
} catch {
16+
return null
17+
}
18+
}

0 commit comments

Comments
 (0)