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

Commit 532516e

Browse files
Merge pull request #86 from mauricerkelly/improve-support-for-umbrella-projects
Account for umbrella projects when determining project path
2 parents f16b3e5 + 9252557 commit 532516e

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

lib/init.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ const findElixirProjectPath = async (editorPath) => {
3131
const editorDir = dirname(editorPath);
3232
const mixexsPath = find(editorDir, 'mix.exs');
3333
if (mixexsPath !== null) {
34+
const pathArray = mixexsPath.split(sep);
35+
if (pathArray.length > 3 && pathArray[pathArray.length - 3] === 'apps') {
36+
// Treat this as an umbrella app. This may be wrong -
37+
// If you happen to keep your code in a directory called 'apps'
38+
pathArray.splice((pathArray.length - 3), 3);
39+
const umbrellaProjectPath = pathArray.join(sep);
40+
41+
// Safety check by looking for a `mix.exs` file in the same directory as
42+
// 'apps'. If it exists, then it's likely an umbrella project
43+
if (existsSync(join(umbrellaProjectPath, 'mix.exs'))) {
44+
return umbrellaProjectPath;
45+
}
46+
}
3447
return dirname(mixexsPath);
3548
}
3649
const projPath = atom.project.relativizePath(editorPath)[0];
@@ -55,10 +68,19 @@ const isMixProject = async (filePath) => {
5568
return existsSync(join(project, 'mix.exs'));
5669
};
5770

71+
const isUmbrellaProject = async (filePath) => {
72+
const project = await elixirProjectPath(filePath);
73+
return existsSync(join(project, 'apps'));
74+
};
75+
5876
const isTestFile = async (filePath) => {
5977
const project = await elixirProjectPath(filePath);
6078
const relativePath = relative(project, filePath);
61-
// Is the first directory of the relative path "test"?
79+
if (isUmbrellaProject(filePath)) {
80+
// Is the structure "apps/app_name/test/..."
81+
return relativePath.split(sep)[2] === 'test';
82+
}
83+
// Is the structure "test/..."
6284
return relativePath.split(sep)[0] === 'test';
6385
};
6486

0 commit comments

Comments
 (0)