Skip to content

Commit

Permalink
Rake task to automate UglifyJS version update
Browse files Browse the repository at this point in the history
  • Loading branch information
lautis committed Dec 30, 2017
1 parent 2fb842d commit f80a66c
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 22 deletions.
13 changes: 9 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@ Then run tests using rake:

git submodule update --init

After that, UglifyJS and source-map are checked out under `vendor/uglifyjs` and `vendor/source-map`.
After that, UglifyJS can be updated to a specific version with rake task.

Use Git commands (e.g. git checkout master) to change the included version. You can even write custom code to yourself. After changing the dependencies, compile new version of the bundled JS file using
rake uglifyjs:update VERSION=3.3.4

bundle exec rake js
To compile JS with dependencies, run

After this, the new JS is used in your development version.
rake uglifyjs:build

You can even write custom patches to UglifyJS in `vendor/uglifyjs` and `vendor/uglifyjs-harmony` directories and compile the bundles JS using the command above. However, for the changes to be releasable, they should be in UglifyJS repository.

To automatically update UglifyJS version and commit changes

rake uglifyjs VERSION=3.3.4

## Reporting issues

Expand Down
89 changes: 71 additions & 18 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,40 +1,93 @@
# encoding: utf-8

# rubocop:disable Metrics/BlockLength

require 'fileutils'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
end

desc "Rebuild lib/uglify.js"
task :js do
cd 'vendor/source-map/' do
`npm install --no-package-lock --no-save`
end
def version
ENV.fetch('VERSION')
end

HEADER = "## next"

cd 'vendor/uglifyjs/' do
# required to run ./uglifyjs2 --self; not bundled.
`npm install --no-package-lock --no-save`
def changelog_tail
changelog = File.read("CHANGELOG.md")
if changelog.start_with?(HEADER)
changelog[HEADER.length + 2..-1]
else
"\n" + changelog
end
end

namespace :uglifyjs do
desc "Update UglifyJS source to version specified in VERSION environment variable"
task :update do
cd 'vendor/uglifyjs' do
`git fetch && git checkout v#{version}`
end

cd 'vendor/uglifyjs-harmony' do
# required to run ./uglifyjs2 --self; not bundled.
`npm install --no-package-lock --no-save`
cd 'vendor/uglifyjs-harmony' do
`git fetch && git checkout harmony-v#{version}`
end
end

FileUtils.cp("vendor/source-map/dist/source-map.js", "lib/source-map.js")
desc "Rebuild lib/uglify*.js"
task :build do
cd 'vendor/source-map/' do
`npm install --no-package-lock --no-save`
end

cd 'vendor/uglifyjs/' do
# required to run ./uglifyjs2 --self; not bundled.
`npm install --no-package-lock --no-save`
end

cd 'vendor/uglifyjs-harmony' do
# required to run ./uglifyjs2 --self; not bundled.
`npm install --no-package-lock --no-save`
end

source = `./vendor/uglifyjs/bin/uglifyjs --self --comments /Copyright/`
File.write("lib/uglify.js", source)
FileUtils.cp("vendor/source-map/dist/source-map.js", "lib/source-map.js")

harmony_source = `./vendor/uglifyjs-harmony/bin/uglifyjs --self --comments /Copyright/`
File.write("lib/uglify-harmony.js", harmony_source)
source = `./vendor/uglifyjs/bin/uglifyjs --self --comments /Copyright/`
File.write("lib/uglify.js", source)

FileUtils.cp("vendor/split/split.js", "lib/split.js")
`patch -p1 -i patches/es5-string-split.patch`
harmony_source = `./vendor/uglifyjs-harmony/bin/uglifyjs --self --comments /Copyright/`
File.write("lib/uglify-harmony.js", harmony_source)

FileUtils.cp("vendor/split/split.js", "lib/split.js")
`patch -p1 -i patches/es5-string-split.patch`
end

desc "Add UglifyJS version bump to changelog"
task :changelog do
item = "- update UglifyJS to #{version}"
changelog = "#{HEADER}\n\n#{item}\n#{changelog_tail}"
File.write("CHANGELOG.md", changelog)
end

desc "Commit changes from UglifyJS version bump"
task :commit do
files = [
'CHANGELOG.md',
'lib/uglify.js',
'lib/uglify-harmony.js',
'vendor/uglifyjs',
'vendor/uglifyjs-harmony'
]
`git add #{files.join(' ')}`
`git commit -m "Update UglifyJS to #{version}"`
end
end

desc "Update UglifyJS to version specified in VERSION environment variable"
task :uglifyjs => ['uglifyjs:update', 'uglifyjs:build', 'uglifyjs:changelog', 'uglifyjs:commit']

begin
require 'rubocop/rake_task'
RuboCop::RakeTask.new(:rubocop)
Expand Down

0 comments on commit f80a66c

Please sign in to comment.