-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
56 lines (48 loc) · 1.43 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'json'
require 'open3'
module Command
class << self
def run(command, environment = {})
out, status = Open3.capture2e(environment.transform_keys(&:to_s), command)
unless status.success?
raise("Failed to run:\n #{command}")
end
out
end
end
end
namespace :lib do
task :install do |_|
puts "Installing dependencies"
puts Command.run("pnpm install")
end
scripts = JSON.parse(File.read('package.json'))['scripts'].keys
scripts.each do |script|
desc "Task based on package.json script: #{script}"
task "#{script}" do
Rake::Task["lib:install"].invoke
sh "pnpm #{script}"
end
end
task :publish do |_|
puts Command.run("pnpm publish")
end
end
namespace :version do
desc "Bump version"
task :bump, [:release] do |_, args|
args.with_defaults(release: 'prerelease')
package_definition = JSON.parse(File.read('package.json'))
current_version = package_definition['version']
release = args[:release]
pre_id = 'RC'
if release == 'prerelease' && !current_version.include?(pre_id)
release = 'preminor'
end
version = Command.run("npm version #{release} --preid=#{pre_id}")
last_message = Command.run("git log -1 --pretty=%B").strip
puts "Bumped version to #{version}"
Command.run("git commit -a --amend -m \"#{last_message} [skip ci]\"")
end
end
task :default => [:'lib:formatting:fix', 'lib:lint:fix', 'lib:test']