diff --git a/README.md b/README.md index 4ad6857..1baa1bd 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/package.json b/package.json index eca4563..dd1a322 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/__tests__/cli-test.ts b/src/__tests__/cli-test.ts index 12a6a46..c563353 100644 --- a/src/__tests__/cli-test.ts +++ b/src/__tests__/cli-test.ts @@ -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(); + }); }); diff --git a/src/cli.ts b/src/cli.ts index 78b97ff..da32c1c 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -46,7 +46,7 @@ async function main(args: string[] = []): Promise { const cliConfig: CliConfig = { ...defaultConfig, ...(await readFileConfig()), - ...readArgsConfig(args) + ...(await readArgsConfig(args)) }; cliConfig.platforms = cliConfig.platforms.map( @@ -80,44 +80,41 @@ async function readFileConfig(): Promise> { } async function readArgsConfig(args: string[]): Promise> { - let argsConfig: Partial = {}; - 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) => { - 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) {