Sha256: 18e350c04c044ced9190e1bb5c3bebe6f2be4c7d120c26d5b01b1c9d825b73ee
Contents?: true
Size: 1.84 KB
Versions: 11
Compression:
Stored size: 1.84 KB
Contents
# frozen_string_literal: true require "rake" require "rake/tasklib" module RuboCop module Katalyst # Provides a custom rake task. # # require 'rubocop/katalyst/prettier_task' # RuboCop::Katalyst::PrettierTask.new class PrettierTask < ::Rake::TaskLib attr_accessor :verbose def initialize(verbose: true) super() @verbose = verbose desc "Run Prettier" unless ::Rake.application.last_description task(prettier: "prettier:lint") task(lint: :prettier) task(autocorrect: "prettier:autocorrect") setup_subtasks end private def yarn(*options) sh("yarn", *options) end def installed? File.exist?(config) end def config File.join(root, ".prettierrc.json") end def install_prettier yarn("add", "--dev", "prettier") File.write(config, <<~JSON) {} JSON yarn("install") end def setup_subtasks namespace :prettier do desc "Install npm packages with yarn" task install: :environment do install_prettier unless installed? end desc "Lint JS/SCSS files using prettier" task lint: :install do yarn("run", "prettier", "--check", *paths) end desc "Autocorrect JS/SCSS files using prettier" task autocorrect: :install do yarn("run", "prettier", "--write", *paths) end end end def paths %w[ app/assets/config app/assets/javascripts app/assets/stylesheets app/javascript app/packs ].map { |path| File.join(root, path) } .select { |path| File.exist?(path) } end def root @root ||= Dir.pwd end end end end
Version data entries
11 entries across 11 versions & 2 rubygems