forked from unpoly/unpoly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
154 lines (131 loc) · 4.45 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
require 'json'
require 'fileutils'
require 'tmpdir'
require "active_support/all"
module Unpoly
class Release
class << self
def version
package_json_path = 'package.json'
package_json_content = File.read(package_json_path)
package_info = JSON.parse(package_json_content)
package_info['version'].presence or raise Error, "Cannot parse { version } from #{package_json_path}"
end
def pre_release?
version =~ /rc|beta|pre|alpha/
end
def run(command, optional: false)
system(command) or optional or raise "Error running command: #{command}"
end
def git_tag
'v' + version
end
def git_tag_message
'Version ' + version
end
def confirm(message)
print "#{message} [y/N] "
reply = STDIN.gets.strip.downcase
unless reply == 'y'
puts "Aborted."
exit
end
end
FILE_GLOBS = [
'package.json',
'unpoly{.js,.min.js}',
'unpoly.es6{.js,.min.js}',
'unpoly{.css,.min.css}',
'unpoly-migrate{.js,.min.js}',
'unpoly-bootstrap{3,4,5}{.js,.min.js}',
'unpoly-bootstrap{3,4,5}{.css,.min.css}',
'README.md',
'CHANGELOG.md',
'LICENSE',
]
def paths
FILE_GLOBS.flat_map { |glob| Dir.glob("dist/#{glob}") }
end
def orphaned_paths
Dir.glob("dist/unpoly*{.css,.js}") - paths
end
end
end
end
namespace :release do
desc 'Clean build files from another major version'
task :clean do
Unpoly::Release.orphaned_paths.each do |path|
puts "Cleaning orphaned file: #{path}"
File.delete(path)
end
end
desc 'Make a fresh production build'
task :build do
puts "Compiling a fresh build..."
system 'npm run build' or raise "Could not build"
end
desc "Prompt user to confirm that they're ready"
task :confirm do
puts "You are about to #{Unpoly::Release.pre_release? ? 'PRE-release' : 'release'} Unpoly version #{Unpoly::Release.version} to npm."
puts
puts "Before continuing, make sure the following tasks are done:"
puts
puts "- Bump the version in package.json"
puts "- Run `npm install` to update version in package-lock.json"
puts "- Update CHANGELOG.md"
puts "- Commit and push changes"
puts "- Make sure you're logged into npm"
puts
puts "Continuing will make a fresh build and publish a new version to npm."
puts
Unpoly::Release.confirm("Continue now?")
end
desc 'Remind user to update unpoly.com'
task :remind_to_update_site do
puts "Now remember to:"
puts
puts "- Make a new release to unpoly-rails with the same version"
puts "- Update unpoly.com (unpoly-site) so users see the updated CHANGELOG and CDN link"
puts "- Post an announcement about the new release to GitHub Discussions"
puts "- Tweet a link to the CHANGELOG as @unpolyjs"
end
desc 'Push version tag to GitHub'
task :push_tag do
tag = Unpoly::Release.git_tag
tag_message = Unpoly::Release.git_tag_message
Unpoly::Release.run("git push origin :refs/tags/#{tag}")
Unpoly::Release.run("git tag --annotate --force --message='#{tag_message}' #{tag} HEAD")
Unpoly::Release.run("git push -f origin #{tag}")
end
desc 'Publish package to npm'
task :publish_to_npm do
if Unpoly::Release.pre_release?
puts 'Publishing a PRE-release'
npm_tag = 'next'
else
npm_tag = 'latest'
end
staging_dir = 'tmp/npm-staging'
FileUtils.rm_rf(staging_dir, secure: true)
FileUtils.mkpath(staging_dir)
puts "Building NPM package in #{staging_dir} ..."
# All contents of our package are either copied or symlinked in dist/.
# This enables us to both to:
#
# (1) `npm publish` from a symlink-dereferenced copy of that folder.
# (2) reference the dist folder as a local npm package during development.
# Copy files in dist folder while following symbolic links
Unpoly::Release.run("cp --recursive --dereference --force #{Unpoly::Release.paths.join(' ')} #{staging_dir}")
puts
Unpoly::Release.run("tree #{staging_dir}")
puts
Unpoly::Release.confirm("Do the package contents look good?")
Dir.chdir(staging_dir) do
Unpoly::Release.run("npm publish --tag #{npm_tag}")
end
end
desc 'Build artifacts, confirm with user and release to npm'
task :process => [:clean, :build, :confirm, :push_tag, :publish_to_npm, :remind_to_update_site] do
end
end