-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.js
46 lines (37 loc) · 1.06 KB
/
init.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
const fs = require('fs');
const replace = require('replace-in-file');
const { exec } = require('child_process');
const yargs = require('yargs')
.option('description', {
alias: 'd',
help: 'A short package description',
default: ''
})
.option('dev', {
default: false,
type: 'boolean'
})
.argv;
try {
const [packageOrg, packageName] = yargs._[0].split('/');
replace.sync({
files: process.cwd() + '/**',
ignore: 'node_modules/**',
from: [/{{package-name}}/g, /{{owner}}/g, /{{description}}/g],
to: [packageName, packageOrg, yargs.description]
});
fs.unlinkSync('README.md');
fs.renameSync('README.template.md', 'README.md');
if (!yargs.dev) {
fs.unlinkSync('init.js');
exec('npm un -D replace-in-file yargs').on('exit', (code) => {
process.exit(code);
});
}
return process.exit(0);
} catch (e) {
console.error(`Please, make sure you have provided the package information in the following format:
node init {github-username-or-org}/{package-name}`);
console.error(e);
return process.exit(1);
}