-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.ts
62 lines (55 loc) · 1.7 KB
/
init.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
// packages
import { mkdirSync, writeFileSync } from "fs";
import { Command, flags } from "@oclif/command";
// utils
import { print, printError, emojis, boilerplateExists } from "../utils";
// constants
import {
globalYaml,
localYaml,
placeholderContent,
templateFunctionContent,
readmeContent,
} from "./init.spec";
const rootPath = "./.boilerplate";
const generateFilesAndFolders = () => {
// create .boilerplate folder
mkdirSync(rootPath);
// create readme
writeFileSync(`${rootPath}/readme.txt`, readmeContent);
// create global args yml file
writeFileSync(`${rootPath}/global.args.yml`, globalYaml);
// create template function
writeFileSync(`${rootPath}/timestamp.js`, templateFunctionContent);
// create component directory (example template out-of-the-box)
mkdirSync(`${rootPath}/component`);
// create local args yml file
writeFileSync(`${rootPath}/component/local.args.yml`, localYaml);
// folder with template arg name
mkdirSync(`${rootPath}/component/___name___`);
// file with template arg name and filetype
writeFileSync(
`${rootPath}/component/___name___/___name___.___filetype___`,
placeholderContent
);
};
export default class Init extends Command {
static description = "create a new boilerplate directory";
static flags = {
help: flags.help({ char: "h" }),
};
async run() {
if (boilerplateExists()) {
this.log(
printError(`looks like you already have a '.boilerplate' folder`)
);
} else {
generateFilesAndFolders();
this.log(
`${emojis([":tropical_drink:", ":dancer:"])} ${print(
`'.boilerplate' folder has been created in the root of the current directory`
)}`
);
}
}
}