@@ -10,11 +10,12 @@ class Package
1010 DEFAULT_SCSS = File . read ( File . expand_path ( '../assets/default_styles.scss' , __FILE__ ) )
1111 SRC_TEMPLATE = Erubis ::Eruby . new ( File . read ( File . expand_path ( '../assets/src.js.erb' , __FILE__ ) ) )
1212
13- attr_reader :root , :warnings
13+ attr_reader :lib_root , : root, :warnings
1414 attr_accessor :requirements_only
1515
1616 def initialize ( dir )
1717 @root = Pathname . new ( File . expand_path ( dir ) )
18+ @lib_root = Pathname . new ( File . join ( @root , 'lib' ) )
1819 @warnings = [ ]
1920 @requirements_only = false
2021 end
@@ -46,10 +47,28 @@ def validate
4647 end
4748 end
4849
50+ def app_js
51+ read_file ( "app.js" )
52+ end
53+
54+ def commonjs_modules
55+ return unless has_lib_js?
56+
57+ lib_files . each_with_object ( { } ) do |file , modules |
58+ name = file . relative_path . gsub! ( /^lib\/ / , '' )
59+ content = file . read
60+ modules [ name ] = content
61+ end
62+ end
63+
4964 def files
5065 non_tmp_files
5166 end
5267
68+ def lib_files
69+ @lib_files ||= files . select { |f | f =~ /^lib\/ .*\. js$/ }
70+ end
71+
5372 def template_files
5473 files . select { |f | f =~ /^templates\/ .*\. hdbs$/ }
5574 end
@@ -76,7 +95,7 @@ def app_translations
7695
7796 def readified_js ( app_name , app_id , asset_url_prefix , settings = { } )
7897 manifest = manifest_json
79- source = read_file ( "app.js" )
98+ source = app_js
8099 name = app_name || manifest [ :name ] || 'Local App'
81100 location = manifest [ :location ]
82101 app_class_name = "app-#{ app_id } "
@@ -97,7 +116,8 @@ def readified_js(app_name, app_id, asset_url_prefix, settings={})
97116 :framework_version => framework_version ,
98117 :templates => templates ,
99118 :settings => settings ,
100- :app_id => app_id
119+ :app_id => app_id ,
120+ :modules => commonjs_modules
101121 )
102122 end
103123
@@ -110,6 +130,10 @@ def has_js?
110130 file_exists? ( "app.js" )
111131 end
112132
133+ def has_lib_js?
134+ lib_files . any?
135+ end
136+
113137 def has_manifest?
114138 file_exists? ( "manifest.json" )
115139 end
0 commit comments