mirror of
https://github.com/github/codeql-action.git
synced 2025-12-30 03:00:13 +08:00
27 lines
751 B
TypeScript
27 lines
751 B
TypeScript
import slash from 'slash2';
|
|
import fs from 'fs-extra';
|
|
|
|
import { LocDir, LocResult } from './directory';
|
|
import { LocFile } from './file';
|
|
|
|
export { LocDir, LocDirOptions } from './directory';
|
|
export { LocFile, LineInfo } from './file';
|
|
|
|
const loc = async (fileOrDir: string): Promise<LocResult> => {
|
|
const stat = await fs.stat(slash(fileOrDir));
|
|
if (stat.isFile()) {
|
|
const locFile = new LocFile(slash(fileOrDir));
|
|
const info = await locFile.getFileInfo();
|
|
const filePath = locFile.path;
|
|
return {
|
|
info: info.lines,
|
|
files: [filePath],
|
|
languages: { [info.languages]: { ...info.lines, sum: 1 } },
|
|
};
|
|
}
|
|
const locDir = new LocDir({ cwd: slash(fileOrDir) });
|
|
return locDir.loadInfo();
|
|
};
|
|
|
|
export default loc;
|