Skip to content

Commit

Permalink
Use util to read JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Jul 21, 2021
1 parent eeb4126 commit 216267b
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 14 deletions.
4 changes: 3 additions & 1 deletion bin/release-it.js
Expand Up @@ -2,8 +2,10 @@

import updater from 'update-notifier';
import parseArgs from 'yargs-parser';
import pkg from '../package.json';
import release from '../lib/index.js';
import { readJSON } from '../lib/util';

const pkg = readJSON('../package.json');

const aliases = {
c: 'config',
Expand Down
4 changes: 3 additions & 1 deletion lib/cli.js
@@ -1,6 +1,8 @@
import pkg from '../package.json';
import { readJSON } from '../lib/util';
import Log from './log';

const pkg = readJSON('../package.json');

const log = new Log();

const helpText = `Release It! v${pkg.version}
Expand Down
4 changes: 2 additions & 2 deletions lib/config.js
Expand Up @@ -5,10 +5,10 @@ import yaml from 'yaml';
import _ from 'lodash';
import isCI from 'is-ci';
import _debug from 'debug';
import defaultConfig from '../config/release-it.json';
import { getSystemInfo } from './util';
import { readJSON, getSystemInfo } from './util';

const debug = _debug('release-it:config');
const defaultConfig = readJSON('../config/release-it.json');

const searchPlaces = [
'package.json',
Expand Down
4 changes: 3 additions & 1 deletion lib/deprecated.js
@@ -1,7 +1,9 @@
import Deprecated from 'deprecated-obj';
import deprecated from '../config/deprecated.json';
import { readJSON } from './util';
import Log from './log';

const deprecated = readJSON('../config/deprecated.json');

export default (config, log = new Log()) => {
const deprecations = new Deprecated(deprecated, config);
const compliant = deprecations.getCompliant();
Expand Down
3 changes: 2 additions & 1 deletion lib/metrics.js
Expand Up @@ -4,9 +4,10 @@ import { v4 as uuidv4 } from 'uuid';
import osName from 'os-name';
import isCi from 'is-ci';
import _debug from 'debug';
import pkg from '../package.json';
import { readJSON } from './util';

const debug = _debug('release-it:metrics');
const pkg = readJSON('../package.json');

const noop = Promise.resolve();

Expand Down
4 changes: 3 additions & 1 deletion lib/plugin/GitRelease.js
@@ -1,7 +1,9 @@
import _ from 'lodash';
import defaultConfig from '../../config/release-it.json';
import { readJSON } from '../util';
import GitBase from './GitBase';

const defaultConfig = readJSON('../../config.release-it.json');

class GitRelease extends GitBase {
static isEnabled(options) {
return options.release;
Expand Down
5 changes: 3 additions & 2 deletions lib/plugin/github/GitHub.js
Expand Up @@ -5,11 +5,12 @@ import globby from 'globby';
import mime from 'mime-types';
import _ from 'lodash';
import retry from 'async-retry';
import pkg from '../../../package.json';
import { format, parseVersion, e } from '../../util';
import { format, parseVersion, readJSON, e } from '../../util';
import Release from '../GitRelease';
import prompts from './prompts';

const pkg = readJSON('../../../package.json');

const docs = 'https://git.io/release-it-github';

const RETRY_CODES = [408, 413, 429, 500, 502, 503, 504, 521, 522, 524];
Expand Down
6 changes: 5 additions & 1 deletion lib/util.js
Expand Up @@ -4,9 +4,12 @@ import _ from 'lodash';
import gitUrlParse from 'git-url-parse';
import semver from 'semver';
import osName from 'os-name';
import pkg from '../package.json';
import Log from './log';

const readJSON = async file => JSON.parse(fs.readFileSync(file, 'utf8'));

const pkg = readJSON('../package.json');

const log = new Log();

const getSystemInfo = () => {
Expand Down Expand Up @@ -97,5 +100,6 @@ export {
parseGitUrl,
hasAccess,
parseVersion,
readJSON,
e
};
4 changes: 3 additions & 1 deletion test/cli.js
@@ -1,7 +1,9 @@
import test from 'ava';
import mockStdIo from 'mock-stdio';
import pkg from '../package.json';
import { version, help } from '../lib/cli';
import { readJSON } from './util';

const pkg = readJSON('../package.json');

test('should print version', t => {
mockStdIo.start();
Expand Down
4 changes: 3 additions & 1 deletion test/config.js
@@ -1,7 +1,9 @@
import test from 'ava';
import mock from 'mock-fs';
import Config from '../lib/config';
import defaultConfig from '../config/release-it.json';
import { readJSON } from './util';

const defaultConfig = readJSON('../config/release-it.json');

const localConfig = { github: { release: true } };

Expand Down
5 changes: 3 additions & 2 deletions test/git.init.js
Expand Up @@ -2,10 +2,11 @@ import test from 'ava';
import sh from 'shelljs';
import Shell from '../lib/shell';
import Git from '../lib/plugin/git/Git';
import { git } from '../config/release-it.json';
import { factory } from './util';
import { factory, readJSON } from './util';
import { mkTmpDir, gitAdd } from './util/helpers';

const { git } = readJSON('../config/release-it.json');

test.serial.beforeEach(t => {
const bare = mkTmpDir();
const target = mkTmpDir();
Expand Down

0 comments on commit 216267b

Please sign in to comment.