-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
foi-toy: starting setup (including build script with moduloze) for fo…
…i-toy web tool
- Loading branch information
Showing
10 changed files
with
123 additions
and
14 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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
node_modules/ | ||
foi-toy/web/js/tokenizer.js | ||
foi-toy/web/js/highlighter.js | ||
package-lock.json |
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,3 +1,4 @@ | ||
.npmignore | ||
.gitignore | ||
foi-toy/web/ | ||
node_modules/ |
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
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,76 @@ | ||
#!/usr/bin/env node | ||
|
||
"use strict"; | ||
|
||
var path = require("path"); | ||
var fsp = require("fs/promises"); | ||
|
||
var { build, } = require("moduloze"); | ||
|
||
var config = { | ||
buildESM: true | ||
}; | ||
|
||
var depMap = { | ||
"src/tokenizer.js": "Tokenizer", | ||
"src/highlighter.js": "Highlighter" | ||
}; | ||
|
||
const ROOT_DIR = path.join(__dirname,".."); | ||
const SRC_DIR = path.join(ROOT_DIR,"src"); | ||
const WEB_JS_DIR = path.join(ROOT_DIR,"web","js"); | ||
|
||
|
||
main().catch(console.log); | ||
|
||
|
||
// ********************** | ||
|
||
async function main() { | ||
console.log("*** Building Foi-Toy Web ***"); | ||
|
||
var [ | ||
packageJSON, | ||
copyrightHeader, | ||
tokenizerCode, | ||
highlighterCode | ||
] = await Promise.all([ | ||
fsp.readFile(path.join(ROOT_DIR,"..","package.json"),"utf-8"), | ||
fsp.readFile(path.join(SRC_DIR,"copyright-header.txt"),"utf-8"), | ||
fsp.readFile(path.join(SRC_DIR,"tokenizer.js"),"utf-8"), | ||
fsp.readFile(path.join(SRC_DIR,"highlighter.js"),"utf-8"), | ||
]); | ||
|
||
packageJSON = JSON.parse(packageJSON); | ||
|
||
// read version number from package.json | ||
var version = packageJSON.version; | ||
var year = (new Date()).getFullYear(); | ||
|
||
copyrightHeader = copyrightHeader | ||
.replace(/`/g,"") | ||
.replace(/#VERSION#/g,version) | ||
.replace(/#YEAR#/g,year); | ||
|
||
var { esm: { code: tokenizerESM, }, } = build( | ||
config, | ||
"src/tokenizer.js", | ||
tokenizerCode, | ||
depMap | ||
); | ||
var { esm: { code: highlighterESM, }, } = build( | ||
config, | ||
"src/highlighter.js", | ||
highlighterCode, | ||
depMap | ||
); | ||
tokenizerESM = `${copyrightHeader.replace("#FILENAME#","tokenizer.js")}${tokenizerESM}`; | ||
highlighterESM = `${copyrightHeader.replace("#FILENAME#","highlighter.js")}${highlighterESM}`; | ||
|
||
await Promise.all([ | ||
fsp.writeFile(path.join(__dirname,"..","web","js","tokenizer.js"),tokenizerESM,"utf-8"), | ||
fsp.writeFile(path.join(__dirname,"..","web","js","highlighter.js"),highlighterESM,"utf-8"), | ||
]); | ||
|
||
console.log("Complete."); | ||
} |
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 @@ | ||
/*! Foi-Toy: #FILENAME# | ||
v#VERSION# (c) #YEAR# Kyle Simpson | ||
MIT License: http://getify.mit-license.org | ||
*/ |
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
Empty file.
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 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Foi-Toy</title> | ||
<link rel="stylesheet" href="css/style.css"> | ||
</head> | ||
<body> | ||
<h1>Foi-Toy</h1> | ||
</body> | ||
<script src="js/app.js"></script> | ||
</html> |
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 @@ | ||
import { tokenize, } from "./tokenizer.js"; | ||
import { highlight, } from "./highlighter.js"; | ||
|
||
|
||
main().catch(console.log); | ||
|
||
// **************************** | ||
|
||
async function main() { | ||
var tokens = await tokenize("def x: \"Hello world!\"; log(x);"); | ||
|
||
for await (let htmlChunk of highlight(tokens)) { | ||
console.log(htmlChunk); | ||
} | ||
} |
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