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
48 changed files
with
7,954 additions
and
1 deletion.
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 | ||
spike.ts | ||
build | ||
dist |
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 @@ | ||
# typedraft | ||
# TypeDraft · ![Build Status](https://github.com/mistlog/typedraft/workflows/build/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/mistlog/typedraft/badge.svg)](https://coveralls.io/github/mistlog/typedraft) | ||
|
||
TypeDraft is a superset of typescript with built-in support for DSL extension and literate programming. | ||
|
||
## Documentation | ||
|
||
The document is matained in [wiki](https://github.com/mistlog/typedraft/wiki). | ||
|
||
## License | ||
|
||
TypeDraft is [MIT licensed](https://github.com/mistlog/typedraft/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,47 @@ | ||
#!/usr/bin/env node | ||
import * as program from "commander"; | ||
//@ts-ignore | ||
import * as package_json from "../../package.json"; | ||
import { ComposeFile, ComposeDirectory, InspectDirectory, InspectFile } from "./literator"; | ||
import { resolve, join } from "path"; | ||
import { lstatSync } from "fs"; | ||
import { readJsonSync } from "fs-extra"; | ||
import { config } from "./config.js"; | ||
|
||
program.version(package_json.version) | ||
program.option("-w, --watch", "compose file or files in directory 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 project_package = readJsonSync(join(working_directory, "package.json")) || { devDependencies: {} }; | ||
const dsl_names = Object.keys(project_package.devDependencies).filter(key => key.startsWith("draft-dsl")); | ||
const dsls = dsl_names.map(name => require(`${join(working_directory, "node_modules", name)}`).dsl); | ||
config.dsls = dsls; | ||
|
||
// | ||
const path = resolve(working_directory, target); | ||
if (lstatSync(path).isDirectory()) | ||
{ | ||
program.watch ? InspectDirectory(path) : ComposeDirectory(path); | ||
} | ||
else | ||
{ | ||
program.watch ? InspectFile(path) : ComposeFile(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,10 @@ | ||
import { IDSL } from "../src"; | ||
|
||
export interface IConfig | ||
{ | ||
dsls: Array<{ name: string, dsl: IDSL }>; | ||
} | ||
|
||
export const config: IConfig = { | ||
dsls: [] | ||
} |
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,96 @@ | ||
import { readFileSync } from "fs"; | ||
import { outputFileSync, removeSync } from "fs-extra"; | ||
import * as traverse from "filewalker"; | ||
import * as watch from "node-watch"; | ||
import { Transcriber, } from "../src"; | ||
import { config } from "./config"; | ||
|
||
function TraverseDirectory(path: string, callback: (name: string, path: string) => void) | ||
{ | ||
const action = (relative: string, stats, absolute: string) => callback(relative, absolute); | ||
traverse(path) | ||
.on("file", action) | ||
.walk(); | ||
} | ||
|
||
export function InspectDirectory(path: string) | ||
{ | ||
ComposeDirectory(path); | ||
|
||
//@ts-ignore | ||
watch(path, { recursive: true }, (event, name: string) => | ||
{ | ||
if (name.endsWith(".tsx")) | ||
{ | ||
console.log(event, name); | ||
try | ||
{ | ||
ComposeFile(name); | ||
} | ||
catch (error) | ||
{ | ||
console.log(error.message); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
export function InspectFile(path: string) | ||
{ | ||
ComposeFile(path); | ||
|
||
//@ts-ignore | ||
watch(path, (event, name: string) => | ||
{ | ||
if (name.endsWith(".tsx")) | ||
{ | ||
console.log(event, name); | ||
try | ||
{ | ||
ComposeFile(name); | ||
} | ||
catch (error) | ||
{ | ||
console.log(error.message); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
export function ComposeDirectory(path: string) | ||
{ | ||
TraverseDirectory(path, (relative: string, absolute: string) => | ||
{ | ||
if (absolute.endsWith(".tsx")) | ||
{ | ||
try | ||
{ | ||
ComposeFile(absolute); | ||
} catch (error) | ||
{ | ||
console.log(`compose file failed: ${error.message}, source: ${relative}`); | ||
} | ||
} | ||
}) | ||
} | ||
|
||
export function CrossoutDirectory(path: string) | ||
{ | ||
TraverseDirectory(path, (relative: string, absolute: string) => | ||
{ | ||
if (absolute.endsWith(".tsx")) | ||
{ | ||
removeSync(absolute.replace(".tsx", ".ts")); | ||
} | ||
}) | ||
} | ||
|
||
export function ComposeFile(source: string) | ||
{ | ||
const code = readFileSync(source, "utf8"); | ||
const transcriber = new Transcriber(code); | ||
config.dsls.forEach(dsl => transcriber.AddDSL(dsl.name, dsl.dsl)); | ||
const result = transcriber.Transcribe(); | ||
outputFileSync(source.replace(".tsx", ".ts"), result, "utf8"); | ||
} | ||
|
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.