├── .gitignore ├── README.md └── update-mathjax-component /.gitignore: -------------------------------------------------------------------------------- 1 | mathjax 2 | mathjax-cleaner 3 | node_modules 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MathJax Component 2 | 3 | This is the MathJax components repo. It contains releases of mathjax, 4 | with the png image fonts removed, since they are often unused, 5 | and take up a large portion of MathJax install size and time. 6 | 7 | The master branch of this repo contains a simple script to update the 8 | [mathjax components repo](https://github.com/components/MathJax). 9 | This clones [MathJax][] and the [MathJax-grunt-cleaner][] repos, 10 | then iterates through each MathJax release tag, 11 | making a corresponding tag on the component repo after running the `grunt component` 12 | command, which strips out the png image fonts. 13 | Any tags already present on the components repo are not updated. 14 | 15 | To update the tags on the components repo when a new MathJax release has been made, run: 16 | 17 | ./update-mathjax-component 18 | 19 | [MathJax]: https://github.com/mathjax/MathJax 20 | [MathJax-grunt-cleaner]: https://github.com/mathjax/MathJax-grunt-cleaner 21 | -------------------------------------------------------------------------------- /update-mathjax-component: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # This script clones the MathJax and MathJax-grunt-cleaner repos, 3 | # and runs the `grunt component` command to take all the tags on the main repo 4 | # and make new tags on the components repo with the image fonts removed. 5 | # Pre-existing tags will not be updated. 6 | 7 | $cleaner_repo = 'https://github.com/mathjax/MathJax-grunt-cleaner' 8 | $mathjax_repo = 'https://github.com/mathjax/MathJax' 9 | $component_repo = 'git@github.com:components/MathJax' 10 | 11 | 12 | def run(cmd) 13 | # echo and run a command, exit on failure 14 | puts "> #{cmd}" 15 | if not system(cmd) 16 | STDERR.write("#{cmd} failed") 17 | Process.exit(1) 18 | end 19 | end 20 | 21 | def clone_repos(mj_path, cleaner_path) 22 | # Clone various repos (cleaner, mathjax, and add components remote to mathjax) 23 | 24 | cleaner_path = File.absolute_path(cleaner_path) 25 | mj_path = File.absolute_path(mj_path) 26 | 27 | if not File.exists? cleaner_path 28 | run "git clone #{$cleaner_repo} #{cleaner_path}" 29 | Dir.chdir cleaner_path do 30 | run "npm install" 31 | end 32 | end 33 | 34 | if not File.exists? mj_path 35 | run "git clone #{$component_repo} -o component #{mj_path}" 36 | end 37 | 38 | Dir.chdir mj_path do 39 | run "git fetch component" 40 | 41 | remotes = `git remote`.split 42 | if not remotes.include? 'upstream' 43 | run "git remote add upstream #{$mathjax_repo}" 44 | end 45 | run "git fetch upstream" 46 | end 47 | 48 | [mj_path, cleaner_path] 49 | end 50 | 51 | def link_files(mj_path, cleaner_path) 52 | # link build files 53 | ['Gruntfile.js', 'node_modules', 'package.json'].each do |f| 54 | mj_file = File.join(mj_path, f) 55 | cleaner_file = File.join(cleaner_path, f) 56 | if not File.exists? mj_file 57 | puts "Symlinking #{mj_file} → #{cleaner_file}" 58 | File.symlink(cleaner_file, mj_file) 59 | end 60 | end 61 | end 62 | 63 | def get_tags(remote) 64 | # get tags from a particular remote 65 | tags = {} 66 | `git ls-remote --tags #{remote}`.split("\n").each do |line| 67 | sha, ref = line.split 68 | if ref.include? '^' or ref.include? '-' 69 | next 70 | end 71 | tag = ref.slice('refs/tags/'.length, ref.length) 72 | tags[tag] = sha 73 | end 74 | tags 75 | end 76 | 77 | 78 | def clear_tags 79 | # Clear the local tags 80 | tags = `git tag`.strip.gsub("\n", " ") 81 | if not tags.empty? 82 | run "git tag -d #{tags}" 83 | end 84 | end 85 | 86 | 87 | def make_component_tag(tag, sha, mj_path, cleaner_path) 88 | # make a component tag from an upstream tag 89 | puts "Making component tag #{tag}" 90 | run "git reset --hard" 91 | run "git checkout #{sha}" 92 | link_files(mj_path, cleaner_path) 93 | run "grunt component" 94 | run "git add unpacked fonts" 95 | run "git commit -m 'strip png-fonts for component release #{tag}'" 96 | run "git tag -f -am 'component tag #{tag}' #{tag}" 97 | end 98 | 99 | 100 | def migrate_tags(mj_path, cleaner_path) 101 | # migrate tags from upstream to component repo 102 | # running Grunt task to strip png image fonts on each 103 | upstream_tags = get_tags "upstream" 104 | component_tags = get_tags "component" 105 | 106 | # filter out existing tags on component repo 107 | component_tags.keys.each do |tag| 108 | upstream_tags.delete(tag) 109 | end 110 | 111 | if upstream_tags.empty? 112 | puts "All tags up-to-date" 113 | return 114 | end 115 | 116 | to_push = [] 117 | upstream_tags.each_pair do |tag, sha| 118 | make_component_tag(tag, sha, mj_path, cleaner_path) 119 | to_push.push(tag) 120 | end 121 | 122 | run "git push component " + to_push.join(" ") 123 | end 124 | 125 | 126 | # actually do it: 127 | mj, cleaner = clone_repos('mathjax', 'mathjax-cleaner') 128 | Dir.chdir mj do 129 | migrate_tags(mj, cleaner) 130 | end 131 | --------------------------------------------------------------------------------