-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a2bd37
commit f2c3e4e
Showing
10 changed files
with
63 additions
and
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
dist: precise | ||
sudo: required | ||
language: node_js | ||
services: mongodb | ||
cache: | ||
|
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
declare let GlobalModulesIndexer: (context: string, dirName: string) => Promise<object>; | ||
declare let GlobalModulesIndexer: (context: string, dirName: string) => object; | ||
export default GlobalModulesIndexer; |
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
declare const _default: { | ||
hasReqParams: (path: string) => boolean; | ||
reqParamsOptions: (path: string) => any; | ||
requireMyTsFile: (path: string) => Function; | ||
requireMyTsFile: (fileName: string, filePath: string) => Function; | ||
}; | ||
export default _default; |
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 |
---|---|---|
@@ -1,63 +1,41 @@ | ||
import fs = require('fs'); | ||
import path = require('path'); | ||
import Utils from '../utils/utils'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import Utils from '../utils/utils'; | ||
|
||
let utils = Utils; | ||
let fileQueue: Array<string> = []; | ||
let dirQueue: Array<string> = []; | ||
|
||
let getPathList = (inputDir: string): Promise<any> => { | ||
return new Promise<any>((resolve, reject) => { | ||
fs.readdir(inputDir, (err, content) => { | ||
if (err) reject(err); | ||
resolve(content.map((item) => path.resolve(inputDir, item))); | ||
}) | ||
let modulesIndex: object = {}; | ||
|
||
let startRecursiveCheck = (filePath: string): void => { | ||
fs.readdir(filePath, (err, content) => { | ||
if (err) throw new Error(err.message); | ||
else content.forEach(e => { | ||
let name = e.replace(/.(j|t)s/, ''); | ||
modulesIndex[name] = {}; | ||
|
||
fs.stat(filePath + '/' + e, (err, result) => { | ||
result.isFile() ? modulesIndex[name] = utils.requireMyTsFile(e, filePath) : nextChecks(name, filePath + '/' + e); | ||
}); | ||
}); | ||
}) | ||
} | ||
|
||
let getStat = (path: string): Promise<any> => { | ||
return new Promise<any>((resolve, reject) => { | ||
fs.stat(path, (err, result) => { | ||
if (err) reject(err); | ||
resolve(result.isFile() ? fileQueue.push(path) : dirQueue.push(path)) | ||
}) | ||
let nextChecks = (name: string, filePath: string): void => { | ||
fs.readdir(filePath, (err, content) => { | ||
if (err) throw new Error(err.message); | ||
else content.forEach(e => { | ||
fs.stat(filePath + '/' + e, (err, result) => { | ||
result.isFile() ? modulesIndex[name] = utils.requireMyTsFile(e, filePath) : nextChecks(name, filePath + '/' + e); | ||
}); | ||
}); | ||
}) | ||
} | ||
|
||
let getAllStat = (pathList: Array<string>): Promise<any> => { | ||
return Promise.all(pathList.map(path => getStat(path))); | ||
} | ||
|
||
let processItemList = (): Promise<any> | Array<string> => { | ||
// if queue, process next item recursive | ||
while (dirQueue.length > 0) return readDir(dirQueue.shift()); | ||
|
||
return fileQueue; | ||
} | ||
|
||
let StartIt = (inputDir): Promise<any> => { | ||
return readDir(inputDir); | ||
} | ||
|
||
let readDir = (inputDir): Promise<any> => { | ||
return getPathList(inputDir) | ||
.then(getAllStat) | ||
.then(processItemList) | ||
} | ||
|
||
let setUpModules = (fileList): object => { | ||
let modulesIndex2 = {} | ||
fileList.forEach(e => { | ||
let name = e.split('\\').pop().replace(/.(j|t)s/, ''); | ||
modulesIndex2[name] = utils.requireMyTsFile(e); | ||
}) | ||
return modulesIndex2 | ||
} | ||
|
||
let GlobalModulesIndexer = (context: string, dirName: string): Promise<object> => { | ||
let GlobalModulesIndexer = (context: string, dirName: string): object => { | ||
let absolutePath = path.join(context, dirName); | ||
|
||
return StartIt(absolutePath).then(setUpModules) | ||
startRecursiveCheck(absolutePath); | ||
|
||
return modulesIndex; | ||
} | ||
|
||
export default GlobalModulesIndexer; |
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
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