-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimmutable_gen.ts
More file actions
130 lines (110 loc) · 3.08 KB
/
immutable_gen.ts
File metadata and controls
130 lines (110 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
** Immutable Generator **
Generate elixir and react code from a genfile
- requires a genfile path as an argument
*/
import * as path from "path";
import { gen_phx } from "./composite/gen_phoenix";
import { gen_react } from "./composite/gen_react";
import { readGenFile } from "./readers/genfile";
import { AppData } from "./readers/get_app_data";
import { setUmbrellaDirCache, writeLog } from "./utils/history_cache";
import { log, setLogLevel } from "./utils/logger";
import { Names } from "./utils/string";
setLogLevel(5);
type ImmutableGenerator = {
name: Names;
AppData: AppData;
generate: {
requests?: ImmutableRequests;
stateSlice?: ImmutableStateSlice;
http_controller?: ImmutableController;
channel_controller?: string;
context?: ImmutableContext;
databaseTable?: string;
schema?: string;
tstype?: string;
appstate?: string;
factory?: boolean;
test?: boolean;
demoComponents?: boolean;
};
[key: string]: any;
};
interface ImmutableContext {
name: string;
apiFunctions: string[];
}
interface ImmutableController {
name: string;
routes: string[];
}
interface ImmutableStateSlice {
name: string;
reducers?: string[];
selectors?: string[];
}
interface ImmutableRequests {
requestFunctions: string[];
}
interface Dict {
[key: string]: string | Dict;
}
interface TypeDict {
name?: string | null;
ts: Dict;
ex: Dict;
}
enum GenTypesKey {
ImmutableGlobal = "ImmutableGlobal",
AppState = "AppState",
InitialAppState = "InitialAppState",
TransitoryState = "TransitoryState",
Schema = "Schema",
DatabaseTable = "DatabaseTable",
TsType = "TsType",
}
type GenTypes = { [key in GenTypesKey]?: TypeDict };
const main = async () => {
const args = process.argv.slice(2);
const filePath = path.resolve(args[0]);
if (args.length < 1) {
console.error("Please provide the input file path as an argument.");
process.exit(1);
}
log({ level: 1, color: "GREEN" }, `\n\n Reading genfile...\n\n`);
const { generator, genTypes } = await readGenFile(filePath);
const {
name: { pluralUpperCamel, singleSnake },
AppData: { AppNameCaps, UmbrellaDir },
} = generator;
setUmbrellaDirCache(UmbrellaDir);
log({ level: 1, color: "BLUE" }, `\nGenerating front end components...`);
await gen_react(generator, genTypes);
log({ level: 1, color: "BLUE" }, `\nGenerating server components...`);
await gen_phx(generator, genTypes);
writeLog(UmbrellaDir, `generate_${singleSnake}`);
log(
{ level: 1, color: "GREEN" },
`\n\Generation Complete.\n\nGenerated ${pluralUpperCamel}\n`
);
log({ level: 1, color: "TEAL" }, ` in ${AppNameCaps} App\n\n`);
log(
{ level: 2, color: "YELLOW" },
"\nDon't forget to update your repository by running migrations:"
);
log({ level: 4, color: "BLUE" }, ` yarn d.mig\n`);
log({ level: 4, color: "BLUE" }, ` or\n`);
log({ level: 4, color: "BLUE" }, ` mix ecto.migrate\n`);
};
main().catch(console.error);
export type {
Dict,
GenTypes,
GenTypesKey,
ImmutableContext,
ImmutableController,
ImmutableGenerator,
Names,
TypeDict,
};