diff options
author | Gleb Mazovetskiy <glex.spb@gmail.com> | 2017-09-03 18:48:59 +0300 |
---|---|---|
committer | Gleb Mazovetskiy <glex.spb@gmail.com> | 2017-09-03 18:48:59 +0300 |
commit | fb2f045b8ed4a17ec5cacffd19bb5bea7e7fe9fd (patch) | |
tree | 867c7a122cff556f7ff6d796fc7857859dae9897 /tasks | |
parent | 29fdf4fac77e7cec42894363d838d99fcc30bc4f (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')
-rw-r--r-- | tasks/updater/js.rb | 35 |
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 |