How to use the mrm-core.packageJson function in mrm-core

To help you get started, we’ve selected a few mrm-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sapegin / mrm / src / tasks / eslint / index.js View on Github external
const preset = config.values().eslintPreset;
	const packages = config.values().eslintPeerDependencies;

	packages.push('eslint');
	if (preset !== 'eslint:recommended') {
		packages.push(`eslint-config-${preset}`);
	}

	// .eslintrc
	const eslintrc = json('.eslintrc');
	if (!eslintrc.get('extends', '').startsWith(preset)) {
		eslintrc.set('extends', preset).save();
	}

	// package.json
	const pkg = packageJson();

	// Keep custom extensions
	let exts = '';
	const lintScript = pkg.getScript('lint');
	if (lintScript) {
		const args = minimist(lintScript.split(' ').slice(1));
		if (args.ext && args.ext !== 'js') {
			exts = ` --ext ${args.ext}`;
		}
	}

	pkg
		// Remove existing JS linters
		.removeScript(/^(lint:js|eslint|jshint|jslint)$/)
		.removeScript('test', / (lint|lint:js|eslint|jshint|jslint)( |$)/)
		// Add lint script
github sapegin / mrm / src / tasks / stylelint / index.js View on Github external
'selector-pseudo-class-no-unknown': [
						true,
						{
							ignorePseudoClasses: [
								// CSS Modules
								'global',
							],
						},
					],
				},
			})
			.save();
	}

	// package.json
	const pkg = packageJson();

	pkg
		// Add lint script
		.setScript('lint:css', `stylelint '**/*${ext}'`)
		// Add pretest script
		.prependScript('pretest', 'npm run lint:css')
		.save();

	// Dependencies
	install(packages);
}
github sapegin / mrm / src / tasks / semantic-release / index.js View on Github external
module.exports = function(config) {
	// Require .travis.yml
	if (!fs.existsSync('.travis.yml')) {
		throw new MrmError(
			`Run travis task first:
  mrm travis`
		);
	}

	// package.json
	const pkg = packageJson();

	if (!pkg.getScript('semantic-release')) {
		throw new MrmError(
			`Setup semantic-release first:
  npx semantic-release-cli setup
  
semantic-release needs to add required auth keys to Travis CI.
WARNING: Do not agree to update your .travis.yml when asked.

More info:
https://github.com/semantic-release/semantic-release#setup
`
		);
	}

	// Remove semantic-release devDependency
github sapegin / mrm / src / tasks / jest / index.js View on Github external
module.exports = function() {
	// package.json
	const pkg = packageJson().merge({
		scripts: {
			'test:jest': 'jest',
			'test:watch': 'jest --watch',
			'test:coverage': 'jest --coverage',
		},
	});

	const needsMigration = oldPackages.some(name => pkg.get(`devDependencies.${name}`));
	const hasBabel = pkg.get(`devDependencies.babel-core`);

	// Babel
	if (hasBabel) {
		packages.push('babel-jest');
		pkg.merge({
			jest: {
				testPathIgnorePatterns: ['/lib/'],
github sapegin / mrm / src / tasks / codecov / index.js View on Github external
.defaults({ readmeFile: 'Readme.md', github: gitUsername() })
		.require('github')
		.values();

	const travisYml = yaml('.travis.yml');

	// Require .travis.yml
	if (!travisYml.exists()) {
		throw new MrmError(
			`Run travis task first:

  mrm travis`
		);
	}

	const pkg = packageJson();

	// Require coverage npm script
	if (!pkg.getScript(coverageScript)) {
		throw new MrmError(
			`${coverageScript} npm script not found. To add Jest run:

  mrm jest`
		);
	}

	// .travis.yml
	if (!travisYml.get('after_success', []).includes(uploadCommand)) {
		travisYml
			.merge({
				script: [`npm run ${coverageScript}`],
				after_success: [uploadCommand],
github sapegin / mrm / src / tasks / readme / index.js View on Github external
const { name, url, github, readmeFile, licenseFile } = config
		.defaults({ github: gitUsername(), readmeFile: 'Readme.md', licenseFile: 'License.md' })
		.defaults(meta)
		.require('name', 'url', 'github')
		.values();

	// Create Readme.md (no update)
	const readme = template(readmeFile, path.join(__dirname, 'Readme.md'));
	if (!readme.exists()) {
		readme
			.apply({
				name,
				url,
				github,
				license: licenseFile,
				package: packageJson().get('name'),
			})
			.save();
	}
}
github sapegin / mrm / src / tasks / license / index.js View on Github external
function task(config) {
	const { name, email, url, licenseFile } = config
		.defaults({ licenseFile: 'License.md' })
		.defaults(meta)
		.require('name', 'email', 'url')
		.values();

	const pkg = packageJson();
	const license = pkg.get('license', defaultLicense);
	const templateFile = path.join(__dirname, `templates/${license}.md`);

	if (!fs.existsSync(templateFile)) {
		console.log(`No template for the "${license}" found, skipping`);
		return;
	}

	template(licenseFile, templateFile)
		.apply({
			name,
			email,
			url,
			year: new Date().getFullYear(),
		})
		.save();