From b69e6a36c3d6db7623bf34bd0a319996a1266c01 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Sun, 26 Apr 2020 11:57:42 +0200 Subject: [PATCH] license in file + package json --- lib/snippets/copyright/index.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/snippets/copyright/index.ts b/lib/snippets/copyright/index.ts index d902ac5..4e19a68 100644 --- a/lib/snippets/copyright/index.ts +++ b/lib/snippets/copyright/index.ts @@ -10,9 +10,10 @@ import path from 'path'; import fs from 'fs-extra'; import { Confirm, Input, AutoComplete } from 'enquirer'; // eslint-disable-next-line id-match -import { findLicense } from 'license'; +import { findLicense, getLicense } from 'license'; import { Snippet } from '../../Snippet'; import { DialogHandler } from '../../dialog'; +import { modify_json } from '../../Helper'; import { CopyrightGenerator } from './copyright_generator'; import { FileMapper } from './file_mapper'; import { CopyrightOptions } from './copyright_options'; @@ -33,6 +34,24 @@ export default class Copyright implements Snippet { this.fix_file_license.bind (this) ); + modify_json ((json) => { + json.author = `${this.options.author} <${this.options.email}>`; + json.license = this.options.has_license + ? this.options.license + : 'UNLICENSED'; + }); + + if (this.options.has_license) { + await fs.writeFile ( + path.join (cwd, 'LICENSE'), + getLicense (this.options.license, { + name: this.options.author, + email: this.options.email, + project: this.options.software + }) + ); + } + if (!this.loaded_from_config && await new Confirm ( { message: 'should those settings be saved for the next run?' } )