Skip to content

Commit

Permalink
fix: windows empty files
Browse files Browse the repository at this point in the history
  • Loading branch information
fyangstudio committed Aug 6, 2021
1 parent b561b06 commit c571f33
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
4 changes: 4 additions & 0 deletions extensions/doctor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log


# 1.1.5

- fix: windows get empty files
# 1.1.4

- fix: codemod 100 score show result
Expand Down
2 changes: 1 addition & 1 deletion extensions/doctor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Doctor",
"description": "A free security and quality audit tool for modern DevOps teams",
"publisher": "iceworks-team",
"version": "1.1.4",
"version": "1.1.5",
"engines": {
"vscode": "^1.41.0"
},
Expand Down
4 changes: 4 additions & 0 deletions packages/doctor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# changelog

## 0.2.3

- Fix Windows get empty files

## 0.2.2

- Feat update @appworks/codemod.
Expand Down
2 changes: 1 addition & 1 deletion packages/doctor/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@appworks/doctor",
"description": "Analyse and running codemods over react/rax projects, troubleshooting and automatically fixing errors",
"version": "0.2.2",
"version": "0.2.3",
"keywords": [
"doctor",
"analysis",
Expand Down
15 changes: 9 additions & 6 deletions packages/doctor/src/getFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ const MAX_CHECK_LOC = 3000;
// Get ignore config from file
const IGNORE_CONFIG_FILES = ['.gitignore'];

function getFileInfo(filePath: string): IFileInfo {
let source = fs.readFileSync(filePath).toString().trim();
function getFileInfo(filePath: string, directory?: string): IFileInfo {
const file = directory ? path.join(directory, filePath) : filePath;

let source = fs.readFileSync(file).toString().trim();

// if begins with shebang
if (source[0] === '#' && source[1] === '!') {
source = `//${source}`;
}

return {
path: filePath,
path: file,
source,
LoC: (source.match(/\n/g) || '').length + 1,
};
Expand All @@ -28,6 +30,7 @@ function getFileInfo(filePath: string): IFileInfo {
export default function getFiles(directory: string, ignoreDirs?: string[]): IFileInfo[] {
const options: any = {
nodir: true,
cwd: directory,
};

if (!fs.existsSync(directory)) {
Expand All @@ -43,7 +46,7 @@ export default function getFiles(directory: string, ignoreDirs?: string[]): IFil
}

if (ignoreDirs) {
options.ignore = ignoreDirs.map((ignoreDir) => `${directory}/**/${ignoreDir}/**`);
options.ignore = ignoreDirs.map((ignoreDir) => `**/${ignoreDir}/**`);
}

IGNORE_CONFIG_FILES.forEach((ignoreConfigFile) => {
Expand All @@ -54,8 +57,8 @@ export default function getFiles(directory: string, ignoreDirs?: string[]): IFil
});

// https://www.npmjs.com/package/glob
return glob.sync(`${directory}/**/*`, options)
.map(getFileInfo)
return glob.sync('**/*', options)
.map((file) => getFileInfo(file, directory))
.filter((file) => {
// https://www.npmjs.com/package/ignore
// Use .ignore file to filter glob result. Same as https://www.npmjs.com/package/glob-gitignore
Expand Down
3 changes: 2 additions & 1 deletion packages/doctor/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as path from 'path';
import getFiles from './getFiles';
import Analyzer from './Analyzer';
import Scanner from './Scanner';
Expand Down Expand Up @@ -27,7 +28,7 @@ class Doctor {
}

scan(directory: string, options?: IScanOptions): Promise<IScannerReports> {
return this.scanner.scan(directory, options);
return this.scanner.scan(path.isAbsolute(directory) ? directory : path.join(process.cwd(), directory), options);
}

analyse(directory: string) {
Expand Down

0 comments on commit c571f33

Please sign in to comment.