|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +let fs = require("fs"); |
| 4 | +let yaml = require("js-yaml"); |
| 5 | + |
| 6 | +const articles = "articles"; |
| 7 | +const bookConfig = yaml.safeLoad(fs.readFileSync(`${articles}/config.yml`, "utf8")); |
| 8 | + |
| 9 | +const reviewPrefix = process.env["REVIEW_PREFIX"] || "bundle exec "; |
| 10 | +const reviewPostfix = process.env["REVIEW_POSTFIX"] || ""; // REVIEW_POSTFIX="-peg" npm run pdf とかするとPEGでビルドできるよ |
| 11 | +const reviewConfig = process.env["REVIEW_CONFIG_FILE"] || "config.yml"; // REVIEW_CONFIG_FILE="config-ebook.yml" npm run pdf のようにすると別のconfigでビルドできるよ |
| 12 | +const reviewPreproc = `${reviewPrefix}review-preproc${reviewPostfix}`; |
| 13 | +const reviewCompile = `${reviewPrefix}review-compile${reviewPostfix}`; |
| 14 | +const reviewPdfMaker = `${reviewPrefix}rake pdf ${reviewPostfix}`; |
| 15 | +const reviewEpubMaker = `${reviewPrefix}rake epub ${reviewPostfix}`; |
| 16 | +const reviewWebMaker = `${reviewPrefix}rake web ${reviewPostfix}`; |
| 17 | +const reviewTextMaker = `${reviewPrefix}rake text ${reviewPostfix}`; |
| 18 | +const reviewIDGXMLMaker = `${reviewPrefix}rake idgxml ${reviewPostfix}`; |
| 19 | +const reviewVivliostyle = `${reviewPrefix}rake vivliostyle ${reviewPostfix}`; |
| 20 | + |
| 21 | +module.exports = grunt => { |
| 22 | + grunt.initConfig({ |
| 23 | + clean: { |
| 24 | + review: { |
| 25 | + src: [ |
| 26 | + `${articles}/${bookConfig.bookname}-*/`, // pdf, epub temp dir |
| 27 | + `${articles}/*.pdf`, |
| 28 | + `${articles}/*.epub`, |
| 29 | + `${articles}/*.html`, |
| 30 | + `${articles}/*.md`, |
| 31 | + `${articles}/*.xml`, |
| 32 | + `${articles}/*.txt`, |
| 33 | + `${articles}/webroot` |
| 34 | + ] |
| 35 | + } |
| 36 | + }, |
| 37 | + shell: { |
| 38 | + preprocess: { |
| 39 | + options: { |
| 40 | + execOptions: { |
| 41 | + cwd: articles, |
| 42 | + } |
| 43 | + }, |
| 44 | + command: `${reviewPreproc} -r --tabwidth=2 **/*.re` |
| 45 | + }, |
| 46 | + compile2text: { |
| 47 | + options: { |
| 48 | + execOptions: { |
| 49 | + cwd: articles, |
| 50 | + } |
| 51 | + }, |
| 52 | + command: `${reviewTextMaker}` |
| 53 | + }, |
| 54 | + compile2markdown: { |
| 55 | + options: { |
| 56 | + execOptions: { |
| 57 | + cwd: articles, |
| 58 | + } |
| 59 | + }, |
| 60 | + command: `${reviewCompile} --target=markdown` |
| 61 | + }, |
| 62 | + compile2html: { |
| 63 | + options: { |
| 64 | + execOptions: { |
| 65 | + cwd: articles, |
| 66 | + } |
| 67 | + }, |
| 68 | + command: `${reviewCompile} --target=html --stylesheet=style.css --chapterlink` |
| 69 | + }, |
| 70 | + compile2latex: { |
| 71 | + options: { |
| 72 | + execOptions: { |
| 73 | + cwd: articles, |
| 74 | + } |
| 75 | + }, |
| 76 | + command: `${reviewCompile} --target=latex --footnotetext` |
| 77 | + }, |
| 78 | + compile2idgxml: { |
| 79 | + options: { |
| 80 | + execOptions: { |
| 81 | + cwd: articles, |
| 82 | + } |
| 83 | + }, |
| 84 | + command: `${reviewCompile} --target=idgxml` |
| 85 | + }, |
| 86 | + compile2pdf: { |
| 87 | + options: { |
| 88 | + execOptions: { |
| 89 | + cwd: articles, |
| 90 | + } |
| 91 | + }, |
| 92 | + command: `${reviewPdfMaker}` |
| 93 | + }, |
| 94 | + compile2epub: { |
| 95 | + options: { |
| 96 | + execOptions: { |
| 97 | + cwd: articles, |
| 98 | + } |
| 99 | + }, |
| 100 | + command: `${reviewEpubMaker}` |
| 101 | + }, |
| 102 | + compile2web: { |
| 103 | + options: { |
| 104 | + execOptions: { |
| 105 | + cwd: articles, |
| 106 | + } |
| 107 | + }, |
| 108 | + command: `${reviewWebMaker}` |
| 109 | + }, |
| 110 | + compile2idgxmlmaker: { |
| 111 | + options: { |
| 112 | + execOptions: { |
| 113 | + cwd: articles, |
| 114 | + } |
| 115 | + }, |
| 116 | + command: `${reviewIDGXMLMaker}` |
| 117 | + }, |
| 118 | + compile2vivliostyle: { |
| 119 | + options: { |
| 120 | + execOptions: { |
| 121 | + cwd: articles, |
| 122 | + } |
| 123 | + }, |
| 124 | + command: `${reviewVivliostyle}` |
| 125 | + } |
| 126 | + } |
| 127 | + }); |
| 128 | + |
| 129 | + function generateTask(target) { |
| 130 | + return ["clean", "shell:preprocess", `shell:compile2${target}`]; |
| 131 | + } |
| 132 | + |
| 133 | + grunt.registerTask( |
| 134 | + "default", |
| 135 | + "原稿をコンパイルしてPDFファイルにする", |
| 136 | + "pdf"); |
| 137 | + |
| 138 | + grunt.registerTask( |
| 139 | + "text", |
| 140 | + "原稿をコンパイルしてTextファイルにする", |
| 141 | + generateTask("text")); |
| 142 | + |
| 143 | + grunt.registerTask( |
| 144 | + "markdown", |
| 145 | + "原稿をコンパイルしてMarkdownファイルにする", |
| 146 | + generateTask("markdown")); |
| 147 | + |
| 148 | + grunt.registerTask( |
| 149 | + "html", |
| 150 | + "原稿をコンパイルしてHTMLファイルにする", |
| 151 | + generateTask("html")); |
| 152 | + |
| 153 | + grunt.registerTask( |
| 154 | + "idgxmlmaker", |
| 155 | + "原稿をコンパイルしてInDesign用XMLファイルにする", |
| 156 | + generateTask("idgxmlmaker")); |
| 157 | + |
| 158 | + grunt.registerTask( |
| 159 | + "pdf", |
| 160 | + "原稿をコンパイルしてLaTeXでpdfファイルにする", |
| 161 | + generateTask("pdf")); |
| 162 | + |
| 163 | + grunt.registerTask( |
| 164 | + "epub", |
| 165 | + "原稿をコンパイルしてepubファイルにする", |
| 166 | + generateTask("epub")); |
| 167 | + |
| 168 | + grunt.registerTask( |
| 169 | + "web", |
| 170 | + "原稿をコンパイルしてWebページファイルにする", |
| 171 | + generateTask("web")); |
| 172 | + |
| 173 | + grunt.registerTask( |
| 174 | + "vivliostyle", |
| 175 | + "原稿をコンパイルしてVivliostyle-CLIでpdfファイルにする", |
| 176 | + generateTask("vivliostyle")); |
| 177 | + |
| 178 | + require('load-grunt-tasks')(grunt); |
| 179 | +}; |
0 commit comments