forked from zhmushan/deno_init
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.ts
86 lines (82 loc) · 2.05 KB
/
mod.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 { mkdirSync, args, cwd, run, mkdir, writeFile, exit } from "deno";
import { green, red } from "https://deno.land/x/colors/mod.ts";
import * as tmpl from "./tmpl.ts";
const projectName = args[1];
function createLog(name: string, colors = green) {
console.log(colors(`CREATE ${name}`));
}
try {
mkdirSync(projectName);
init(projectName);
} catch (err) {
console.error(err);
}
function init(name: string) {
mkdir(`${name}/.vscode`).then(() => {
writeFile(
`${name}/${tmpl.vscodeSettingsPath}`,
new TextEncoder().encode(tmpl.vscodeSettings)
)
.then(() => {
createLog(tmpl.vscodeSettingsPath);
})
.catch(() => {
createLog(tmpl.vscodeSettingsPath, red);
});
});
writeFile(
`${name}/${tmpl.gitignorePath}`,
new TextEncoder().encode(tmpl.gitignore)
)
.then(() => {
createLog(tmpl.gitignorePath);
})
.catch(() => {
createLog(tmpl.gitignorePath, red);
});
writeFile(
`${name}/${tmpl.denolibjsonPath}`,
new TextEncoder().encode(tmpl.denolibjson)
)
.then(() => {
createLog(tmpl.denolibjsonPath);
})
.catch(() => {
createLog(tmpl.denolibjsonPath, red);
});
writeFile(`${name}/${tmpl.modtsPath}`, new TextEncoder().encode(tmpl.modts))
.then(() => {
createLog(tmpl.modtsPath);
})
.catch(() => {
createLog(tmpl.modtsPath, red);
});
writeFile(
`${name}/${tmpl.tsconfigjsonPath}`,
new TextEncoder().encode(tmpl.tsconfigjson)
)
.then(() => {
createLog(tmpl.tsconfigjsonPath);
})
.catch(() => {
createLog(tmpl.tsconfigjsonPath, red);
});
writeFile(
`${name}/${tmpl.packagejsonPath}`,
new TextEncoder().encode(tmpl.packagejson)
)
.then(() => {
createLog(tmpl.packagejsonPath);
run({
args: ["npm", "i", "typescript", "deno_ls_plugin", "--save-dev"],
cwd: `${cwd()}/${name}`
})
.status()
.then(status => {
exit(status.code);
});
})
.catch(() => {
createLog(tmpl.packagejsonPath, red);
});
}