-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.js
52 lines (48 loc) · 1.84 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
47
48
49
50
51
52
const fs = require('fs')
const path = require('path')
console.log('process.argv:', JSON.stringify(process.argv));
const [nodePath, scriptPath, target, inputsRaw = '{}'] = process.argv
const inputs = JSON.parse(inputsRaw)
const config = {
'$schema': 'https://docs.renovatebot.com/renovate-schema.json',
extends: [
`github>bettermarks/renovate-config${inputs.javascript ? ':javascript' : ''}`,
inputs.python ? 'github>bettermarks/renovate-config:python' : '',
inputs.secrets ? 'github>bettermarks/renovate-secrets' : '',
inputs.automerge,
].filter(Boolean)
};
console.log(config);
let configFile = path.join(target, 'renovate.json')
if (!target || !fs.existsSync(target)) {
throw 'first argument target has to be a path to a directory but does not exist, was ' + target
}
if (!fs.existsSync(configFile) || inputs.force ) {
fs.writeFileSync(configFile, JSON.stringify(config, null, 2), 'utf-8');
console.error(`written to ${configFile}`)
} else {
console.error(`NOT modifying existing ${configFile}!`)
}
let relativeWorkflowFile = ".github/workflows/renovate-config-validator.yml"
let workflowFile = path.join(target, relativeWorkflowFile)
if (!fs.existsSync(workflowFile) || inputs.force ) {
fs.cpSync(relativeWorkflowFile, workflowFile)
console.error(`created ${workflowFile}!`)
} else {
console.error(`NOT modifying existing ${workflowFile}!`)
}
if (inputs.javascript) {
const npmrcFile = path.join(target, '.npmrc');
const saveExact = `save-exact=true`;
const existingContent = fs.existsSync(npmrcFile) && fs.readFileSync(npmrcFile, 'utf8');
let write = false
if (!existingContent) {
write = `${saveExact}\n`
} else if (!/^save-exact/.test(existingContent)) {
write = `${existingContent}\n${saveExact}\n`
}
if (write) {
fs.writeFileSync(npmrcFile, write)
console.error(`added "${saveExact}" to ${npmrcFile}!`)
}
}