-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.ts
131 lines (118 loc) · 3.41 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
// Copyright © 2024 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 dir from 'https://deno.land/x/[email protected]/mod.ts';
import Ask from 'https://deno.land/x/[email protected]/mod.ts';
import { Monk } from 'https://deno.land/x/[email protected]/mod.ts';
// Utilities
// Runner function
async function Run(command: string) {
console.log(`${colors.dim('$')} ${colors.bold(command)}`);
const cmd = command.split(' ');
const run = new Deno.Command(cmd[0], { args: cmd.slice(1) });
const result = await run.output();
if (result.code !== 0) {
console.error(
`The command was not executed correctly:\n${
colors.dim(command)
}\n - Error Detailed:\n${
colors.red(colors.bold(new TextDecoder().decode(result.stderr)))
}`,
);
Deno.exit(result.code);
}
}
// Bin path for the executable
const BIN = join(dir('home')!, '.deno', 'bin');
// Prompt
const ask = new Ask({
suffix: '?',
prefix: '>',
});
let installation: 'canary' | 'stable' = 'stable';
if (Deno.args[0] == 'canary') {
installation = 'canary';
}
if (Deno.args[0] == 'stable') {
installation = 'stable';
}
await Monk({
versions: {
downloadVersion: installation,
stable: {
url: 'https://github.com/dpmland/dpm',
branch: 'main',
},
canary: {
url: 'https://github.com/dpmland/dpm',
branch: 'dev',
},
},
files: {
appName: 'dpm',
stable: {
importMapFile: './import_map.json',
mainFile: './dpm.ts',
},
canary: {
importMapFile: './import_map.json',
mainFile: './dpm.ts',
},
},
social: {
github: 'https://github.com/dpmland/dpm',
discord: 'https://discord.com/invite/Um27YPJKud',
errors: 'https://github.com/dpmland/dpm/issues',
},
});
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 and templates with DPM!\n',
),
);
if (dracoInfo.platform() == 'windows') {
if (dracoFiles.exists(join(BIN, 'dpm.exe'))) {
await Run(`${join(BIN, 'dpm.exe')} docs -I`);
console.log(colors.yellow('Installed the documentation!'));
if (installation == 'canary') {
await Run(`${join(BIN, 'dpm')} init -D`);
console.log(colors.yellow('Installed the license templates!'));
}
} 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 -I`);
console.log(colors.yellow('Installed the documentation!'));
if (installation == 'canary') {
await Run(`${join(BIN, 'dpm')} init -I`);
console.log(colors.yellow('Installed the license templates!'));
}
} else {
console.log(
colors.red(
'Not found the file compiled! Re run the installer or report the error on github.',
),
);
}
}
}
console.log(
`Run ${colors.green('dpm --help')} for usage information\n`,
);