UNPKG

@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.

86 lines (85 loc) 4.14 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.runTasks = void 0; const chalk_1 = __importDefault(require("chalk")); const path_1 = __importDefault(require("path")); const child_process_1 = require("child_process"); const functions_1 = require("./functions"); const git_1 = require("./functions/git"); async function runPackageManager(projectPath, packageManager) { let command = (0, functions_1.handlePackageManager)(projectPath, packageManager); if (!command) { console.log(chalk_1.default.green(`\nUnable to identify the package manager, Using NPM`)); command = 'npm install'; } try { (0, child_process_1.execSync)(command, { stdio: 'inherit', cwd: projectPath }); } catch (err) { console.log(chalk_1.default.red.bold('\nUnable to run the command. Please try again.')); process.exit(1); } } /** * Running all the tasks to create a new project. */ async function runTasks() { console.log(chalk_1.default.bold('\nWelcome to Project Initialization Wizard!')); const projectName = await (0, functions_1.askProjectName)(); const projectPath = path_1.default.join(process.cwd(), projectName); if ((0, functions_1.isDirectoryNotEmpty)(projectPath)) { console.log(chalk_1.default.red.bold('\nError: The project folder is not empty. Please choose a different name or use an empty folder.')); } const platform = await (0, functions_1.askFramework)(); const PlatformClass = await Promise.resolve(`${`./src/${platform.toLocaleLowerCase()}`}`).then(s => __importStar(require(s))).catch(console.log); if (!PlatformClass) { console.log(chalk_1.default.red.bold(`\nError: ${platform} is not a valid platform.`)); process.exit(1); } const packageManager = await (0, functions_1.askPackageManager)((0, functions_1.getPackageManager)(process.cwd()), PlatformClass.default.supportedPackageManagers); const platformInstance = new PlatformClass.default({ projectName, packageManager }); if (!(0, functions_1.isNodeVersionCompatible)(platformInstance.node)) { console.log(chalk_1.default.red.bold("\nCouldn't Scaffold the project. Minimum required NodeJs version is %s"), platformInstance.node); process.exit(1); } await platformInstance.handle().catch(() => { console.log(chalk_1.default.red.bold("\nCouldn't Scaffold the project. Please try again.")); process.exit(1); }); const gitSetup = new git_1.GitSetup(projectName, projectPath, platform); await gitSetup.setupGit().catch((err) => { if (!err) console.log(''); console.log(chalk_1.default.red.bold("\nCouldn't initialize GIT. Please run git init")); err && console.log(chalk_1.default.red.bold("\nCouldn't initialize GIT. Please run git init")); process.exit(1); }); await runPackageManager(projectPath, packageManager); } exports.runTasks = runTasks;