1 | const fs = require('fs');
|
2 | const c = require('chalk');
|
3 | const findUp = require('find-up');
|
4 | const {readConfig, validateConfig} = require('./core/config');
|
5 | const {getRepoSlug} = require('./core/git');
|
6 | const {makeError} = require('./core/utils');
|
7 |
|
8 | const validate = argv => {
|
9 | const configPath = argv.config || argv._[1] || findUp.sync('.update-node.json');
|
10 | if (!configPath) throw makeError('Missing config to validate', {exitCode: 2});
|
11 | const config = readConfig(configPath);
|
12 | try {
|
13 | validateConfig(config);
|
14 | process.stdout.write(c.bold.green('Given configuration is valid\n'));
|
15 | } catch (err) {
|
16 | throw makeError('Config has no valid schema', {exitCode: 1, details: err.message});
|
17 | }
|
18 | };
|
19 |
|
20 | const setup = argv => {
|
21 | const existingConfig = findUp.sync('.update-node.json');
|
22 | if (existingConfig)
|
23 | throw makeError('.update-node.json already exist', {
|
24 | detail: `at following path ${existingConfig}`,
|
25 | exitCode: 3
|
26 | });
|
27 |
|
28 | const repoSlug = getRepoSlug();
|
29 | const packageManager = fs.existsSync('yarn.lock') ? 'yarn' : 'npm';
|
30 | const defaultConfig = {
|
31 | repoSlug,
|
32 | baseBranch: 'master',
|
33 | packageManager,
|
34 | reviewers: [],
|
35 | teamReviewers: [],
|
36 | label: 'Upgrades :outbox_tray:',
|
37 | 'auto-bump': false,
|
38 | node: {
|
39 | branch: 'upgrade-node',
|
40 | nvmrc: true,
|
41 | dockerfile: false,
|
42 | travis: false,
|
43 | package: false
|
44 | },
|
45 | dependencies: [
|
46 | {
|
47 | name: 'core',
|
48 | message: 'Update core dependencies',
|
49 | branch: 'update-core',
|
50 | dependencies: [],
|
51 | devDependencies: []
|
52 | }
|
53 | ]
|
54 | };
|
55 |
|
56 | fs.writeFileSync('.update-node.json', JSON.stringify(defaultConfig, null, 2), 'utf-8');
|
57 | };
|
58 |
|
59 | module.exports = {validate, setup};
|