Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clean-publish

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clean-publish - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

npm-scripts.js

126

clean-publish.js
#!/usr/bin/env node
const fs = require('fs');
const fse = require('fs-extra');
const omit = require('lodash.omit');
const {
spawn,
execSync,
} = require('child_process');
const chalk = require('chalk')
const fs = require('fs')
const { spawn } = require('child_process')
const fse = require('fs-extra')
const omit = require('lodash.omit')
const pick = require('lodash.pick')
const yargs = require('yargs')
const IGNORE_FILES = require('./ignore-files');
const IGNORE_FIELDS = require('./ignore-fields');
const IGNORE_FILES = require('./ignore-files')
const IGNORE_FIELDS = require('./ignore-fields')
const NPM_SCRIPTS = require('./npm-scripts')
/* eslint-disable */
Array.prototype.reIndexOf = function(item) {
for (var i in this) {
if (this[i].toString().match(item)) {
return i;
}
}
return -1;
};
/* eslint-enable */
const { argv } = yargs
.usage('$0')
.option('files', {
type: 'array',
desc: 'One or more exclude files'
})
.option('fields', {
type: 'array',
desc: 'One or more exclude package.json fields'
});
(function () {
const tmp = fs.mkdtempSync('tmp');
const src = './'
const packageJSON = 'package.json'
fs.readdirSync(src).forEach(i => {
if (i !== tmp) {
if (IGNORE_FILES.indexOf(i) == -1 || fs.statSync(i).isDirectory()) {
fse.copy(i, `${tmp}/${i}`)
.then(() => {
if (i === packageJSON) {
fse.readJson(packageJSON, (err, obj) => {
fse.writeJsonSync(`./${tmp}/${packageJSON}`, omit(obj, IGNORE_FIELDS), {
spaces: 2
})
fs.mkdtemp('tmp', (makeTmpDirErr, tmpDir) => {
if (makeTmpDirErr) {
console.error(chalk.red(makeTmpDirErr))
process.exit()
}
fs.readdir(src, (readSrcDirErr, files) => {
if (readSrcDirErr) {
console.error(chalk.red(readSrcDirErr))
process.exit()
}
const ignoreFiles = argv.files
? IGNORE_FILES.concat(argv.files)
: IGNORE_FILES
files
.forEach(file => {
if (file !== tmpDir) {
if (ignoreFiles.reIndexOf(file) === -1) {
fse.copy(file, `${ tmpDir }/${ file }`, copyErr => {
if (copyErr) {
console.error(chalk.red(copyErr))
process.exit()
}
if (file === packageJSON) {
fse.readJson(packageJSON, (err, obj) => {
if (err) {
console.error(chalk.red(err))
process.exit()
}
const ignoreFields = argv.fields
? IGNORE_FIELDS.concat(argv.fields)
: IGNORE_FIELDS
const modifiedPackageJSON = Object.assign(
omit(obj, ignoreFields),
{
scripts: pick(obj.scripts, NPM_SCRIPTS)
}
)
fse.writeJson(
`./${ tmpDir }/${ packageJSON }`,
modifiedPackageJSON,
{ spaces: 2 }
)
})
}
})
}
});
}
}
}
})
})
process.chdir(tmpDir)
const publish = spawn('npm', ['publish'], {
stdio: 'inherit'
})
publish.on('exit', () => {
fse.remove(tmpDir, removeTmpDirErr => {
if (removeTmpDirErr) {
console.error(chalk.red(removeTmpDirErr))
process.chdir('../')
process.exit()
}
})
})
process.chdir('../')
})
process.chdir(tmp);
const publish = spawn('npm', ['publish'], {
stdio: 'inherit'
});
publish.on('exit', () => {
fse.removeSync(tmp);
})
process.chdir('../');
})();
})()

@@ -8,2 +8,4 @@ module.exports = [

'babel',
];
'lint-staged',
'pre-commit'
]
module.exports = [
'.eslintrc',
'.eslintignore',
'.babelrc',

@@ -12,4 +13,5 @@ '.editorconfig',

'yarn.lock',
'package-lock.json',
'yarn-error.log',
'appveyor.yml'
]
{
"name": "clean-publish",
"version": "1.0.2",
"version": "1.0.3",
"description": "Clean your package before publish",

@@ -15,14 +15,15 @@ "keywords": [

"bin": "clean-publish.js",
"scripts": {
"clean-publish": "node clean-publish.js",
"clean": "clean-publish"
"engines": {
"node": ">=6.11.5"
},
"bugs": {
"url": "https://github.com/shashkovdanil/clean-publish/issues"
},
"homepage": "https://github.com/shashkovdanil/clean-publish#readme",
"dependencies": {
"chalk": "^2.4.1",
"fs-extra": "^6.0.1",
"lodash.omit": "^4.5.0"
"lodash.omit": "^4.5.0",
"lodash.pick": "^4.4.0",
"yargs": "^12.0.1"
},
"scripts": {
"test": "jest && yarn run lint"
}
}

@@ -1,1 +0,151 @@

# Clean Publish [![Cult Of Martians][cult-img]][cult]
# Clean Publish
Clean publish is a tool for removing configuration files and fields in package.json before publishing to npm.
## How it works
`clean-publish` command copies project files (excluding configuration files) to a temporary folder, removes the extra from package.json, and calls npm publish on the temporary folder.
## Usage
First, install `clean-publish`:
```sh
$ npm install --save-dev clean-publish
# or
$ yarn add clean-publish --dev
```
Add `clean-publish` script to `package.json`:
```json
{
"scripts": "clean-publish"
}
```
Usage with arguments:
```sh
$ npm run clean-publish --files file1.js file2.js --fields scripts name
```
## Exclude files and package.json fields
**Files:**
- `.eslintrc`,
- `.eslintignore`,
- `.babelrc`,
- `.editorconfig`,
- `.jsdocrc`,
- `.lintstagedrc`,
- `.size-limit`,
- `.yaspellerrc`,
- `jest.config.js`,
- `.travis.yml`,
- `yarn.lock`,
- `package-lock.json`,
- `yarn-error.log`,
- `appveyor.ym`
**Fields:**
- `eslintConfig`,
- `jest`,
- `yaspeller`,
- `size-limit`,
- `devDependencies`,
- `babel`
## Example
* Before `clean-publish`
**Files and directories**
```
node_modules
.eslintrc
.prettierrc
jest.config.js
CHANGELOG.md
package.json
README.md
yarn.lock
```
**package.json**
```json
{
"name": "your-package",
"version": "1.0.0",
"description": "description",
"author": "author",
"license": "MIT",
"scripts": {
"test": "test"
},
"dependencies": {
"chalk": "^2.4.1",
"fs-extra": "^6.0.1",
"lodash.omit": "^4.5.0"
},
"devDependencies": {
"eslint": "^5.1.0",
"eslint-config-logux": "^23.0.2",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-jest": "^21.17.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-security": "^1.4.0",
"eslint-plugin-standard": "^3.1.0"
}
}
```
* After `clean-publish`
**Files and directories**
```diff
node_modules
CHANGELOG.md
package.json
README.md
- .eslintrc
- .prettierrc
- jest.config.js
- yarn.lock
```
**package.json**
```diff
{
"name": "your-package",
"version": "1.0.0",
"description": "description",
"author": "author",
"license": "MIT",
"scripts": {
"test": "test"
},
"dependencies": {
"chalk": "^2.4.1",
"fs-extra": "^6.0.1",
"lodash.omit": "^4.5.0"
},
- "devDependencies": {
- "eslint": "^5.1.0",
- "eslint-config-logux": "^23.0.2",
- "eslint-config-standard": "^11.0.0",
- "eslint-plugin-import": "^2.13.0",
- "eslint-plugin-jest": "^21.17.0",
- "eslint-plugin-node": "^6.0.1",
- "eslint-plugin-promise": "^3.8.0",
- "eslint-plugin-security": "^1.4.0",
- "eslint-plugin-standard": "^3.1.0"
- }
}
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc