Compare commits

..

No commits in common. "6a525d81201c333e3800b90b9acda1596f14c087" and "90515c1679d3ed51711a9be11b197d344bd6088e" have entirely different histories.

21 changed files with 56 additions and 148 deletions

View File

@ -1,8 +1,8 @@
/* /*
* Copyright (C) SapphireCode - All Rights Reserved * Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause. * This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details. * See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, April 2020 * Created by Timo Hocker <timo@scode.ovh>, March 2020
*/ */
module.exports = { module.exports = {

View File

@ -1,8 +0,0 @@
{
"has_license": true,
"license": "BSD-3-Clause",
"author": "Timo Hocker",
"company": "SapphireCode",
"email": "timo@scode.ovh",
"software": "Snippeteer"
}

View File

@ -1,12 +1,5 @@
#!/usr/bin/env node #!/usr/bin/env node
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, April 2020
*/
'use strict'; 'use strict';
// @ts-ignore // @ts-ignore

View File

@ -1,8 +1,8 @@
/* /*
* Copyright (C) SapphireCode - All Rights Reserved * Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause. * This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details. * See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, April 2020 * Created by Timo Hocker <timo@scode.ovh>, March 2020
*/ */
/* eslint-disable no-process-exit */ /* eslint-disable no-process-exit */

View File

@ -1,8 +1,8 @@
/* /*
* Copyright (C) SapphireCode - All Rights Reserved * Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause. * This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details. * See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, April 2020 * Created by Timo Hocker <timo@scode.ovh>, March 2020
*/ */
module.exports = { module.exports = {

View File

@ -1,10 +1,3 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, April 2020
*/
export interface Snippet { export interface Snippet {
start(cwd: string): Promise<void>; start(cwd: string): Promise<void>;
} }

7
lib/asset.d.ts vendored
View File

@ -1,10 +1,3 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, April 2020
*/
declare module '*.asset' { declare module '*.asset' {
const content: any; const content: any;
export default content; export default content;

View File

@ -1,5 +0,0 @@
class DialogHandler {
public static catch (): void {
process.exit ();
}
}

7
lib/enquirer.d.ts vendored
View File

@ -1,8 +1 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, April 2020
*/
declare module 'enquirer'; declare module 'enquirer';

View File

@ -1,10 +1,3 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, April 2020
*/
import path from 'path'; import path from 'path';
import fs from 'fs-extra'; import fs from 'fs-extra';
import { AutoComplete } from 'enquirer'; import { AutoComplete } from 'enquirer';

View File

@ -1,10 +1,3 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, April 2020
*/
import { CopyrightOptions } from './copyright_options'; import { CopyrightOptions } from './copyright_options';
export class CopyrightGenerator { export class CopyrightGenerator {

View File

@ -1,10 +1,3 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, April 2020
*/
export class CopyrightOptions { export class CopyrightOptions {
public has_license = false; public has_license = false;
public license = ''; public license = '';

View File

@ -1,10 +1,3 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, April 2020
*/
/* eslint-disable no-await-in-loop */ /* eslint-disable no-await-in-loop */
import path from 'path'; import path from 'path';
import fs from 'fs-extra'; import fs from 'fs-extra';

View File

@ -1,10 +1,3 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, April 2020
*/
/* eslint-disable no-await-in-loop */ /* eslint-disable no-await-in-loop */
import path from 'path'; import path from 'path';
import fs from 'fs-extra'; import fs from 'fs-extra';
@ -17,84 +10,68 @@ 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 cwd: string = '';
async start (cwd: string): Promise<void> { async start (cwd: string): Promise<void> {
this.cwd = cwd; const options = (await this.load_options_file (cwd))
await this.load_options_file(); || (await this.gather_options ());
if (!this.options)
await this.gather_options ();
await FileMapper.map_all_files ( await FileMapper.map_all_files (
this.cwd, cwd,
this.fix_file_license.bind(this) Copyright.fix_file_license,
[ options ]
); );
if (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> { private async gather_options (): Promise<CopyrightOptions> {
this.options = (new CopyrightOptions); const options = (new CopyrightOptions);
this.options.author = await new Input ({ message: 'author' }) options.author = await new Input ({ message: 'author' })
.run ().catch(DialogHandler.catch); .run ();
this.options.email = await new Input ({ message: 'email' }) options.email = await new Input ({ message: 'email' })
.run ().catch(DialogHandler.catch); .run ();
this.options.company = await new Input ({ message: 'company' }) options.company = await new Input ({ message: 'company' })
.run ().catch(DialogHandler.catch); .run ();
this.options.software = await new Input ({ message: 'software name' }) options.software = await new Input ({ message: 'software name' })
.run ().catch(DialogHandler.catch); .run ();
this.options.has_license = await new Confirm ({ options.has_license = await new Confirm ({
message: message:
'would you like to specify a license?' 'would you like to specify a license?'
}) })
.run ().catch(DialogHandler.catch); .run ();
if (this.options.has_license) { if (options.has_license) {
this.options.license = await new AutoComplete ({ options.license = await new AutoComplete ({
name: 'license', name: 'license',
message: 'choose a license', message: 'choose a license',
limit: 10, limit: 10,
choices: findLicense ('') choices: findLicense ('')
}) })
.run ().catch(DialogHandler.catch); .run ();
} }
return options;
} }
private async load_options_file (): Promise<void> { private async load_options_file
const file_path = path.join (this.cwd, '.liconfig.json'); (folder: string): Promise<CopyrightOptions|null> {
this.options = null; const file_path = path.join (folder, '.liconfig.json');
if (await fs.pathExists (file_path)) { if (await fs.pathExists (file_path)) {
const options = JSON.parse ( return 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;
} }
return null;
} }
private async save_options_file(): Promise<void> { private async save_options_file
const file_path = path.join (this.cwd, '.liconfig.json'); (folder: string, options: CopyrightOptions): Promise<void> {
await fs.writeFile (file_path, JSON.stringify (this.options, null, 2), 'utf-8'); const file_path = path.join (folder, '.liconfig.json');
await fs.writeFile (file_path, JSON.stringify (options, null, 2), 'utf-8');
} }
private fix_file_license ( private static fix_file_license (
data: string, data: string,
filename: string filename: string,
[ options ]: [CopyrightOptions]
): string | null { ): string | null {
const regex = /\/\*\s+\*\sCopyright[\s\S]*?\*\/\n{0,2}/gu; const regex = /\/\*\s+\*\sCopyright[\s\S]*?\*\/\n{0,2}/gu;
const shebang = /^#!.*?\n\n/gu; const shebang = /^#!.*?\n\n/gu;
@ -103,7 +80,7 @@ license: ${options.license}`);
if (!(/\.(?:js|ts|mjs)$/u).test (filename) && !regex.test (data)) if (!(/\.(?:js|ts|mjs)$/u).test (filename) && !regex.test (data))
return null; return null;
return (shebang_line ? shebang_line[0] : '') return (shebang_line ? shebang_line[0] : '')
+ CopyrightGenerator.get_copyright_notice (this.options as CopyrightOptions) + CopyrightGenerator.get_copyright_notice (options)
+ data.replace (regex, '') + data.replace (regex, '')
.replace (shebang, ''); .replace (shebang, '');
} }

View File

@ -1,8 +1,8 @@
/* /*
* Copyright (C) SapphireCode - All Rights Reserved * Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause. * This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details. * See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, April 2020 * Created by Timo Hocker <timo@scode.ovh>, March 2020
*/ */
/* eslint-disable no-magic-numbers */ /* eslint-disable no-magic-numbers */

View File

@ -1,8 +1,8 @@
/* /*
* Copyright (C) SapphireCode - All Rights Reserved * Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause. * This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details. * See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, April 2020 * Created by Timo Hocker <timo@scode.ovh>, March 2020
*/ */
/* eslint-disable no-magic-numbers */ /* eslint-disable no-magic-numbers */

View File

@ -1,8 +1,8 @@
/* /*
* Copyright (C) SapphireCode - All Rights Reserved * Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause. * This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details. * See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, April 2020 * Created by Timo Hocker <timo@scode.ovh>, March 2020
*/ */
/* eslint-disable no-sync */ /* eslint-disable no-sync */

View File

@ -1,8 +1,8 @@
/* /*
* Copyright (C) SapphireCode - All Rights Reserved * Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause. * This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details. * See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, April 2020 * Created by Timo Hocker <timo@scode.ovh>, March 2020
*/ */
/* eslint-disable no-process-exit */ /* eslint-disable no-process-exit */

View File

@ -1,8 +1,8 @@
/* /*
* Copyright (C) SapphireCode - All Rights Reserved * Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause. * This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details. * See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, April 2020 * Created by Timo Hocker <timo@scode.ovh>, March 2020
*/ */
/* eslint-disable no-sync */ /* eslint-disable no-sync */

View File

@ -1,8 +1,8 @@
/* /*
* Copyright (C) SapphireCode - All Rights Reserved * Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause. * This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details. * See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, April 2020 * Created by Timo Hocker <timo@scode.ovh>, March 2020
*/ */
module.exports = { module.exports = {

View File

@ -1,7 +1,7 @@
/* /*
* Copyright (C) SapphireCode - All Rights Reserved * Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause. * This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details. * See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, April 2020 * Created by Timo Hocker <timo@scode.ovh>, March 2020
*/ */