Compare commits
3 Commits
90515c1679
...
6a525d8120
Author | SHA1 | Date | |
---|---|---|---|
6a525d8120 | |||
05d4839dea | |||
2094287af8 |
@ -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.
|
||||
* See file 'LICENSE' for full license details.
|
||||
* Created by Timo Hocker <timo@scode.ovh>, March 2020
|
||||
* Created by Timo Hocker <timo@scode.ovh>, April 2020
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
|
8
.liconfig.json
Normal file
8
.liconfig.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"has_license": true,
|
||||
"license": "BSD-3-Clause",
|
||||
"author": "Timo Hocker",
|
||||
"company": "SapphireCode",
|
||||
"email": "timo@scode.ovh",
|
||||
"software": "Snippeteer"
|
||||
}
|
7
index.js
7
index.js
@ -1,5 +1,12 @@
|
||||
#!/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';
|
||||
|
||||
// @ts-ignore
|
||||
|
@ -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.
|
||||
* See file 'LICENSE' for full license details.
|
||||
* Created by Timo Hocker <timo@scode.ovh>, March 2020
|
||||
* Created by Timo Hocker <timo@scode.ovh>, April 2020
|
||||
*/
|
||||
|
||||
/* eslint-disable no-process-exit */
|
||||
|
@ -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.
|
||||
* See file 'LICENSE' for full license details.
|
||||
* Created by Timo Hocker <timo@scode.ovh>, March 2020
|
||||
* Created by Timo Hocker <timo@scode.ovh>, April 2020
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
|
@ -1,3 +1,10 @@
|
||||
/*
|
||||
* 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 {
|
||||
start(cwd: string): Promise<void>;
|
||||
}
|
||||
|
7
lib/asset.d.ts
vendored
7
lib/asset.d.ts
vendored
@ -1,3 +1,10 @@
|
||||
/*
|
||||
* 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' {
|
||||
const content: any;
|
||||
export default content;
|
||||
|
5
lib/dialog.ts
Normal file
5
lib/dialog.ts
Normal file
@ -0,0 +1,5 @@
|
||||
class DialogHandler {
|
||||
public static catch (): void {
|
||||
process.exit ();
|
||||
}
|
||||
}
|
7
lib/enquirer.d.ts
vendored
7
lib/enquirer.d.ts
vendored
@ -1 +1,8 @@
|
||||
/*
|
||||
* 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';
|
||||
|
@ -1,3 +1,10 @@
|
||||
/*
|
||||
* 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 fs from 'fs-extra';
|
||||
import { AutoComplete } from 'enquirer';
|
||||
|
@ -1,3 +1,10 @@
|
||||
/*
|
||||
* 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';
|
||||
|
||||
export class CopyrightGenerator {
|
||||
|
@ -1,3 +1,10 @@
|
||||
/*
|
||||
* 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 {
|
||||
public has_license = false;
|
||||
public license = '';
|
||||
|
@ -1,3 +1,10 @@
|
||||
/*
|
||||
* 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 */
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
|
@ -1,3 +1,10 @@
|
||||
/*
|
||||
* 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 */
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
@ -10,68 +17,84 @@ import { FileMapper } from './file_mapper';
|
||||
import { CopyrightOptions } from './copyright_options';
|
||||
|
||||
export default class Copyright implements Snippet {
|
||||
private options: CopyrightOptions | null = null;
|
||||
private cwd: string = '';
|
||||
|
||||
async start (cwd: string): Promise<void> {
|
||||
const options = (await this.load_options_file (cwd))
|
||||
|| (await this.gather_options ());
|
||||
this.cwd = cwd;
|
||||
await this.load_options_file();
|
||||
if (!this.options)
|
||||
await this.gather_options ();
|
||||
|
||||
await FileMapper.map_all_files (
|
||||
cwd,
|
||||
Copyright.fix_file_license,
|
||||
[ options ]
|
||||
this.cwd,
|
||||
this.fix_file_license.bind(this)
|
||||
);
|
||||
|
||||
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<CopyrightOptions> {
|
||||
const options = (new CopyrightOptions);
|
||||
options.author = await new Input ({ message: 'author' })
|
||||
.run ();
|
||||
options.email = await new Input ({ message: 'email' })
|
||||
.run ();
|
||||
options.company = await new Input ({ message: 'company' })
|
||||
.run ();
|
||||
options.software = await new Input ({ message: 'software name' })
|
||||
.run ();
|
||||
options.has_license = await new Confirm ({
|
||||
private async gather_options (): Promise<void> {
|
||||
this.options = (new CopyrightOptions);
|
||||
this.options.author = await new Input ({ message: 'author' })
|
||||
.run ().catch(DialogHandler.catch);
|
||||
this.options.email = await new Input ({ message: 'email' })
|
||||
.run ().catch(DialogHandler.catch);
|
||||
this.options.company = await new Input ({ message: 'company' })
|
||||
.run ().catch(DialogHandler.catch);
|
||||
this.options.software = await new Input ({ message: 'software name' })
|
||||
.run ().catch(DialogHandler.catch);
|
||||
this.options.has_license = await new Confirm ({
|
||||
message:
|
||||
'would you like to specify a license?'
|
||||
})
|
||||
.run ();
|
||||
if (options.has_license) {
|
||||
options.license = await new AutoComplete ({
|
||||
.run ().catch(DialogHandler.catch);
|
||||
if (this.options.has_license) {
|
||||
this.options.license = await new AutoComplete ({
|
||||
name: 'license',
|
||||
message: 'choose a license',
|
||||
limit: 10,
|
||||
choices: findLicense ('')
|
||||
})
|
||||
.run ();
|
||||
.run ().catch(DialogHandler.catch);
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
private async load_options_file
|
||||
(folder: string): Promise<CopyrightOptions|null> {
|
||||
const file_path = path.join (folder, '.liconfig.json');
|
||||
private async load_options_file (): Promise<void> {
|
||||
const file_path = path.join (this.cwd, '.liconfig.json');
|
||||
this.options = null;
|
||||
|
||||
if (await fs.pathExists (file_path)) {
|
||||
return JSON.parse (
|
||||
const options = JSON.parse (
|
||||
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
|
||||
(folder: string, options: CopyrightOptions): Promise<void> {
|
||||
const file_path = path.join (folder, '.liconfig.json');
|
||||
await fs.writeFile (file_path, JSON.stringify (options, null, 2), 'utf-8');
|
||||
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');
|
||||
}
|
||||
|
||||
private static fix_file_license (
|
||||
private fix_file_license (
|
||||
data: string,
|
||||
filename: string,
|
||||
[ options ]: [CopyrightOptions]
|
||||
filename: string
|
||||
): string | null {
|
||||
const regex = /\/\*\s+\*\sCopyright[\s\S]*?\*\/\n{0,2}/gu;
|
||||
const shebang = /^#!.*?\n\n/gu;
|
||||
@ -80,7 +103,7 @@ export default class Copyright implements Snippet {
|
||||
if (!(/\.(?:js|ts|mjs)$/u).test (filename) && !regex.test (data))
|
||||
return null;
|
||||
return (shebang_line ? shebang_line[0] : '')
|
||||
+ CopyrightGenerator.get_copyright_notice (options)
|
||||
+ CopyrightGenerator.get_copyright_notice (this.options as CopyrightOptions)
|
||||
+ data.replace (regex, '')
|
||||
.replace (shebang, '');
|
||||
}
|
||||
|
@ -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.
|
||||
* See file 'LICENSE' for full license details.
|
||||
* Created by Timo Hocker <timo@scode.ovh>, March 2020
|
||||
* Created by Timo Hocker <timo@scode.ovh>, April 2020
|
||||
*/
|
||||
|
||||
/* eslint-disable no-magic-numbers */
|
||||
|
@ -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.
|
||||
* See file 'LICENSE' for full license details.
|
||||
* Created by Timo Hocker <timo@scode.ovh>, March 2020
|
||||
* Created by Timo Hocker <timo@scode.ovh>, April 2020
|
||||
*/
|
||||
|
||||
/* eslint-disable no-magic-numbers */
|
||||
|
@ -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.
|
||||
* See file 'LICENSE' for full license details.
|
||||
* Created by Timo Hocker <timo@scode.ovh>, March 2020
|
||||
* Created by Timo Hocker <timo@scode.ovh>, April 2020
|
||||
*/
|
||||
|
||||
/* eslint-disable no-sync */
|
||||
|
@ -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.
|
||||
* See file 'LICENSE' for full license details.
|
||||
* Created by Timo Hocker <timo@scode.ovh>, March 2020
|
||||
* Created by Timo Hocker <timo@scode.ovh>, April 2020
|
||||
*/
|
||||
|
||||
/* eslint-disable no-process-exit */
|
||||
|
@ -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.
|
||||
* See file 'LICENSE' for full license details.
|
||||
* Created by Timo Hocker <timo@scode.ovh>, March 2020
|
||||
* Created by Timo Hocker <timo@scode.ovh>, April 2020
|
||||
*/
|
||||
|
||||
/* eslint-disable no-sync */
|
||||
|
@ -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.
|
||||
* See file 'LICENSE' for full license details.
|
||||
* Created by Timo Hocker <timo@scode.ovh>, March 2020
|
||||
* Created by Timo Hocker <timo@scode.ovh>, April 2020
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
|
@ -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.
|
||||
* See file 'LICENSE' for full license details.
|
||||
* Created by Timo Hocker <timo@scode.ovh>, March 2020
|
||||
* Created by Timo Hocker <timo@scode.ovh>, April 2020
|
||||
*/
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user