diff --git a/extensions/doctor/CHANGELOG.md b/extensions/doctor/CHANGELOG.md index 9c62abb0f..a2f57ef90 100644 --- a/extensions/doctor/CHANGELOG.md +++ b/extensions/doctor/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log + +# 1.1.5 + +- fix: windows get empty files # 1.1.4 - fix: codemod 100 score show result diff --git a/extensions/doctor/package.json b/extensions/doctor/package.json index 663ac5cf4..b926768ab 100644 --- a/extensions/doctor/package.json +++ b/extensions/doctor/package.json @@ -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" }, diff --git a/packages/doctor/CHANGELOG.md b/packages/doctor/CHANGELOG.md index 8add7e0bb..2fa84a034 100644 --- a/packages/doctor/CHANGELOG.md +++ b/packages/doctor/CHANGELOG.md @@ -1,5 +1,9 @@ # changelog +## 0.2.3 + +- Fix Windows get empty files + ## 0.2.2 - Feat update @appworks/codemod. diff --git a/packages/doctor/package.json b/packages/doctor/package.json index 1809e603b..5b30d6379 100644 --- a/packages/doctor/package.json +++ b/packages/doctor/package.json @@ -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", diff --git a/packages/doctor/src/getFiles.ts b/packages/doctor/src/getFiles.ts index 095e399b1..6991339ea 100644 --- a/packages/doctor/src/getFiles.ts +++ b/packages/doctor/src/getFiles.ts @@ -10,8 +10,10 @@ 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] === '!') { @@ -19,7 +21,7 @@ function getFileInfo(filePath: string): IFileInfo { } return { - path: filePath, + path: file, source, LoC: (source.match(/\n/g) || '').length + 1, }; @@ -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)) { @@ -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) => { @@ -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 diff --git a/packages/doctor/src/index.ts b/packages/doctor/src/index.ts index 452d742a2..9d31a0d31 100644 --- a/packages/doctor/src/index.ts +++ b/packages/doctor/src/index.ts @@ -1,3 +1,4 @@ +import * as path from 'path'; import getFiles from './getFiles'; import Analyzer from './Analyzer'; import Scanner from './Scanner'; @@ -27,7 +28,7 @@ class Doctor { } scan(directory: string, options?: IScanOptions): Promise { - return this.scanner.scan(directory, options); + return this.scanner.scan(path.isAbsolute(directory) ? directory : path.join(process.cwd(), directory), options); } analyse(directory: string) {