├── .gitignore ├── .npmignore ├── CHANGELOG.md ├── package.json ├── README.md ├── LICENSE └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 0.1.0 2 | 3 | * Initial release 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "broccoli-concat-filenames", 3 | "description": "Concatenates (transformed) filenames into a file", 4 | "version": "0.1.1", 5 | "main": "index.js", 6 | "license": "MIT", 7 | "repository": "https://github.com/pangratz/broccoli-concat-filenames", 8 | "author": "Clemens Müller", 9 | "dependencies": { 10 | "broccoli-writer": "^0.1.1", 11 | "broccoli-kitchen-sink-helpers": "^0.2.0", 12 | "mkdirp": "^0.3.5" 13 | }, 14 | "keywords": [ 15 | "broccoli-plugin", 16 | "concatenate", 17 | "filenames" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # broccoli-concat-filenames 2 | 3 | Concatenate filenames into a single file. 4 | 5 | ## Usage 6 | 7 | ```js 8 | var concatFilenames = require('broccoli-concat-filenames'); 9 | 10 | var testsMain = concatFilenames(sourceTree, { 11 | inputFiles: ['tests/**/*_test.js'], 12 | outputFile: '/tests_main.js', 13 | transform: function(fileName, fileNameWithExtension) { 14 | var out = []; 15 | out.push("// require module " + fileNameWithExtension); 16 | out.push("require('" + fileName + "');"); 17 | out.push("\n"); 18 | return out.join("\n"); 19 | } 20 | }); 21 | ``` 22 | 23 | For a directory with the structure 24 | 25 | ``` 26 | - tests/ 27 | - utils_test.js 28 | - controllers/ 29 | - index_test.js 30 | - list_test.js 31 | ``` 32 | 33 | this creates a file at `/tests_main.js` with the content 34 | 35 | ```js 36 | // require module tests/utils_test.js 37 | require("tests/utils_test"); 38 | 39 | // require module tests/controllers/index_test.js 40 | require("tests/controllers/index_test"); 41 | 42 | // require module tests/controllers/list_test.js 43 | require("tests/controllers/list_test"); 44 | ``` 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Clemens Müller 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs') 2 | var path = require('path') 3 | var mkdirp = require('mkdirp') 4 | var helpers = require('broccoli-kitchen-sink-helpers') 5 | var Writer = require('broccoli-writer') 6 | 7 | module.exports = ConcatFilenames 8 | 9 | ConcatFilenames.prototype = Object.create(Writer.prototype) 10 | ConcatFilenames.prototype.constructor = ConcatFilenames 11 | function ConcatFilenames(inputTree, options) { 12 | if (!(this instanceof ConcatFilenames)) return new ConcatFilenames(inputTree, options) 13 | this.inputTree = inputTree 14 | this.inputFiles = options.inputFiles; 15 | this.outputFile = options.outputFile; 16 | this.transform = options.transform; 17 | } 18 | 19 | ConcatFilenames.prototype.write = function (readTree, destDir) { 20 | var self = this 21 | return readTree(this.inputTree).then(function (srcDir) { 22 | var output = [] 23 | 24 | var inputFiles = helpers.multiGlob(self.inputFiles, { cwd: srcDir }) 25 | for (i = 0; i < inputFiles.length; i++) { 26 | var fileName = inputFiles[i]; 27 | var bareFileName = fileName; 28 | var lastDotIndex = fileName.lastIndexOf("."); 29 | if (lastDotIndex !== -1) { 30 | bareFileName = fileName.slice(0, lastDotIndex); 31 | } 32 | 33 | output.push(self.transform(bareFileName, fileName)); 34 | } 35 | 36 | helpers.assertAbsolutePaths([self.outputFile]) 37 | mkdirp.sync(path.join(destDir, path.dirname(self.outputFile))) 38 | fs.writeFileSync(path.join(destDir, self.outputFile), output.join("\n")) 39 | }); 40 | } 41 | --------------------------------------------------------------------------------