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