Skip to content

Commit 17bd2b6

Browse files
committed
chore: Move all cli scripts into lib folder.
1 parent 0ffd82d commit 17bd2b6

12 files changed

Lines changed: 63 additions & 64 deletions

File tree

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
node_modules/*
2-
dist
2+
lib-dist
33
test/fixtures
44
coverage
55
esdocs

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# compiled es6 code
2-
dist/
2+
lib-dist/
33
coverage
44
node_modules
55
npm-debug.log

bin/index.js

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
11
#!/usr/bin/env node
22

3-
import findUp from 'find-up';
4-
import yargs from 'yargs';
5-
import log from '../lib/log';
6-
7-
import build from './build';
8-
import newFile from './new';
9-
import watch from './watch';
10-
import clean from './clean';
11-
import init from './init';
12-
import serve from './serve';
13-
14-
const commands = {
15-
build,
16-
new: newFile,
17-
watch,
18-
clean,
19-
init,
20-
serve,
21-
};
3+
const path = require('path');
4+
const findUp = require('find-up');
5+
const yargs = require('yargs');
226

237
yargs
248
.command('init', 'scaffold a new site')
@@ -45,33 +29,36 @@ yargs
4529
.help('help')
4630
.default('help');
4731

48-
const argv = yargs.argv;
32+
module.exports = function reptarCli({ log, libPath }) {
33+
const argv = yargs.argv;
4934

50-
process.stdout.write('reptar\n\n');
35+
process.stdout.write('reptar\n\n');
5136

52-
if (argv.version) {
53-
let packageJson;
54-
try {
55-
// eslint-disable-next-line
56-
packageJson = require(findUp.sync('package.json', {
57-
cwd: __dirname,
58-
}));
59-
} catch (e) { /* noop */ }
37+
if (argv.version) {
38+
let packageJson;
39+
try {
40+
// eslint-disable-next-line
41+
packageJson = require(findUp.sync('package.json', {
42+
cwd: __dirname,
43+
}));
44+
} catch (e) { /* noop */ }
6045

61-
process.stdout.write(packageJson.version);
62-
process.stdout.write('\n');
63-
} else if (argv._.length === 0) {
64-
yargs.showHelp('log');
65-
process.exit(0);
66-
} else {
67-
const command = argv._[0];
68-
const commandHandler = commands[command];
69-
70-
if (!commandHandler) {
71-
log.error(`Unknown command: ${argv._.join(' ')}`);
46+
process.stdout.write(packageJson.version);
7247
process.stdout.write('\n');
73-
yargs.showHelp();
48+
} else if (argv._.length === 0) {
49+
yargs.showHelp('log');
50+
process.exit(0);
7451
} else {
75-
commandHandler(argv);
52+
const command = argv._[0];
53+
const commandPath = path.join(libPath, 'cli', command);
54+
55+
try {
56+
const commandHandler = require(commandPath).default; // eslint-disable-line
57+
commandHandler(argv);
58+
} catch (e) {
59+
log.error(`Unknown command: ${argv._.join(' ')}`);
60+
process.stdout.write('\n');
61+
yargs.showHelp();
62+
}
7663
}
77-
}
64+
};

bin/reptar-debug.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#!/usr/bin/env node
2+
/* eslint-disable global-require */
23

34
require('babel-polyfill');
45
require('babel-register');
56

6-
require('./index');
7+
const path = require('path');
8+
9+
require('./index')({
10+
log: require('../lib/log').default,
11+
libPath: path.join(__dirname, '..', 'lib'),
12+
});

bin/reptar.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#!/usr/bin/env node
2+
/* eslint-disable global-require */
23

34
require('babel-polyfill');
45

5-
require('./index');
6+
const path = require('path');
7+
8+
require('./index')({
9+
log: require('../lib-dist/log').default,
10+
libPath: path.join(__dirname, '..', 'lib-dist'),
11+
});

bin/build.js renamed to lib/cli/build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import log from '../lib/log';
2-
import Reptar from '../lib';
1+
import log from '../log';
2+
import Reptar from '../index';
33

44
export default async function build(options) {
55
const id = log.startActivity('building\t\t\t');

bin/clean.js renamed to lib/cli/clean.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import log from '../lib/log';
2-
import Reptar from '../lib';
1+
import log from '../log';
2+
import Reptar from '../index';
33

44
export default function () {
55
const reptar = new Reptar();

bin/init.js renamed to lib/cli/init.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import moment from 'moment';
33
import path from 'path';
44
import inquirer from 'inquirer';
55
import spawn from 'cross-spawn';
6-
import log from '../lib/log';
7-
import Constants from '../lib/constants';
6+
import log from '../log';
7+
import Constants from '../constants';
88

99
const dateNowFormatted = moment().format('YYYY-M-D');
1010

bin/new.js renamed to lib/cli/new.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import path from 'path';
33
import moment from 'moment';
44
import fs from 'fs-extra';
55
import inquirer from 'inquirer';
6-
import Config from '../lib/config';
7-
import Url from '../lib/url';
8-
import log from '../lib/log';
6+
import Config from '../config';
7+
import Url from '../url';
8+
import log from '../log';
99

1010
const newTypes = {
1111
file: {

bin/serve.js renamed to lib/cli/serve.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Hapi from 'hapi';
22
import inert from 'inert';
33
import path from 'path';
4-
import Config from '../lib/config';
5-
import log from '../lib/log';
4+
import Config from '../config';
5+
import log from '../log';
66

77
export default async function serve() {
88
const config = new Config();

0 commit comments

Comments
 (0)