Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8cc739b

Browse files
author
coderwhy
committed
实现create addcpn功能
1 parent46fafb1 commit8cc739b

File tree

850 files changed

+95895
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

850 files changed

+95895
-0
lines changed

‎.DS_Store

6 KB
Binary file not shown.

‎index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env node
2+
constprogram=require('commander');
3+
4+
consthelpOptions=require('./lib/core/help');
5+
constcreateCommands=require('./lib/core/create');
6+
7+
constlog=require('./lib/utils/log');
8+
9+
// 定义显示模块的版本号
10+
program.version(require('./package.json').version);
11+
12+
// 给help增加其他选项
13+
helpOptions();
14+
15+
// 创建命令
16+
createCommands();
17+
18+
// 解析终端指令
19+
program.parse(process.argv);
20+
21+
22+
23+

‎lib/config/repo_config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
constvueGitRepo="direct:https://github.com/coderwhy/hy-vue-temp.git";
2+
3+
4+
module.exports={
5+
vueGitRepo
6+
}

‎lib/core/actions.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const{ promisify}=require('util');
2+
constpath=require('path');
3+
4+
constprogram=require('commander');
5+
constdownloadRepo=promisify(require('download-git-repo'));
6+
constopen=require('open');
7+
8+
constlog=require('../utils/log');
9+
constterminal=require('../utils/terminal');
10+
const{ ejsCompile, writeFile}=require('../utils/file');
11+
constrepoConfig=require('../config/repo_config');
12+
13+
constcreateProject=async(project,otherArg)=>{
14+
// 1.提示信息
15+
log.hint('coderwhy helps you create your project, please wait a moment~');
16+
17+
// 2.clone项目从仓库
18+
awaitdownloadRepo(repoConfig.vueGitRepo,project,{clone:true});
19+
20+
// 3.执行终端命令npm install
21+
// terminal.exec('npm install', {cwd: `./${project}`});
22+
constnpm=project.platform==='win32' ?'npm.cmd' :'npm';
23+
awaitterminal.spawn(npm,['install'],{cwd:`./${project}`});
24+
25+
// 4.打开浏览器
26+
open('http://localhost:8080/');
27+
28+
// 5.运行项目
29+
awaitterminal.spawn(npm,['run','serve'],{cwd:`./${project}`});
30+
}
31+
32+
constaddComponent=async(name)=>{
33+
console.log(name,program.dest);
34+
35+
// 1.获取模块引擎的路径
36+
consttemplatePath=path.resolve(__dirname,'../template/component.vue.ejs');
37+
constresult=awaitejsCompile(templatePath,{name});
38+
39+
// 2.写入文件中
40+
consttargetPath=path.resolve(program.dest,`${name}.vue`);
41+
writeFile(targetPath,result);
42+
}
43+
44+
module.exports={
45+
createProject,
46+
addComponent
47+
}

‎lib/core/create.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
constprogram=require('commander');
2+
3+
const{
4+
createProject,
5+
addComponent
6+
}=require('./actions');
7+
8+
constcreateCommands=()=>{
9+
// 创建项目指令
10+
program
11+
.command('create <project> [otherArgs...]')
12+
.description('clone a repository into a newly created directory')
13+
.action(createProject);
14+
15+
program
16+
.command('addcpn <name>')
17+
.description('add vue component, 例如: coderwhy addcpn NavBar -d src/components')
18+
.action(addComponent)
19+
20+
program.command('test').action(()=>{
21+
// terminal.spawn("npm", ['--version']);
22+
// terminal.exec("npm --version");
23+
// open('http://localhost:8080/');
24+
})
25+
}
26+
27+
module.exports=createCommands;

‎lib/core/help.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
constprogram=require('commander');
2+
3+
consthelpOptions=()=>{
4+
program.option('-w --why','a coderwhy option');
5+
6+
program.option('-s --src <src>','a source folder');
7+
program.option('-d --dest <dest>','a destination folder, 例如: -d src/pages, 错误/src/pages');
8+
program.option('-f --framework <framework>','your framework name');
9+
10+
program.on('--help',function(){
11+
console.log("");
12+
console.log("usage");
13+
console.log(" coderwhy -v");
14+
console.log(" coderwhy -version");
15+
})
16+
}
17+
18+
module.exports=helpOptions;

