diff --git a/lib/config.js b/lib/config.js index 3ec682d..dc51962 100644 --- a/lib/config.js +++ b/lib/config.js @@ -23,6 +23,7 @@ exports.defaults = function() { strategy: "packageRoot", forceLatest: true, exclude: [], + unknownMainFullCopy: false, overridesArrays: {}, overridesObjects: {}, mainOverrides: {}, @@ -33,7 +34,7 @@ exports.defaults = function() { }; exports.placeholder = function() { - return "\t\n\n # bower: # Configuration for bower module\n # watch: true # Whether or not to watch the bower.json file to automatically\n # kick off a bower install when it changes.\n # bowerDir:\n # path: \".mimosa/bower/bower_components\" # The location mimosa-bower places temporary\n # bower assets.\n # clean: true # whether or not to remove temporary bower assets after install\n\n # copy: # configuration for the copying of assets from bower temp\n # directories into the project\n # enabled: true # whether or not to copy the assets out of the bowerDir.path\n # into the project vendor location\n # trackChanges: true # When set to true, mimosa-bower will keep track of your\n # bower.json and mimosa-config \"bower\" configuration and kick\n # off installs based on changes. When set to false, bower's\n # default checking is used. This is based on the contents of\n # bowerDir.path. If bowerDir.clean is true, and trackChanges is\n # false, mimosa-bower will not perform installs during \"watch\"\n # and \"build\" because installs would occur every time mimosa\n # starts up.\n # outRoot: null # A string path to append to the vendor directory before\n # copying in assets. All copied assets would go inside this\n # directory. Example: \"bower-managed\". null means no outRoot\n # is applied.\n # exclude:[] # An array of string paths or regexes. Files to exclude from\n # copying. Paths should be relative to the bowerdir.path or\n # absolute.\n # mainOverrides: {} # Occasionally bower packages do not clearly indicate what file\n # is the main library file. In those cases, mimosa cannot find\n # the main files to copy them to the vendor directory. json2 is\n # a good example. mainOverrides allows for setting which files\n # should be copied for a package. The key for this object is\n # the name of the package. The value is an array of path\n # strings representing the package's main files. The paths\n # should be relative to the root of the package. For example:\n # {\"json2\":[\"json2.js\",\"json_parse.js\"]}. The paths can also\n # be to directories. That will include all the directory's\n # files. mainOverrides packages can also be provided an object\n # in addition to string paths. The object maps input paths to\n # output paths and allow for specific placement of files and\n # folders. Ex {\"json2\":{\"json2.js\":\"json-utils/json2.js\"}. In\n # this case the \"json2.js\" file will be placed in\n # \"json-utils/json2.js\" in the vendor.javascripts folder.\n # strategy: \"packageRoot\" # The copying strategy. \"vendorRoot\" places all files at the\n # root of the vendor directory. \"packageRoot\" places the files\n # in the vendor directory in a folder named for that package.\n # \"none\" will copy the assets into the vendor directory without\n # modification. strategy can also be an object with keys that\n # match the names of packages and values of strategy types.\n # When using a strategy object, the key of \"*\" provides a\n # default strategy. If only 2 of 10 packages are specified\n # the rest get the \"*\" strategy. If no \"*\" is provided,\n # \"packageRoot\" is the assumed default.\n # forceLatest: true # If you are running into a problem where dependency versions\n # are clashing, use forceLatest to make it so the latest\n # version is loaded. For instance, you might have jquery 2.0.0\n # as a package, but something else depends on 1.8.1.\n # pathMod: [] # pathMod can be an array of strings or a regex. It is used to\n # strip full pieces of a path from the output file when the\n # selected strategy is \"none\". If a bower package script is in\n # \"packageName/lib/js/foo.js\" and \"pathMod\" is set to\n # ['js', 'lib'] the output path would have \"lib\" and \"js\"\n # stripped. Feel free to suggest additions to this based on\n # your experience!\n"; + return "\t\n\n # bower: # Configuration for bower module\n # watch: true # Whether or not to watch the bower.json file to automatically\n # kick off a bower install when it changes.\n # bowerDir:\n # path: \".mimosa/bower/bower_components\" # The location mimosa-bower places temporary\n # bower assets.\n # clean: true # whether or not to remove temporary bower assets after install\n\n # copy: # configuration for the copying of assets from bower temp\n # directories into the project\n # enabled: true # whether or not to copy the assets out of the bowerDir.path\n # into the project vendor location\n # trackChanges: true # When set to true, mimosa-bower will keep track of your\n # bower.json and mimosa-config \"bower\" configuration and kick\n # off installs based on changes. When set to false, bower's\n # default checking is used. This is based on the contents of\n # bowerDir.path. If bowerDir.clean is true, and trackChanges is\n # false, mimosa-bower will not perform installs during \"watch\"\n # and \"build\" because installs would occur every time mimosa\n # starts up.\n # outRoot: null # A string path to append to the vendor directory before\n # copying in assets. All copied assets would go inside this\n # directory. Example: \"bower-managed\". null means no outRoot\n # is applied.\n # exclude:[] # An array of string paths or regexes. Files to exclude from\n # copying. Paths should be relative to the bowerdir.path or\n # absolute.\n # unknownMainFullCopy: false # When set to true, any bower package that does not have main\n # files configured in its bower.json will have its entire\n # folder contents copied in.\n # mainOverrides: {} # Occasionally bower packages do not clearly indicate what file\n # is the main library file. In those cases, mimosa cannot find\n # the main files to copy them to the vendor directory. json2 is\n # a good example. mainOverrides allows for setting which files\n # should be copied for a package. The key for this object is\n # the name of the package. The value is an array of path\n # strings representing the package's main files. The paths\n # should be relative to the root of the package. For example:\n # {\"json2\":[\"json2.js\",\"json_parse.js\"]}. The paths can also\n # be to directories. That will include all the directory's\n # files. mainOverrides packages can also be provided an object\n # in addition to string paths. The object maps input paths to\n # output paths and allow for specific placement of files and\n # folders. Ex {\"json2\":{\"json2.js\":\"json-utils/json2.js\"}. In\n # this case the \"json2.js\" file will be placed in\n # \"json-utils/json2.js\" in the vendor.javascripts folder.\n # strategy: \"packageRoot\" # The copying strategy. \"vendorRoot\" places all files at the\n # root of the vendor directory. \"packageRoot\" places the files\n # in the vendor directory in a folder named for that package.\n # \"none\" will copy the assets into the vendor directory without\n # modification. strategy can also be an object with keys that\n # match the names of packages and values of strategy types.\n # When using a strategy object, the key of \"*\" provides a\n # default strategy. If only 2 of 10 packages are specified\n # the rest get the \"*\" strategy. If no \"*\" is provided,\n # \"packageRoot\" is the assumed default.\n # forceLatest: true # If you are running into a problem where dependency versions\n # are clashing, use forceLatest to make it so the latest\n # version is loaded. For instance, you might have jquery 2.0.0\n # as a package, but something else depends on 1.8.1.\n # pathMod: [] # pathMod can be an array of strings or a regex. It is used to\n # strip full pieces of a path from the output file when the\n # selected strategy is \"none\". If a bower package script is in\n # \"packageName/lib/js/foo.js\" and \"pathMod\" is set to\n # ['js', 'lib'] the output path would have \"lib\" and \"js\"\n # stripped. Feel free to suggest additions to this based on\n # your experience!\n"; }; strategyVal = function(errors, strat) { @@ -61,6 +62,7 @@ exports.validate = function(config, validators) { validators.ifExistsIsBoolean(errors, "bower.copy.enabled", b.copy.enabled); validators.ifExistsIsBoolean(errors, "bower.copy.trackChanges", b.copy.trackChanges); validators.ifExistsIsBoolean(errors, "bower.copy.forceLatest", b.copy.forceLatest); + validators.ifExistsIsBoolean(errors, "bower.copy.unknownMainFullCopy", b.copy.unknownMainFullCopy); if (b.copy.outRoot === null) { b.copy.outRoot = ''; } else if (typeof b.copy.outRoot !== "string") { diff --git a/lib/utils.js b/lib/utils.js index dbc08cb..1cec991 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -94,7 +94,13 @@ _resolvePaths = function(mimosaConfig, names, paths) { */ } else { - logger.warn("Cannot determine main file for [[ " + lib + " ]] at [[ " + aPath + " ]]. Consider adding a mainOverrides entry."); + if (mimosaConfig.bower.copy.unknownMainFullCopy) { + logger.warn("Cannot determine main file for [[ " + lib + " ]] at [[ " + aPath + " ]]. Copying entire folder because unknownMainFullCopy is set to true. Consider adding a mainOverrides entry."); + mimosaConfig.bower.copy.strategy[lib] = 'none'; + _processOverridesList(mimosaConfig, [''], fullLibPath, resolvedPaths[lib]); + } else { + logger.warn("Cannot determine main file for [[ " + lib + " ]] at [[ " + aPath + " ]]. Consider adding a mainOverrides entry or setting unknownMainFullCopy to true."); + } } } } else { diff --git a/package.json b/package.json index ab94abf..ef9b70d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "mimosa-bower", - "version": "1.2.0", - "homepage": "http://mimosa.io", + "version": "1.3.0", + "homepage": "http://www.mimosa.io", "author": "David Bashford", "description": "A Bower integration module for Mimosa", "contributors": [ @@ -27,7 +27,7 @@ "wrench": "1.5.1", "lodash": "1.3.1", "bower": "1.2.6", - "chokidar": "0.6.3" + "chokidar": "0.7.0" }, "license": "MIT", "engines": { diff --git a/src/config.coffee b/src/config.coffee index 3b66232..d2910f7 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -19,6 +19,7 @@ exports.defaults = -> strategy: "packageRoot" forceLatest: true exclude: [] + unknownMainFullCopy: false overridesArrays: {} overridesObjects: {} mainOverrides: {} @@ -55,6 +56,9 @@ exports.placeholder = -> # exclude:[] # An array of string paths or regexes. Files to exclude from # copying. Paths should be relative to the bowerdir.path or # absolute. + # unknownMainFullCopy: false # When set to true, any bower package that does not have main + # files configured in its bower.json will have its entire + # folder contents copied in. # mainOverrides: {} # Occasionally bower packages do not clearly indicate what file # is the main library file. In those cases, mimosa cannot find # the main files to copy them to the vendor directory. json2 is @@ -118,6 +122,7 @@ exports.validate = (config, validators) -> validators.ifExistsIsBoolean(errors, "bower.copy.enabled", b.copy.enabled) validators.ifExistsIsBoolean(errors, "bower.copy.trackChanges", b.copy.trackChanges) validators.ifExistsIsBoolean(errors, "bower.copy.forceLatest", b.copy.forceLatest) + validators.ifExistsIsBoolean(errors, "bower.copy.unknownMainFullCopy", b.copy.unknownMainFullCopy) if b.copy.outRoot is null b.copy.outRoot = '' diff --git a/src/utils.coffee b/src/utils.coffee index b6b7c8f..1027072 100644 --- a/src/utils.coffee +++ b/src/utils.coffee @@ -84,7 +84,13 @@ _resolvePaths = (mimosaConfig, names, paths) -> ### else - logger.warn "Cannot determine main file for [[ #{lib} ]] at [[ #{aPath} ]]. Consider adding a mainOverrides entry." + if mimosaConfig.bower.copy.unknownMainFullCopy + logger.warn "Cannot determine main file for [[ #{lib} ]] at [[ #{aPath} ]]. Copying entire folder because unknownMainFullCopy is set to true. Consider adding a mainOverrides entry." + mimosaConfig.bower.copy.strategy[lib] = 'none' + _processOverridesList mimosaConfig, [''], fullLibPath, resolvedPaths[lib] + else + logger.warn "Cannot determine main file for [[ #{lib} ]] at [[ #{aPath} ]]. Consider adding a mainOverrides entry or setting unknownMainFullCopy to true." + else joinedPath = path.join fullLibPath, aPath if fs.existsSync joinedPath