remove files that don't need to be tracked
This commit is contained in:
3
dist/example-def.d.ts
vendored
3
dist/example-def.d.ts
vendored
@ -1,3 +0,0 @@
|
||||
import { SystemDef } from './systemGenService';
|
||||
declare let def: SystemDef;
|
||||
export default def;
|
50
dist/processDef.d.ts
vendored
50
dist/processDef.d.ts
vendored
@ -1,50 +0,0 @@
|
||||
interface SystemDef {
|
||||
storage: StorageDef;
|
||||
views: ViewDef[];
|
||||
}
|
||||
interface StorageDef {
|
||||
tables: TableDef[];
|
||||
relations: ManyToManyDef[];
|
||||
}
|
||||
interface ViewDef {
|
||||
component: string;
|
||||
type: ('list' | 'count' | 'item' | 'distinct')[];
|
||||
columns: string[];
|
||||
orderBy?: Order[];
|
||||
filters?: Filter[];
|
||||
}
|
||||
interface Order {
|
||||
column: string;
|
||||
direction: 'asc' | 'desc';
|
||||
}
|
||||
interface Filter {
|
||||
param: string;
|
||||
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 };
|
119
dist/processDef.js
vendored
119
dist/processDef.js
vendored
@ -1,119 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var path = __importStar(require("path"));
|
||||
// import simmer from './simmer-def-example';
|
||||
var ncp = require('ncp').ncp;
|
||||
var fs = __importStar(require("fs"));
|
||||
var example_def_1 = __importDefault(require("./example-def"));
|
||||
var outDir = 'test';
|
||||
function createDatabase(storageDef) {
|
||||
var tableCreationQueries = [];
|
||||
var tableDeletionQueries = [];
|
||||
for (var i in storageDef.tables) {
|
||||
tableCreationQueries.push(getTableCreationString(storageDef.tables[i]));
|
||||
tableDeletionQueries.push(getTableDeletionString(storageDef.tables[i]));
|
||||
}
|
||||
for (var i in storageDef.relations) {
|
||||
tableCreationQueries.push(getTableRelationsCreationString(storageDef.relations[i]));
|
||||
tableDeletionQueries.push(getTableRelationsDeletionString(storageDef.relations[i]));
|
||||
}
|
||||
tableCreationQueries.map(function (query) {
|
||||
console.log(query);
|
||||
});
|
||||
tableDeletionQueries.map(function (query) {
|
||||
console.log(query);
|
||||
});
|
||||
return {
|
||||
up: tableCreationQueries,
|
||||
down: tableDeletionQueries,
|
||||
};
|
||||
}
|
||||
function getTableCreationString(tableDef) {
|
||||
var primaryKeyString = tableDef.name + "_id VARCHAR(36) PRIMARY KEY";
|
||||
var columnString = "" + primaryKeyString;
|
||||
var defaultColumns = "created DATETIME NOT NULL DEFAULT NOW(), modified DATETIME NOT NULL DEFAULT NOW()";
|
||||
var indexString = "";
|
||||
// columns
|
||||
for (var i in tableDef.columns) {
|
||||
var column = tableDef.columns[i];
|
||||
columnString = columnString + ", " + createColumnString(column);
|
||||
}
|
||||
// relations
|
||||
for (var i in tableDef.relations) {
|
||||
var relation = tableDef.relations[i];
|
||||
columnString = columnString + ", " + relation.table + "_id VARCHAR(36)";
|
||||
}
|
||||
// default created & modified
|
||||
columnString = columnString + ", " + defaultColumns;
|
||||
return "CREATE TABLE IF NOT EXISTS " + tableDef.name + " (" + columnString + (indexString !== '' ? ', ' + indexString : '') + ");";
|
||||
}
|
||||
function getTableDeletionString(tableDef) {
|
||||
return "DROP TABLE IF EXISTS " + tableDef.name + ";";
|
||||
}
|
||||
function createColumnString(column) {
|
||||
var typeMap = {
|
||||
"blob": "BLOB",
|
||||
"boolean": "BOOLEAN",
|
||||
"date": "DATE",
|
||||
"dateTIME": "DATETIME",
|
||||
"number": "INT",
|
||||
"string": "VARCHAR(255)",
|
||||
};
|
||||
return column.name + " " + typeMap[column.type] + (column.nullable ? '' : ' NOT NULL') + (column.default ? ' DEFAULT ' + column.default : '') + (column.autoIncrement ? ' AUTO_INCREMENT' : '') + (column.unique ? ' UNIQUE' : '');
|
||||
}
|
||||
function getTableRelationsCreationString(relationsDef) {
|
||||
var columnString = relationsDef.left + "_id VARCHAR(36) NOT NULL, " + relationsDef.right + "_id VARCHAR(36) NOT NULL";
|
||||
var indexString = "INDEX " + relationsDef.left + "_id_index (" + relationsDef.left + "_id), INDEX " + relationsDef.right + "_id_index (" + relationsDef.right + "_id)";
|
||||
if (relationsDef.columns && relationsDef.columns.length) {
|
||||
for (var i in relationsDef.columns) {
|
||||
var column = relationsDef.columns[i];
|
||||
columnString = columnString + ", " + createColumnString(column);
|
||||
}
|
||||
}
|
||||
return "CREATE TABLE IF NOT EXISTS " + relationsDef.left + "_" + relationsDef.right + " (" + columnString + (indexString !== '' ? ', ' + indexString : '') + ");";
|
||||
}
|
||||
function getTableRelationsDeletionString(relationsDef) {
|
||||
return "DROP TABLE IF EXISTS " + relationsDef.left + "_" + relationsDef.right + ";";
|
||||
}
|
||||
function dateString() {
|
||||
var date = new Date();
|
||||
return "" + date.getFullYear() + (date.getMonth() + 1) + date.getDate();
|
||||
}
|
||||
function writeMigrationsToFile(migrations) {
|
||||
var migrationFileContents = "\n--up\n" + migrations.up.join('\n') + "\n--down\n" + migrations.down.join('\n') + "\n ";
|
||||
var migrationFilePath = path.join(process.cwd(), outDir, 'src', 'migrationJobs', dateString() + "-create-database.sql");
|
||||
fs.writeFileSync(migrationFilePath, migrationFileContents);
|
||||
}
|
||||
ncp(path.join(process.cwd(), 'frame'), path.join(process.cwd(), outDir), function (err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
}
|
||||
else {
|
||||
console.log('success copying files');
|
||||
var creationMigrations = createDatabase(example_def_1.default.storage);
|
||||
// let creationMigrations = createDatabase(simmer.storage);
|
||||
writeMigrationsToFile(creationMigrations);
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user