Skip to content
Snippets Groups Projects
Commit 87cc6469 authored by Rhys Arkins's avatar Rhys Arkins
Browse files

Allow configurable package.json path

parent 15593d55
No related branches found
No related tags found
No related merge requests found
...@@ -17,17 +17,22 @@ if (!module.parent) { ...@@ -17,17 +17,22 @@ if (!module.parent) {
// https://github.com/settings/tokens/new // https://github.com/settings/tokens/new
const token = process.argv[2]; const token = process.argv[2];
const repoName = process.argv[3]; const repoName = process.argv[3];
let packageFile = process.argv[4];
if (!token || !repoName) { if (!token || !repoName) {
console.error(`Usage: node index.js <token> <repo>`); console.error(`Usage: node index.js <token> <repo>`);
process.exit(1); process.exit(1);
} }
updateRepo({ token, repoName }) if (!packageFile) {
packageFile = 'package.json';
}
updateRepo({ token, repoName, packageFile })
.catch(err => console.log(err.stack || err)); .catch(err => console.log(err.stack || err));
} }
function updateRepo({ token, repoName }) { function updateRepo({ token, repoName, packageFile }) {
const repoPath = `tmp/${repoName}`; const repoPath = `tmp/${repoName}`;
rimraf.sync(repoPath); rimraf.sync(repoPath);
mkdirp.sync(repoPath); mkdirp.sync(repoPath);
...@@ -57,7 +62,7 @@ function updateRepo({ token, repoName }) { ...@@ -57,7 +62,7 @@ function updateRepo({ token, repoName }) {
}) })
.then(commit => { .then(commit => {
headCommit = commit; headCommit = commit;
return readFile(headCommit, 'package.json'); return readFile(headCommit, packageFile);
}) })
.then(blob => { .then(blob => {
const pkg = JSON.parse(blob); const pkg = JSON.parse(blob);
...@@ -112,7 +117,7 @@ function updateRepo({ token, repoName }) { ...@@ -112,7 +117,7 @@ function updateRepo({ token, repoName }) {
return repo.getBranchCommit(branchName) return repo.getBranchCommit(branchName)
.then(_commit => { .then(_commit => {
commit = _commit; commit = _commit;
return readFile(commit, 'package.json'); return readFile(commit, packageFile);
}) })
.then(blob => { .then(blob => {
const pkg = JSON.parse(String(blob)); const pkg = JSON.parse(String(blob));
...@@ -122,7 +127,7 @@ function updateRepo({ token, repoName }) { ...@@ -122,7 +127,7 @@ function updateRepo({ token, repoName }) {
} }
pkg[depType][depName] = nextVersion; pkg[depType][depName] = nextVersion;
fs.writeFileSync(`${repoPath}/package.json`, JSON.stringify(pkg, null, 2) + '\n'); fs.writeFileSync(`${repoPath}/${packageFile}`, JSON.stringify(pkg, null, 2) + '\n');
return commitAndPush(commit, depName, nextVersion, branchName); return commitAndPush(commit, depName, nextVersion, branchName);
}); });
...@@ -138,7 +143,7 @@ function updateRepo({ token, repoName }) { ...@@ -138,7 +143,7 @@ function updateRepo({ token, repoName }) {
.refreshIndex() .refreshIndex()
.then(indexResult => { .then(indexResult => {
index = indexResult; index = indexResult;
return index.addByPath('package.json'); return index.addByPath(packageFile);
}) })
.then(() => index.write()) .then(() => index.write())
.then(() => index.writeTree()) .then(() => index.writeTree())
...@@ -213,7 +218,7 @@ function updateRepo({ token, repoName }) { ...@@ -213,7 +218,7 @@ function updateRepo({ token, repoName }) {
function readFile(commit, filename) { function readFile(commit, filename) {
return commit return commit
.getEntry('package.json') .getEntry(packageFile)
.then(entry => entry.getBlob()) .then(entry => entry.getBlob())
.then(blob => String(blob)); .then(blob => String(blob));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment