-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathchange.js
77 lines (70 loc) · 1.59 KB
/
change.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
/**
* Utils to change files in all repositories.
*
* @author Carlos Abraham Hernandez (abranhe.com) <abraham@abranhe.com>
*/
'use strict';
const fs = require('fs');
const path = require('path');
const exist = require('dtfe');
const chalk = require('chalk');
const shell = require('shelljs');
const repos = require('../repos.json');
const bufferFile = (file) => {
return fs.readFileSync(path.join(__dirname, `../templates/${file}.txt`), {
encoding: 'utf8',
});
};
const files = [
{
template: 'license',
to: 'license',
},
{
template: 'readme',
to: 'readme.md',
},
{
template: 'code-of-conduct',
to: '.github/code-of-conduct.md',
},
{
template: 'contributing',
to: '.github/contributing.md',
},
{
template: 'issue-template',
to: '.github/issue-template.md',
},
{
template: 'pull-request-template',
to: '.github/pull-request-template.md',
},
];
if (exist('./projects')) {
shell.cd('./projects');
}
try {
repos.forEach((repo) => {
// To create folders, and files individually
// const global = `${repo}/src/.gitkeep`;
// if (!exist(global)) {
// shell.touch(global);
// }
if (exist(repo)) {
files.forEach((file) => {
const filename = `${repo}/${file.to}`;
const data = bufferFile(file.template);
fs.writeFile(filename, data, 'utf8', (err) => {
if (err) {
console.log(err);
return;
}
});
});
}
});
console.log(chalk.green('Done!'));
} catch (_) {
console.log(chalk.red('Something went wrong cloning the repos.'));
}