Ok, so for anyone following along I’ve made some more progress and the current code for the custom extension looks like this:
class Dart2Js < Middleman::Extension
def initialize(app, options_hash={}, &block)
super
end
def manipulate_resource_list(resources)
resources.each do |resource|
# check if extension isn't a ".dart" file
next if resource.ext != ".dart"
# check if file is a library dependency
next if resource.source_file.include? "packages"
# change the destination file extension to JS
resource.destination_path = resource.destination_path.chomp(".dart") + ".js"
# create build file path
FileUtils.mkdir_p("build/javascripts") unless File.exists?("build/javascripts")
# run the dart2js compiler
system("dart2js #{resource.source_file} --out=build/#{resource.destination_path} --package-root=source/javascripts/packages")
end
end
end
Dart2Js.register(:dart2js)
The only problem I have left is that when I run the build process with the extension active I get these errors:
error build/javascripts/dashboard.js
Not found
Option :lang is not supported by Slim::Engine
Option :lang is not supported by Slim::Engine
Option :locals is not supported by Slim::Engine
remove build/javascripts/dashboard.js.deps
remove build/javascripts/dashboard.js.gz
remove build/javascripts/dashboard.js.map
remove build/javascripts/dashboard.precompiled.js
gzip build/javascripts/dashboard.js.gz (1.5 MB smaller)
gzip Total gzip savings: 1.5 MB
There were errors during this build
I’m not entirely sure what’s causing Middleman to think that the file doesn’t exist even though the file is present in the build folder with this path build/javascripts/dashboard.js
…