Created
August 16, 2023 05:13
-
-
Save dooderstem/b949e5dfcb7ec9347ec82701db490b8c to your computer and use it in GitHub Desktop.
shell & prompt script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("node:fs"); | |
const sh = require("shelljs"); | |
if (!sh.which("git")) { | |
sh.echo("Sorry, this script requires git"); | |
sh.exit(1); | |
} | |
let schema = new CreateSchema(); | |
prompter(); | |
function CreateSchema() { | |
this.error = new Error(); | |
this.projectName = { | |
properties: { | |
"project name": { | |
pattern: /^[a-zA-Z\s\-]+$/, | |
message: this.error.message, | |
required: true, | |
}, | |
}, | |
}; | |
this.scriptName = { | |
properties: { | |
"script name": { | |
pattern: /^[a-zA-Z\s\-]+$/, | |
message: this.error.message, | |
required: true, | |
}, | |
}, | |
}; | |
} | |
function prompter() { | |
const prompt = require("prompt"); | |
const { stdin, stdout } = require("node:process"); | |
prompt.stop = function (msg) { | |
if (prompt.stopped || !prompt.started) return; | |
stdin.destroy(); | |
prompt.emit("stop"); | |
sh.exec("clear", () => {}); | |
console.log(msg); | |
prompt.stopped = true; | |
prompt.started = false; | |
prompt.paused = false; | |
return prompt; | |
}; | |
let projectName; | |
let scriptName; | |
prompt.start(); // Start the prompt | |
prompt.get(schema.projectName, (err, data) => { | |
if (data["project name"] == " ") throw new Error(err.message); | |
projectName = data["project name"]; | |
const projectNameArr = projectName.trim().split(" "); | |
if (projectNameArr.length > 1) throw new Error(err.message); | |
console.log(projectName); | |
// createProjectName(projectName); | |
/* | |
prompt.get(schema.scriptName, (err, data) => { | |
if (data["schema name"] == " ") throw new Error(err.message); | |
scriptName = data["script name"]; | |
}); | |
*/ | |
}); | |
function createProjectName(project) { | |
const tampermonkey = "Tampermonkey"; | |
const dist = `${tampermonkey}/${project}`; | |
if (!fs.existsSync(tampermonkey)) { | |
fs.mkdirSync(tampermonkey).catch((err) => console.log(err.message)); | |
if (!fs.existsSync(dist)) { | |
console.log(`creating ${dist}....`); | |
fs.mkdir(dist, (err) => { | |
if (err) { | |
console.log(err); | |
return; | |
} | |
}); | |
} else { | |
console.log("heyy"); | |
prompt.stop("didnt work"); | |
} | |
} | |
} | |
} | |
function writeData() { | |
const dist = "metadata-gen/dist"; | |
fs.writeFile(dist + "/data.js", require("./metadata"), "utf8", () => {}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment