Prepare for command-line schem compiler tool

This commit is contained in:
Tony Garnock-Jones 2021-03-09 19:29:31 +01:00
parent 447380218e
commit 8187337187
12 changed files with 58 additions and 35 deletions

View File

@ -0,0 +1,3 @@
#!/usr/bin/env node
require('../dist/bin/preserves-schema-ts.js').main(process.argv.slice(2));

View File

@ -30,5 +30,8 @@
"veryclean": "npm run clean && rm -rf node_modules",
"watch": "npx tsc -w"
},
"bin": {
"preserves-schema-ts": "./bin/preserves-schema-ts.js"
},
"dependencies": {}
}

View File

@ -23,7 +23,7 @@ function es6(insertion, extra) {
};
}
export default {
export default [{
input: 'lib/index.js',
output: [
umd(''),
@ -31,4 +31,15 @@ export default {
es6(''),
es6('.min', { plugins: [terser()] }),
],
}
}, {
input: 'lib/bin/preserves-schema-ts.js',
output: [{
file: 'dist/bin/preserves-schema-ts.js',
format: 'umd',
name: 'PreservesC_TS',
globals: {
'fs': 'fs',
},
}],
external: ['fs'],
}]

View File

@ -0,0 +1,12 @@
import { BASE, compile, readSchema } from '../schema/index';
import fs from 'fs';
export function main(argv: Array<string>) {
console.log('// ' + JSON.stringify(argv));
const src = fs.readFileSync(__dirname + '/../../../../schema/schema.txt', 'utf-8');
const sch = readSchema(src);
console.log(compile(
[{ moduleName: 'BASE', modulePath: 'BASE', schema: BASE, inline: true }],
sch,
'..'));
}

View File

@ -1,21 +1,6 @@
export * from './annotated';
export * from './bytes';
export * from './codec';
export * from './decoder';
export * from './dictionary';
export * from './encoder';
export * from './flex';
export * from './float';
export * from './fold';
export * from './fromjs';
export * from './is';
export * from './reader';
export * from './record';
export * from './strip';
export * from './symbols';
export * from './text';
export * from './values';
export * from './runtime';
export * as Constants from './constants';
export * as Schema from './schema/index';
const _Array = Array;
type _Array<T> = Array<T>;

View File

@ -0,0 +1,17 @@
export * from './annotated';
export * from './bytes';
export * from './codec';
export * from './decoder';
export * from './dictionary';
export * from './encoder';
export * from './flex';
export * from './float';
export * from './fold';
export * from './fromjs';
export * from './is';
export * from './reader';
export * from './record';
export * from './strip';
export * from './symbols';
export * from './text';
export * from './values';

View File

@ -1,4 +1,4 @@
import { Record, KeyedDictionary } from '..';
import { Record, KeyedDictionary } from '../runtime';
import { AtomKind, Pattern, Schema } from './meta';
import * as M from './meta';

View File

@ -1,6 +1,6 @@
import { Pattern, NamedPattern, Schema, Input } from "./meta";
import * as M from './meta';
import { Annotated, Bytes, Dictionary, Fold, fold, preserves, Record, Tuple, Value } from "..";
import { Annotated, Bytes, Dictionary, Fold, fold, preserves, Record, Tuple, Value } from "../runtime";
import { Formatter, parens, seq, Item, opseq, block, commas, brackets, anglebrackets, braces } from "./block";
function fnblock(... items: Item[]): Item {
@ -302,14 +302,3 @@ export function sourceCodeFor(v: Value<any>): Item {
},
});
}
import fs from 'fs';
import { readSchema } from "./reader";
import { BASE } from "./base";
function main() {
const src = fs.readFileSync(__dirname + '/../../../../schema/schema.txt', 'utf-8');
const sch = readSchema(src);
console.log(compile([{ moduleName: 'BASE', modulePath: 'BASE', schema: BASE, inline: true }], sch, '..'));
}
main();

View File

@ -0,0 +1,3 @@
export * from './reader';
export * from './compiler';
export * from './base';

View File

@ -1,6 +1,6 @@
import { Environment, Pattern, NamedPattern, lookup } from "./meta";
import * as M from './meta';
import { Value, Float, Bytes, is, isPointer, Record, Dictionary, Set } from "..";
import { Value, Float, Bytes, is, isPointer, Record, Dictionary, Set } from "../runtime";
export function validator(env: Environment, p: Pattern): (v: Value<any>) => boolean {
function walk(p: Pattern, v: Value<any>, recordOkAsTuple = false): boolean {

View File

@ -1,4 +1,4 @@
import { Dictionary, KeyedDictionary, Record, Value, preserves } from '..';
import { Dictionary, KeyedDictionary, Record, Value, preserves } from '../runtime';
export type Input = Value<never>;

View File

@ -1,4 +1,4 @@
import { Annotated, Dictionary, is, KeyedDictionary, peel, preserves, Record, strip, Tuple } from '..';
import { Annotated, Dictionary, is, KeyedDictionary, peel, preserves, Record, strip, Tuple } from '../runtime';
import { Input, NamedPattern, Pattern, Schema } from './meta';
import * as M from './meta';