fix
This commit is contained in:
parent
9663fc3579
commit
0d1b3aac2e
@ -19,20 +19,20 @@ import { FileMapper } from './file_mapper';
|
|||||||
import { CopyrightOptions } from './copyright_options';
|
import { CopyrightOptions } from './copyright_options';
|
||||||
|
|
||||||
export default class Copyright implements Snippet {
|
export default class Copyright implements Snippet {
|
||||||
private options: CopyrightOptions | null = null;
|
private _options: CopyrightOptions | null = null;
|
||||||
private cwd = '';
|
private _cwd = '';
|
||||||
private loaded_from_config = false;
|
private _loaded_from_config = false;
|
||||||
|
|
||||||
async start (cwd: string): Promise<void> {
|
async start (cwd: string): Promise<void> {
|
||||||
this.cwd = cwd;
|
this._cwd = cwd;
|
||||||
await this.load_options_file ();
|
await this.load_options_file ();
|
||||||
if (!this.options)
|
if (!this._options)
|
||||||
await this.gather_options ();
|
await this.gather_options ();
|
||||||
|
|
||||||
const options = this.options as CopyrightOptions;
|
const options = this._options as CopyrightOptions;
|
||||||
|
|
||||||
await FileMapper.map_all_files (
|
await FileMapper.map_all_files (
|
||||||
this.cwd,
|
this._cwd,
|
||||||
this.fix_file_license.bind (this)
|
this.fix_file_license.bind (this)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ export default class Copyright implements Snippet {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.loaded_from_config && await new Confirm (
|
if (!this._loaded_from_config && 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 ()
|
||||||
@ -64,27 +64,27 @@ 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);
|
.catch (DialogHandler.catch);
|
||||||
this.options.email = await new Input ({ message: 'email' })
|
this._options.email = await new Input ({ message: 'email' })
|
||||||
.run ()
|
.run ()
|
||||||
.catch (DialogHandler.catch);
|
.catch (DialogHandler.catch);
|
||||||
this.options.company = await new Input ({ message: 'company' })
|
this._options.company = await new Input ({ message: 'company' })
|
||||||
.run ()
|
.run ()
|
||||||
.catch (DialogHandler.catch);
|
.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);
|
.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);
|
.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',
|
||||||
message: 'choose a license',
|
message: 'choose a license',
|
||||||
limit: 10,
|
limit: 10,
|
||||||
@ -96,8 +96,8 @@ export default class Copyright implements Snippet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
this._options = null;
|
||||||
|
|
||||||
if (await fs.pathExists (file_path)) {
|
if (await fs.pathExists (file_path)) {
|
||||||
const options = JSON.parse (
|
const options = JSON.parse (
|
||||||
@ -116,17 +116,17 @@ license: ${options.license}`);
|
|||||||
.run ()
|
.run ()
|
||||||
.catch (DialogHandler.catch);
|
.catch (DialogHandler.catch);
|
||||||
if (should_load) {
|
if (should_load) {
|
||||||
this.options = options;
|
this._options = options;
|
||||||
this.loaded_from_config = true;
|
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');
|
const file_path = path.join (this._cwd, '.liconfig.json');
|
||||||
await fs.writeFile (
|
await fs.writeFile (
|
||||||
file_path,
|
file_path,
|
||||||
JSON.stringify (this.options, null, 2),
|
JSON.stringify (this._options, null, 2),
|
||||||
'utf-8'
|
'utf-8'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -143,7 +143,7 @@ license: ${options.license}`);
|
|||||||
return null;
|
return null;
|
||||||
return (shebang_line ? shebang_line[0] : '')
|
return (shebang_line ? shebang_line[0] : '')
|
||||||
+ CopyrightGenerator.get_copyright_notice (
|
+ CopyrightGenerator.get_copyright_notice (
|
||||||
this.options as CopyrightOptions
|
this._options as CopyrightOptions
|
||||||
)
|
)
|
||||||
+ data.replace (regex, '')
|
+ data.replace (regex, '')
|
||||||
.replace (shebang, '');
|
.replace (shebang, '');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user