diff options
author | Clement Ho <clemmakesapps@gmail.com> | 2017-02-17 22:46:23 +0300 |
---|---|---|
committer | Clement Ho <clemmakesapps@gmail.com> | 2017-02-17 22:46:23 +0300 |
commit | f2552696277a502927b6ceaf5a2c4ec78afbc48e (patch) | |
tree | dd1cb5d8c9a537b491ff4f78c9432f913ea2ee8a /lib | |
parent | 63cb6c843fd6b7f99042049c31643bbeceef4a95 (diff) | |
parent | c77b68d627f9f8e8eaacd61bc352aadf0b904c16 (diff) |
Merge branch 'add-yarn-documentation' into 'master'
Update documentation to include yarn in our dependencies
See merge request !9316
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/upgrader.rb | 8 | ||||
-rw-r--r-- | lib/tasks/eslint.rake | 7 | ||||
-rw-r--r-- | lib/tasks/gitlab/assets.rake | 22 | ||||
-rw-r--r-- | lib/tasks/karma.rake | 9 | ||||
-rw-r--r-- | lib/tasks/yarn.rake | 40 |
5 files changed, 62 insertions, 24 deletions
diff --git a/lib/gitlab/upgrader.rb b/lib/gitlab/upgrader.rb index 7fd4935191c..4cc34e34460 100644 --- a/lib/gitlab/upgrader.rb +++ b/lib/gitlab/upgrader.rb @@ -60,15 +60,17 @@ module Gitlab "Get latest code" => %W(#{Gitlab.config.git.bin_path} fetch), "Switch to new version" => %W(#{Gitlab.config.git.bin_path} checkout v#{latest_version}), "Install gems" => %W(bundle), - "Install node modules" => %W(npm install --production), "Migrate DB" => %W(bundle exec rake db:migrate), - "Recompile assets" => %W(bundle exec rake gitlab:assets:clean gitlab:assets:compile), + "Recompile assets" => %W(bundle exec rake yarn:install gitlab:assets:clean gitlab:assets:compile), "Clear cache" => %W(bundle exec rake cache:clear) } end def env - { 'RAILS_ENV' => 'production' } + { + 'RAILS_ENV' => 'production', + 'NODE_ENV' => 'production' + } end def upgrade diff --git a/lib/tasks/eslint.rake b/lib/tasks/eslint.rake index 2514b050695..51f5d768102 100644 --- a/lib/tasks/eslint.rake +++ b/lib/tasks/eslint.rake @@ -1,7 +1,8 @@ unless Rails.env.production? desc "GitLab | Run ESLint" - task :eslint do - system("yarn", "run", "eslint") + task eslint: ['yarn:check'] do + unless system('yarn run eslint') + abort('rake eslint failed') + end end end - diff --git a/lib/tasks/gitlab/assets.rake b/lib/tasks/gitlab/assets.rake index b6ef8260191..3eb5fc07b3c 100644 --- a/lib/tasks/gitlab/assets.rake +++ b/lib/tasks/gitlab/assets.rake @@ -1,21 +1,21 @@ namespace :gitlab do namespace :assets do desc 'GitLab | Assets | Compile all frontend assets' - task :compile do - Rake::Task['assets:precompile'].invoke - Rake::Task['webpack:compile'].invoke - Rake::Task['gitlab:assets:fix_urls'].invoke - end + task compile: [ + 'yarn:check', + 'assets:precompile', + 'webpack:compile', + 'gitlab:assets:fix_urls' + ] desc 'GitLab | Assets | Clean up old compiled frontend assets' - task :clean do - Rake::Task['assets:clean'].invoke - end + task clean: ['assets:clean'] desc 'GitLab | Assets | Remove all compiled frontend assets' - task :purge do - Rake::Task['assets:clobber'].invoke - end + task purge: ['assets:clobber'] + + desc 'GitLab | Assets | Uninstall frontend dependencies' + task purge_modules: ['yarn:clobber'] desc 'GitLab | Assets | Fix all absolute url references in CSS' task :fix_urls do diff --git a/lib/tasks/karma.rake b/lib/tasks/karma.rake index 35cfed9dc75..40465ea3bf0 100644 --- a/lib/tasks/karma.rake +++ b/lib/tasks/karma.rake @@ -1,6 +1,4 @@ unless Rails.env.production? - Rake::Task['karma'].clear if Rake::Task.task_defined?('karma') - namespace :karma do desc 'GitLab | Karma | Generate fixtures for JavaScript tests' RSpec::Core::RakeTask.new(:fixtures) do |t| @@ -10,7 +8,7 @@ unless Rails.env.production? end desc 'GitLab | Karma | Run JavaScript tests' - task :tests do + task tests: ['yarn:check'] do sh "yarn run karma" do |ok, res| abort('rake karma:tests failed') unless ok end @@ -18,8 +16,5 @@ unless Rails.env.production? end desc 'GitLab | Karma | Shortcut for karma:fixtures and karma:tests' - task :karma do - Rake::Task['karma:fixtures'].invoke - Rake::Task['karma:tests'].invoke - end + task karma: ['karma:fixtures', 'karma:tests'] end diff --git a/lib/tasks/yarn.rake b/lib/tasks/yarn.rake new file mode 100644 index 00000000000..2ac88a039e7 --- /dev/null +++ b/lib/tasks/yarn.rake @@ -0,0 +1,40 @@ + +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 --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'] |