Skip to content

Commit b918687

Browse files
committed
Add the create option
1 parent 2d2bca2 commit b918687

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
import arg from 'arg';
22
import inquirer from 'inquirer';
33
import simpleGit from 'simple-git/promise';
4-
import builder from '../src/main'
4+
import build from './parse';
5+
import create from './create';
56
import fs from 'fs';
67

78
const localGit = '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-
const git = simpleGit(__dirname);
50+
const git = simpleGit(__dirname);
4951
const isRepo = await git.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
export async function cli(args) {
129131
let options = 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 = await promptForMissingOptions(options);
138-
console.log(options);
139-
config = await builder(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 = await promptForMissingOptions(options);
142+
console.log(options);
143+
config = await build(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+
import ncp from 'ncp';
2+
import path from 'path';
3+
import { promisify } from 'util';
4+
5+
const copy = promisify(ncp);
6+
7+
const copyFiles = async (filePath) => {
8+
9+
try {
10+
11+
const templateDirectory = path.resolve(
12+
new URL(import.meta.url).pathname,
13+
path.join('..', 'templates'),
14+
);
15+
16+
const targetDirectory = process.cwd();
17+
18+
await copy(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+
export default copyFiles;

0 commit comments

Comments
 (0)