-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: defactoring deps usage analizer
- Loading branch information
1 parent
36a6ca7
commit 86fa2a9
Showing
9 changed files
with
305 additions
and
238 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const { getPackageInfo, getProjectFiles, getComponentUsagesInFiles } = require('../utils'); | ||
|
||
/** | ||
* Analyzes a project by retrieving package information, project files, and component usages. | ||
* @param {string} dir - The path to the project directory. | ||
* @param {Object} [options={}] - Additional options for fetching package information. | ||
* @returns {Object} - An object containing information about the analyzed project, | ||
* including package details, component usages, and Paragon version associated with each usage. | ||
*/ | ||
function analyzeProject(dir, options = {}) { | ||
const packageInfo = getPackageInfo(dir, options); | ||
const files = getProjectFiles(dir); | ||
const usages = getComponentUsagesInFiles(files, dir); | ||
|
||
// Add Paragon version to each component usage | ||
Object.keys(usages).forEach(componentName => { | ||
usages[componentName].usages = usages[componentName].map(usage => ({ | ||
...usage, | ||
version: packageInfo.version, | ||
})); | ||
}); | ||
|
||
return { ...packageInfo, usages }; | ||
} | ||
|
||
module.exports = { analyzeProject }; |
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,33 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const glob = require('glob'); | ||
|
||
/** | ||
* Finds projects that include Paragon as a dependency. | ||
* @param {string} dir - The path to the directory to search for projects. | ||
* @returns {Array.<string>} - An array of directory paths containing projects with Paragon as a dependency. | ||
*/ | ||
function findProjectsToAnalyze(dir) { | ||
// Find all directories containing a package.json file. | ||
const packageJSONFiles = glob.sync(`${dir}/**/package.json`, { ignore: [`${dir}/**/node_modules/**`] }); | ||
|
||
// If paragon isn't included in the package.json file then skip analyzing it | ||
const packageJSONFilesWithParagon = packageJSONFiles.filter(packageJSONFile => { | ||
const { dependencies, peerDependencies } = JSON.parse(fs.readFileSync(packageJSONFile, { encoding: 'utf-8' })); | ||
|
||
const hasDependency = (depsObject, orgs) => { | ||
return orgs.some(org => depsObject && depsObject[`${org}/paragon`] !== undefined); | ||
}; | ||
|
||
const hasDirectDependency = hasDependency(dependencies, ['@edx', '@openedx']); | ||
const hasPeerDependency = hasDependency(peerDependencies, ['@edx', '@openedx']); | ||
|
||
return hasDirectDependency || hasPeerDependency; | ||
}); | ||
|
||
console.log(packageJSONFilesWithParagon) | ||
|
||
return packageJSONFilesWithParagon.map(packageJSONFile => path.dirname(packageJSONFile)); | ||
} | ||
|
||
module.exports = { findProjectsToAnalyze }; |
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,4 @@ | ||
const { analyzeProject } = require('./analyzeProject'); | ||
const { findProjectsToAnalyze } = require('./findProjectsToAnalyze'); | ||
|
||
module.exports = { analyzeProject, findProjectsToAnalyze }; |
Oops, something went wrong.