Skip to content

Commit c11e231

Browse files
markemerOS-pedrogustavobilrojcesarmobile
authored
fix: make 'android-lang' optional, with java as default (#151)
* fix: Make --android-lang optional with java as default * fix: fail when android-lang option is invalid * fix: using 'kt' did not remove java folder * chore: fix lint issues * chore: revert 86a3a74 Following PR discussion * chore: remove kt option * chore: Improve error handling for android-lang * chore: update template since androidLang is not optional anymore --------- Co-authored-by: OS-pedrogustavobilro <pedro.gustavo.bilro@outsystems.com> Co-authored-by: jcesarmobile <jcesarmobile@gmail.com>
1 parent 5dc4e19 commit c11e231

4 files changed

Lines changed: 22 additions & 13 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ As of the `0.8.0` release, example apps for testing are included when initializi
3030
--author <author> ......... Author name and email (e.g. "Name <name@example.com>")
3131
--license <id> ............ SPDX License ID (e.g. "MIT")
3232
--description <text> ...... Short description of plugin features
33-
--android-lang <text> ..... Language for Android plugin development (either "kotlin" or "java")
33+
--android-lang <text> ..... Language for Android plugin development (either "kotlin" or "java", default is "java")
3434
```

src/help.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const help = `
1010
--author <author> ......... Author name and email (e.g. "Name <name@example.com>")
1111
--license <id> ............ SPDX License ID (e.g. "MIT")
1212
--description <text> ...... Short description of plugin features
13-
--android-lang ............ Language for Android plugin development (either "kotlin" or "java")
13+
--android-lang ............ Language for Android plugin development (either "kotlin" or "java", default is "java")
1414
1515
-h, --help ................ Print help, then quit
1616
--verbose ................. Print verbose output to stderr

src/options.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export const VALIDATORS: Validators = {
6868
description: (value) =>
6969
typeof value !== 'string' || value.trim().length === 0 ? `Must provide a description` : true,
7070
'android-lang': (value) =>
71-
typeof value === 'string' && value.trim().length > 0 && /^(kotlin|kt|java)$/i.test(value)
71+
value === undefined || value === '' || (typeof value === 'string' && /^(kotlin|java)$/i.test(value))
7272
? true
7373
: `Must be either "kotlin" or "java"`,
7474
dir: (value) =>
@@ -99,12 +99,24 @@ export const getOptions = (): Options => {
9999

100100
if (typeof validatorResult === 'string') {
101101
debug(`invalid option: --%s %O: %s`, option, value, validatorResult);
102+
103+
// 'android-lang' is not prompted, so it should fail if invalid
104+
if (option === 'android-lang') {
105+
process.stderr.write(`ERR: Invalid --android-lang value "${value}": ${validatorResult}\n`);
106+
process.exit(1);
107+
}
102108
}
103109

104110
opts[option] = validatorResult === true ? value : undefined;
105111

106112
return opts;
107113
}, {} as Options);
108114

109-
return { ...argValues, ...optionValues };
115+
const allOptions = { ...argValues, ...optionValues };
116+
117+
if (!allOptions['android-lang']) {
118+
allOptions['android-lang'] = 'java';
119+
}
120+
121+
return allOptions;
110122
};

src/prompt.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,6 @@ export const gatherDetails = (initialOptions: Options): Promise<OptionValues> =>
8282
message: `Enter a SPDX license identifier for your plugin.\n`,
8383
validate: VALIDATORS.license,
8484
},
85-
{
86-
type: 'select',
87-
name: 'android-lang',
88-
message: `What language would you like to use for your Android plugin?\n`,
89-
choices: [
90-
{ title: 'Kotlin', value: 'kotlin' },
91-
{ title: 'Java', value: 'java' },
92-
],
93-
},
9485
{
9586
type: 'text',
9687
name: 'description',
@@ -105,5 +96,11 @@ export const gatherDetails = (initialOptions: Options): Promise<OptionValues> =>
10596
process.exit(1);
10697
},
10798
},
99+
).then(
100+
(result) =>
101+
({
102+
...result,
103+
'android-lang': initialOptions['android-lang'],
104+
}) as OptionValues,
108105
);
109106
};

0 commit comments

Comments
 (0)