|
1 |
| -module.exports = function (grunt) { |
2 |
| - function generateTypeScriptCompileSettings() { |
3 |
| - var srcFileList = grunt.file.expand([ |
4 |
| - 'code/**/*.ts', |
5 |
| - '!code/**/*-invalid.ts', // コンパイルが通らないコード |
6 |
| - '!code/**/invalid.ts', // コンパイルが通らないコード |
7 |
| - '!code/**/*-invalid.d.ts', // コンパイルが通らないコード |
8 |
| - '!code/**/invalid.d.ts', // コンパイルが通らないコード |
9 |
| - '!code/**/*-1.3.0.ts', // 1.3.0 限定コード |
10 |
| - '!code/**/node_modules/**/*.ts' |
11 |
| - ]); |
12 |
| - var tasks = {}; |
13 |
| - srcFileList.forEach(function (file) { |
14 |
| - taskName = file.replace(/\./g, "-dot-"); |
15 |
| - var task = tasks[taskName] = { |
16 |
| - src: file, |
17 |
| - options: { |
18 |
| - compiler: './node_modules/.bin/tsc', |
19 |
| - target: 'es6', |
20 |
| - module: 'commonjs', |
21 |
| - noImplicitAny: true, |
22 |
| - sourceMap: false, |
23 |
| - declaration: false |
24 |
| - } |
25 |
| - }; |
26 |
| - switch (file) { |
27 |
| - case "notExists/hogehoge.ts": |
28 |
| - task.options.declaration = true; |
29 |
| - break; |
30 |
| - default: |
31 |
| - break; |
32 |
| - } |
33 |
| - switch (file) { |
34 |
| - case "notExists/fugafuga.ts": |
35 |
| - task.options.module = "amd"; |
36 |
| - break; |
37 |
| - default: |
38 |
| - break; |
39 |
| - } |
40 |
| - }); |
41 |
| - return tasks; |
42 |
| - } |
| 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}`; |
43 | 17 |
|
| 18 | +module.exports = grunt => { |
44 | 19 | grunt.initConfig({
|
45 |
| - ts: generateTypeScriptCompileSettings(), |
46 |
| - tslint: { |
47 |
| - options: { |
48 |
| - configuration: grunt.file.readJSON("tslint.json") |
49 |
| - }, |
50 |
| - files: { |
| 20 | + clean: { |
| 21 | + review: { |
51 | 22 | src: [
|
52 |
| - 'code/**/*.ts' |
| 23 | + `${articles}/${bookConfig.bookname}-*/`, // pdf, epub temp dir |
| 24 | + `${articles}/*.pdf`, |
| 25 | + `${articles}/*.epub`, |
| 26 | + `${articles}/*.html`, |
| 27 | + `${articles}/*.xml`, |
| 28 | + `${articles}/*.txt` |
53 | 29 | ]
|
| 30 | + }, |
| 31 | + publish: { |
| 32 | + src: `${publish}/` |
54 | 33 | }
|
55 | 34 | },
|
56 |
| - dtsm: { |
57 |
| - client: { |
58 |
| - options: { |
59 |
| - // optional: specify config file |
60 |
| - confog: './dtsm.json' |
61 |
| - } |
62 |
| - } |
63 |
| - }, |
64 |
| - less: { |
65 |
| - blog: { |
| 35 | + sass: { |
| 36 | + dist: { |
66 | 37 | options: {
|
67 |
| - paths: ["articles"] |
| 38 | + bundleExec: true, |
| 39 | + sourcemap: 'none' |
68 | 40 | },
|
69 | 41 | files: {
|
70 |
| - "articles/style.css": "articles/style.less" |
71 |
| - } |
72 |
| - }, |
73 |
| - epub: { |
74 |
| - options: { |
75 |
| - paths: ["articles"] |
76 |
| - }, |
77 |
| - files: { |
78 |
| - "articles/epub.css": "articles/review.less" |
| 42 | + 'articles/style.css': 'articles/style.scss', |
| 43 | + 'articles/style-web.css': 'articles/style-web.scss', |
79 | 44 | }
|
80 | 45 | }
|
81 | 46 | },
|
82 | 47 | copy: {
|
83 |
| - blog: { |
| 48 | + publish: { |
84 | 49 | files: [
|
85 |
| - {src: 'articles/_review-ext.rb', dest: 'articles/review-ext.rb'}, |
86 |
| - {src: 'articles/layouts/_layout.html.erb', dest: 'articles/layouts/layout.html.erb'} |
| 50 | + {expand: true, cwd: `${articles}/webroot/`, src: ['**'], dest: `${publish}/`} |
87 | 51 | ]
|
88 |
| - }, |
89 |
| - public: { |
90 |
| - expand: true, |
91 |
| - cwd: 'articles/', |
92 |
| - src: [ |
93 |
| - '*.html', |
94 |
| - 'style.css', |
95 |
| - 'images/**' |
96 |
| - ], |
97 |
| - dest: 'public/' |
98 | 52 | }
|
99 | 53 | },
|
100 |
| - clean: { |
101 |
| - ts: { |
102 |
| - src: [ |
103 |
| - 'code-2.0/**/*.js', |
104 |
| - 'code-2.0/**/*.js.map' |
105 |
| - ] |
106 |
| - }, |
107 |
| - review: { |
108 |
| - src: [ |
109 |
| - 'articles/c87-typescript-pdf/', |
110 |
| - 'articles/*.pdf', |
111 |
| - 'articles/*.epub', |
112 |
| - 'articles/*.html', |
113 |
| - 'articles/*.css', |
114 |
| - // grifletがgruntを叩けないので |
115 |
| - '!articles/epub.css', |
116 |
| - // epubとhtmlでカスタムテンプレ利用有無を切り替える |
117 |
| - 'articles/layouts/layout.html.erb', |
118 |
| - 'articles/review-ext.rb' |
119 |
| - ] |
120 |
| - }, |
121 |
| - public: { |
122 |
| - src: [ |
123 |
| - 'public/' |
124 |
| - ] |
125 |
| - } |
126 |
| - }, |
127 |
| - exec: { |
| 54 | + shell: { |
128 | 55 | preprocess: {
|
129 |
| - cwd: "./articles", |
130 |
| - cmd: function () { |
131 |
| - var command = "bundle exec review-preproc"; |
132 |
| - var files = [ |
133 |
| - "articles" |
134 |
| - ]; |
135 |
| - var exec = command + " -r --tabwidth=2 *.re"; |
136 |
| - console.log(exec); |
137 |
| - return exec; |
138 |
| - } |
| 56 | + options: { |
| 57 | + execOptions: { |
| 58 | + cwd: articles, |
| 59 | + } |
| 60 | + }, |
| 61 | + command: `${reviewPreproc} -r --tabwidth=2 *.re` |
139 | 62 | },
|
140 | 63 | compile2text: {
|
141 |
| - cwd: "./articles", |
142 |
| - cmd: function () { |
143 |
| - return "bundle exec review-compile --all --target=text --footnotetext --stylesheet=style.css"; |
144 |
| - } |
| 64 | + options: { |
| 65 | + execOptions: { |
| 66 | + cwd: articles, |
| 67 | + } |
| 68 | + }, |
| 69 | + command: `${reviewCompile} --target=text` |
145 | 70 | },
|
146 | 71 | compile2html: {
|
147 |
| - cwd: "./articles", |
148 |
| - cmd: function () { |
149 |
| - return "bundle exec review-compile --all --target=html --footnotetext --stylesheet=style.css --chapterlink"; |
150 |
| - } |
| 72 | + options: { |
| 73 | + execOptions: { |
| 74 | + cwd: articles, |
| 75 | + } |
| 76 | + }, |
| 77 | + command: `${reviewCompile} --target=html --yaml=config.yml --chapterlink --footnotetext` |
151 | 78 | },
|
152 | 79 | compile2latex: {
|
153 |
| - cwd: "./articles", |
154 |
| - cmd: function () { |
155 |
| - return "bundle exec review-compile --all --target=latex --footnotetext --stylesheet=style.css"; |
156 |
| - } |
| 80 | + options: { |
| 81 | + execOptions: { |
| 82 | + cwd: articles, |
| 83 | + } |
| 84 | + }, |
| 85 | + command: `${reviewCompile} --target=latex --footnotetext` |
157 | 86 | },
|
158 | 87 | compile2idgxml: {
|
159 |
| - cwd: "./articles", |
160 |
| - cmd: function () { |
161 |
| - return "bundle exec review-compile --all --target=idgxml --footnotetext --stylesheet=style.css"; |
162 |
| - } |
| 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` |
163 | 102 | },
|
164 | 103 | compile2pdf: {
|
165 |
| - cwd: "./articles", |
166 |
| - cmd: function () { |
167 |
| - return "bundle exec review-pdfmaker config.yml"; |
168 |
| - } |
| 104 | + options: { |
| 105 | + execOptions: { |
| 106 | + cwd: articles, |
| 107 | + } |
| 108 | + }, |
| 109 | + command: `${reviewPdfMaker} config.yml` |
169 | 110 | },
|
170 | 111 | compile2epub: {
|
171 |
| - cwd: "./articles", |
172 |
| - cmd: function () { |
173 |
| - return "bundle exec review-epubmaker config.yml"; |
174 |
| - } |
175 |
| - } |
| 112 | + options: { |
| 113 | + execOptions: { |
| 114 | + cwd: articles, |
| 115 | + } |
| 116 | + }, |
| 117 | + command: `${reviewEpubMaker} config.yml` |
| 118 | + }, |
176 | 119 | }
|
177 | 120 | });
|
178 | 121 |
|
179 | 122 | function generateTask(target, pretask) {
|
180 | 123 | pretask = pretask || [];
|
181 |
| - return [/* 'clean' */, /* 'typescript-formatter', */ 'ts'].concat(pretask).concat(['exec:preprocess', 'exec:compile2' + target]); |
| 124 | + return ["clean"].concat(pretask).concat(["shell:preprocess", `shell:compile2${target}`]); |
182 | 125 | }
|
183 | 126 |
|
184 | 127 | grunt.registerTask(
|
185 |
| - 'default', |
| 128 | + "default", |
186 | 129 | "原稿をコンパイルしてPDFファイルにする",
|
187 | 130 | "pdf");
|
188 | 131 |
|
189 | 132 | grunt.registerTask(
|
190 |
| - 'text', |
| 133 | + "text", |
191 | 134 | "原稿をコンパイルしてTextファイルにする",
|
192 | 135 | generateTask("text"));
|
193 | 136 |
|
194 | 137 | grunt.registerTask(
|
195 |
| - 'html', |
| 138 | + "html", |
196 | 139 | "原稿をコンパイルしてHTMLファイルにする",
|
197 |
| - generateTask("html", ['less:blog', 'copy:blog']).concat(['copy:public'])); |
| 140 | + generateTask("html", ["sass"])); |
198 | 141 |
|
199 | 142 | grunt.registerTask(
|
200 |
| - 'idgxml', |
| 143 | + "idgxml", |
201 | 144 | "原稿をコンパイルしてInDesign用XMLファイルにする",
|
202 | 145 | generateTask("idgxml"));
|
203 | 146 |
|
204 | 147 | grunt.registerTask(
|
205 |
| - 'pdf', |
| 148 | + "web", |
| 149 | + "原稿をコンパイルしてwebページにする", |
| 150 | + generateTask("web", ["sass"]).concat(['copy:publish'])); |
| 151 | + |
| 152 | + grunt.registerTask( |
| 153 | + "pdf", |
206 | 154 | "原稿をコンパイルしてpdfファイルにする",
|
207 | 155 | generateTask("pdf"));
|
208 | 156 |
|
209 | 157 | grunt.registerTask(
|
210 |
| - 'epub', |
| 158 | + "epub", |
211 | 159 | "原稿をコンパイルしてepubファイルにする",
|
212 |
| - generateTask("epub", ['less:epub'])); |
| 160 | + generateTask("epub")); |
213 | 161 |
|
214 | 162 | require('load-grunt-tasks')(grunt);
|
215 | 163 | };
|
0 commit comments