fix
This commit is contained in:
parent
0118737289
commit
814957e9bc
@ -1,10 +1,12 @@
|
||||
/*
|
||||
* 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.
|
||||
* Created by Timo Hocker <timo@scode.ovh>, March 2020
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* eslint-disable no-sync */
|
||||
/* eslint-disable no-console */
|
||||
/* eslint-disable no-await-in-loop */
|
||||
@ -26,14 +28,15 @@ async function map_all_files (folder, func) {
|
||||
if ([ 'node_modules' ].includes (file))
|
||||
continue;
|
||||
const abs_path = path.join (folder, file);
|
||||
if ((await fs.stat (abs_path)).isDirectory ())
|
||||
if ((await fs.stat (abs_path)).isDirectory ()) {
|
||||
map_all_files (abs_path, func);
|
||||
|
||||
const data = await fs.readFile (abs_path);
|
||||
const res = func (data);
|
||||
continue;
|
||||
}
|
||||
const data = await fs.readFile (abs_path, 'utf-8');
|
||||
const res = func (data, file);
|
||||
if (res === null)
|
||||
continue;
|
||||
await fs.writeFile (abs_path, res);
|
||||
await fs.writeFile (abs_path, res, 'utf-8');
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,11 +83,13 @@ function get_copyright_notice (license = '', software = '') {
|
||||
* @param {string} software software name
|
||||
*/
|
||||
async function fix_all_copy (folder, license = '', software = '') {
|
||||
const regex = /\/\*\s+\*\sCopyright[\s\S]*?\*\//gu;
|
||||
await map_all_files (folder, (data) => {
|
||||
if (!regex.test (data))
|
||||
const regex = /\/\*\s+\*\sCopyright[\s\S]*?\*\/\n{0,2}/gu;
|
||||
await map_all_files (folder, (data, filename) => {
|
||||
const shebang = /^#!.*?\n\n/gu;
|
||||
const shebang_line = shebang.exec(data);
|
||||
if (!/\.js$/.test(filename) && !regex.test (data))
|
||||
return null;
|
||||
return get_copyright_notice (license, software) + data.replace (regex, '');
|
||||
return (shebang_line ? shebang_line[0] : '') + get_copyright_notice (license, software) + data.replace (regex, '').replace(shebang, '');
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user