-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_app.py
108 lines (90 loc) · 4 KB
/
create_app.py
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
import os
def createApp(path):
access_rights = 0o755
# try:
os.makedirs(path, access_rights)
os.makedirs(f"{path}/graphql", access_rights)
queries = open(f"{path}/graphql/queries.ts", "a+")
queries.write('import gql from "graphql-tag";\n')
queries.close()
mutations = open(f"{path}/graphql/mutations.ts", "a+")
mutations.write('import gql from "graphql-tag";\n')
mutations.close()
#open(f"{path}/utils.ts", "a+").close()
# except:
# print("Creation of the directory %s failed" % path)
# else:
# print("created succefully")
def createInfo(path,name):
info = open(f"{path}/info.ts", "a+")
info.writelines(['import { ColumnsType } from "antd/lib/table";\n',
'import { FieldType, FormInputType } from "../../lib/form/types";\n'])
info.writelines([f'export const {name}Columns: ColumnsType = [];\n',
f'export const {name}Inputs: FormInputType = {{ title: "", fields: [], info: "" }};\n',
f'export const {name}Filters: FieldType[] = [];\n'])
def createComponent(path):
create = open(f"{path}/create.tsx", "a+")
create.writelines(["import React, { ReactElement } from 'react';\n",
'import GraphQLForm from "../../lib/form/GraphQLForm";\n',
'import { createMutation } from "../../lib/utils";\n'
'import { browserHistory } from "../../config";\n',
f'import {{{name}Inputs as inputs}} from "./info"\n'
])
create.writelines(['interface Props {}\n',
'export default function create({}: Props): ReactElement {\n',
'return (\n',
'<GraphQLForm\n',
'title=""\n',
'span={12}\n',
'history={browserHistory}\n',
'inputs={inputs}\n',
'initialValues={{}}\n',
'mutation={createMutation("create_nested_client","CreateClientInput!" )}\n',
'/>\n',
' );\n',
'}\n'])
create.close()
def listComponent(path,name):
view = open(f"{path}/list.tsx", "a+")
view.writelines(['import React, { ReactElement } from "react";\n',
f'import {{{name}Columns as columns}} from "./info"\n',
f'import {{{name}Filters as filters}} from "./info"\n',
'import { browserHistory } from "../../config";\n',
'import GraphQLTableView from "../../lib/views/GraphQLTableView";\n',
'import { deleteMutation,createMutation } from "../../lib/utils";\n'])
view.writelines(['interface Props {}\n', 'export default function list({}: Props): ReactElement {\n', ' return (\n',
'<div>\n',
' <GraphQLTableView\n',
' columns={columns}\n',
'filters={filters}\n',
'createLink=""\n',
'actions={[]}\n',
'initVariables={{}}\n',
'deleteColumn={false}\n',
'updateColumn={false}\n',
'history={browserHistory}\n',
'graphql={{\n'
'all:"" ,\n'
'delete: deleteMutation(""),\n'
' update: createMutation("", ""),\n'
' }}\n'
'/>\n'
' </div>\n'
');}\n'])
view.close()
def createIndex(path, name):
index = open(f"{path}/index.tsx", "a+")
index.writelines([
'export {{ default as {0}List }} from "./list"\n'.format(
name.capitalize()),
'export {{ default as {0}Create }} from "./create"\n'.format(
name.capitalize()),
])
current_path = os.getcwd()
name = input('app name : ')
path = f"{current_path}/src/apps/{name}"
createApp(path)
listComponent(path,name)
createComponent(path)
createIndex(path, name)
createInfo(path,name)