src/utils/exports.coffee |
|
|---|---|
This file contains some utilities to deal with exports and requires. Table Of Content |
{resolve, basename} = require 'path' {puts, error, warn, missing} = require './logs' {findSync} = require "../utils/files" |
namespace |
|
Decorates an object properties with the given If the object contains a property named
|
namespace = (namespace, exports) -> packaged = {} packaged[namespace] = exports["index"] if exports["index"]? packaged["#{namespace}:#{k}"] = v for k,v of exports when k isnt "index" packaged |
combine |
|
Combines in a single object all the exports of files that match
the passed-in This function is used to aggregate all the commands and generators in a project and initialize the Neat command line tool with them. Below is a real world example from the generators index file.
|
combine = (filePattern, paths) -> [filePattern, paths] = [paths, filePattern] if Array.isArray filePattern files = findSync filePattern, 'js', paths packaged = {} for file in files |
The |
try required = require file packaged[k] = v for k,v of required catch e s = error """#{"Broken file #{file}".red} #{e.stack}""" error s.red packaged module.exports = {namespace, combine} |