complete other snippets
This commit is contained in:
@ -19,42 +19,48 @@ import { CopyrightOptions } from './copyright_options';
|
||||
|
||||
export default class Copyright implements Snippet {
|
||||
private options: CopyrightOptions | null = null;
|
||||
private cwd: string = '';
|
||||
private loaded_from_config: boolean = false;
|
||||
private cwd = '';
|
||||
private loaded_from_config = false;
|
||||
|
||||
async start (cwd: string): Promise<void> {
|
||||
this.cwd = cwd;
|
||||
await this.load_options_file();
|
||||
await this.load_options_file ();
|
||||
if (!this.options)
|
||||
await this.gather_options ();
|
||||
|
||||
await FileMapper.map_all_files (
|
||||
this.cwd,
|
||||
this.fix_file_license.bind(this)
|
||||
this.fix_file_license.bind (this)
|
||||
);
|
||||
|
||||
if (!this.loaded_from_config && await new Confirm({
|
||||
message: 'should those settings be saved for the next run?'
|
||||
}).run().catch(DialogHandler.catch)) {
|
||||
this.save_options_file();
|
||||
}
|
||||
if (!this.loaded_from_config && await new Confirm (
|
||||
{ message: 'should those settings be saved for the next run?' }
|
||||
)
|
||||
.run ()
|
||||
.catch (DialogHandler.catch))
|
||||
this.save_options_file ();
|
||||
}
|
||||
|
||||
private async gather_options (): Promise<void> {
|
||||
this.options = (new CopyrightOptions);
|
||||
this.options.author = await new Input ({ message: 'author' })
|
||||
.run ().catch(DialogHandler.catch);
|
||||
.run ()
|
||||
.catch (DialogHandler.catch);
|
||||
this.options.email = await new Input ({ message: 'email' })
|
||||
.run ().catch(DialogHandler.catch);
|
||||
.run ()
|
||||
.catch (DialogHandler.catch);
|
||||
this.options.company = await new Input ({ message: 'company' })
|
||||
.run ().catch(DialogHandler.catch);
|
||||
.run ()
|
||||
.catch (DialogHandler.catch);
|
||||
this.options.software = await new Input ({ message: 'software name' })
|
||||
.run ().catch(DialogHandler.catch);
|
||||
.run ()
|
||||
.catch (DialogHandler.catch);
|
||||
this.options.has_license = await new Confirm ({
|
||||
message:
|
||||
'would you like to specify a license?'
|
||||
})
|
||||
.run ().catch(DialogHandler.catch);
|
||||
.run ()
|
||||
.catch (DialogHandler.catch);
|
||||
if (this.options.has_license) {
|
||||
this.options.license = await new AutoComplete ({
|
||||
name: 'license',
|
||||
@ -62,7 +68,8 @@ export default class Copyright implements Snippet {
|
||||
limit: 10,
|
||||
choices: findLicense ('')
|
||||
})
|
||||
.run ().catch(DialogHandler.catch);
|
||||
.run ()
|
||||
.catch (DialogHandler.catch);
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,26 +81,32 @@ export default class Copyright implements Snippet {
|
||||
const options = JSON.parse (
|
||||
await fs.readFile (file_path, 'utf-8')
|
||||
);
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`author: ${options.author}
|
||||
|
||||
// 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){
|
||||
const should_load = await new Confirm (
|
||||
{ message: 'should those options be used?' }
|
||||
)
|
||||
.run ()
|
||||
.catch (DialogHandler.catch);
|
||||
if (should_load) {
|
||||
this.options = options;
|
||||
this.loaded_from_config = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async save_options_file(): Promise<void> {
|
||||
private async save_options_file (): Promise<void> {
|
||||
const file_path = path.join (this.cwd, '.liconfig.json');
|
||||
await fs.writeFile (file_path, JSON.stringify (this.options, null, 2), 'utf-8');
|
||||
await fs.writeFile (
|
||||
file_path,
|
||||
JSON.stringify (this.options, null, 2),
|
||||
'utf-8'
|
||||
);
|
||||
}
|
||||
|
||||
private fix_file_license (
|
||||
@ -107,7 +120,9 @@ license: ${options.license}`);
|
||||
if (!(/\.(?:js|ts|mjs)$/u).test (filename) && !regex.test (data))
|
||||
return null;
|
||||
return (shebang_line ? shebang_line[0] : '')
|
||||
+ CopyrightGenerator.get_copyright_notice (this.options as CopyrightOptions)
|
||||
+ CopyrightGenerator.get_copyright_notice (
|
||||
this.options as CopyrightOptions
|
||||
)
|
||||
+ data.replace (regex, '')
|
||||
.replace (shebang, '');
|
||||
}
|
||||
|
Reference in New Issue
Block a user