-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
80 lines (68 loc) · 1.72 KB
/
index.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
#!/usr/bin/env node
import boxen from "boxen";
import chalk from "chalk";
import { Argument, Command } from "commander";
import { execa } from "execa";
import fse from "fs-extra";
import path from "path";
import { Output } from "./helpers/output.js";
const program = new Command();
program.version("1.0.0", "-v, --version");
program.usage(`${chalk.blue("project-directory")} [options]`);
// Arguments
program.addArgument(
new Argument("<project-directory>", "specify path for collections")
.argOptional()
.default("collections")
);
program.parse(process.argv);
(async () => {
const directory = program.processedArgs[0];
const rootPath = path.resolve(directory);
if (await fse.pathExists(rootPath)) {
const stat = await fse.stat(rootPath);
if (stat.isDirectory() === false) {
Output.error(
`Destination ${chalk.magentaBright(
directory
)} already exists and is not a directory.`
);
process.exit(1);
}
const files = await fse.readdir(rootPath);
if (files.length > 0) {
Output.error(
`Destination ${chalk.magentaBright(
directory
)} already exists and is not an empty directory.`
);
process.exit(1);
}
} else {
await fse.mkdir(rootPath);
}
Output.info("Installing Collections");
try {
await execa(
"npx",
[
"--silent",
"-y",
"@collectionscms/collections",
"init",
`-p ${directory}`,
],
{ stdio: "inherit" }
);
} catch (err) {
Output.error(err.message || "Unknown error");
process.exit(1);
}
console.log(
boxen(Output.nextSteps(directory), {
padding: 1,
borderColor: "green",
margin: 1,
})
);
})();