initialize components, routes, and services

This commit is contained in:
2020-07-08 18:54:19 -05:00
parent d212d3b36c
commit 69466406cd
13 changed files with 333 additions and 11 deletions

105
src/systemGenService.ts Normal file
View File

@ -0,0 +1,105 @@
import * as path from 'path';
const ncp = require('ncp').ncp;
import { createDatabase, writeMigrationsToFile } from './database/database-creator';
import { createViews } from './views/views-creator';
class SystemGenService {
public runSysGen(defs: SystemDef) {
ncp(path.join(process.cwd(), 'frame'), path.join(process.cwd(), defs.name), (err: any) => {
if (err) {
console.log(err);
} else {
console.log('success copying files');
this.buildDatabase(defs.storage, defs.name);
this.buildViews(defs, defs.name);
}
});
}
public buildDatabase(storage: StorageDef, outDir: string) {
let creationMigrations = createDatabase(storage);
writeMigrationsToFile(creationMigrations, outDir);
}
public buildViews(systemDef: SystemDef, outDir: string) {
createViews(systemDef);
}
}
const systemGenService = new SystemGenService();
interface SystemDef {
name: string;
storage: StorageDef;
views: ViewDef[];
// TODO: add Views, ACLs, Behaviors, UX
}
interface StorageDef {
tables: TableDef[];
relations: ManyToManyDef[];
}
interface ViewDef {
component: string;
type: ('list' | 'count' | 'item' | 'distinct')[];
columns: string[];
orderBy?: Order[];
filters?: Filter[];
// if type is 'list' it will always include skip and limit for pagination
}
interface Order {
column: string;
direction: 'asc' | 'desc';
}
interface Filter {
param: string; // the query param used to get the value
column: string;
comparison: '=' | '!=' | '>' | '<' | 'contains';
value?: string;
required?: boolean;
}
interface TableDef {
name: string;
columns: ColumnDef[],
relations: BelongsToDef[],
}
interface ColumnDef {
name: string;
type: "blob" | "boolean" | "date" | "dateTIME" | "number" | "string";
nullable: boolean;
unique?: boolean;
autoIncrement?: boolean;
default?: string;
}
interface BelongsToDef {
type: 'belongs-to';
table: string;
}
interface ManyToManyDef {
left: string;
relation: 'many-to-many';
right: string;
columns?: ColumnDef[];
}
export {
SystemDef,
StorageDef,
ViewDef,
Order,
Filter,
TableDef,
ColumnDef,
BelongsToDef,
ManyToManyDef,
systemGenService
}