| 1 |
#!/usr/bin/env node |
| 2 |
|
| 3 |
const pf = require.resolve(`${process.cwd()}/package.json`) |
| 4 |
const pj = require(pf) |
| 5 |
|
| 6 |
if (!pj.repository && process.env.GITHUB_REPOSITORY) { |
| 7 |
const fs = require('fs') |
| 8 |
const server = process.env.GITHUB_SERVER_URL || 'https://github.com' |
| 9 |
const repo = `${server}/${process.env.GITHUB_REPOSITORY}` |
| 10 |
pj.repository = repo |
| 11 |
const json = fs.readFileSync(pf, 'utf8') |
| 12 |
const match = json.match(/^\s*\{[\r\n]+([ \t]*)"/) |
| 13 |
const indent = match[1] |
| 14 |
const output = JSON.stringify(pj, null, indent || 2) + '\n' |
| 15 |
fs.writeFileSync(pf, output) |
| 16 |
} |