-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.ts
228 lines (206 loc) · 6.34 KB
/
install.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// Copyright © 2022 Dpm Land. All Rights Reserved.
import * as colors from 'https://deno.land/[email protected]/fmt/colors.ts';
import { join } from 'https://deno.land/[email protected]/path/mod.ts';
import { dracoFiles, dracoInfo } from 'https://deno.land/x/[email protected]/mod.ts';
import Ask from 'https://deno.land/x/[email protected]/mod.ts';
import figlet from 'https://x.nest.land/[email protected]/mod.js';
// Utilities
// Runner function
async function Run(command: string) {
const cmd = command.split(' ');
const run = Deno.run({
cmd: cmd,
});
const { success } = await run.status();
if (success == false) {
console.error(
colors.red(`The command was not executed correctly:\n${command}`),
);
Deno.exit(1);
}
}
// Temp Path
const TEMP = join(dracoFiles.homeDir()!, '.deno', 'dpm');
// Bin path for the executable
const BIN = join(dracoFiles.homeDir()!, '.deno', 'bin');
// Prompt
const ask = new Ask({
suffix: '?',
prefix: '>',
});
// Copy the files to the bin function!
async function MoveBinToMain() {
if (dracoInfo.platform() == 'windows') {
if (dracoFiles.exists(join(TEMP, 'canary', 'dpm.ts'))) {
console.log(colors.cyan('Found the DPM executable!'));
console.log(colors.cyan('Copying the executable to the BIN path!'));
await Deno.copyFile(
`${join(Deno.cwd(), 'dpm.exe')}`,
`${join(BIN, 'dpm.exe')}`,
);
console.log(
colors.cyan('Removing the dpm.exe file from the current path!'),
);
await Deno.remove(`${join(Deno.cwd(), 'dpm.exe')}`);
} else {
console.log(
colors.red(
'Not found the file compiled! Re run the installer or report the error on github.',
),
);
}
} else if (
dracoInfo.platform() == 'linux' || dracoInfo.platform() == 'darwin'
) {
if (dracoFiles.exists(join(TEMP, 'canary', 'dpm.ts'))) {
console.log(colors.cyan('Found the DPM executable!'));
console.log(colors.cyan('Copying the executable to the BIN path!'));
await Deno.copyFile(
`${join(Deno.cwd(), 'dpm')}`,
`${join(BIN, 'dpm')}`,
);
console.log(colors.cyan('Removing the dpm file from the current path!'));
await Deno.remove(`${join(Deno.cwd(), 'dpm')}`);
} else {
console.log(
colors.red(
'Not found the file compiled! Re run the installer or report the error on github.',
),
);
}
} else {
console.log(
colors.red(
'Not found the main TypeScript File! Re run the installer or report the error on github.',
),
);
}
}
// Seppare by functions the CANARY and the STABLE
export async function CanaryInstallation() {
console.log('Installing from canary!\n');
if (dracoFiles.exists(join(TEMP, 'canary'))) {
await Deno.remove(join(TEMP, 'canary'), { recursive: true });
console.log(colors.yellow('Cleaned the temp dpm dir!\n'));
}
await Run(
`git clone -b dev --depth=1 https://github.com/dpmland/dpm ${
join(TEMP, 'canary')
}`,
);
console.log();
console.log('Compiling the executable for better preformance!\n');
await Run(
`${Deno.execPath()} compile -A --unstable --import-map ${
join(TEMP, 'canary', './import_map.json')
} --target ${Deno.build.target} ${join(TEMP, 'canary', 'dpm.ts')}`,
);
await MoveBinToMain();
}
export async function StableInstallation() {
console.log('Install from stable!\n');
if (dracoFiles.exists(join(TEMP, 'stable'))) {
await Deno.remove(join(TEMP, 'stable'), { recursive: true });
console.log(colors.yellow('Cleaned the temp dpm dir!\n'));
}
await Run(
`git clone -b main --depth=1 https://github.com/dpmland/dpm ${
join(TEMP, 'stable')
}`,
);
console.log();
console.log('Running the installation with the Deno help!\n');
await Run(
`${Deno.execPath()} compile -A --unstable --import-map ${
join(TEMP, 'stable', './import_map.json')
} --target ${Deno.build.target} ${join(TEMP, 'stable', 'dpm.ts')}`,
);
await MoveBinToMain();
}
// Add the directly access without the prompt!
if (Deno.args[0] == 'canary') {
await CanaryInstallation();
Deno.exit();
}
if (Deno.args[0] == 'stable') {
await StableInstallation();
Deno.exit();
}
/*********************************************/
/*********************************************/
/** START THE INSTALLER WORK */
/*********************************************/
/*********************************************/
console.log(colors.cyan(await figlet('DPM INSTALLER')));
const answers = await ask.prompt([
{
name: 'versionOpt',
message: 'Install canary or stable ( Answers: canary | stable )',
},
]);
switch (answers.versionOpt) {
case 'canary': {
await CanaryInstallation();
break;
}
case 'stable': {
await StableInstallation();
break;
}
default: {
console.log(
colors.red(
'Not found this target only 2 options: canary | stable.\nClosing the installer',
),
);
Deno.exit(2);
}
}
console.log();
const answers2 = await ask.prompt([
{
name: 'allTools',
message: 'Do you want install the documentation and all tools?',
type: 'confirm',
},
]);
if (answers2.allTools) {
console.log(
colors.magenta('Installing the offline documentation with DPM!\n'),
);
if (dracoInfo.platform() == 'windows') {
if (dracoFiles.exists(join(BIN, 'dpm.exe'))) {
await Run(`${join(BIN, 'dpm.exe')} docs -u`);
console.log(colors.yellow('Installed the documentation!'));
} else {
console.log(
colors.red(
'Not found the file compiled! Re run the installer or report the error on github.',
),
);
}
} else if (
dracoInfo.platform() == 'linux' || dracoInfo.platform() == 'darwin'
) {
if (dracoFiles.exists(join(BIN, 'dpm'))) {
await Run(`${join(BIN, 'dpm')} docs -u`);
console.log(colors.yellow('Installed the documentation!'));
} else {
console.log(
colors.red(
'Not found the file compiled! Re run the installer or report the error on github.',
),
);
}
}
}
console.log(colors.brightGreen(await figlet('DONE!')));
console.log('🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥\n');
console.log(
`Run ${colors.green('dpm --help')} for usage information\n`,
);
console.log(
`See ${
colors.green('https://discord.gg/Um27YPJKud')
} for help and propose new ideas at Discord!\n`,
);