Skip to content

Commit 57d6ee0

Browse files
author
Ives van Hoorne
committed
Types
1 parent 9bc9305 commit 57d6ee0

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/sandbox/utils/resolve-module.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// @flow
2-
import type { Module } from '../../app/store/entities/modules/';
3-
import type { Directory } from '../../app/store/entities/directories/';
2+
import type { Module, Directory } from 'common/types';
43

54
const compareTitle = (original: string, test: string) => {
65
if (original === test) return true;
@@ -16,7 +15,7 @@ export default (
1615
path: string,
1716
modules: Array<Module>,
1817
directories: Array<Directory>,
19-
startdirectoryShortid: ?string = undefined,
18+
startdirectoryShortid: ?string = undefined
2019
) => {
2120
// Split path
2221
const splitPath = path.replace(/^.\//, '').split('/');
@@ -36,46 +35,46 @@ export default (
3635
// For == check on null
3736
// eslint-disable-next-line eqeqeq
3837
const directoriesInDirectory = directories.filter(
39-
m => m.directoryShortid == dirId,
38+
m => m.directoryShortid == dirId
4039
);
4140
const nextDirectory = directoriesInDirectory.find(d =>
42-
compareTitle(d.title, pathPart),
41+
compareTitle(d.title, pathPart)
4342
);
4443

4544
if (nextDirectory == null)
4645
throw new Error(`Cannot find module in ${path}`);
4746

4847
return nextDirectory.id;
4948
},
50-
startdirectoryShortid,
49+
startdirectoryShortid
5150
);
5251

5352
const lastPath = splitPath[splitPath.length - 1];
5453
// eslint-disable-next-line eqeqeq
5554
const modulesInFoundDirectory = modules.filter(
56-
m => m.directoryShortid == founddirectoryShortid,
55+
m => m.directoryShortid == founddirectoryShortid
5756
);
5857

5958
// Find module with same name
6059
const foundModule = modulesInFoundDirectory.find(m =>
61-
compareTitle(m.title, lastPath),
60+
compareTitle(m.title, lastPath)
6261
);
6362
if (foundModule) return foundModule;
6463

6564
// eslint-disable-next-line eqeqeq
6665
const directoriesInFoundDirectory = directories.filter(
67-
m => m.directoryShortid == founddirectoryShortid,
66+
m => m.directoryShortid == founddirectoryShortid
6867
);
6968
const foundDirectory = directoriesInFoundDirectory.find(m =>
70-
compareTitle(m.title, lastPath),
69+
compareTitle(m.title, lastPath)
7170
);
7271

7372
if (foundDirectory) {
7473
// eslint-disable-next-line eqeqeq
7574
const indexModule = modules.find(
7675
m =>
7776
m.directoryShortid == foundDirectory.id &&
78-
compareTitle(m.title, 'index'),
77+
compareTitle(m.title, 'index')
7978
);
8079
if (indexModule == null) throw new Error(`Cannot find module in ${path}`);
8180
return indexModule;
@@ -84,7 +83,7 @@ export default (
8483
if (splitPath[splitPath.length - 1] === '') {
8584
// Last resort, check if there is something in the same folder called index
8685
const indexModule = modulesInFoundDirectory.find(m =>
87-
compareTitle(m.title, 'index'),
86+
compareTitle(m.title, 'index')
8887
);
8988
if (indexModule) return indexModule;
9089
}

0 commit comments

Comments
 (0)