Skip to content

Commit 1110e94

Browse files
Merge pull request #8 from 6RiverSystems/replacements
Replacements
2 parents 637589a + d70613e commit 1110e94

File tree

4 files changed

+56
-14
lines changed

4 files changed

+56
-14
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,7 @@ Run with the `--verbose` flag to see debug information
5858
| --old | The name of the branch to rename | master |
5959
| --new | The new branch name | main |
6060
| --confirm | Run without prompting for confirmation | false |
61+
62+
## Replacements
63+
64+
TODO document how to write replacements

replacements/circleci.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = function (owner, repo, old, target) {
2+
return {
3+
path: "./circleci/config.yml",
4+
replacements: [
5+
{
6+
from: `- ${old}`,
7+
to: `- ${target}`
8+
},
9+
{
10+
from : `branch: ${old}`,
11+
to: `branch: ${target}`
12+
},
13+
{
14+
from: `only: ${old}`,
15+
to: `only: ${target}`
16+
}
17+
]
18+
};
19+
}

replacements/readme.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = function (owner, repo, old, target) {
2+
return {
3+
path: "README.md",
4+
replacements: [
5+
{
6+
from: `@${old}`,
7+
to: `@${target}`,
8+
},
9+
{
10+
from: `${owner}/${repo}.svg?branch=${old}`,
11+
to: `${owner}/${repo}.svg?branch=${target}`,
12+
},
13+
],
14+
};
15+
}

src/update-content.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1+
const fs = require('fs');
2+
const util = require('util');
13
const replaceAll = require("string.prototype.replaceall");
24

5+
const ls = util.promisify(fs.readdir);
6+
37
module.exports = async function (
48
owner,
59
repo,
610
old,
711
target,
812
octokit,
913
isVerbose,
10-
isDryRun
14+
isDryRun,
1115
) {
12-
const replacements = {
13-
"README.md": [
14-
{
15-
from: `@${old}`,
16-
to: `@${target}`,
17-
},
18-
{
19-
from: `${owner}/${repo}.svg?branch=${old}`,
20-
to: `${owner}/${repo}.svg?branch=${target}`,
21-
},
22-
],
23-
};
24-
16+
const files = (await ls(`${__dirname}/../replacements`)).filter((f) => f.endsWith('.js'));
17+
const replacements = files.reduce((acc, next) => {
18+
const { path, replacements } = require(`../replacements/${next}`)(
19+
owner,
20+
repo,
21+
old,
22+
target,
23+
octokit,
24+
isVerbose,
25+
isDryRun,
26+
);
27+
return Object.assign(acc, { [path]: replacements });
28+
}, {});
2529
for (let path in replacements) {
2630
try {
2731
let file = await loadFile(owner, repo, path, octokit);

0 commit comments

Comments
 (0)