Sha256: 731f27b0333aba48b8921e5884d5b28909140967539051ec1d197bee226d6d67

Contents?: true

Size: 1.44 KB

Versions: 29

Compression:

Stored size: 1.44 KB

Contents

require "fileutils"

namespace :futurism do
  desc "Let's look into a brighter future with futurism and CableReady"
  task install: :environment do
    system "yarn add @minthesize/futurism"

    filepath = %w[
      app/javascript/channels/index.js
      app/javascript/channels/index.ts
      app/javascript/packs/application.js
      app/javascript/packs/application.ts
    ]
      .select { |path| File.exist?(path) }
      .map { |path| Rails.root.join(path) }
      .first

    puts "Updating #{filepath}"
    lines = File.open(filepath, "r") { |f| f.readlines }

    unless lines.find { |line| line.start_with?("import * as Futurism") }
      matches = lines.select { |line| line =~ /\A(require|import)/ }
      lines.insert lines.index(matches.last).to_i + 1, "import * as Futurism from '@minthesize/futurism'\n"
    end

    unless lines.find { |line| line.start_with?("import consumer") }
      matches = lines.select { |line| line =~ /\A(require|import)/ }
      lines.insert lines.index(matches.last).to_i + 1, "import consumer from '../channels/consumer'\n"
    end

    initialize_line = lines.find { |line| line.start_with?("Futurism.initializeElements") }
    lines << "Futurism.initializeElements()\n" unless initialize_line

    subscribe_line = lines.find { |line| line.start_with?("Futurism.createSubscription") }
    lines << "Futurism.createSubscription(consumer)\n" unless subscribe_line

    File.open(filepath, "w") { |f| f.write lines.join }
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
futurism-1.2.0.pre9 lib/tasks/futurism_tasks.rake~
futurism-1.2.0.pre8 lib/tasks/futurism_tasks.rake~
futurism-1.2.0.pre7 lib/tasks/futurism_tasks.rake~
futurism-1.2.0.pre6 lib/tasks/futurism_tasks.rake~
futurism-1.2.0.pre5 lib/tasks/futurism_tasks.rake~
futurism-1.2.0.pre4 lib/tasks/futurism_tasks.rake~
futurism-1.2.0.pre3 lib/tasks/futurism_tasks.rake~
futurism-1.2.0.pre2 lib/tasks/futurism_tasks.rake~
futurism-1.2.0.pre1 lib/tasks/futurism_tasks.rake~
futurism-1.1.0 lib/tasks/futurism_tasks.rake~
futurism-1.0.1 lib/tasks/futurism_tasks.rake~
futurism-1.0.0 lib/tasks/futurism_tasks.rake~
futurism-0.8.0 lib/tasks/futurism_tasks.rake
futurism-0.7.2 lib/tasks/futurism_tasks.rake
futurism-0.7.1 lib/tasks/futurism_tasks.rake
futurism-0.7.0 lib/tasks/futurism_tasks.rake
futurism-0.6.0 lib/tasks/futurism_tasks.rake
futurism-0.5.4 lib/tasks/futurism_tasks.rake
futurism-0.5.2 lib/tasks/futurism_tasks.rake
futurism-0.5.1 lib/tasks/futurism_tasks.rake