Skip to content

Commit

Permalink
refactor: ♻️ html-vue模板增加package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
MuyianKing committed Nov 6, 2024
1 parent 837cf84 commit d1b158c
Show file tree
Hide file tree
Showing 13 changed files with 371 additions and 78,706 deletions.
7 changes: 0 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
## [0.1.3](https://github.com/MuyianKing/cli/compare/v0.1.2...v0.1.3) (2024-11-06)



## [0.1.2](https://github.com/MuyianKing/cli/compare/v0.1.0...v0.1.2) (2024-11-06)


### Bug Fixes

* :bug: 修改README.md ([c16c99d](https://github.com/MuyianKing/cli/commit/c16c99d9bace9c1007e63acc564e28a022fae9bb))
Expand Down
42 changes: 22 additions & 20 deletions cli/bin/command/inquirer.html.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
const inquirer = require('inquirer');
const { copyDir, checkMkdirExists } = require("../copy");
const path = require("path");
const path = require('node:path')
const process = require('node:process')
const inquirer = require('inquirer')
const { copyDir, checkMkdirExists } = require('../copy')

function inquirerPrompt(argv) {
const { name } = argv;
const { name } = argv
return new Promise((resolve, reject) => {
inquirer.prompt([
{
type: 'input',
name: 'name',
message: '项目名称',
default: name,
validate: function (val) {
validate(val) {
if (!val) {
return "请输入项目名称:";
return '请输入项目名称:'
}
return true;
return true
},
},
]).then(answers => {
]).then((answers) => {
resolve(answers)
}).catch(error => {
}).catch((error) => {
reject(error)
})
})

}

exports.inquirerHtmlPrompt = function(argv){
exports.inquirerHtmlPrompt = function (argv) {
inquirerPrompt(argv).then((answers) => {
const { name } = answers;
const { name } = answers
const isMkdirExists = checkMkdirExists(
path.resolve(process.cwd(), `./${name}`)
);
path.resolve(process.cwd(), `./${name}`),
)

if (isMkdirExists) {
console.log(`${name}文件夹已经存在`);
console.log(`${name}文件夹已经存在`)
} else {
copyDir(
path.resolve(__dirname, `../../template/html/vue`),
path.resolve(process.cwd(), `./${name}`)
);
path.resolve(process.cwd(), `./${name}`),
)

console.log('\x1B[32m%s\x1B[0m', `
create successful
cd ./${name} and can use live-server run
cd ./${name}
pnpm i
live-server
`)
}
});
};
})
}
7 changes: 4 additions & 3 deletions cli/bin/command/inquirer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const process = require('node:process')

exports.inquirerPrompt = function () {
if (process.argv.length === 2) {
console.log(`缺少执行的命令:npm <command>
Expand All @@ -6,7 +8,6 @@ exports.inquirerPrompt = function () {
mu c|create 创建一个项目
mu html 创建普通项目(没有打包工具)
`);
return;
`)
}
};
}
49 changes: 24 additions & 25 deletions cli/bin/command/inquirer.project.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,60 @@
const inquirer = require('inquirer');
const { copyDir, checkMkdirExists } = require("../copy");
const path = require("path");
const path = require('node:path')
const process = require('node:process')
const inquirer = require('inquirer')
const { copyDir, checkMkdirExists } = require('../copy')

function inquirerPrompt(argv) {
const { name } = argv;
const { name } = argv
return new Promise((resolve, reject) => {
inquirer.prompt([
{
type: 'input',
name: 'name',
message: '项目名称',
default: name,
validate: function (val) {
validate(val) {
if (!val) {
return "请输入项目名称:";
return '请输入项目名称:'
}
return true;
return true
},
},
{
type: 'list',
name: 'build_type',
message: '构建工具',
choices: ['rsbuild', 'vite'],
filter: function (value) {
filter(value) {
return {
'rsbuild': "rsbuild",
'vite': "vite",
}[value];
rsbuild: 'rsbuild',
vite: 'vite',
}[value]
},
},
]).then(answers => {
]).then((answers) => {
resolve(answers)
}).catch(error => {
}).catch((error) => {
reject(error)
})
})
}



exports.inquirerProjectPrompt = function(argv){
exports.inquirerProjectPrompt = function (argv) {
inquirerPrompt(argv).then((answers) => {
const { name, build_type } = answers;
const { name, build_type } = answers
const isMkdirExists = checkMkdirExists(
path.resolve(process.cwd(), `./${name}`)
);
path.resolve(process.cwd(), `./${name}`),
)

if (isMkdirExists) {
console.log(`${name}文件夹已经存在`);
console.log(`${name}文件夹已经存在`)
} else {
copyDir(
path.resolve(__dirname, ` ../../template/projects/${build_type}`),
path.resolve(process.cwd(), `./${name}`)
);
path.resolve(process.cwd(), `./${name}`),
)

console.log('\x1B[32m%s\x1B[0m', `cd ./${name}`)
}
});
};
})
}
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@muyianking/cli",
"version": "0.1.3",
"version": "0.1.0",
"description": "慕易安的脚手架",
"author": "muyian",
"license": "ISC",
Expand Down
58 changes: 28 additions & 30 deletions cli/template/html/vue/index.html
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>vue template</title>
<link rel="stylesheet" href="./node_modules/element-plus/dist/index.css" />
</head>

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>vue template</title>
<link rel="stylesheet" href="./source/element-plus.css" />
</head>
<body>
<script src="./node_modules/vue/dist/vue.global.js"></script>
<script src="./node_modules/element-plus/dist//index.full.min.js"></script>

<body>
<script src="./source/vue.global.js"></script>
<script src="./source/element-plus.js"></script>
<div id="app">
<el-button type="primary">测试</el-button>
</div>

<div id="app">
<el-button type="primary">测试</el-button>
</div>
<script>
const { createApp, ref } = Vue

<script>
const { createApp, ref } = Vue

createApp({
setup() {
const message = ref('Hello vue!')
return {
message
}
}
})
.use(ElementPlus)
.mount('#app')
</script>
</body>

</html>
createApp({
setup() {
const message = ref('Hello vue!')
return {
message,
}
},
})
.use(ElementPlus)
.mount('#app')
</script>
</body>
</html>
14 changes: 14 additions & 0 deletions cli/template/html/vue/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "html-vue",
"version": "1.0.0",
"description": "",
"author": "",
"license": "ISC",
"keywords": [],
"main": "index.js",
"scripts": {},
"dependencies": {
"element-plus": "^2.8.7",
"vue": "^3.5.12"
}
}
1 change: 0 additions & 1 deletion cli/template/html/vue/source/element-plus.css

This file was deleted.

Loading

0 comments on commit d1b158c

Please sign in to comment.