forked from verekia/js-stack-from-scratch
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathRakefile
67 lines (54 loc) · 3.34 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require 'fileutils'
require 'rake/clean'
CONCAT_FILE = "qiita.md"
HEADER_COMMENT = <<-EOB
(訳者注: これは、[JavaScript Stack from Scratch](https://github.com/verekia/js-stack-from-scratch)を翻訳し、まとめて読めるように1ファイルにしたものです。元の翻訳と各種ファイルについては、[日本語訳forkリポジトリ](https://github.com/takahashim/js-stack-from-scratch)を参照してください。また、原文が活発に更新されているため、訳文も追従して更新されます。ご了承ください。)
EOB
TOC = <<-EOB
[1 - Node、NPM、Yarn、そして package.json](#1---nodenpmyarnそしてpackagejson)
[2 - packageのインストールと使用](#2---パッケージのインストールと利用)
[3 - Babel と Gulp による ES6 のセットアップ](#3---babelとgulpによるes6のセットアップ)
[4 - ES6のクラス構文を使う](#4---es6のクラス構文を使う)
[5 - ES6モジュール構文](#5---es6モジュール構文)
[6 - ESLint](#6---eslint)
[7 - Webpackによるクライアントアプリ](#7---webpackによるクライアントアプリ)
[8 - React](#8---react)
[9 - Redux](#9---redux)
[10 - Immutable JS と Redux の改良](#10---immutable-jsとreduxの改良)
[11 - Mocha、Chai、Sinonによるテスティング](#11---mochachaisinonによるテスティング)
[12 - Flowによる型検査](#12---flow)
EOB
IMAGES = <<EOB
[](https://yarnpkg.com/)[](https://facebook.github.io/react/)[](http://gulpjs.com/)[](http://redux.js.org/)[](http://eslint.org/)[](https://webpack.github.io/)[](https://mochajs.org/)[](http://chaijs.com/)[](https://flowtype.org/)
EOB
def preface
readme0 = File.read("README.md")
readme0.gsub!(/(## 目次\n).*(## 今後の予定\n)/m){ $1 + TOC + $2 }
readme0.gsub!(/(## 翻訳\n).*(## Credits\n)/m){ $2 }
readme0.gsub!(%r{\[!\[Build Status\].*\(https://flowtype.org/\)\n}m){ IMAGES }
HEADER_COMMENT + readme0
end
def trimming(file)
content = File.read(file)
content.gsub!(/^\s*次章.*$/m,"")
content.gsub!(/^\s*\[前章.*$/m,"")
content
end
def detect_chapnum(file)
f1 = file.gsub(%r|tutorial/|, "")
f2 = f1.gsub(/\-.*$/,"")
f2.to_i
end
task :default => :concat
desc 'cocant all README.md files'
task :concat do
chaps = []
chaps[0] = preface
Dir.glob("tutorial/*/README.md").each do |file|
num = detect_chapnum(file)
chaps[num] = trimming(file)
end
File.open(CONCAT_FILE,"w") do |f|
f.write(chaps.join("\n\n"))
end
end