Sha256: f49e9696721d6368045c3d1d2ac4934e1a026a757dc2428c29590d6a191900e3

Contents?: true

Size: 1.81 KB

Versions: 5

Compression:

Stored size: 1.81 KB

Contents

require "webpacker/configuration"

additional_packages = ""
example_source = "typescript"

# Additional configuration is required for React projects
package_json = Jets.root.join("package.json")
if File.exist?(package_json)
  package = JSON.parse(File.read(package_json))
  package["dependencies"] ||= {}

  if package["dependencies"].keys.include?("react")
    additional_packages = "@types/react @types/react-dom"
    example_source = "react"
  end
end

say "Copying typescript loader to config/webpack/loaders"
copy_file "#{__dir__}/loaders/typescript.js", Jets.root.join("config/webpack/loaders/typescript.js").to_s

say "Adding typescript loader to config/webpack/environment.js"
insert_into_file Jets.root.join("config/webpack/environment.js").to_s,
  "const typescript =  require('./loaders/typescript')\n",
  after: /require\(('|")@rails\/webpacker\1\);?\n/

insert_into_file Jets.root.join("config/webpack/environment.js").to_s,
  "environment.loaders.prepend('typescript', typescript)\n",
  before: "module.exports"

say "Copying tsconfig.json to the Rails root directory for typescript"
copy_file "#{__dir__}/examples/#{example_source}/tsconfig.json", "tsconfig.json"

say "Updating webpack paths to include .ts file extension"
insert_into_file Webpacker.config.config_path, "- .ts\n".indent(4), after: /\s+extensions:\n/

say "Updating webpack paths to include .tsx file extension"
insert_into_file Webpacker.config.config_path, "- .tsx\n".indent(4), after: /\s+extensions:\n/

say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
copy_file "#{__dir__}/examples/typescript/hello_typescript.ts",
  "#{Webpacker.config.source_entry_path}/hello_typescript.ts"

say "Installing all typescript dependencies"
run "yarn add typescript ts-loader #{additional_packages}"

say "Webpacker now supports typescript 🎉", :green

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
jetpacker-0.4.2 lib/install/typescript.rb
jetpacker-0.4.1 lib/install/typescript.rb
jetpacker-0.4.0 lib/install/typescript.rb
jetpacker-0.3.0 lib/install/typescript.rb
jetpacker-0.2.0 lib/install/typescript.rb