Skip to content

Commit

Permalink
Warn if no files field in package.json or .npmignore file present
Browse files Browse the repository at this point in the history
  • Loading branch information
cironunes authored and Ciro Nunes committed Jun 2, 2019
1 parent 71880f9 commit e5daf5f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions source/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ module.exports = async (options, pkg) => {
const extraBaseUrls = ['gitlab.com'];
const repoUrl = pkg.repository && githubUrlFromGit(pkg.repository.url, {extraBaseUrls});

util.checkIgnoreStrategy(pkg);

console.log(`\nPublish a new version of ${chalk.bold.magenta(pkg.name)} ${chalk.dim(`(current: ${oldVersion})`)}\n`);

const prompts = [
Expand Down
16 changes: 16 additions & 0 deletions source/util.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
'use strict';
const {existsSync} = require('fs');
const path = require('path');
const readPkgUp = require('read-pkg-up');
const issueRegex = require('issue-regex');
const terminalLink = require('terminal-link');
const execa = require('execa');
const pMemoize = require('p-memoize');
const ow = require('ow');
const chalk = require('chalk');

exports.readPkg = () => {
const {pkg} = readPkgUp.sync();
Expand Down Expand Up @@ -61,3 +64,16 @@ exports.getTagVersionPrefix = pMemoize(async options => {
return 'v';
}
});

exports.checkIgnoreStrategy = ({files}) => {
const npmignoreExists = existsSync(path.resolve(getRootDir(), '.npmignore'));

if (!files && !npmignoreExists) {
console.log(`\nNo ${chalk.bold.cyan('files')} field specified in the ${chalk.bold.magenta('package.json')} or ${chalk.bold.magenta('.npmignore')} file present in the root folder. Make sure you have one them.`);
}
};

const getRootDir = () => {
const sourceDir = path.dirname(require.main.filename);
return path.resolve(sourceDir, '..');
};

0 comments on commit e5daf5f

Please sign in to comment.