Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #86 from mauricerkelly/improve-support-for-umbrell…
Browse files Browse the repository at this point in the history
…a-projects

Account for umbrella projects when determining project path
  • Loading branch information
mauricerkelly authored Apr 17, 2017
2 parents f16b3e5 + 9252557 commit 532516e
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ const findElixirProjectPath = async (editorPath) => {
const editorDir = dirname(editorPath);
const mixexsPath = find(editorDir, 'mix.exs');
if (mixexsPath !== null) {
const pathArray = mixexsPath.split(sep);
if (pathArray.length > 3 && pathArray[pathArray.length - 3] === 'apps') {
// Treat this as an umbrella app. This may be wrong -
// If you happen to keep your code in a directory called 'apps'
pathArray.splice((pathArray.length - 3), 3);
const umbrellaProjectPath = pathArray.join(sep);

// Safety check by looking for a `mix.exs` file in the same directory as
// 'apps'. If it exists, then it's likely an umbrella project
if (existsSync(join(umbrellaProjectPath, 'mix.exs'))) {
return umbrellaProjectPath;
}
}
return dirname(mixexsPath);
}
const projPath = atom.project.relativizePath(editorPath)[0];
Expand All @@ -55,10 +68,19 @@ const isMixProject = async (filePath) => {
return existsSync(join(project, 'mix.exs'));
};

const isUmbrellaProject = async (filePath) => {
const project = await elixirProjectPath(filePath);
return existsSync(join(project, 'apps'));
};

const isTestFile = async (filePath) => {
const project = await elixirProjectPath(filePath);
const relativePath = relative(project, filePath);
// Is the first directory of the relative path "test"?
if (isUmbrellaProject(filePath)) {
// Is the structure "apps/app_name/test/..."
return relativePath.split(sep)[2] === 'test';
}
// Is the structure "test/..."
return relativePath.split(sep)[0] === 'test';
};

Expand Down

0 comments on commit 532516e

Please sign in to comment.