Skip to content

Instantly share code, notes, and snippets.

@nruth
Last active September 3, 2019 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nruth/dd41d9d323b15a74e1f29582e941f82a to your computer and use it in GitHub Desktop.
Save nruth/dd41d9d323b15a74e1f29582e941f82a to your computer and use it in GitHub Desktop.
Ember Shucker - unpodding old projects (stupid simple grep/mv ruby fileutils script)
# pods aren't really a thing going forward, and come up as a problem during paid code reivews
# there is/was an alternative in the works to do with modules, but it's best to be on the old
# default ember-cli directory structure so that any new codemods can work
require 'fileutils'
app_pods = "app/pods"
puts "Shucking Routes"
routes = Dir.glob(File.join(app_pods, "**", "route.js"))
routes.each do |route_path|
concept = route_path.match(%r{app/pods/([-\w/_]+)/route.js})[1]
target_path = File.join("app", "routes", "#{concept}.js")
FileUtils.makedirs(File.dirname(target_path))
FileUtils.mv route_path, target_path, verbose: true
end
puts "Shucking Templates"
templates = Dir.glob(File.join(app_pods, "**", "template.hbs"))
templates.each do |template_path|
concept = template_path.match(%r{app/pods/([-\w/_]+)/template.hbs})[1]
target_path = File.join("app", "templates", "#{concept}.hbs")
FileUtils.makedirs(File.dirname(target_path))
FileUtils.mv template_path, target_path, verbose: true
end
puts "Shucking Components"
components = Dir.glob(File.join(app_pods, "components", "**", "component.js"))
components.each do |component_path|
concept = component_path.match(%r{app/pods/components([-\w/_]+)/component.js})[1]
target_path = File.join("app", "components", "#{concept}.js")
FileUtils.makedirs(File.dirname(target_path))
FileUtils.mv component_path, target_path, verbose: true
end
puts "Shucking Services"
services = Dir.glob(File.join(app_pods, "**", "service.js"))
services.each do |component_path|
concept = component_path.match(%r{app/pods([-\w/_]+)/service.js})[1]
target_path = File.join("app", "services", "#{concept}.js")
FileUtils.makedirs(File.dirname(target_path))
FileUtils.mv component_path, target_path, verbose: true
end
puts "Listing Component Templates (should be none left)"
puts component_templates = Dir.glob(File.join(app_pods, "components", "**", "template.hbs"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment