dialog fix
This commit is contained in:
parent
05d4839dea
commit
6a525d8120
5
lib/dialog.ts
Normal file
5
lib/dialog.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
class DialogHandler {
|
||||||
|
public static catch (): void {
|
||||||
|
process.exit ();
|
||||||
|
}
|
||||||
|
}
|
@ -33,7 +33,7 @@ export default class Copyright implements Snippet {
|
|||||||
|
|
||||||
if (await new Confirm({
|
if (await new Confirm({
|
||||||
message: 'should those settings be saved for the next run?'
|
message: 'should those settings be saved for the next run?'
|
||||||
}).run()) {
|
}).run().catch(DialogHandler.catch)) {
|
||||||
this.save_options_file();
|
this.save_options_file();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -41,18 +41,18 @@ export default class Copyright implements Snippet {
|
|||||||
private async gather_options (): Promise<void> {
|
private async gather_options (): Promise<void> {
|
||||||
this.options = (new CopyrightOptions);
|
this.options = (new CopyrightOptions);
|
||||||
this.options.author = await new Input ({ message: 'author' })
|
this.options.author = await new Input ({ message: 'author' })
|
||||||
.run ();
|
.run ().catch(DialogHandler.catch);
|
||||||
this.options.email = await new Input ({ message: 'email' })
|
this.options.email = await new Input ({ message: 'email' })
|
||||||
.run ();
|
.run ().catch(DialogHandler.catch);
|
||||||
this.options.company = await new Input ({ message: 'company' })
|
this.options.company = await new Input ({ message: 'company' })
|
||||||
.run ();
|
.run ().catch(DialogHandler.catch);
|
||||||
this.options.software = await new Input ({ message: 'software name' })
|
this.options.software = await new Input ({ message: 'software name' })
|
||||||
.run ();
|
.run ().catch(DialogHandler.catch);
|
||||||
this.options.has_license = await new Confirm ({
|
this.options.has_license = await new Confirm ({
|
||||||
message:
|
message:
|
||||||
'would you like to specify a license?'
|
'would you like to specify a license?'
|
||||||
})
|
})
|
||||||
.run ();
|
.run ().catch(DialogHandler.catch);
|
||||||
if (this.options.has_license) {
|
if (this.options.has_license) {
|
||||||
this.options.license = await new AutoComplete ({
|
this.options.license = await new AutoComplete ({
|
||||||
name: 'license',
|
name: 'license',
|
||||||
@ -60,20 +60,31 @@ export default class Copyright implements Snippet {
|
|||||||
limit: 10,
|
limit: 10,
|
||||||
choices: findLicense ('')
|
choices: findLicense ('')
|
||||||
})
|
})
|
||||||
.run ();
|
.run ().catch(DialogHandler.catch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async load_options_file (): Promise<void> {
|
private async load_options_file (): Promise<void> {
|
||||||
const file_path = path.join (this.cwd, '.liconfig.json');
|
const file_path = path.join (this.cwd, '.liconfig.json');
|
||||||
|
this.options = null;
|
||||||
|
|
||||||
if (await fs.pathExists (file_path)) {
|
if (await fs.pathExists (file_path)) {
|
||||||
this.options = JSON.parse (
|
const options = JSON.parse (
|
||||||
await fs.readFile (file_path, 'utf-8')
|
await fs.readFile (file_path, 'utf-8')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(`author: ${options.author}
|
||||||
|
email: ${options.email}
|
||||||
|
company: ${options.company}
|
||||||
|
software name: ${options.software}
|
||||||
|
license: ${options.license}`);
|
||||||
|
const should_load = await new Confirm({
|
||||||
|
message: 'should those options be used?'
|
||||||
|
}).run().catch(DialogHandler.catch);
|
||||||
|
if (should_load)
|
||||||
|
this.options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.options = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async save_options_file(): Promise<void> {
|
private async save_options_file(): Promise<void> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user