Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap-rubygem.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGleb Mazovetskiy <glex.spb@gmail.com>2017-09-03 18:48:59 +0300
committerGleb Mazovetskiy <glex.spb@gmail.com>2017-09-03 18:48:59 +0300
commitfb2f045b8ed4a17ec5cacffd19bb5bea7e7fe9fd (patch)
tree867c7a122cff556f7ff6d796fc7857859dae9897 /tasks/updater
parent29fdf4fac77e7cec42894363d838d99fcc30bc4f (diff)
Update the JS updater script for the latest v4-dev
There is no longer a list of JS files in the correct order in package.js, so we scan and topologically sort `import`s instead.
Diffstat (limited to 'tasks/updater')
-rw-r--r--tasks/updater/js.rb35
1 files changed, 31 insertions, 4 deletions
diff --git a/tasks/updater/js.rb b/tasks/updater/js.rb
index 32eee9a..0c5109b 100644
--- a/tasks/updater/js.rb
+++ b/tasks/updater/js.rb
@@ -1,3 +1,5 @@
+require 'tsort'
+
class Updater
module Js
def update_javascript_assets
@@ -28,10 +30,35 @@ class Updater
def bootstrap_js_files
@bootstrap_js_files ||= begin
- package_json = get_file(file_url 'package.json')
- JSON.parse(package_json)['scripts']['js-compile-bundle']
- .match(/shx cat (.*?) \|/)[1].split(/\s+/)
- .map { |p| p.sub %r(\Ajs/src/), '' }
+ src_files = get_paths_by_type('js/src', /\.js$/) - %w[index.js]
+ imports = Deps.new
+ # Get the imports from the ES6 files to order requires correctly.
+ read_files('js/src', src_files).each do |name, content|
+ imports.add name,
+ *content.scan(%r{import [a-zA-Z]* from '\./(\w+)})
+ .flatten(1).map { |f| "#{f}.js" }
+ end
+ imports.tsort
+ end
+ end
+
+ class Deps
+ include TSort
+
+ def initialize
+ @imports = {}
+ end
+
+ def add(from, *tos)
+ (@imports[from] ||= []).push(*tos)
+ end
+
+ def tsort_each_child(node, &block)
+ @imports[node].each(&block)
+ end
+
+ def tsort_each_node(&block)
+ @imports.each_key(&block)
end
end
end