Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- loadModules = (arrayOfFilePaths) ->
- new Promise (resolve) ->
- require arrayOfFilePaths, (ms...) ->
- for module in ms
- module ModuleAPI
- resolve()
- # in my library
- load = (path_to_file) ->
- (require path_to_file).do_something()
- # in my app (using the 'compiled' libary)
- cool_library.load("file_that_exists_in_my_app")
- # in my library
- load = (module) ->
- module.do_something()
- # in my app (using the 'compiled' libary)
- module = require("file_that_exists_in_my_app")
- cool_library.load(module)
- function loadInContext(filename) {
- return new Promise(function(resolve){
- require(['./'+filename], resolve);
- })
- }
- function loadModules(namesInContext){
- return Promise.all(namesInContext.map(loadInContext));
- }
- loadModules(arrayOfFiles).then(function(){
- modules.forEach(function(module){
- module(moduleAPI);
- })
- });
- // modulesConfig.js
- module.exports = [
- require(...),
- ....
- ]
- // run.js
- require('modulesConfig').forEach(function(module){
- module(moduleAPI);
- })
Add Comment
Please, Sign In to add comment