‎lib/template/component.vue.ejs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<%_if(data) { _%>
2+
<template>
3+
<divclass="<%= data.name %>">
4+
<h2>{{ message }}</h2>
5+
</div>
6+
</template>
7+
8+
<script>
9+
exportdefault {
10+
name:"<%= data.name %>",
11+
components: {
12+
13+
},
14+
mixins: [],
15+
props: {
16+
17+
},
18+
data:function() {
19+
return {
20+
message:"Hello <%= data.name %>"
21+
}
22+
},
23+
created:function() {
24+
25+
},
26+
mounted:function() {
27+
28+
},
29+
computed: {
30+
31+
},
32+
methods: {
33+
34+
}
35+
}
36+
</script>
37+
38+
<style scoped>
39+
.<%=data.name%> {
40+
41+
}
42+
</style>
43+
44+
<%_ } _%>

‎lib/template/test.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<template>
2+
<div>
3+
4+
</div>
5+
</template>
6+
7+
<script>
8+
exportdefault {
9+
10+
}
11+
</script>
12+
13+
<style scoped>
14+
15+
</style>

‎lib/utils/file.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
constfs=require('fs');
2+
constejs=require('ejs');
3+
4+
constlog=require('./log');
5+
6+
constejsCompile=(templatePath,data={},options={})=>{
7+
returnnewPromise((resolve,reject)=>{
8+
ejs.renderFile(templatePath,{data},options,(err,str)=>{
9+
if(err){
10+
reject(err);
11+
return;
12+
}
13+
resolve(str);
14+
})
15+
})
16+
}
17+
18+
constwriteFile=(path,content)=>{
19+
if(fs.existsSync(path)){
20+
log.error("the file already exists~")
21+
return;
22+
}
23+
returnfs.promises.writeFile(path,content);
24+
}
25+
26+
module.exports={
27+
ejsCompile,
28+
writeFile
29+
}

‎lib/utils/log.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
constchalk=require('chalk');
2+
3+
consthint=(...info)=>{
4+
console.log(chalk.blue(info));
5+
}
6+
7+
consterror=(...info)=>{
8+
console.log(chalk.red(info));
9+
}
10+
11+
constclear=()=>{
12+
console.clear();
13+
}
14+
15+
module.exports={
16+
hint,
17+
error,
18+
clear
19+
}

‎lib/utils/terminal.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const{ spawn, exec}=require('child_process');
2+
3+
4+
constspawnCommand=(...args)=>{
5+
returnnewPromise((resole,reject)=>{
6+
constchildProcess=spawn(...args);
7+
childProcess.stdout.pipe(process.stdout);
8+
childProcess.stderr.pipe(process.stderr);
9+
childProcess.on('close',()=>{
10+
resole();
11+
})
12+
})
13+
}
14+
15+
constexecCommand=(...args)=>{
16+
returnnewPromise((resolve,reject)=>{
17+
exec(...args,(err,stdout,stderr)=>{
18+
if(err){
19+
reject(err);
20+
return;
21+
}
22+
console.log(stdout.replace('\n',''));
23+
// console.log(stderr);
24+
resolve();
25+
})
26+
})
27+
}
28+
29+
module.exports={
30+
spawn:spawnCommand,
31+
exec:execCommand
32+
};

‎node_modules/.bin/ejs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎node_modules/.bin/is-docker

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎node_modules/.bin/jake

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎node_modules/.bin/rimraf

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎node_modules/.bin/seek-bunzip

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎node_modules/.bin/seek-table

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎node_modules/@sindresorhus/is/dist/example.d.ts

Whitespace-only changes.

‎node_modules/@sindresorhus/is/dist/example.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎node_modules/@sindresorhus/is/dist/example.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎node_modules/@sindresorhus/is/dist/index.d.ts

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp