-
-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from yamadashy/chore/more-coverage
chore: refactor codes
- Loading branch information
Showing
33 changed files
with
763 additions
and
341 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
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { getVersion } from '../../core/file/packageJsonParser.js'; | ||
import { logger } from '../../shared/logger.js'; | ||
|
||
export const runVersionAction = async (): Promise<void> => { | ||
const version = await getVersion(); | ||
logger.log(version); | ||
}; |
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 was deleted.
Oops, something went wrong.
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,47 @@ | ||
import * as fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import { isBinary } from 'istextorbinary'; | ||
import jschardet from 'jschardet'; | ||
import iconv from 'iconv-lite'; | ||
import { logger } from '../../shared/logger.js'; | ||
import { RawFile } from './fileTypes.js'; | ||
|
||
export const collectFiles = async (filePaths: string[], rootDir: string): Promise<RawFile[]> => { | ||
const rawFiles: RawFile[] = []; | ||
|
||
for (const filePath of filePaths) { | ||
const fullPath = path.resolve(rootDir, filePath); | ||
const content = await readRawFile(fullPath); | ||
if (content) { | ||
rawFiles.push({ path: filePath, content }); | ||
} | ||
} | ||
|
||
return rawFiles; | ||
}; | ||
|
||
const readRawFile = async (filePath: string): Promise<string | null> => { | ||
if (isBinary(filePath)) { | ||
logger.debug(`Skipping binary file: ${filePath}`); | ||
return null; | ||
} | ||
|
||
logger.trace(`Processing file: ${filePath}`); | ||
|
||
try { | ||
const buffer = await fs.readFile(filePath); | ||
|
||
if (isBinary(null, buffer)) { | ||
logger.debug(`Skipping binary file (content check): ${filePath}`); | ||
return null; | ||
} | ||
|
||
const encoding = jschardet.detect(buffer).encoding || 'utf-8'; | ||
const content = iconv.decode(buffer, encoding); | ||
|
||
return content; | ||
} catch (error) { | ||
logger.warn(`Failed to read file: ${filePath}`, error); | ||
return null; | ||
} | ||
}; |
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,27 @@ | ||
import { RepopackConfigMerged } from '../../config/configTypes.js'; | ||
import { getFileManipulator } from './fileManipulater.js'; | ||
import { ProcessedFile, RawFile } from './fileTypes.js'; | ||
|
||
export const processFiles = (rawFiles: RawFile[], config: RepopackConfigMerged): ProcessedFile[] => { | ||
return rawFiles.map((rawFile) => ({ | ||
path: rawFile.path, | ||
content: processContent(rawFile.content, rawFile.path, config), | ||
})); | ||
}; | ||
|
||
export const processContent = (content: string, filePath: string, config: RepopackConfigMerged): string => { | ||
let processedContent = content; | ||
const manipulator = getFileManipulator(filePath); | ||
|
||
if (config.output.removeComments && manipulator) { | ||
processedContent = manipulator.removeComments(processedContent); | ||
} | ||
|
||
if (config.output.removeEmptyLines && manipulator) { | ||
processedContent = manipulator.removeEmptyLines(processedContent); | ||
} | ||
|
||
processedContent = processedContent.trim(); | ||
|
||
return processedContent; | ||
}; |
Oops, something went wrong.