Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cli support customize project name #1340

Merged
merged 14 commits into from
Jul 3, 2024
2 changes: 1 addition & 1 deletion packages/create-mako/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/dist
/node_modules
/node_modules
2 changes: 2 additions & 0 deletions packages/create-mako/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
"license": "MIT",
"dependencies": {
"glob": "^10.3.15",
"inquirer": "^9.3.1",
"yargs-parser": "^21.1.1"
},
"devDependencies": {
"@types/inquirer": "^9.0.7",
"@types/node": "^20.12.5",
"@types/yargs-parser": "^21.0.3",
"typescript": "^5.4.3"
Expand Down
25 changes: 23 additions & 2 deletions packages/create-mako/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import fs from 'fs';
import path from 'path';
import yargs from 'yargs-parser';
import { globSync } from 'glob';
import packageJson from '../package.json';

async function main() {
const args = yargs(process.argv.slice(2));

async function init(projectName: string) {
let templatePath = path.join(__dirname, '../templates/react');
let files = globSync('**/*', { cwd: templatePath, nodir: true });
let cwd = path.join(process.cwd(), 'mako-project');
let cwd = path.join(process.cwd(), projectName);

let npmClient = (() => {
let script = process.argv[1];
Expand Down Expand Up @@ -38,6 +42,23 @@ async function main() {
console.log('Happy coding!');
}

async function main() {
let name = args._[0];
if (!name) {
const inquirer = (await import('inquirer')).default;
let answers = await inquirer.prompt([
{
type: 'input',
name: 'name',
message: 'Project name:',
default: 'mako-project',
},
]);
name = answers.name;
}
return init(String(name))
}

main().catch((err) => {
console.error(err);
process.exit(1);
Expand Down
3 changes: 2 additions & 1 deletion packages/create-mako/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
"rootDir": "./src",
"resolveJsonModule": true
},
"include": ["src"]
}
Loading
Loading