Skip to content

Commit

Permalink
Fix CLI flags (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeirola authored Feb 1, 2022
1 parent 830a5b4 commit e68c389
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 39 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ Supported configuration values are
| `platforms` | `["android", "ios"]` | Array of platforms for which application launcher icons should be generated. Possible values are `android` and `ios`. |
| `force` | `false` | When `true`, output files will always be written even if they are newer than the input files. |

Alternatively, the configuration parameters can also be set as CLI flags. See `react-native-svg-app-icon --help` for details.

## Icon format

The input icon should be a SVG file adhering to the [Android adaptive icon specification](https://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive). Specifically, the image should:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"url": "https://github.com/aeirola/react-native-svg-app-icon.git"
},
"dependencies": {
"coa": "^2.0.2",
"fs-extra": ">=3.0.0",
"sharp": ">=0.23.0",
"svg2vectordrawable": "2.6.26"
Expand Down
12 changes: 12 additions & 0 deletions src/__tests__/cli-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,16 @@ describe("cli", () => {

await expect(main()).resolves.toBeUndefined();
});

it("reads icon path from arguments", async () => {
await fse.ensureDir(path.join("ios", "project", "Images.xcassets"));

await expect(
main([
"/usr/local/bin/node",
"cli.js",
`--foreground-path=${path.join(fixturesPath, "example", "icon.svg")}`
])
).resolves.toBeUndefined();
});
});
75 changes: 36 additions & 39 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async function main(args: string[] = []): Promise<void> {
const cliConfig: CliConfig = {
...defaultConfig,
...(await readFileConfig()),
...readArgsConfig(args)
...(await readArgsConfig(args))
};

cliConfig.platforms = cliConfig.platforms.map(
Expand Down Expand Up @@ -80,44 +80,41 @@ async function readFileConfig(): Promise<Partial<CliConfig>> {
}

async function readArgsConfig(args: string[]): Promise<Partial<CliConfig>> {
let argsConfig: Partial<CliConfig> = {};
coa
.Cmd()
.name("react-native-svg-app-icon")
.helpful()
// --background-path
.opt()
.name("backgroundPath")
.title("Background path")
.long("background-path")
.end()
// --foreground-path
.opt()
.name("foregroundPath")
.title("Foreground path")
.long("foreground-path")
.end()
// --platform
.opt()
.name("platforms")
.title("Platform")
.long("platform")
.arr()
.end()
// --force
.opt()
.name("force")
.title("Force")
.long("force")
.short("f")
.flag()
.end()
.act((opts: Partial<CliConfig>) => {
argsConfig = opts;
})
.run(args.slice(2));

return argsConfig;
return new Promise((resolve) =>
coa
.Cmd()
.name("react-native-svg-app-icon")
.helpful()
// --background-path
.opt()
.name("backgroundPath")
.title("Background path")
.long("background-path")
.end()
// --foreground-path
.opt()
.name("foregroundPath")
.title("Foreground path")
.long("foreground-path")
.end()
// --platform
.opt()
.name("platforms")
.title("Platform")
.long("platform")
.arr()
.end()
// --force
.opt()
.name("force")
.title("Force")
.long("force")
.short("f")
.flag()
.end()
.act(resolve)
.run(args.slice(2))
);
}

if (require.main === module) {
Expand Down

0 comments on commit e68c389

Please sign in to comment.