UNPKG

aj-flutter-cli

Version:
117 lines (106 loc) • 3.21 kB
import Ora from "Ora"; import chalk from "chalk"; import inquirer from "inquirer"; import logSymbols from "log-symbols"; import child_process from "child_process"; import { downloadFromGithub } from "../../utils"; import REMOTE_URL from "../../value"; import targetFileDisplayReplace from "./targetFileDisplayReplace"; import updateNullSafetyTargetFile from "./updateNullSafetyTargetFile"; export const COMMON_NULL_SAFETY = "flutter_getx_template"; export const regNameWithNullsafety = "name: flutter_getx_template"; export const regDescription = "description: A new Flutter project."; export const regVersion = "version: 1.0.0+1"; const createFlutterApp = async (projectName: string, targetDir: string) => { try { const { flutterVersion } = await inquirer.prompt([ { type: "list", name: "flutterVersion", message: "Which flutter version do you want to create", default: "null-safety", choices: ["null-safety"], validate(val) { return true; } } ]); const { description, version } = await inquirer.prompt([ { type: "input", name: "description", message: "Please input your project description", default: "description", validate(val) { return true; } }, { type: "input", name: "version", message: "Please input project version", default: "1.0.0", validate(val) { return true; }, transformer(val) { return val; } } ]); console.log( chalk.white(`\n\n✨ Creating project in ${chalk.yellow(targetDir)}.`) ); console.log(chalk.white(`\nšŸ—ƒ Initializing git repository....\n`)); child_process.execSync(`flutter create ${projectName}`, { stdio: [0, 1], windowsHide: true }); // åˆ‡ę¢å½“å‰ē›®å½•åˆ°ē›®ę ‡ę–‡ä»¶å¤¹ process.chdir(`./${projectName}`); const spinner = Ora({ text: `Download template from ajFlutter git repository... This might take a while....\n` }); spinner.start(); const remoteUrl = flutterVersion === "null-safety" ? REMOTE_URL.FLUTTER_NULL_SAFETY : REMOTE_URL.FLUTTER_NULL_SAFETY; const templateName = flutterVersion === "null-safety" ? COMMON_NULL_SAFETY : COMMON_NULL_SAFETY; await downloadFromGithub(remoteUrl, templateName).catch(err => { console.log(logSymbols.error, err); spinner.fail( chalk.red("Sorry, it may be network error,please check it out. \n") ); process.exit(-1); }); targetFileDisplayReplace( projectName, flutterVersion, `${targetDir}/${templateName}` ); // ę ¹ę®äøåŒē‰ˆęœ¬čæ›č”ŒäøåŒēš„ę“ä½œ if (flutterVersion === "null-safety") updateNullSafetyTargetFile( projectName, targetDir, description, version, spinner ); else updateNullSafetyTargetFile( projectName, targetDir, description, version, spinner ); } catch (error) { console.log(error); } }; export default createFlutterApp;