-
Notifications
You must be signed in to change notification settings - Fork 14
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
7 changed files
with
294 additions
and
265 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 |
---|---|---|
|
@@ -13,4 +13,4 @@ insert_final_newline = true | |
trim_trailing_whitespace = false | ||
|
||
[Makefile] | ||
indent_style = tab | ||
indent_style = tab |
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,80 +1,81 @@ | ||
import * as path from 'path'; | ||
import { DependencyTreeData } from './dependencyTreeData'; | ||
import * as dependencyTree from 'dependency-tree'; | ||
import { analysesFile } from '../fileAnalysis/javascript/javascriptAnalysis'; | ||
|
||
import { | ||
statusMsgGetFolderPath, | ||
statusMsgGetPackageJsonPath, | ||
statusMsgGetEntryFile, | ||
statusMsgGetDependencyData, | ||
statusMsgGetDependencyProcessData | ||
statusMsgGetFolderPath, | ||
statusMsgGetPackageJsonPath, | ||
statusMsgGetEntryFile, | ||
statusMsgGetDependencyData, | ||
statusMsgGetDependencyProcessData | ||
} from '../utils/message/messages'; | ||
|
||
import { | ||
getPackageJsonPath, | ||
getMainFilePath, | ||
getDependencyTree, | ||
processTreeData, | ||
getCurrentFolderPath | ||
getPackageJsonPath, | ||
getMainFilePath, | ||
getDependencyTree, | ||
processTreeData, | ||
getCurrentFolderPath | ||
} from './dependencyTreeMethods'; | ||
|
||
import { getEntryFilePath } from '../utils/config'; | ||
import { getEntryFileRelativePath } from '../utils/config'; | ||
import { onError } from '../utils/error/onError'; | ||
import { | ||
NO_DEPENDENCY, | ||
NO_FOLDER, | ||
NO_PACKAGE_JSON, | ||
NO_MAIN_FILE, | ||
GET_DEPENDENCY_TREE_FAIL | ||
NO_DEPENDENCY, | ||
NO_FOLDER, | ||
NO_PACKAGE_JSON, | ||
NO_MAIN_FILE, | ||
GET_DEPENDENCY_TREE_FAIL | ||
} from '../utils/error/errorKey'; | ||
|
||
import { pathExists } from '../utils/utils'; | ||
|
||
export const getDependencyTreeData = (postMessage?: boolean): DependencyTreeData | undefined => { | ||
// find folder Path catch path sendStatus | ||
const folderPath = getCurrentFolderPath(); | ||
if (!folderPath || !pathExists(folderPath)) { | ||
onError(NO_FOLDER); | ||
postMessage ? statusMsgGetFolderPath.postError() : null; | ||
return undefined; | ||
} | ||
postMessage ? statusMsgGetFolderPath.postSuccess() : null; | ||
// find folder Path catch path sendStatus | ||
const folderPath = getCurrentFolderPath(); | ||
if (!folderPath || !pathExists(folderPath)) { | ||
onError(NO_FOLDER); | ||
postMessage ? statusMsgGetFolderPath.postError() : null; | ||
return undefined; | ||
} | ||
postMessage ? statusMsgGetFolderPath.postSuccess() : null; | ||
|
||
// find cached path sendStatus | ||
let mainFilePath = getEntryFilePath(); | ||
if (mainFilePath === undefined) { | ||
// find package.json and main file | ||
const packageJsonPath = getPackageJsonPath(folderPath); | ||
if (!packageJsonPath) { | ||
onError(NO_PACKAGE_JSON); | ||
postMessage ? statusMsgGetPackageJsonPath.postError() : null; | ||
return undefined; | ||
} | ||
postMessage ? statusMsgGetPackageJsonPath.postSuccess() : null; | ||
mainFilePath = getMainFilePath(folderPath, packageJsonPath); | ||
} | ||
if (!mainFilePath || !pathExists(mainFilePath)) { | ||
onError(NO_MAIN_FILE); | ||
postMessage ? statusMsgGetEntryFile.postError() : null; | ||
return undefined; | ||
} | ||
postMessage ? statusMsgGetEntryFile.postSuccess() : null; | ||
// find cached path sendStatus | ||
let mainFilePath = getEntryFileRelativePath(); | ||
if (mainFilePath === undefined) { | ||
// find package.json and main file | ||
const packageJsonPath = getPackageJsonPath(folderPath); | ||
if (!packageJsonPath) { | ||
onError(NO_PACKAGE_JSON); | ||
postMessage ? statusMsgGetPackageJsonPath.postError() : null; | ||
return undefined; | ||
} | ||
postMessage ? statusMsgGetPackageJsonPath.postSuccess() : null; | ||
mainFilePath = getMainFilePath(folderPath, packageJsonPath); | ||
} | ||
if (!mainFilePath || !pathExists(path.join(folderPath, mainFilePath))) { | ||
onError(NO_MAIN_FILE); | ||
postMessage ? statusMsgGetEntryFile.postError() : null; | ||
return undefined; | ||
} | ||
postMessage ? statusMsgGetEntryFile.postSuccess() : null; | ||
|
||
const { dependencyTree: processedTreeData, dependencyHash } = analysesFile(mainFilePath, folderPath); | ||
// const dependencyTreeData = getDependencyTree(mainFilePath, folderPath); | ||
// if (!dependencyTreeData || !Object.keys(dependencyTreeData as dependencyTree.DependencyObj).length) { | ||
// onError(GET_DEPENDENCY_TREE_FAIL); | ||
// postMessage ? statusMsgGetDependencyData.postError() : null; | ||
// return undefined; | ||
// } | ||
// postMessage ? statusMsgGetDependencyData.postSuccess() : null; | ||
const { dependencyTree: processedTreeData, dependencyHash } = analysesFile(path.join(folderPath, mainFilePath), folderPath); | ||
// const dependencyTreeData = getDependencyTree(mainFilePath, folderPath); | ||
// if (!dependencyTreeData || !Object.keys(dependencyTreeData as dependencyTree.DependencyObj).length) { | ||
// onError(GET_DEPENDENCY_TREE_FAIL); | ||
// postMessage ? statusMsgGetDependencyData.postError() : null; | ||
// return undefined; | ||
// } | ||
// postMessage ? statusMsgGetDependencyData.postSuccess() : null; | ||
|
||
// const processedTreeData = processTreeData(dependencyTreeData as dependencyTree.DependencyObj, folderPath); | ||
if (!processedTreeData) { | ||
onError(NO_DEPENDENCY); | ||
postMessage ? statusMsgGetDependencyProcessData.postError() : null; | ||
} | ||
postMessage ? statusMsgGetDependencyProcessData.postSuccess() : null; | ||
// const processedTreeData = processTreeData(dependencyTreeData as dependencyTree.DependencyObj, folderPath); | ||
if (!processedTreeData) { | ||
onError(NO_DEPENDENCY); | ||
postMessage ? statusMsgGetDependencyProcessData.postError() : null; | ||
} | ||
postMessage ? statusMsgGetDependencyProcessData.postSuccess() : null; | ||
|
||
return processedTreeData; | ||
return processedTreeData; | ||
}; |
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
Oops, something went wrong.