-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
103 lines (80 loc) · 2.51 KB
/
index.js
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
#! /usr/bin/env node
// Import Packages
import fs from "fs";
import { setTimeout } from "node:timers/promises";
import { dirname } from "path";
import { fileURLToPath } from "url";
// Import External Packages
import * as p from "@clack/prompts";
import color from "picocolors";
// Import Utility Files
import createDirectoryContents from "./utilities/createDirectoryContents.js";
// Define Variables
const CURR_DIR = process.cwd();
const __dirname = dirname(fileURLToPath(import.meta.url));
// Main
async function main() {
console.clear();
await setTimeout(1000);
p.intro(`${color.bgCyan(color.black(" d365-plugin-generator "))}`);
// Get Available Templates
const CHOICES = fs.readdirSync(`${__dirname}/templates`);
let choiceOptions = CHOICES.map((choice) => ({
value: choice,
label: choice,
}));
const switchProj = await p.group({
template: () =>
p.select({
message: "Select the project template you want to clone.",
options: choiceOptions,
}),
});
if (switchProj.template != null) {
// Dynamic Module Import
const module = await import(
`./templates/${switchProj.template}/_config.js`
);
// Import relevant questions from Template _config file
const questions = module.questions;
// If generate confirmation is receivied
// TODO: Implement generic check
if (questions.generate) {
const s = p.spinner();
// TODO: Implement Note passed back from Config File
p.note(
`
Generating plugin in ${questions.path}.
With a namespace of ${questions.namespace}.
With a class name of ${questions.classname}.
For entity ${questions.entity}.
`,
`
Configuration`
);
s.start("Generating Files");
// Create Folder at specififed directory
fs.mkdirSync(`${CURR_DIR}/${questions.path}`);
// Copy content from Template Folder to specified directory
await createDirectoryContents(
`${__dirname}/templates/${switchProj.template}`,
`${questions.path}`,
switchProj.template,
questions
);
await setTimeout(2500);
s.stop("Files Generated");
}
// TODO: Implement Next Steps passed back from Config File
let nextSteps = `
cd ${questions.path}
Update plugin file.
Build.
Register.`;
p.note(nextSteps, "Next steps.");
p.outro(
`Problems? ${color.underline(color.cyan("https://github.com/maichopra/plugin-generator-cli/issues"))}`
);
}
}
main().catch(console.error);