prepare-package 0.0.13 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.js +21 -11
  2. package/package.json +5 -4
  3. package/src/index.js +21 -11
package/dist/index.js CHANGED
@@ -5,6 +5,11 @@ const chalk = require('chalk');
5
5
  const thisPackageJSON = require('../package.json');
6
6
  const theirPackageJSON = require(path.join(process.cwd(), 'package.json'));
7
7
  const isLivePreparation = theirPackageJSON.name !== 'prepare-package';
8
+ const argv = require('yargs').argv;
9
+
10
+ const options = {
11
+ prepare: argv['--purge'] || argv['-p'],
12
+ };
8
13
 
9
14
  // fix
10
15
  theirPackageJSON.main = theirPackageJSON.main || './dist/index.js';
@@ -41,14 +46,19 @@ if (isLivePreparation) {
41
46
  )
42
47
  }
43
48
 
44
- fetch(`https://purge.jsdelivr.net/npm/${theirPackageJSON.name}@latest`, {
45
- response: 'json',
46
- tries: 3,
47
- })
48
- .then(result => {
49
- // console.log(chalk.green(`[prepare-package]: Purged... name=${theirPackageJSON.name}`), result);
50
- console.log(chalk.green(`[prepare-package]: Purged... ${theirPackageJSON.name}`));
51
- })
52
- .catch(e => {
53
- console.log(chalk.red(`[prepare-package]: Failed to purge... ${theirPackageJSON.name}`, e));
54
- })
49
+ if (options.prepare === 'false') {
50
+ return;
51
+ } else {
52
+ return fetch(`https://purge.jsdelivr.net/npm/${theirPackageJSON.name}@latest`, {
53
+ response: 'json',
54
+ tries: 3,
55
+ })
56
+ .then(result => {
57
+ // console.log(chalk.green(`[prepare-package]: Purged... name=${theirPackageJSON.name}`), result);
58
+ console.log(chalk.green(`[prepare-package]: Purged... ${theirPackageJSON.name}`));
59
+ })
60
+ .catch(e => {
61
+ console.log(chalk.red(`[prepare-package]: Failed to purge... ${theirPackageJSON.name}`, e));
62
+ })
63
+ }
64
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prepare-package",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "Prepare a Node.js package before being published",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -35,9 +35,10 @@
35
35
  "dependencies": {
36
36
  "chalk": "^4.1.2",
37
37
  "fs-jetpack": "^4.3.1",
38
- "wonderful-fetch": "^0.0.14"
38
+ "wonderful-fetch": "^0.0.14",
39
+ "yargs": "^17.5.1"
39
40
  },
40
41
  "devDependencies": {
41
- "mocha": "^8.0.1"
42
+ "mocha": "^8.4.0"
42
43
  }
43
- }
44
+ }
package/src/index.js CHANGED
@@ -5,6 +5,11 @@ const chalk = require('chalk');
5
5
  const thisPackageJSON = require('../package.json');
6
6
  const theirPackageJSON = require(path.join(process.cwd(), 'package.json'));
7
7
  const isLivePreparation = theirPackageJSON.name !== 'prepare-package';
8
+ const argv = require('yargs').argv;
9
+
10
+ const options = {
11
+ prepare: argv['--purge'] || argv['-p'],
12
+ };
8
13
 
9
14
  // fix
10
15
  theirPackageJSON.main = theirPackageJSON.main || './dist/index.js';
@@ -41,14 +46,19 @@ if (isLivePreparation) {
41
46
  )
42
47
  }
43
48
 
44
- fetch(`https://purge.jsdelivr.net/npm/${theirPackageJSON.name}@latest`, {
45
- response: 'json',
46
- tries: 3,
47
- })
48
- .then(result => {
49
- // console.log(chalk.green(`[prepare-package]: Purged... name=${theirPackageJSON.name}`), result);
50
- console.log(chalk.green(`[prepare-package]: Purged... ${theirPackageJSON.name}`));
51
- })
52
- .catch(e => {
53
- console.log(chalk.red(`[prepare-package]: Failed to purge... ${theirPackageJSON.name}`, e));
54
- })
49
+ if (options.prepare === 'false') {
50
+ return;
51
+ } else {
52
+ return fetch(`https://purge.jsdelivr.net/npm/${theirPackageJSON.name}@latest`, {
53
+ response: 'json',
54
+ tries: 3,
55
+ })
56
+ .then(result => {
57
+ // console.log(chalk.green(`[prepare-package]: Purged... name=${theirPackageJSON.name}`), result);
58
+ console.log(chalk.green(`[prepare-package]: Purged... ${theirPackageJSON.name}`));
59
+ })
60
+ .catch(e => {
61
+ console.log(chalk.red(`[prepare-package]: Failed to purge... ${theirPackageJSON.name}`, e));
62
+ })
63
+ }
64
+