2022-11-21 09:25:34 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2022-11-19 17:37:53 +00:00
|
|
|
import fs, { createWriteStream, mkdir, readdir, readdirSync } from "fs";
|
2022-11-20 06:40:54 +00:00
|
|
|
import { copySync, removeSync } from "fs-extra";
|
2022-11-19 07:01:57 +00:00
|
|
|
import * as inquirer from "inquirer";
|
|
|
|
import getPackageManager from "../lib/getPackageManager";
|
|
|
|
import install from "../lib/installDependencies";
|
2022-11-19 13:09:25 +00:00
|
|
|
import * as logger from "../utils/logger"
|
2022-11-19 13:34:00 +00:00
|
|
|
import constants from "../lib/constants"
|
|
|
|
import getConstant from "../lib/constants";
|
2022-11-19 17:37:53 +00:00
|
|
|
import stream from "got";
|
|
|
|
import unzip from "unzip-stream";
|
2022-11-22 09:06:12 +00:00
|
|
|
import validateClient from "../lib/validateClient";
|
2022-11-19 13:34:00 +00:00
|
|
|
|
|
|
|
const weclomeASCII = getConstant("welcomeMessage")
|
2022-11-21 16:26:42 +00:00
|
|
|
console.log(weclomeASCII)
|
2022-11-19 07:01:57 +00:00
|
|
|
|
|
|
|
inquirer
|
2022-11-19 13:09:25 +00:00
|
|
|
.prompt([
|
|
|
|
{
|
|
|
|
type: "input",
|
|
|
|
name: "location",
|
|
|
|
message: "Where should the project be initialized?"
|
|
|
|
},
|
2022-11-19 07:01:57 +00:00
|
|
|
{
|
|
|
|
type: 'list',
|
|
|
|
name: 'flavor',
|
|
|
|
message: 'Which flavor?',
|
|
|
|
choices: ['TypeScript', 'JavaScript'],
|
|
|
|
filter(val) {
|
|
|
|
return val.toLowerCase();
|
|
|
|
},
|
|
|
|
},
|
2022-11-19 13:09:25 +00:00
|
|
|
|
2022-11-19 07:01:57 +00:00
|
|
|
])
|
|
|
|
.then((answers) => {
|
2022-11-22 09:06:12 +00:00
|
|
|
validateClient()
|
2022-11-19 13:09:25 +00:00
|
|
|
mkdir(answers.location, (e) => {
|
|
|
|
if (e && e.code != "EEXIST") {
|
|
|
|
logger.error("Failed to create project directory.")
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e) {
|
|
|
|
if (e.code == "EEXIST") {
|
|
|
|
readdir(answers.location, (_, files) => {
|
|
|
|
if (files.length) {
|
|
|
|
logger.error("Directory not empty.")
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-11-19 07:01:57 +00:00
|
|
|
let packageManager = getPackageManager()
|
|
|
|
|
2022-11-21 09:31:34 +00:00
|
|
|
const start = async (TEMPLATE_DOWNLOAD_URL: string) => {
|
2022-11-21 09:13:02 +00:00
|
|
|
const download = stream(TEMPLATE_DOWNLOAD_URL, { isStream: true }).pipe(createWriteStream(`${answers.location}/create-guilded-bot_ts.zip`));
|
|
|
|
download.on("finish", () => {
|
|
|
|
fs.createReadStream(`${answers.location}/create-guilded-bot_ts.zip`)
|
|
|
|
.pipe(unzip.Extract({ path: `${answers.location}` }))
|
|
|
|
.on("finish", () => {
|
|
|
|
removeSync(`${answers.location}/create-guilded-bot_ts.zip`)
|
|
|
|
logger.success("🚀 Let's get started.")
|
|
|
|
})
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-11-19 17:37:53 +00:00
|
|
|
if (answers.flavor == "typescript") {
|
2022-11-21 09:31:34 +00:00
|
|
|
const TEMPLATE_DOWNLOAD_URL = "https://files.devcomp.xyz/r/create-guilded-bot_ts.zip"
|
2022-11-19 17:37:53 +00:00
|
|
|
|
2022-11-21 09:13:02 +00:00
|
|
|
start(TEMPLATE_DOWNLOAD_URL).then(() => {
|
|
|
|
install(packageManager as "npm" | "pnpm" | "yarn" | null, answers.location)
|
|
|
|
})
|
|
|
|
}
|
2022-11-19 17:37:53 +00:00
|
|
|
|
2022-11-21 09:13:02 +00:00
|
|
|
if (answers.flavor == "javascript") {
|
2022-11-21 09:31:34 +00:00
|
|
|
const TEMPLATE_DOWNLOAD_URL = "https://files.devcomp.xyz/r/create-guilded-bot_js.zip"
|
2022-11-19 17:37:53 +00:00
|
|
|
|
2022-11-19 07:01:57 +00:00
|
|
|
|
2022-11-21 09:13:02 +00:00
|
|
|
start(TEMPLATE_DOWNLOAD_URL).then(() => {
|
|
|
|
install(packageManager as "npm" | "pnpm" | "yarn" | null, answers.location)
|
|
|
|
})
|
2022-11-20 06:40:54 +00:00
|
|
|
}
|
2022-11-19 13:09:25 +00:00
|
|
|
|
2022-11-19 07:01:57 +00:00
|
|
|
});
|