This repository has been archived by the owner on Jul 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
94 lines (77 loc) · 2.36 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env node
'use strict';
const proc = require('process');
const getPkg = require('@tunnckocore/package-json').default;
const charlike = require('charlike').default;
const cli = require('mri')(process.argv.slice(2), {
alias: {
owner: 'O',
name: 'N',
desc: 'D',
repo: 'R',
engine: 'E',
locals: 'L',
templates: 'T',
help: 'h',
version: 'v',
},
});
proc.title = 'charlike-cli';
const name = cli._[0] || cli.name;
const desc = cli._[1] || cli.desc;
delete cli._;
function get(pkgName, field = 'version') {
return getPkg(pkgName).then((pkg) => pkg[field]);
}
async function showHelp(status = 0) {
console.log(`
${await get('charlike-cli', 'description')}
(charlike-cli v${await get('charlike-cli')})
(charlike v${await get('charlike')})
Usage
$ charlike <name> <description> [flags]
Common Flags
--help Show this output
--version Show version
Options
--owner, -O Project github owner - username or organization
--name, -N Name of the project, same as to pass first param
--desc, -D Project description, same as to pass second param
--repo, -R Repository pattern like username/projectName
--engine, -E Engine to be used, j140 by default
--locals, -L Context to pass to template files (support dot notation)
--templates, -T Path to templates folder
--cwd, -C Folder to be used as current working dir
Examples
$ charlike my-awesome-project 'some cool description'
$ charlike minibase-data 'we are awesome' --owner node-minibase
$ charlike -D 'abc description here' -N beta-trans -O gulpjs
Issues 1: ${await get('charlike', 'homepage')}
Issues 2: ${await get('charlike-cli', 'homepage')}
`);
if (status !== 1) {
throw new Error('foo');
}
proc.exit(status);
}
if (cli.help) {
showHelp();
}
if (!name || !desc) {
showHelp(1).catch(() => proc.exit(1));
} else {
cli.description = desc;
/* eslint-disable promise/always-return */
charlike(name, desc, cli)
.then((dest) => {
console.log(`Project "${name}" scaffolded to "${dest}"`);
})
.catch((err) => {
/* istanbul ignore next */
console.error(`Sorry, some error occured!`);
/* istanbul ignore next */
console.error(`ERROR: ${err.message}`);
/* istanbul ignore next */
proc.exit(1);
});
}