This repository has been archived by the owner on Sep 2, 2020. It is now read-only.
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
Showing
24 changed files
with
5,568 additions
and
2 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,31 @@ | ||
name: build | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [8.x, 10.x, 12.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: npm install, build, and test | ||
run: | | ||
npm ci | ||
npm run build --if-present | ||
npm test | ||
env: | ||
CI: true | ||
- name: Coveralls GitHub Action | ||
uses: coverallsapp/github-action@v1.0.1 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
github-token: ${{ secrets.github_token }} |
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 @@ | ||
node_modules | ||
coverage | ||
build | ||
dist | ||
spike.ts |
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,15 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Current TS File", | ||
"type": "node", | ||
"request": "launch", | ||
"args": ["${relativeFile}"], | ||
"runtimeArgs": ["--nolazy", "-r", "ts-node/register"], | ||
"sourceMaps": true, | ||
"cwd": "${workspaceRoot}", | ||
"protocol": "inspector", | ||
} | ||
] | ||
} |
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 |
---|---|---|
@@ -1,2 +1,11 @@ | ||
# source-view | ||
A simple tool for turning code into document | ||
# Source View · ![Build Status](https://github.com/mistlog/source-view/workflows/build/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/mistlog/source-view/badge.svg)](https://coveralls.io/github/mistlog/source-view) | ||
|
||
Source view is a simple tool for turning code into document. | ||
|
||
## Documentation | ||
|
||
The document is matained in [wiki](https://github.com/mistlog/source-view/wiki). | ||
|
||
## License | ||
|
||
Source view is [MIT licensed](https://github.com/mistlog/source-view/blob/master/LICENSE). |
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,32 @@ | ||
#!/usr/bin/env node | ||
import * as program from "commander"; | ||
//@ts-ignore | ||
import * as package_json from "../../package.json"; | ||
import { resolve, join } from "path"; | ||
import { lstatSync } from "fs"; | ||
import { GenerateDocument, GenerateDocumentWatch } from "./utility"; | ||
|
||
program.version(package_json.version) | ||
program.option("-w, --watch", "generate document in watch mode"); | ||
program.parse(process.argv); | ||
|
||
const args = program.args; | ||
|
||
if (args.length === 0) | ||
{ | ||
program.help(); | ||
} | ||
else | ||
{ | ||
const working_directory = process.cwd(); | ||
const [target] = args; | ||
if (target) | ||
{ | ||
const path = resolve(working_directory, target); | ||
const output_path = join(working_directory,"source-view"); | ||
if (lstatSync(path).isDirectory()) | ||
{ | ||
program.watch ? GenerateDocumentWatch(path, output_path) : GenerateDocument(path, output_path); | ||
} | ||
} | ||
} |
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,48 @@ | ||
import { readFileSync } from "fs"; | ||
import * as traverse from "filewalker"; | ||
import { CodeToMarkdown } from "../src/source-view"; | ||
import { outputFileSync, removeSync } from "fs-extra"; | ||
import { relative, join } from "path"; | ||
import { resolve } from "url"; | ||
import * as watch from "node-watch"; | ||
|
||
export function GenerateDocument(source: string, target: string) | ||
{ | ||
removeSync(target); | ||
traverse(source).on("file", (relative: string, stats: object, absolute: string) => | ||
{ | ||
if (absolute.endsWith(".tsx")) | ||
{ | ||
const code = readFileSync(absolute, "utf8"); | ||
const markdown = CodeToMarkdown(code); | ||
const output = relative.replace(".tsx", ".md") | ||
outputFileSync(join(target, output), markdown); | ||
} | ||
}).walk(); | ||
} | ||
|
||
export function GenerateDocumentWatch(source: string, target: string) | ||
{ | ||
GenerateDocument(source, target); | ||
|
||
//@ts-ignore | ||
watch(source, { recursive: true }, (event, path: string) => | ||
{ | ||
if (path.endsWith(".tsx")) | ||
{ | ||
try | ||
{ | ||
const code = readFileSync(path, "utf8"); | ||
const markdown = CodeToMarkdown(code); | ||
const relative_path = relative(source, path); | ||
const target_path = join(target, relative_path).replace(".tsx", ".md"); | ||
outputFileSync(target_path, markdown, "utf8"); | ||
console.log(event, target_path); | ||
} | ||
catch (error) | ||
{ | ||
console.log(error.message); | ||
} | ||
} | ||
}); | ||
} |
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 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
notify: true | ||
}; |
Oops, something went wrong.