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.
|
* 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>, March 2020
|
* Created by Timo Hocker <timo@scode.ovh>, April 2020
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = {
|
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
|
#!/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
|
||||||
|
@ -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>, March 2020
|
* Created by Timo Hocker <timo@scode.ovh>, April 2020
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* eslint-disable no-process-exit */
|
/* 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.
|
* 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>, March 2020
|
* Created by Timo Hocker <timo@scode.ovh>, April 2020
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = {
|
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 {
|
export interface Snippet {
|
||||||
start(cwd: string): Promise<void>;
|
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' {
|
declare module '*.asset' {
|
||||||
const content: any;
|
const content: any;
|
||||||
export default content;
|
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';
|
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 path from 'path';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import { AutoComplete } from 'enquirer';
|
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';
|
import { CopyrightOptions } from './copyright_options';
|
||||||
|
|
||||||
export class CopyrightGenerator {
|
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 {
|
export class CopyrightOptions {
|
||||||
public has_license = false;
|
public has_license = false;
|
||||||
public license = '';
|
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 */
|
/* eslint-disable no-await-in-loop */
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs-extra';
|
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 */
|
/* eslint-disable no-await-in-loop */
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
@ -10,68 +17,84 @@ 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> {
|
||||||
const options = (await this.load_options_file (cwd))
|
this.cwd = cwd;
|
||||||
|| (await this.gather_options ());
|
await this.load_options_file();
|
||||||
|
if (!this.options)
|
||||||
|
await this.gather_options ();
|
||||||
|
|
||||||
await FileMapper.map_all_files (
|
await FileMapper.map_all_files (
|
||||||
cwd,
|
this.cwd,
|
||||||
Copyright.fix_file_license,
|
this.fix_file_license.bind(this)
|
||||||
[ 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<CopyrightOptions> {
|
private async gather_options (): Promise<void> {
|
||||||
const options = (new CopyrightOptions);
|
this.options = (new CopyrightOptions);
|
||||||
options.author = await new Input ({ message: 'author' })
|
this.options.author = await new Input ({ message: 'author' })
|
||||||
.run ();
|
.run ().catch(DialogHandler.catch);
|
||||||
options.email = await new Input ({ message: 'email' })
|
this.options.email = await new Input ({ message: 'email' })
|
||||||
.run ();
|
.run ().catch(DialogHandler.catch);
|
||||||
options.company = await new Input ({ message: 'company' })
|
this.options.company = await new Input ({ message: 'company' })
|
||||||
.run ();
|
.run ().catch(DialogHandler.catch);
|
||||||
options.software = await new Input ({ message: 'software name' })
|
this.options.software = await new Input ({ message: 'software name' })
|
||||||
.run ();
|
.run ().catch(DialogHandler.catch);
|
||||||
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);
|
||||||
if (options.has_license) {
|
if (this.options.has_license) {
|
||||||
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,
|
||||||
choices: findLicense ('')
|
choices: findLicense ('')
|
||||||
})
|
})
|
||||||
.run ();
|
.run ().catch(DialogHandler.catch);
|
||||||
}
|
}
|
||||||
|
|
||||||
return options;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async load_options_file
|
private async load_options_file (): Promise<void> {
|
||||||
(folder: string): Promise<CopyrightOptions|null> {
|
const file_path = path.join (this.cwd, '.liconfig.json');
|
||||||
const file_path = path.join (folder, '.liconfig.json');
|
this.options = null;
|
||||||
|
|
||||||
if (await fs.pathExists (file_path)) {
|
if (await fs.pathExists (file_path)) {
|
||||||
return JSON.parse (
|
const options = 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
|
private async save_options_file(): Promise<void> {
|
||||||
(folder: string, options: CopyrightOptions): Promise<void> {
|
const file_path = path.join (this.cwd, '.liconfig.json');
|
||||||
const file_path = path.join (folder, '.liconfig.json');
|
await fs.writeFile (file_path, JSON.stringify (this.options, null, 2), 'utf-8');
|
||||||
await fs.writeFile (file_path, JSON.stringify (options, null, 2), 'utf-8');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static fix_file_license (
|
private 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;
|
||||||
@ -80,7 +103,7 @@ export default class Copyright implements Snippet {
|
|||||||
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 (options)
|
+ CopyrightGenerator.get_copyright_notice (this.options as CopyrightOptions)
|
||||||
+ data.replace (regex, '')
|
+ data.replace (regex, '')
|
||||||
.replace (shebang, '');
|
.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.
|
* 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>, March 2020
|
* Created by Timo Hocker <timo@scode.ovh>, April 2020
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* eslint-disable no-magic-numbers */
|
/* 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.
|
* 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>, March 2020
|
* Created by Timo Hocker <timo@scode.ovh>, April 2020
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* eslint-disable no-magic-numbers */
|
/* 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.
|
* 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>, March 2020
|
* Created by Timo Hocker <timo@scode.ovh>, April 2020
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* eslint-disable no-sync */
|
/* 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.
|
* 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>, March 2020
|
* Created by Timo Hocker <timo@scode.ovh>, April 2020
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* eslint-disable no-process-exit */
|
/* 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.
|
* 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>, March 2020
|
* Created by Timo Hocker <timo@scode.ovh>, April 2020
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* eslint-disable no-sync */
|
/* 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.
|
* 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>, March 2020
|
* Created by Timo Hocker <timo@scode.ovh>, April 2020
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = {
|
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.
|
* 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>, March 2020
|
* Created by Timo Hocker <timo@scode.ovh>, April 2020
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user