Skip to content

Commit

Permalink
feat(init): 初期化
Browse files Browse the repository at this point in the history
  • Loading branch information
Himenon committed Sep 29, 2018
0 parents commit 86bdcae
Show file tree
Hide file tree
Showing 18 changed files with 4,278 additions and 0 deletions.
1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repo_token: OJQFJsqKb354S0h7sEmemBDpWbovm3Xha
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.site
.nyc_output
coverage
package-lock.json
node_modules
lib
test.js.snap
.vscode
*.log
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: node_js
cache: yarn
before_script:
- yarn install
node_js:
- "9.8.0"
script:
- commitlint-travis
- yarn run test:coverage
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# JavaScript Library Sample

[![Build Status](https://travis-ci.org/Himenon/js-one-shot.svg?branch=master)](https://travis-ci.org/Himenon/js-one-shot)

[![Coverage Status](https://coveralls.io/repos/github/Himenon/js-one-shot/badge.svg?branch=master)](https://coveralls.io/github/Himenon/js-one-shot?branch=master)

## Library

* gray-matter

## Setup commit-lint

<https://github.com/marionebl/commitlint>

```bash
yarn add -D @commitlint/config-conventional @commitlint/cli husky pre-commit
```

## Setup jest

```ts
yarn add -D jest jest-cli ts-jest @types/jest
```
34 changes: 34 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"automock": false,
"unmockedModulePathPatterns": [
"<rootDir>/node_modules/*"
],
"roots": [
"<rootDir>/src"
],
"globals": {
"__DEV__": true,
"ts-jest": {
"tsConfig": "tsconfig.json"
}
},
"moduleDirectories": [
"node_modules"
],
"moduleFileExtensions": [
"js",
"jsx",
"node",
"ts",
"tsx"
],
"testMatch": [
"**/__tests__/*.test.+(ts|tsx)"
],
"collectCoverage": true,
"transform": {
"^.+\\.(ts|tsx)$": "ts-jest"
},
"preset": "ts-jest",
"testEnvironment": "node"
}
35 changes: 35 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "js-one-shot",
"version": "1.0.0",
"description": "Libraryの調査",
"main": "entry.js",
"author": "Himenon",
"license": "MIT",
"scripts": {
"test": "jest -c jest.config.json",
"test:coverage": "yarn run test -- --coverage && cat ./coverage/lcov.info | npx coveralls",
"test:watch": "yarn run test -- --watchAll"
},
"devDependencies": {
"@commitlint/cli": "^7.1.2",
"@commitlint/config-conventional": "^7.1.2",
"@types/jest": "^23.3.2",
"@types/js-yaml": "^3.11.2",
"@types/node": "^10.11.3",
"coveralls": "^3.0.2",
"gray-matter": "^4.0.1",
"husky": "^1.0.1",
"jest": "^23.6.0",
"jest-cli": "^23.6.0",
"js-yaml": "^3.12.0",
"pre-commit": "^1.2.2",
"ts-jest": "^23.10.2",
"ts-node": "^7.0.1",
"typescript": "^3.1.1"
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}
66 changes: 66 additions & 0 deletions src/gray-matter/__tests__/gray-matter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { getConfigDataFromMarkdown } from "../oneshot";
import * as path from 'path'
import { YAMLException } from 'js-yaml'

test("通常のMarkdownが読み込み可能か", () => {
const params = getConfigDataFromMarkdown(path.join(__dirname, "./sample-01.md"));
expect(params.data).toEqual({})
expect(params.content).toEqual('<h1>Hello world!</h1>\n')
});

test("MarkdownのHeaderに書いた設定が取得可能か", () => {
const params = getConfigDataFromMarkdown(path.join(__dirname, "./sample-02.md"));
expect(params.data).toEqual({
title: 'Hello',
slug: 'home'
})
expect(params.content).toEqual('<h1>Hello world!</h1>\n')
});

test("設定の階層構造の読み込みが可能か", () => {
const params = getConfigDataFromMarkdown(path.join(__dirname, "./sample-03.md"));
expect(params.data).toEqual({
meta: {
'twitter:og': 'twitter-ogp'
}
})
expect(params.content).toEqual('<h1>Hello world!</h1>\n')
});

test("文法が間違っているときのExceptionの確認", () => {
const t = () => {
getConfigDataFromMarkdown(path.join(__dirname, "./sample-04.md"))
}
expect(t).toThrow(YAMLException);
})

test("YAMLの設定の前に文字列が合った場合のExceptionの確認", () => {
const params = getConfigDataFromMarkdown(path.join(__dirname, "./sample-05.md"))
expect(params.data).not.toEqual({
meta: {
title: 'Before Contents'
}
})
expect(params.data).toEqual({})
expect(params.content).not.toEqual('設定の前に文字列が合った場合')
expect(params.content).toEqual(`設定の前に文字列が合った場合
---
title: Before Contents
---
`)
})

test("複数のSectionがあるときの処理", () => {
const params = getConfigDataFromMarkdown(path.join(__dirname, "./sample-06.md"))
expect(params.data).toEqual({
title: '複数のSectionがある時'
})
expect(params.content).toEqual(`設定の前に文字列が合った場合
---
title: 2つ目のSection
section: 2
---
`)
})
1 change: 1 addition & 0 deletions src/gray-matter/__tests__/sample-01.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hello world!</h1>
5 changes: 5 additions & 0 deletions src/gray-matter/__tests__/sample-02.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Hello
slug: home
---
<h1>Hello world!</h1>
5 changes: 5 additions & 0 deletions src/gray-matter/__tests__/sample-03.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
meta:
'twitter:og': twitter-ogp
---
<h1>Hello world!</h1>
4 changes: 4 additions & 0 deletions src/gray-matter/__tests__/sample-04.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: Syntax Error
miss: space error
---
5 changes: 5 additions & 0 deletions src/gray-matter/__tests__/sample-05.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
設定の前に文字列が合った場合

---
title: Before Contents
---
9 changes: 9 additions & 0 deletions src/gray-matter/__tests__/sample-06.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: 複数のSectionがある時
---
設定の前に文字列が合った場合

---
title: 2つ目のSection
section: 2
---
9 changes: 9 additions & 0 deletions src/gray-matter/oneshot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as fs from 'fs'
import * as matter from 'gray-matter'
import { resolvePath } from '../utils'

export function getConfigDataFromMarkdown(filePath: string) {
const raw = fs.readFileSync(resolvePath(filePath), 'utf8')
const params = matter(raw)
return params
}
5 changes: 5 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as path from 'path'
const cwd = process.cwd()

export const resolvePath = (relativePath: string) => path.resolve(cwd, relativePath)

52 changes: 52 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"formatCodeOptions": {
"indentSize": 2,
"tabSize": 2
},
"compilerOptions": {
"outDir": "lib",
"module": "commonjs",
"target": "esnext",
"lib": [
"es6",
"dom",
"esnext"
],
"experimentalDecorators": true,
"removeComments": true,
"sourceMap": true,
"allowJs": true,
"jsx": "react",
"moduleResolution": "node",
"rootDir": ".",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strict": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"baseUrl": "./src",
"paths": {
"gray-matter": [
"./typings/grapy-matter"
]
},
},
"include": [
"src/**/*.ts"
],
"exclude": [
"./node_modules",
"./dist",
"jest"
],
"ordered-imports": [
true,
{
"import-sources-order": "any",
"named-imports-order": "case-insensitive"
}
]
}
Loading

0 comments on commit 86bdcae

Please sign in to comment.