-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.ts
120 lines (109 loc) · 2.42 KB
/
init.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
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
/** Content of deno.json file */
export interface DenoConfig {
importMap?: string;
imports?: Record<string, string>;
tasks?: Record<string, string>;
compilerOptions?: CompilerOptions;
unstable?: string[];
[key: string]: unknown;
}
export interface CompilerOptions {
jsx?: "jsx" | "react-jsx" | "precompile";
jsxImportSource?: string;
jsxImportSourceTypes?: string;
jsxFactory?: string;
jsxFragmentFactory?: string;
types?: string[];
}
/** Lume plugin options */
export interface LumePlugin {
name: string;
url?: string;
}
/** Lume configuration */
export interface LumeConfig {
version: string;
file: string;
plugins: LumePlugin[];
src: string;
theme?: Theme;
}
/** Theme manifest */
export interface Theme {
id: string;
name: string;
description: string;
tags: string[];
author: {
name: string;
url: string;
};
repo: string;
demo: string;
screens: {
desktop: string[];
mobile: string[];
};
module: {
name: string;
origin: string;
main: string;
cms?: string;
src?: string[];
srcdir?: string;
unstable?: string[];
imports?: Record<string, string>;
compilerOptions?: CompilerOptions;
};
}
/** Step of the initialization */
type Step = (init: Init) => false | void | Promise<void | false>;
export interface InitConfig {
dev?: boolean;
path: string;
src?: string;
theme?: string;
plugins?: string[];
mode?: string;
cms?: boolean;
version?: string;
}
/** Class to manage the initialization */
export class Init {
config: InitConfig;
path: string;
dev: boolean;
steps = new Map<number, Step[]>();
deno: DenoConfig = {};
lume: LumeConfig = {
version: "",
file: "",
src: "",
plugins: [],
};
files = new Map<string, string | Uint8Array>();
constructor(config: InitConfig) {
this.config = config;
this.path = config.path;
this.dev = config.dev || false;
const src = config.src || "";
this.lume.src = src !== "" && !src.startsWith("/") ? `/${src}` : src;
}
use(step: Step, order = 0) {
const steps = this.steps.get(order) || [];
steps.push(step);
this.steps.set(order, steps);
}
async run() {
const orders = Array.from(this.steps.keys()).sort();
for (const order of orders) {
const steps = this.steps.get(order)!;
for (const step of steps) {
const next = await step(this);
if (next === false) {
return;
}
}
}
}
}