2022-11-19 13:09:25 +00:00
|
|
|
import { mkdir, readdir, readdirSync } from "fs";
|
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";
|
|
|
|
|
|
|
|
const weclomeASCII = getConstant("welcomeMessage")
|
|
|
|
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-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-19 13:09:25 +00:00
|
|
|
install(packageManager as "npm" | "pnpm" | "yarn" | null, answers.location)
|
|
|
|
|
2022-11-19 07:01:57 +00:00
|
|
|
});
|