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

Commitb918687

Browse files
committed
Add the create option
1 parent2d2bca2 commitb918687

File tree

2 files changed

+55
-15
lines changed

2 files changed

+55
-15
lines changed

‎src/cli.js

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
importargfrom'arg';
22
importinquirerfrom'inquirer';
33
importsimpleGitfrom'simple-git/promise';
4-
importbuilderfrom'../src/main'
4+
importbuildfrom'./parse';
5+
importcreatefrom'./create';
56
importfsfrom'fs';
67

78
constlocalGit='Local directory';
@@ -28,6 +29,7 @@ function parseArgumentsIntoOptions(rawArgs) {
2829
}
2930
);
3031
return{
32+
command:args['_'][1],
3133
git:args['--git'],
3234
dir:args['--dir'],
3335
codeBranch:args['--code'],
@@ -45,11 +47,11 @@ async function promptForMissingOptions(options) {
4547
if(!options.git&&!options.dir){
4648

4749
// check if the current dir is a valid repo
48-
constgit=simpleGit(__dirname);
50+
constgit=simpleGit(__dirname);
4951
constisRepo=awaitgit.checkIsRepo();
5052

5153
if(!isRepo){
52-
54+
5355
questions.push({
5456
type:'list',
5557
name:'source',
@@ -127,22 +129,32 @@ async function promptForMissingOptions(options) {
127129

128130
exportasyncfunctioncli(args){
129131
letoptions=parseArgumentsIntoOptions(args);
130-
132+
131133
// If help called just print the help text and exit
132134
if(options.help){
133-
console.log('help message...');
135+
console.log('Docs can be found at github: https://github.com/coderoad/builder-cli/');
134136
}
135137
else{
136-
// Otherwise, continue with the other options
137-
options=awaitpromptForMissingOptions(options);
138-
console.log(options);
139-
config=awaitbuilder(options);
140-
141-
if(options.output){
142-
fs.writeFileSync(options.output,config,'utf8');
143-
}
144-
else{
145-
console.log(JSON.stringify(config))
138+
switch(options.command){
139+
case'build':
140+
// Otherwise, continue with the other options
141+
options=awaitpromptForMissingOptions(options);
142+
console.log(options);
143+
config=awaitbuild(options);
144+
145+
if(config){
146+
if(options.output){
147+
fs.writeFileSync(options.output,config,'utf8');
148+
}
149+
else{
150+
console.log(JSON.stringify(config));
151+
}
152+
}
153+
break;
154+
155+
case'create':
156+
create(__dirname);
157+
break;
146158
}
147159
}
148160
}

‎src/create.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
importncpfrom'ncp';
2+
importpathfrom'path';
3+
import{promisify}from'util';
4+
5+
constcopy=promisify(ncp);
6+
7+
constcopyFiles=async(filePath)=>{
8+
9+
try{
10+
11+
consttemplateDirectory=path.resolve(
12+
newURL(import.meta.url).pathname,
13+
path.join('..','templates'),
14+
);
15+
16+
consttargetDirectory=process.cwd();
17+
18+
awaitcopy(templateDirectory,targetDirectory,{
19+
clobber:false,
20+
});
21+
}
22+
catch(e){
23+
console.log('Error on creating the files:');
24+
console.log(JSON.stringify(e,null,1));
25+
}
26+
}
27+
28+
exportdefaultcopyFiles;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp