Commit e6529879 authored by Mike Greiling's avatar Mike Greiling

ensure rake tasks produce helpful error messages for node dependency issues

parent b36542e1
unless Rails.env.production? unless Rails.env.production?
desc "GitLab | Run ESLint" desc "GitLab | Run ESLint"
task :eslint do task eslint: ['yarn:check'] do
system("yarn", "run", "eslint") sh "yarn run eslint" do |ok, res|
abort('rake eslint failed') unless ok
end
end end
end end
namespace :gitlab do namespace :gitlab do
namespace :assets do namespace :assets do
desc 'GitLab | Assets | Compile all frontend assets' desc 'GitLab | Assets | Compile all frontend assets'
task :compile do task compile: [
Rake::Task['assets:precompile'].invoke 'yarn:check',
Rake::Task['webpack:compile'].invoke 'assets:precompile',
Rake::Task['gitlab:assets:fix_urls'].invoke 'webpack:compile',
end 'gitlab:assets:fix_urls'
]
desc 'GitLab | Assets | Clean up old compiled frontend assets' desc 'GitLab | Assets | Clean up old compiled frontend assets'
task :clean do task clean: ['assets:clean']
Rake::Task['assets:clean'].invoke
end
desc 'GitLab | Assets | Remove all compiled frontend assets' desc 'GitLab | Assets | Remove all compiled frontend assets'
task :purge do task purge: ['assets:clobber']
Rake::Task['assets:clobber'].invoke
end desc 'GitLab | Assets | Uninstall frontend dependencies'
task purge_modules: ['yarn:clobber']
desc 'GitLab | Assets | Fix all absolute url references in CSS' desc 'GitLab | Assets | Fix all absolute url references in CSS'
task :fix_urls do task :fix_urls do
......
unless Rails.env.production? unless Rails.env.production?
Rake::Task['karma'].clear if Rake::Task.task_defined?('karma')
namespace :karma do namespace :karma do
desc 'GitLab | Karma | Generate fixtures for JavaScript tests' desc 'GitLab | Karma | Generate fixtures for JavaScript tests'
RSpec::Core::RakeTask.new(:fixtures) do |t| RSpec::Core::RakeTask.new(:fixtures) do |t|
...@@ -10,7 +8,7 @@ unless Rails.env.production? ...@@ -10,7 +8,7 @@ unless Rails.env.production?
end end
desc 'GitLab | Karma | Run JavaScript tests' desc 'GitLab | Karma | Run JavaScript tests'
task :tests do task tests: ['yarn:check'] do
sh "yarn run karma" do |ok, res| sh "yarn run karma" do |ok, res|
abort('rake karma:tests failed') unless ok abort('rake karma:tests failed') unless ok
end end
...@@ -18,8 +16,5 @@ unless Rails.env.production? ...@@ -18,8 +16,5 @@ unless Rails.env.production?
end end
desc 'GitLab | Karma | Shortcut for karma:fixtures and karma:tests' desc 'GitLab | Karma | Shortcut for karma:fixtures and karma:tests'
task :karma do task karma: ['karma:fixtures', 'karma:tests']
Rake::Task['karma:fixtures'].invoke
Rake::Task['karma:tests'].invoke
end
end end
namespace :yarn do
desc 'Ensure Yarn is installed'
task :available do
unless system('yarn --version', out: File::NULL)
warn(
'Error: Yarn executable was not detected in the system.'.color(:red),
'Download Yarn at https://yarnpkg.com/en/docs/install'.color(:green)
)
abort
end
end
desc 'Ensure Node dependencies are installed'
task check: ['yarn:available'] do
unless system('yarn check --ignore-engines', out: File::NULL)
warn(
'Error: You have unmet dependencies. (`yarn check` command failed)'.color(:red),
'Run `yarn install` to install missing modules.'.color(:green)
)
abort
end
end
desc 'Install Node dependencies with Yarn'
task install: ['yarn:available'] do
unless system('yarn install --force --pure-lockfile --ignore-engines')
abort 'Error: Unable to install node modules.'.color(:red)
end
end
desc 'Remove Node dependencies'
task :clobber do
warn 'Purging ./node_modules directory'.color(:red)
FileUtils.rm_rf 'node_modules'
end
end
desc 'Install Node dependencies with Yarn'
task yarn: ['yarn:install']
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment