This repository was archived by the owner on Aug 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrchat.js
More file actions
59 lines (50 loc) · 1.64 KB
/
arrchat.js
File metadata and controls
59 lines (50 loc) · 1.64 KB
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
const cli = require('commander');
cli.version('<%= version %>');
const fs = require('fs');
const path = require('path');
const mkdirp = require('mkdirp');
const colors = require('colors');
const ejs = require('ejs');
global.mkdir = dest => mkdirp.sync(path.dirname(path.normalize(dest)));
// https://gist.github.com/wvffle/0deea63696b993c7364c9d7ecfa1ecf1
String.prototype.format = function format() {
const args = arguments;
return this.replace(/\{\d+\}/g, a => {
a = args[a.slice(1, -1)];
return a != null ? a : '';
});
}
global.copy = (src, dest) => {
dest = path.normalize(dest);
mkdir(dest);
const read = fs.createReadStream(src);
read.pipe(fs.createWriteStream(dest));
read.on('end', () => {
console.log('created '.green + dest);
});
}
global.copyTpl = (src, dest, data) => {
src = path.normalize(`${__dirname}/../templates/${src}`);
dest = path.normalize(dest.format(data.name));
const renderdata = {
camel: str => str.replace(/(\-[a-z])/g, m => m.toUpperCase().slice(1)),
};
for (let key in data) {
if (data.hasOwnProperty(key)) {
const value = data[key];
renderdata[key] = path.basename(value);
}
}
const escape = s => s.replace(/__%/g, '<'+'%').replace(/%__/g, '%'+'>');
const content = fs.readFileSync(src).toString();
mkdir(dest);
fs.writeFileSync(dest, ejs.render(content, renderdata, { escape }));
console.log('created '.green + dest);
}
<% commands.forEach(function(command) { %>
cli.command('<%= command.name %>')
.description('<%= command.description %>')
.action(<%= command.action %>);
<% }) %>
cli.parse(process.argv);
if (!process.argv.slice(2).length) cli.outputHelp();