-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.multiple.ts
86 lines (72 loc) · 2.42 KB
/
page.multiple.ts
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
import { bgBlack, brightGreen, brightMagenta } from "./deps.ts"
import { presets } from "./templates/tailwind.ts"
import { create_dir, create_page_file, page_exist, stdOut } from "./actions.ts"
import { create_macro_block } from "./block.macro.ts"
import { _replace, ReplaceOptions, TemplatesMap } from "./shared.ts"
export const fns = {
create_macro_block,
create_dir,
stdOut,
create_page_file,
page_exist,
}
// eslint-disable-next-line max-lines-per-function
export function create_multiple_configs(name: string) {
const { templates: t } = presets["tailwind"]
if (fns.page_exist(name)) {
fns.stdOut(`\n${brightMagenta("Already Created Page:")} ${name}.`)
return
}
fns.create_dir("blocks/layouts")
fns.create_dir("makers")
fns.create_macro_block("pages_title", false)
create_multiple_files(name, t)
// todo: e2e colors, output
fns.stdOut(
`\n${brightGreen("tailwind.config.js")} - Update content property:`,
)
fns.stdOut(bgBlack(brightMagenta("\n\n./" + name + "/**/*.{html,js}\n\n")))
fns.stdOut(brightGreen("Adjust as needed."))
}
function create_multiple_files(name: string, t: { [key: string]: string }) {
fns.create_page_file(_layouts_file(name), t["layout.pages"])
fns.create_page_file(_layouts_file("paginator"), t["layout.index"])
create_indices_files(name, t)
create_pages_files(name, t)
}
function create_pages_files(name: string, t: { [key: string]: string }) {
for (const type of ["api", "css", "js"]) {
fns.create_page_file(_pages_file(name, type), _replace_page(t, type, { name }))
}
}
function create_indices_files(name: string, t: { [key: string]: string }) {
for (const type of ["api", "css", "js"]) {
fns.create_page_file(
_indice_file(name, type),
_replace_indice(t, type, { name }),
)
}
}
function _replace_indice(
TEMPLATES: TemplatesMap,
type: string,
replace_opts?: ReplaceOptions,
): string {
return _replace(TEMPLATES, `indice.${type}`, replace_opts)
}
function _replace_page(
TEMPLATES: TemplatesMap,
type: string,
replace_opts?: ReplaceOptions,
): string {
return _replace(TEMPLATES, `pages.${type}`, replace_opts)
}
function _indice_file(name: string, type: string): string {
return `makers/${name}/indice/${type}.indice.js`
}
function _pages_file(name: string, type: string): string {
return `makers/${name}/pages/${type}.pages.js`
}
function _layouts_file(name: string): string {
return `blocks/layouts/${name}.pages.html`
}