Skip to content

Commit

Permalink
Merge pull request #186 from asciidwango/feat-nodecli-read-file-toc
Browse files Browse the repository at this point in the history
feat(nodecli): read-fileの見出しとサンプルコードの完成形
  • Loading branch information
Suguru Inatomi authored Feb 9, 2017
2 parents c29e902 + 53db2ee commit 3806e00
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion source/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
- [Node.jsでCLIアプリ](use-case/nodecli/README.md)
- [Node.jsでHello World](use-case/nodecli/helloworld/README.md)
- [コマンドライン引数を処理する](use-case/nodecli/argument-parse/README.md)
- ファイルを読み込む
- [ファイルを読み込む](use-case/nodecli/read-file/README.md)
- MarkdownをHTMLに変換する
- ユニットテストを記述する
- TODOアプリ
16 changes: 16 additions & 0 deletions source/use-case/nodecli/read-file/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
author: laco
---

# ファイルを読み込む

前のセクションではコマンドライン引数を受け取って、Node.jsのスクリプト中で利用できるようになりました。
このセクションではコマンドライン引数に指定されたファイルを読み込んで、標準出力に表示してみましょう。

## ファイルパスを受け取る

## fsモジュールを使ってファイルを読み込む

### fsモジュール

### readFile関数を使う
14 changes: 14 additions & 0 deletions source/use-case/nodecli/read-file/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const program = require("commander");
const fs = require("fs");

program.parse(process.argv);
const filePath = program.args[0];
fs.readFile(filePath, (err, file) => {
if (err) {
console.error(err);
process.exit(1);
return;
}
const text = file.toString();
console.log(text);
});
15 changes: 15 additions & 0 deletions source/use-case/nodecli/read-file/src/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "nodecli",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"commander": "^2.9.0"
}
}
1 change: 1 addition & 0 deletions source/use-case/nodecli/read-file/src/sample.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# sample
4 changes: 3 additions & 1 deletion test/front-matter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ describe("front-matter", function() {
// 目次は除く
`!${sourceDir}/index.html.md`,
`!${sourceDir}/README.md`,
`!${sourceDir}/OUTLINE.md`
`!${sourceDir}/OUTLINE.md`,
// サンプルコードの一部
`!${sourceDir}/use-case/nodecli/read-file/src/sample.md`,
]);
context("author", function() {
files.forEach(filePath => {
Expand Down

0 comments on commit 3806e00

Please sign in to comment.