{"id":17749459,"url":"https://github.com/oresoftware/requirejs-metagen","last_synced_at":"2025-03-15T01:31:44.442Z","repository":{"id":65489151,"uuid":"42085892","full_name":"ORESoftware/requirejs-metagen","owner":"ORESoftware","description":"Groups AMD dependencies as desired.","archived":false,"fork":false,"pushed_at":"2016-09-28T17:59:37.000Z","size":26,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-02T11:46:40.664Z","etag":null,"topics":["amd","amd-is-the-best","amd-modules","requirejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ORESoftware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-08T02:41:38.000Z","updated_at":"2024-08-05T21:32:47.000Z","dependencies_parsed_at":"2023-01-25T16:55:11.849Z","dependency_job_id":null,"html_url":"https://github.com/ORESoftware/requirejs-metagen","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ORESoftware%2Frequirejs-metagen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ORESoftware%2Frequirejs-metagen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ORESoftware%2Frequirejs-metagen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ORESoftware%2Frequirejs-metagen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ORESoftware","download_url":"https://codeload.github.com/ORESoftware/requirejs-metagen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243671216,"owners_count":20328584,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["amd","amd-is-the-best","amd-modules","requirejs"],"created_at":"2024-10-26T11:23:24.450Z","updated_at":"2025-03-15T01:31:44.049Z","avatar_url":"https://github.com/ORESoftware.png","language":"JavaScript","readme":"\nNote:\nThis project has been superceded by the following project which is more generic:\nhttps://github.com/smartprocure/directory-metagen\n\nYou can read about this effort by reading this issue:\nhttps://github.com/ORESoftware/requirejs-metagen/issues/1\n\n\n# requirejs-metagen\n\nGenerate requirejs modules that represent dependencies in entire directories, useful for grouping controllers, views, etc.\nPlease note that the paradigm espoused by this system goes against bundling for production. So using this methodology is not highly recommended. IMO the ideal way to build production-grade apps with RequireJS is create separate bundles for separate parent views. You load all the shared code on first page load. Then you load new code in the browser on demand for each new parent view, as the user switches views in the app.\n\nYou can read about that methodology here:\nPete Hunt @OSCON - https://www.youtube.com/watch?v=VkTCL6Nqm6Y\n\n\n\n# how to use\n\n\nWe might have something like this on our front-end, most likely in a router module:\n\n```js\n   controllerRoute: function (controllerName, actionName, id) {\n              \n         require([\"app/js/controllers/all/\" + controllerName], function (cntr) {\n                  \n                    if (typeof cntr[actionName] === 'function') {\n                        cntr[actionName](id);\n                    }\n                    else {\n                        cntr['default'](id);\n                    }\n                    \n                });\n       }\n```\n\n//so in order to require all those controllers, especially for use with r.js (the optimizer), we can do:\n\n```js\nvar grm = require('requirejs-metagen'); \n\nvar controllerOpts =  {\n        inputFolder: './public/static/app/js/controllers/all',\n        appendThisToDependencies: 'app/js/controllers/',\n        appendThisToReturnedItems: '',\n        eliminateSharedFolder: true,     //will drop 'all' from the front of all return items\n        output: './public/static/app/js/meta/allControllers.js' //puts all controllers in a directory its subdirectories into one RequireJS file/module\n    };\n    \n    \ngrm(controllerOpts, function (err) {\n     //handle any unlikely errors your way\n  });\n```\n  \n----\u003e  output looks like this module below:\n\n\n```js\n//app/js/meta//allControllers.js\n\ndefine(\n    [\n        \"app/js/controllers/all/jobs\",\n\t\t\"app/js/controllers/all/more/cars\",\n\t\t\"app/js/controllers/all/more/evenMore/spaceships\",\n\t\t\"app/js/controllers/all/users\"\n    ],\n    function(){\n\n        return {\n\n            \"jobs\": arguments[0],\n\t\t\t\"more/cars\": arguments[1],\n\t\t\t\"more/evenMore/spaceships\": arguments[2],\n\t\t\t\"users\": arguments[3]\n        }\n  });\n  ```\n  \n  in your front-end program I recommend doing this:\n  \n```js\n  requirejs.config({\n \n   paths: {\n   \n      \"#allControllers\":\"app/js/meta/allControllers\"\n   \n      }\n  });\n```\n  \n  then you can do:\n  \n```js\n  require(['#allControllers'],function(allControllers){\n  \n      var carController = allControllers['more/cars'];\n  \n  });\n```\n\nor better yet, since those dependences are already loaded, you can use synchronous syntax easily\n\n\n```js\nvar allControllers = require('#allControllers');\nvar carController = allControllers['more/cars'];\n```\n\n## usage with Gulp.js:\n\nto use this library with Gulp, you can do it like so:\n\n```js\nvar metagens = {\n\n    \"controllers\": {\n        inputFolder: './public/static/app/js/controllers/all',\n        appendThisToDependencies: 'app/js/controllers/',\n        appendThisToReturnedItems: '',\n        eliminateSharedFolder: true,\n        output: './public/static/app/js/meta/allControllers.js'\n    },\n    \"templates\": {\n        inputFolder: './public/static/app/templates',\n        appendThisToDependencies: 'text!app/',\n        appendThisToReturnedItems: '',\n        eliminateSharedFolder: false,\n        output: './public/static/app/js/meta/allTemplates.js'\n    },\n    \"css\": {\n        inputFolder: './public/static/cssx',\n        appendThisToDependencies: 'text!',\n        appendThisToReturnedItems: '',\n        eliminateSharedFolder: false,\n        output: './public/static/app/js/meta/allCSS.js'\n    },\n    \"flux-constants\": {\n        inputFolder: './public/static/app/js/flux/constants',\n        appendThisToDependencies: 'app/js/flux/',\n        appendThisToReturnedItems: '',\n        eliminateSharedFolder: false,\n        output: './public/static/app/js/meta/allFluxConstants.js'\n    },\n    \"flux-actions\": {\n        inputFolder: './public/static/app/js/flux/actions',\n        appendThisToDependencies: 'app/js/flux/',\n        appendThisToReturnedItems: '',\n        eliminateSharedFolder: false,\n        output: './public/static/app/js/meta/allFluxActions.js'\n    },\n    \"all-views\": {\n        inputFolder: './public/static/app/js/jsx',\n        appendThisToDependencies: 'app/js/',\n        appendThisToReturnedItems: '',\n        eliminateSharedFolder: true,\n        output: './public/static/app/js/meta/allViews.js'\n    }\n }\n\n\ngulp.task('metagen:all', ['transpile-jsx'], function (done) { // we may need to transpile JSX or whatnot before running the metagen\n\n    var taskNames = Object.keys(metagens);\n    var funcs = [];\n\n    taskNames.forEach(function (name, index) {\n        funcs.push(function (cb) {\n            grm(metagens[name], function (err) {\n                cb(err);\n            });\n        });\n    });\n\n    async.parallel(funcs, function (err) {\n        done(err);\n    });\n});\n```\n\nany questions you can open an issue on Github or email me at alex@oresoftware.com, thanks\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foresoftware%2Frequirejs-metagen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foresoftware%2Frequirejs-metagen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foresoftware%2Frequirejs-metagen/lists"}