-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 86bdcae
Showing
18 changed files
with
4,278 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
repo_token: OJQFJsqKb354S0h7sEmemBDpWbovm3Xha |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
--- | ||
`) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Hello world!</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Hello | ||
slug: home | ||
--- | ||
<h1>Hello world!</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
meta: | ||
'twitter:og': twitter-ogp | ||
--- | ||
<h1>Hello world!</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: Syntax Error | ||
miss: space error | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
設定の前に文字列が合った場合 | ||
|
||
--- | ||
title: Before Contents | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
title: 複数のSectionがある時 | ||
--- | ||
設定の前に文字列が合った場合 | ||
|
||
--- | ||
title: 2つ目のSection | ||
section: 2 | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
Oops, something went wrong.