clean-publish
Advanced tools
Comparing version 1.0.2 to 1.0.3
#!/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" | ||
} | ||
} |
152
README.md
@@ -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" | ||
- } | ||
} | ||
``` |
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
8396
9
162
151
5
1
1
+ Addedchalk@^2.4.1
+ Addedlodash.pick@^4.4.0
+ Addedyargs@^12.0.1
+ Addedansi-regex@2.1.13.0.1(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedcamelcase@5.3.1(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcliui@4.1.0(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedcross-spawn@6.0.6(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedexeca@1.0.0(transitive)
+ Addedfind-up@3.0.0(transitive)
+ Addedget-caller-file@1.0.3(transitive)
+ Addedget-stream@4.1.0(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedinvert-kv@2.0.0(transitive)
+ Addedis-fullwidth-code-point@1.0.02.0.0(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedlcid@2.0.0(transitive)
+ Addedlocate-path@3.0.0(transitive)
+ Addedlodash.pick@4.4.0(transitive)
+ Addedmap-age-cleaner@0.1.3(transitive)
+ Addedmem@4.3.0(transitive)
+ Addedmimic-fn@2.1.0(transitive)
+ Addednice-try@1.0.5(transitive)
+ Addednpm-run-path@2.0.2(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedos-locale@3.1.0(transitive)
+ Addedp-defer@1.0.0(transitive)
+ Addedp-finally@1.0.0(transitive)
+ Addedp-is-promise@2.1.0(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@3.0.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedpath-exists@3.0.0(transitive)
+ Addedpath-key@2.0.1(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedrequire-main-filename@1.0.1(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedshebang-command@1.2.0(transitive)
+ Addedshebang-regex@1.0.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedstring-width@1.0.22.1.1(transitive)
+ Addedstrip-ansi@3.0.14.0.0(transitive)
+ Addedstrip-eof@1.0.0(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedwhich-module@2.0.1(transitive)
+ Addedwrap-ansi@2.1.0(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedy18n@4.0.3(transitive)
+ Addedyargs@12.0.5(transitive)
+ Addedyargs-parser@11.1.1(transitive)