xd.js
Version:
XD.JS ==== [](https://npmjs.com/xd.js) [](https://npmjs.com/xd.js)<br> How do I install it? ``` npm i -g
136 lines (131 loc) • 4.76 kB
JavaScript
const XD = require('../index')
const prompts = require('prompts');
let boxen = require('boxen')
async function firstQuestions(){
let FirstQuestions = [
{
type: 'select',
name: 'type',
message: 'Pick a type',
choices: [
{ title: 'Class', description: 'A class, called with the new keyword.', value: 'class' },
{ title: 'Function', value: 'function', description: 'A function.' }
]
},
{
type: "text",
name: "name",
message: "Name of the class/function",
validate: value => value == "" ? `Can't be blank` : true
},
{
type: "text",
name: "path",
message: "The path to the file your class/function will be created in",
validate: value => value == "" ? `Can't be blank` : true
}
]
const FirstAnswers = await prompts(FirstQuestions);
return FirstAnswers
}
async function finalQuestions(){
let FirstQuestions = [
{
type: 'text',
name: 'description',
message: 'The description of the whole function/class',
validate: value => value == "" ? `Can't be blank` : true
},
{
type: "text",
name: "example",
message: "Example of the class/function (you can skip)"
},
{
type: "text",
name: "code",
message: "The native code for the function/class (can be blank)"
}
]
const FirstAnswers = await prompts(FirstQuestions);
return FirstAnswers
}
async function Params(){
const Params = await prompts([{
type: 'list',
name: 'params',
message: 'Enter param names. Seperated with a ,',
initial: '',
separator: ',',
validate: value => value == [] ? `Can't be blank` : true
}])
let OptoParamo = []
Params.params.map(p=>{
OptoParamo.push({
type: "text",
name: `ParamDesc${p}`,
message: `What is the description of the param ${p}`,
validate: value => value == "" ? `Can't be blank` : true
})
})
let OptoParamoTypes = []
Params.params.map(p=>{
OptoParamoTypes.push({
type: "text",
name: `ParamType${p}`,
message: `What is the type of the param ${p}`
})
})
let ParamDescs = await prompts(OptoParamo)
let ParamTypes = await prompts(OptoParamoTypes)
let TheActualParams = []
Params.params.map(p=>{
TheActualParams.push({
name: p,
description: ParamDescs["ParamDesc"+p],
type: ParamTypes["ParamType"+p]
})
})
return TheActualParams
}
function box(txt){
return boxen(txt, {
padding: 1,
margin: 1,
borderColor: 'yellow',
backgroundColor: 'magenta',
borderStyle: {
topLeft: '+',
topRight: '+',
bottomLeft: '+',
bottomRight: '+',
horizontal: '-',
vertical: '|'
}
})
}
let args = process.argv.slice(2)
if(!args[0]) return console.log("Run `xd help` for help.")
if(["help","h"].includes(args[0].toLowerCase())){
console.log(box("Help\nhelp | h - View the commands\ngen | generate - Generate a project"))
}else if(["generate", "gen"].includes(args[0].toLowerCase())){
(async()=>{
console.log(box("Generate a new project! Part 1"))
let FirstQuestions = await firstQuestions()
switch(FirstQuestions.type){
case "class":
let Paramsa = await Params()
let FinalQuestionsA = await finalQuestions()
XD.makeClass(FirstQuestions.path,FirstQuestions.name,Paramsa,FinalQuestionsA.code,FinalQuestionsA.description,FinalQuestionsA.example)
console.log(box(`Created your ${FirstQuestions.type} called ${FirstQuestions.name} !`))
break;
case "function":
let Paramsb = await Params()
let FinalQuestionsB = await finalQuestions()
XD.makeFunction(FirstQuestions.path,FirstQuestions.name,Paramsb,FinalQuestionsB.code,FinalQuestionsB.description,FinalQuestionsB.example)
console.log(box(`Created your ${FirstQuestions.type} called ${FirstQuestions.name} !`))
break;
}
})();
}