Skip to content

Commit 14eff81

Browse files
committed
ビルド手順をC90系のリポジトリと同様の側に寄せた
1 parent d50bfcb commit 14eff81

File tree

4 files changed

+112
-177
lines changed

4 files changed

+112
-177
lines changed

Gruntfile.js

Lines changed: 102 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -1,215 +1,163 @@
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}`;
4317

18+
module.exports = grunt => {
4419
grunt.initConfig({
45-
ts: generateTypeScriptCompileSettings(),
46-
tslint: {
47-
options: {
48-
configuration: grunt.file.readJSON("tslint.json")
49-
},
50-
files: {
20+
clean: {
21+
review: {
5122
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`
5329
]
30+
},
31+
publish: {
32+
src: `${publish}/`
5433
}
5534
},
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: {
6637
options: {
67-
paths: ["articles"]
38+
bundleExec: true,
39+
sourcemap: 'none'
6840
},
6941
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',
7944
}
8045
}
8146
},
8247
copy: {
83-
blog: {
48+
publish: {
8449
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}/`}
8751
]
88-
},
89-
public: {
90-
expand: true,
91-
cwd: 'articles/',
92-
src: [
93-
'*.html',
94-
'style.css',
95-
'images/**'
96-
],
97-
dest: 'public/'
9852
}
9953
},
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: {
12855
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`
13962
},
14063
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`
14570
},
14671
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`
15178
},
15279
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`
15786
},
15887
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`
163102
},
164103
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`
169110
},
170111
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+
},
176119
}
177120
});
178121

179122
function generateTask(target, pretask) {
180123
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}`]);
182125
}
183126

184127
grunt.registerTask(
185-
'default',
128+
"default",
186129
"原稿をコンパイルしてPDFファイルにする",
187130
"pdf");
188131

189132
grunt.registerTask(
190-
'text',
133+
"text",
191134
"原稿をコンパイルしてTextファイルにする",
192135
generateTask("text"));
193136

194137
grunt.registerTask(
195-
'html',
138+
"html",
196139
"原稿をコンパイルしてHTMLファイルにする",
197-
generateTask("html", ['less:blog', 'copy:blog']).concat(['copy:public']));
140+
generateTask("html", ["sass"]));
198141

199142
grunt.registerTask(
200-
'idgxml',
143+
"idgxml",
201144
"原稿をコンパイルしてInDesign用XMLファイルにする",
202145
generateTask("idgxml"));
203146

204147
grunt.registerTask(
205-
'pdf',
148+
"web",
149+
"原稿をコンパイルしてwebページにする",
150+
generateTask("web", ["sass"]).concat(['copy:publish']));
151+
152+
grunt.registerTask(
153+
"pdf",
206154
"原稿をコンパイルしてpdfファイルにする",
207155
generateTask("pdf"));
208156

209157
grunt.registerTask(
210-
'epub',
158+
"epub",
211159
"原稿をコンパイルしてepubファイルにする",
212-
generateTask("epub", ['less:epub']));
160+
generateTask("epub"));
213161

214162
require('load-grunt-tasks')(grunt);
215163
};

circle.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,9 @@ machine:
1313
GIT_AUTHOR_NAME: vvakame
1414
GIT_AUTHOR_EMAIL: [email protected]
1515

16-
checkout:
17-
post:
18-
- git submodule update --init
19-
2016
dependencies:
2117
pre:
22-
# LaTeX入れようかと思ったけど必要になるまではいいや
23-
# https://github.com/TechBooster/FirstStepReVIEW/blob/master/article/how_to_install.re
24-
- npm install -g grunt-cli
25-
- gem install bundler
18+
- npm run global
2619

2720
test:
2821
override:

dtsm.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,24 @@
77
"npm": "3.0.0"
88
},
99
"scripts": {
10-
"setup": "gem install bundler",
11-
"preinstall": "git submodule update --init",
10+
"global": "gem install bundler",
1211
"postinstall": "bundle install",
13-
"update": "git submodule update",
14-
"build": "tsc -p ./ && grunt pdf"
12+
"pdf": "grunt pdf",
13+
"web": "grunt web",
14+
"html": "grunt html",
15+
"build:ts": "tsc -p ./"
1516
},
1617
"dependencies": {},
1718
"devDependencies": {
1819
"grunt": "^1.0.1",
20+
"grunt-cli": "^1.2.0",
1921
"grunt-contrib-clean": "^1.0.0",
2022
"grunt-contrib-copy": "^1.0.0",
2123
"grunt-contrib-less": "^1.3.0",
22-
"grunt-dtsm": "^1.0.0",
23-
"grunt-exec": "^1.0.0",
24+
"grunt-contrib-sass": "^1.0.0",
2425
"grunt-open": "^0.2.3",
25-
"grunt-ts": "^5.5.1",
26-
"grunt-tslint": "^3.1.1",
26+
"grunt-shell": "^1.3.0",
27+
"js-yaml": "^3.6.1",
2728
"load-grunt-tasks": "^3.5.0",
2829
"tslint": "^3.13.0",
2930
"typescript": "^2.0.0",

0 commit comments

Comments
 (0)