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
40 changed files
with
7,190 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,12 @@ | ||
node_modules | ||
coverage | ||
spike.ts | ||
build | ||
dist | ||
.vscode | ||
*.tgz | ||
/src/dsl/*.ts | ||
/src/plug-in/*.ts | ||
/src/section/*.ts | ||
/src/generator/*.ts | ||
/src/transcriber/*.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 |
---|---|---|
@@ -1,2 +1,18 @@ | ||
# svelte-draft | ||
Develop svelte app in typedraft | ||
# SvelteDraft · ![Build Status](https://github.com/mistlog/svelte-draft/workflows/build/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/mistlog/svelte-draft/badge.svg)](https://coveralls.io/github/mistlog/svelte-draft) | ||
|
||
Develop svelte app in typedraft, with possibly complete typescript support. | ||
|
||
Currently it's working in progress, reference materials: | ||
|
||
* [starter project](https://github.com/mistlog/svelte-draft-template) | ||
|
||
* [TodoMVC implementation](https://github.com/mistlog/svelte-draft-todo-mvc) | ||
|
||
* unit test: see all supported features | ||
|
||
## License | ||
|
||
SvelteDraft is [MIT licensed](https://github.com/mistlog/svelte-draft/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"; | ||
import { ComposeFile, ComposeDirectory, InspectDirectory, InspectFile } from "./literator"; | ||
import { resolve, join } from "path"; | ||
import { lstatSync } from "fs"; | ||
import { readJsonSync, readJSONSync } from "fs-extra"; | ||
import { config } from "./config.js"; | ||
|
||
const package_json = readJSONSync(resolve(__dirname, "../../package.json")); | ||
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"), { throws: false }) || { 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)}`)?.MakeDSL()); | ||
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 "typedraft"; | ||
|
||
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,115 @@ | ||
import { outputFileSync, removeSync, readFileSync, existsSync } from "fs-extra"; | ||
import * as traverse from "filewalker"; | ||
import * as watch from "node-watch"; | ||
import { SvelteTranscriber } 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", ".svelte")); | ||
} | ||
}) | ||
} | ||
|
||
export function ComposeFile(source: string) | ||
{ | ||
// | ||
const code = readFileSync(source, "utf8"); | ||
const transcriber = new SvelteTranscriber(code); | ||
config.dsls.forEach(dsl => transcriber.AddDSL(dsl.name, dsl.dsl)); | ||
const { import_section, script_section, template_section } = transcriber.TranscribeToSections(); | ||
|
||
// | ||
const style = source.replace(".tsx", ".css"); | ||
const style_section = existsSync(style) ? readFileSync(style, "utf8") : ""; | ||
|
||
// | ||
const component = [ | ||
"<script>", | ||
import_section, | ||
"\n", | ||
script_section, | ||
"</script>", | ||
"\n", | ||
template_section, | ||
"\n", | ||
"<style>", | ||
style_section, | ||
"</style>" | ||
].join("\n"); | ||
outputFileSync(source.replace(".tsx", ".svelte"), component, "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.