-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move schemes into separate JSON files (#13)
This has the benefits of separating data from code and of having a language-agnostic specification of schemes (for implementations of Sanscript in other programming languages). This also adds a build step integrating the scheme data into the JS file -- the file that now contains only the code has been moved to a subdirectory and the build step (npm run dist) outputs to sanscript.js (so this causes no breaking changes).
- Loading branch information
Showing
81 changed files
with
1,336 additions
and
1,397 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,3 @@ | ||
*.*~ | ||
node_modules | ||
/sanscript.js |
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,54 @@ | ||
const fsp = require("fs").promises; | ||
const path = require("path"); | ||
|
||
async function main() { | ||
// Get lists of Brahmic and roman schemes | ||
// Each of bschemes and rschemes is an array of which each element is of | ||
// the form [filename, filepath] | ||
const [bschemes, rschemes] = await Promise.all( | ||
["brahmic", "roman"].map(async x => { | ||
const dirpath = path.join(__dirname, "src", "schemes", x) | ||
let paths = []; | ||
for (const filename of await fsp.readdir(dirpath)) { | ||
paths.push([filename, path.join(dirpath, filename)]); | ||
} | ||
return paths; | ||
}) | ||
); | ||
|
||
// Get arrays of Brahmic and roman scheme file contents | ||
// Each of bfiles and rfiles is an array of which each element is of the | ||
// form [schemeName, fileContents] | ||
const [bfiles, rfiles] = await Promise.all([bschemes, rschemes].map(x => | ||
Promise.all(x.map(async ([filename, filepath]) => { | ||
let schemeName = filename.split("."); | ||
schemeName.pop(); | ||
const fileContents = await fsp.readFile(filepath); | ||
return [schemeName, fileContents]; | ||
})) | ||
)); | ||
|
||
// Get file handle for sanscript.js | ||
let out; | ||
try { | ||
out = await fsp.open( | ||
path.join(__dirname, "sanscript.js"), "w" | ||
); | ||
out.write("var schemes = {};\n"); | ||
for (const [scheme, contents] of bfiles) { | ||
out.write(`schemes.${scheme} = ${contents};\n`); | ||
} | ||
for (const [scheme, contents] of rfiles) { | ||
out.write(`schemes.${scheme} = ${contents};\n`); | ||
} | ||
// Write the code to the output file | ||
out.write(await fsp.readFile( | ||
path.join(__dirname, "src", "sanscript.js") | ||
)); | ||
} finally { | ||
if (out !== undefined) | ||
await out.close(); | ||
} | ||
} | ||
|
||
main().catch(console.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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.