xd.js
Version:
XD.JS ==== [](https://npmjs.com/xd.js) [](https://npmjs.com/xd.js)<br> How do I install it? ``` npm i -g
59 lines (55 loc) • 2.05 kB
JavaScript
//Package engine core.
const outdent = require('outdent')
module.exports={
makeClass(path,className,params,nativeCode,description,example){
const fs = require('fs')
fs.writeFileSync(path.endsWith("/") ? `${path}${className}.js` : `${path}/${className}.js`,outdent`
class ${className} {
//JSDoc stuff...
/**${params.map(p=>`
* @param {${p.type}} ${p.name} ${p.description}
`).join("")}
* @example
* ${example||"No example :("}
* @description ${description || "No description :("}
* @class
*/
constructor(${params.map(p=>p.name).join(", ")}) {
${nativeCode || ""}
}
}
/*
Export it so you can use it like so:
const { ${className} } = require("${path.endsWith("/") ? path : path+"/"}")
Note other imports may be required for the path.
*/
module.exports={
${className}: ${className}
}`)
},
makeFunction(path,functionName,params,nativeCode,description,example){
const fs = require('fs')
fs.writeFileSync(path.endsWith("/") ? `${path}${functionName}.js` : `${path}/${functionName}.js`,outdent`
function ${functionName}(${params.map(p=>p.name)}){
//JSDoc stuff...
/**${params.map(p=>`
* @param {${p.type}} ${p.name} ${p.description}
`).join("")}
* @example
* ${example||"No example :("}
* @description ${description || "No description :("}
* @function
*/
${nativeCode || ""}
}
/*
Export it so you can use it like so.
const { ${functionName} } = require("${path.endsWith("/") ? path : path+"/"}")
Note other imports may be required for the path.
*/
module.exports = {
${functionName}: ${functionName}
}
}`)
}
}