|
| 1 | +module.exports = function(grunt) { |
| 2 | + |
| 3 | + // load all grunt tasks |
| 4 | + require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); |
| 5 | + |
| 6 | + grunt.initConfig({ |
| 7 | + // Read package.json |
| 8 | + pkg: grunt.file.readJSON("package.json"), |
| 9 | + |
| 10 | + open : { |
| 11 | + dev: { |
| 12 | + path: 'http://localhost:1919' |
| 13 | + } |
| 14 | + }, |
| 15 | + |
| 16 | + connect: { |
| 17 | + server: { |
| 18 | + options: { |
| 19 | + port: 1919, |
| 20 | + base: 'docs/build', |
| 21 | + livereload: true |
| 22 | + } |
| 23 | + } |
| 24 | + }, |
| 25 | + copy: { |
| 26 | + fonts: { |
| 27 | + files: [ |
| 28 | + { |
| 29 | + expand: true, |
| 30 | + flatten: true, |
| 31 | + src: ['fonts/Lato/*'], |
| 32 | + dest: 'pytorch_sphinx_theme/static/fonts/Lato', |
| 33 | + filter: 'isFile' |
| 34 | + } |
| 35 | + ] |
| 36 | + } |
| 37 | + }, |
| 38 | + |
| 39 | + sass: { |
| 40 | + dev: { |
| 41 | + options: { |
| 42 | + style: 'expanded' |
| 43 | + }, |
| 44 | + files: [{ |
| 45 | + expand: true, |
| 46 | + cwd: 'scss', |
| 47 | + src: ['*.scss'], |
| 48 | + dest: 'pytorch_sphinx_theme/static/css', |
| 49 | + ext: '.css' |
| 50 | + }] |
| 51 | + }, |
| 52 | + build: { |
| 53 | + options: { |
| 54 | + style: 'compressed', |
| 55 | + sourcemap: 'none' |
| 56 | + }, |
| 57 | + files: [{ |
| 58 | + expand: true, |
| 59 | + cwd: 'scss', |
| 60 | + src: ['*.scss'], |
| 61 | + dest: 'pytorch_sphinx_theme/static/css', |
| 62 | + ext: '.css' |
| 63 | + }] |
| 64 | + } |
| 65 | + }, |
| 66 | + |
| 67 | + browserify: { |
| 68 | + dev: { |
| 69 | + options: { |
| 70 | + external: ['jquery'], |
| 71 | + alias: { |
| 72 | + 'pytorch-sphinx-theme': './js/theme.js' |
| 73 | + } |
| 74 | + }, |
| 75 | + src: ['js/*.js'], |
| 76 | + dest: 'pytorch_sphinx_theme/static/js/theme.js' |
| 77 | + }, |
| 78 | + build: { |
| 79 | + options: { |
| 80 | + external: ['jquery'], |
| 81 | + alias: { |
| 82 | + 'pytorch-sphinx-theme': './js/theme.js' |
| 83 | + } |
| 84 | + }, |
| 85 | + src: ['js/*.js'], |
| 86 | + dest: 'pytorch_sphinx_theme/static/js/theme.js' |
| 87 | + } |
| 88 | + }, |
| 89 | + uglify: { |
| 90 | + dist: { |
| 91 | + options: { |
| 92 | + sourceMap: false, |
| 93 | + mangle: { |
| 94 | + reserved: ['jQuery'] // Leave 'jQuery' identifier unchanged |
| 95 | + }, |
| 96 | + ie8: true // compliance with IE 6-8 quirks |
| 97 | + }, |
| 98 | + files: [{ |
| 99 | + expand: true, |
| 100 | + src: ['pytorch_sphinx_theme/static/js/*.js', '!pytorch_sphinx_theme/static/js/*.min.js'], |
| 101 | + dest: 'pytorch_sphinx_theme/static/js/', |
| 102 | + rename: function (dst, src) { |
| 103 | + // Use unminified file name for minified file |
| 104 | + return src; |
| 105 | + } |
| 106 | + }] |
| 107 | + } |
| 108 | + }, |
| 109 | + usebanner: { |
| 110 | + dist: { |
| 111 | + options: { |
| 112 | + position: 'top', |
| 113 | + banner: '/* <%= pkg.name %> version <%= pkg.version %> | MIT license */\n' + |
| 114 | + '/* Built <%= grunt.template.today("yyyymmdd HH:mm") %> */', |
| 115 | + linebreak: true |
| 116 | + }, |
| 117 | + files: { |
| 118 | + src: [ 'pytorch_sphinx_theme/static/js/theme.js', 'pytorch_sphinx_theme/static/css/theme.css' ] |
| 119 | + } |
| 120 | + } |
| 121 | + }, |
| 122 | + exec: { |
| 123 | + build_sphinx: { |
| 124 | + cmd: 'sphinx-build docs/ docs/build' |
| 125 | + } |
| 126 | + }, |
| 127 | + clean: { |
| 128 | + build: ["docs/build"], |
| 129 | + fonts: ["pytorch_sphinx_theme/static/fonts"], |
| 130 | + css: ["pytorch_sphinx_theme/static/css"], |
| 131 | + js: ["pytorch_sphinx_theme/static/js/*", "!pytorch_sphinx_theme/static/js/modernizr.min.js"] |
| 132 | + }, |
| 133 | + |
| 134 | + watch: { |
| 135 | + /* Compile scss changes into theme directory */ |
| 136 | + sass: { |
| 137 | + files: ['scss/*.scss'], |
| 138 | + tasks: ['sass:dev'] |
| 139 | + }, |
| 140 | + /* Changes in theme dir rebuild sphinx */ |
| 141 | + sphinx: { |
| 142 | + files: ['pytorch_sphinx_theme/**/*', 'README.rst', 'docs/**/*.rst', 'docs/**/*.py'], |
| 143 | + tasks: ['clean:build','exec:build_sphinx'] |
| 144 | + }, |
| 145 | + /* JavaScript */ |
| 146 | + browserify: { |
| 147 | + files: ['js/*.js'], |
| 148 | + tasks: ['browserify:dev'] |
| 149 | + }, |
| 150 | + /* live-reload the docs if sphinx re-builds */ |
| 151 | + livereload: { |
| 152 | + files: ['docs/build/**/*'], |
| 153 | + options: { livereload: true } |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + }); |
| 158 | + |
| 159 | + grunt.loadNpmTasks('grunt-exec'); |
| 160 | + grunt.loadNpmTasks('grunt-contrib-connect'); |
| 161 | + grunt.loadNpmTasks('grunt-contrib-watch'); |
| 162 | + grunt.loadNpmTasks('grunt-contrib-sass'); |
| 163 | + grunt.loadNpmTasks('grunt-contrib-clean'); |
| 164 | + grunt.loadNpmTasks('grunt-contrib-copy'); |
| 165 | + grunt.loadNpmTasks('grunt-open'); |
| 166 | + grunt.loadNpmTasks('grunt-browserify'); |
| 167 | + |
| 168 | + grunt.registerTask('default', ['clean','copy:fonts','sass:dev','browserify:dev','usebanner','exec:build_sphinx','connect','open','watch']); |
| 169 | + grunt.registerTask('build', ['clean','copy:fonts','sass:build','browserify:build','uglify','usebanner','exec:build_sphinx']); |
| 170 | +} |
0 commit comments