Skip to content

Commit

Permalink
Merge branch 'master' into amarzavery-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Schulte authored Nov 12, 2018
2 parents 6a07b5f + 9358628 commit f04888b
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions .scripts/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ export function resolvePath(...paths: string[]): string {
return path.resolve(...paths).split("\\").join("/");
}

function exists(path: string): boolean {
function exists(path: string | undefined): boolean {
if (!path) {
return false;
}

return fs.existsSync(path);
}

Expand Down Expand Up @@ -109,13 +113,33 @@ function getPackageJsonFilePath(packageFolder: string): string {
return resolvePath(packageFolder, "package.json");
}

function getPackageNameFromPackageJson(packageJsonFilePath: string): string {
const packageJson: { name: string } = getPackageJson(packageJsonFilePath);
return packageJson.name;
}

/**
* Get the absolute path to the local clone of the repository with the provided name.
* @param {string} repoName The name of the repository.
* @returns {string} The absolute path to the local clone of the repository.
*/
export function getLocalRepositoryPath(repoName: string): string {
return resolvePath(getThisRepositoryFolderPath(), "..", repoName);
export function getLocalRepositoryPath(repoName: string): string | undefined {
const repositoriesRoot: string = resolvePath(getThisRepositoryFolderPath(), "..");
const repositoryPaths: string[] = fs.readdirSync(repositoriesRoot).map(childDir => resolvePath(repositoriesRoot, childDir));

for (const repositoryPath of repositoryPaths) {
const packageJsonPath = getPackageJsonFilePath(repositoryPath);
if (!fs.existsSync(packageJsonPath)) {
continue;
}

const packageName = getPackageNameFromPackageJson(packageJsonPath);
if (packageName === repoName) {
return repositoryPath;
}
}

return undefined;
}

/**
Expand Down Expand Up @@ -158,7 +182,11 @@ function getClonedRepositories(dependencies?: { [packageName: string]: string })
* @returns {void}
*/
export function runLocalRepositoryNPMScript(repoName: string, scriptName: string): void {
const repoFolderPath: string = getLocalRepositoryPath(repoName);
const repoFolderPath: string | undefined = getLocalRepositoryPath(repoName);
if (!repoFolderPath) {
return;
}

const packageJsonFilePath: string = getPackageJsonFilePath(repoFolderPath);
const packageJson: any = getPackageJson(packageJsonFilePath);
const repoScripts: any = packageJson.scripts;
Expand Down

0 comments on commit f04888b

Please sign in to comment.