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 May 22, 2019
1 parent 71880f9 commit b9ce621
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions source/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ updateNotifier({pkg: cli.pkg}).notify();
(async () => {
const pkg = util.readPkg();

util.checkIgnoreStrategy(pkg);

const defaultFlags = {
cleanup: true,
publish: true,
Expand Down
27 changes: 27 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,27 @@ exports.getTagVersionPrefix = pMemoize(async options => {
return 'v';
}
});

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

if (!files && !npmignoreExists) {
console.log(
`\n
╭───────────────────────────────────────────────────╮
│ │
│ ⚠️ Warning ⚠️ │
│ No ${chalk.bold.cyan('files')} field specified in ${chalk.bold.magenta('package.json')}
│ or ${chalk.bold.magenta('.npmignore')} file present in the root folder. │
│ Make sure you have either one or the other. │
│ │
╰───────────────────────────────────────────────────╯
`
);
}
};

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

0 comments on commit b9ce621

Please sign in to comment.