-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
184 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
shamefully-hoist = true | ||
|
||
registry = https://mirrors.tencent.com/npm/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,70 @@ | ||
import { readFile } from 'node:fs/promises'; | ||
import { extname, join } from 'node:path'; | ||
|
||
import { globby } from 'globby'; | ||
import { logger } from './utils.mjs'; | ||
|
||
import { ignore as defaultIgnore } from '@bring-it/utils'; | ||
const LINE_NUMBERS = 3025; | ||
|
||
import { logger } from './utils.mjs'; | ||
class Store extends Map { | ||
constructor() { | ||
super([ | ||
['prologue', []], | ||
['patterns', []], | ||
['epilogue', []], | ||
]); | ||
} | ||
|
||
const lineBreak = /(\r\n|\n|\r)+/; | ||
const lineBreakAll = /^(\r\n|\n|\r)+$/; | ||
toLists() { | ||
return [ | ||
...this.get('prologue'), | ||
...this.get('patterns'), | ||
...this.get('epilogue'), | ||
].flat(); | ||
} | ||
|
||
function read(file, config) { | ||
return readFile(join(config.cwd, file), 'utf8'); | ||
length() { | ||
return ( | ||
this.get('prologue').length + | ||
this.get('patterns').length + | ||
this.get('epilogue').length | ||
); | ||
} | ||
} | ||
|
||
const LINE_NUMBERS = 3050; | ||
const lineBreak = /(\r\n|\n|\r)+/; | ||
|
||
function readLine(file) { | ||
return readFile(file.path, 'utf8').then((code) => | ||
code.split(lineBreak).filter((line) => line.trim() !== ''), | ||
); | ||
} | ||
|
||
export async function picker(lists, config) { | ||
const io = []; | ||
async function mapper(io, key, lists) { | ||
const patterns = lists[key]; | ||
|
||
for (const file of lists) { | ||
if (io.length < LINE_NUMBERS) { | ||
await read(file, config) | ||
.then((code) => | ||
code | ||
.split(lineBreak) | ||
.filter((line) => !lineBreakAll.test(line)) | ||
.filter((line) => !/\s*\/\//.test(line)), | ||
) | ||
for (const file of patterns) { | ||
if (LINE_NUMBERS > io.length()) { | ||
await readLine(file) | ||
.then((lines) => { | ||
io.push(...lines); | ||
logger.okay(file); | ||
io.get(key).push(...lines.slice(0, LINE_NUMBERS - io.length())); | ||
|
||
logger.okay(file.name); | ||
}) | ||
.catch((error) => { | ||
logger.fail(file); | ||
logger.fail(file.name); | ||
throw error; | ||
}); | ||
} else { | ||
break; | ||
} | ||
} | ||
|
||
return io.join('\n').trim(); | ||
} | ||
|
||
export function scan(config) { | ||
return globby(config.pattern, { | ||
cwd: config.cwd, | ||
ignore: [ | ||
...defaultIgnore, | ||
...config.ignore, | ||
'**/.best-shot/**', | ||
'**/.bring-it/**', | ||
'**/.github/**', | ||
'**/dist/**', | ||
'**/License', | ||
'**/License.*', | ||
'**/*.md', | ||
'**/.{gitattributes,gitignore,gitkeep}', | ||
'**/.editorconfig', | ||
'**/.npmrc', | ||
'**/*.env.*', | ||
'**/*.env', | ||
'**/pnpm-lock.yaml', | ||
'**/yarn.lock', | ||
'**/package-lock.json', | ||
], | ||
gitignore: true, | ||
onlyFiles: true, | ||
dot: true, | ||
caseSensitiveMatch: false, | ||
}) | ||
.then((list) => | ||
config.extensions.length > 0 | ||
? list.filter((item) => | ||
config.extensions.includes(extname(item).replace(/^\./, '')), | ||
) | ||
: list, | ||
) | ||
.then((list) => { | ||
if (list.length === 0) { | ||
throw new Error('Not match anything'); | ||
} | ||
export async function picker(lists) { | ||
const io = new Store(); | ||
|
||
return list; | ||
}) | ||
.then((list) => list.sort()) | ||
.then((list) => { | ||
for (const item of list) { | ||
logger.file(item); | ||
} | ||
await mapper(io, 'prologue', lists); | ||
await mapper(io, 'epilogue', lists); | ||
await mapper(io, 'patterns', lists); | ||
|
||
return list; | ||
}); | ||
return io.toLists().join('\n').trim(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { extname, join } from 'node:path'; | ||
|
||
import { globby } from 'globby'; | ||
|
||
import { ignore as defaultIgnore } from '@bring-it/utils'; | ||
|
||
import { logger } from './utils.mjs'; | ||
|
||
const ignore = [ | ||
...defaultIgnore, | ||
'**/.{gitattributes,gitkeep}', | ||
'**/.*ignore', | ||
'**/.best-shot/**', | ||
'**/.bring-it/**', | ||
'**/.editorconfig', | ||
'**/.github/**', | ||
'**/.npmrc', | ||
'**/*.env.*', | ||
'**/*.env', | ||
'**/dist/**', | ||
'**/License.*', | ||
'**/License', | ||
'**/package-lock.json', | ||
'**/pnpm-lock.yaml', | ||
'**/yarn.lock', | ||
]; | ||
|
||
function find(key, config) { | ||
const patterns = config[key]; | ||
|
||
return patterns.length > 0 | ||
? globby(patterns, { | ||
cwd: config.cwd, | ||
ignore: [...ignore, ...config.ignore], | ||
gitignore: true, | ||
onlyFiles: true, | ||
dot: true, | ||
caseSensitiveMatch: false, | ||
}) | ||
.then((list) => | ||
config.extensions.length > 0 | ||
? list.filter((item) => config.extensions.includes(extname(item))) | ||
: list, | ||
) | ||
.then((list) => list.sort()) | ||
.then((list) => { | ||
for (const item of list) { | ||
logger.log(`[${key}]`, item); | ||
} | ||
|
||
return list; | ||
}) | ||
: []; | ||
} | ||
|
||
export async function scaner(config) { | ||
const prologue = await find('prologue', config); | ||
const epilogue = await find('epilogue', config); | ||
const patterns = await find('patterns', config) // | ||
.then((list) => | ||
list.filter( | ||
(item) => !prologue.includes(item) && !epilogue.includes(item), | ||
), | ||
); | ||
|
||
function wrapper(list) { | ||
return list.map((name) => ({ | ||
name, | ||
path: join(config.cwd, name), | ||
})); | ||
} | ||
|
||
return { | ||
prologue: wrapper(prologue), | ||
epilogue: wrapper(epilogue), | ||
patterns: wrapper(patterns), | ||
}; | ||
} |
Oops, something went wrong.