-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinit.ts
More file actions
118 lines (105 loc) · 2.48 KB
/
Copy pathinit.ts
File metadata and controls
118 lines (105 loc) · 2.48 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
import { CompilerOptions, Theme } from "./deps.ts";
/** Content of deno.json file */
export interface DenoConfig {
importMap?: string;
imports?: Record<string, string>;
tasks?: Record<string, string | Task>;
permissions?: Record<string, DenoPermissions>;
compilerOptions?: CompilerOptions;
unstable?: string[];
allowScripts?: {
deny?: string[];
};
[key: string]: unknown;
lint?: {
plugins?: string[];
rules?: {
exclude?: string[];
};
};
}
export interface DenoPermissions {
all?: boolean;
read?: DenoPermissionValue;
write?: DenoPermissionValue;
import?: DenoPermissionValue;
env?: DenoPermissionValue;
net?: DenoPermissionValue;
run?: DenoPermissionValue;
ffi?: DenoPermissionValue;
sys?: DenoPermissionValue;
}
export type DenoPermissionValue = string[] | boolean | {
allow?: string[] | boolean;
deny?: string[] | boolean;
};
export interface Task {
description?: string;
command: 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;
}
/** 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;
javascript?: boolean;
}
/** Class to manage the initialization */
export class Init {
config: InitConfig;
denoFile = "deno.json";
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;
}
}
}
}
}