@craftnotion/init-project
Version:
A CLI tool to initialize a new project with AdonisJS, NextJS, NestJS, React Native, Strapi, TypeScript, Husky, Git-CZ and more.
131 lines (130 loc) • 4.13 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const inquirer_1 = __importDefault(require("inquirer"));
const base_1 = require("../base");
const functions_1 = require("../../functions");
class Strapi extends base_1.Base {
static supportedPackageManagers = ['npm', 'yarn'];
node = '18.0.0';
/**
* Base command for adonisjs
*/
constructor(data) {
const { packageManager = 'npm', projectName } = data;
super(packageManager);
if (packageManager === 'pnpm')
return;
this.command += this.baseCommand(packageManager, projectName);
}
baseCommand(packageManager, projectName) {
const commandMap = {
npm: ` strapi-app@latest ${projectName}`,
yarn: ` create strapi-app ${projectName}`,
};
return commandMap[packageManager];
}
async handle() {
const useTypeScript = await (0, functions_1.askUseTypeScript)();
if (useTypeScript) {
this.updateCommand('alias', 'typescript');
}
this.updateCommand('alias', 'no-run');
const { quick } = await this.promptInstallationType();
if (!quick) {
const { dbclient } = await this.promptDatabaseClient();
if (dbclient === 'sqlite') {
const { dbfile } = await this.promptDatabaseFilePath();
this.updateCommand('alias', { dbclient, dbfile });
}
else {
const database = await this.promptDatabaseDetails(dbclient);
this.updateCommand('alias', { ...database, dbclient });
}
}
else {
this.updateCommand('alias', 'quickstart');
}
await this.scaffold();
}
async promptInstallationType() {
return await inquirer_1.default.prompt({
type: 'list',
name: 'quick',
message: 'Choose your installation type',
choices: [
{
name: 'Quickstart (recommended)',
value: true,
},
{
name: 'Custom (manual settings)',
value: false,
},
],
});
}
async promptDatabaseClient() {
return await inquirer_1.default.prompt({
type: 'list',
name: 'dbclient',
message: 'Database client',
choices: ['sqlite', 'postgres', 'mysql'],
default: 'sqlite',
});
}
async promptDatabaseFilePath() {
return await inquirer_1.default.prompt({
type: 'input',
name: 'dbfile',
message: 'Database file path for sqlite',
default: '.tmp/data.db',
});
}
async promptDatabaseDetails(dbclient) {
return await inquirer_1.default.prompt([
{
type: 'input',
name: 'dbname',
message: 'Database name',
default: 'default',
},
{
type: 'input',
name: 'dbhost',
message: 'Database host',
default: '127.0.0.1',
},
{
type: 'input',
name: 'dbport',
message: 'Database port',
default: defaultPorts[dbclient],
},
{
type: 'input',
name: 'dbusername',
message: 'Database username',
},
{
type: 'password',
name: 'dbpassword',
message: 'Database password',
},
{
type: 'confirm',
name: 'dbssl',
message: 'Database SSL',
default: false,
},
]);
}
}
exports.default = Strapi;
const defaultPorts = {
postgres: 5432,
mysql: 3306,
sqlite: 3306,
};