node-power-user 0.0.18 → 0.0.21
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.
- package/README.md +1 -0
- package/dist/index.js +50 -9
- package/package.json +6 -6
- package/src/index.js +50 -9
package/README.md
CHANGED
|
@@ -47,6 +47,7 @@ Note: you may have to run cli commands with `npx npu <command>` if you install t
|
|
|
47
47
|
* `npu bump 1`: Bump the last number (`patch` version).
|
|
48
48
|
* `npu bump 2`: Bump the middle number (`minor` version).
|
|
49
49
|
* `npu bump 3`: Bump the first number (`major` version).
|
|
50
|
+
* `npu match`: Compare the versions of installed modules to those in your package.json
|
|
50
51
|
|
|
51
52
|
## Final Words
|
|
52
53
|
If you are still having difficulty, we would love for you to post a question to [the Node Power User issues page](https://github.com/itw-creative-works/node-power-user/issues). It is much easier to answer questions that include your code and relevant files! So if you can provide them, we'd be extremely grateful (and more likely to help you find the answer!)
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
// https://www.sitepoint.com/javascript-command-line-interface-cli-node-js/
|
|
6
6
|
// https://github.com/sitepoint-editors/ginit
|
|
7
|
-
|
|
8
7
|
const jetpack = require('fs-jetpack');
|
|
9
8
|
const chalk = require('chalk');
|
|
10
9
|
const _ = require('lodash');
|
|
@@ -13,13 +12,15 @@ const path = require('path');
|
|
|
13
12
|
const { spawn, exec } = require('child_process');
|
|
14
13
|
const argv = require('yargs').argv;
|
|
15
14
|
const JSON5 = require('json5');
|
|
15
|
+
const { isEqual } = require('lodash');
|
|
16
|
+
// const npm = require('npm');
|
|
16
17
|
|
|
17
18
|
function Main() {
|
|
18
19
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
Main.prototype.process = async function (args) {
|
|
22
|
-
|
|
23
|
+
const self = this;
|
|
23
24
|
args = args || process.argv
|
|
24
25
|
self.options = {};
|
|
25
26
|
self.argv = argv;
|
|
@@ -27,10 +28,7 @@ Main.prototype.process = async function (args) {
|
|
|
27
28
|
try {
|
|
28
29
|
self.npu_packageJSON = require('../package.json');
|
|
29
30
|
} catch (e) {
|
|
30
|
-
|
|
31
|
-
version: '0.0.0'
|
|
32
|
-
}
|
|
33
|
-
console.error(chalk.red(`This project does not contain a valid package.json file!: \n${e}`));
|
|
31
|
+
throw new Error(`NPU does not contain a valid package.json file!: \n${e}`);
|
|
34
32
|
}
|
|
35
33
|
|
|
36
34
|
try {
|
|
@@ -38,8 +36,14 @@ Main.prototype.process = async function (args) {
|
|
|
38
36
|
self.proj_packageJSONPath = path.resolve(self.proj_path, './package.json');
|
|
39
37
|
self.proj_packageJSON = require(self.proj_packageJSONPath);
|
|
40
38
|
} catch (e) {
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
self.proj_packageJSON = {
|
|
40
|
+
name: 'Unknown Name',
|
|
41
|
+
version: '0.0.0',
|
|
42
|
+
dependencies: {},
|
|
43
|
+
devDependencies: {},
|
|
44
|
+
peerDependencies: {},
|
|
45
|
+
}
|
|
46
|
+
console.error(chalk.red(`This project does not contain a valid package.json file!: \n${e}`));
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
if (Array.isArray(args)) {
|
|
@@ -64,11 +68,12 @@ Main.prototype.process = async function (args) {
|
|
|
64
68
|
|
|
65
69
|
if (self.options.pv || self.options['project-version'] || self.options.project) {
|
|
66
70
|
self.log(chalk.blue(`The current project (${chalk.bold(self.proj_packageJSON.name)}) is v${chalk.bold(self.proj_packageJSON.version)}`));
|
|
67
|
-
return self.proj_packageJSON.
|
|
71
|
+
return self.proj_packageJSON.version;
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
if (self.options.lp || self.options.listpackages || self.options['-lp'] || self.options['--listpackages']) {
|
|
71
75
|
self.log(chalk.blue.bold(`Dependencies:`));
|
|
76
|
+
|
|
72
77
|
Object.keys(self.proj_packageJSON.dependencies || {})
|
|
73
78
|
.forEach((dep, i) => {
|
|
74
79
|
self.log(chalk.blue(`${dep} @ ${self.proj_packageJSON.dependencies[dep]}`));
|
|
@@ -93,6 +98,42 @@ Main.prototype.process = async function (args) {
|
|
|
93
98
|
};
|
|
94
99
|
}
|
|
95
100
|
|
|
101
|
+
if (self.options.mm || self.options.matchmodules || self.options.match || self.options['-mm'] || self.options['--matchmodules'] || self.options['--match']) {
|
|
102
|
+
self.log(chalk.blue.bold(`Match:`));
|
|
103
|
+
|
|
104
|
+
const response = {};
|
|
105
|
+
const isEqualFn = require('semver/functions/eq')
|
|
106
|
+
const coerceFn = require('semver/functions/coerce')
|
|
107
|
+
|
|
108
|
+
Object.keys(self.proj_packageJSON.dependencies || {})
|
|
109
|
+
.forEach(async (dep, i) => {
|
|
110
|
+
const packageVersion = coerceFn(self.proj_packageJSON.dependencies[dep]);
|
|
111
|
+
const installedVersion = coerceFn(
|
|
112
|
+
(await asyncCommand(`npm list ${dep} --depth=0 | grep ${dep}`))
|
|
113
|
+
.split(' ')[1]
|
|
114
|
+
.split('@')[1]
|
|
115
|
+
);
|
|
116
|
+
const isEqual = isEqualFn(installedVersion, packageVersion);
|
|
117
|
+
const verb = isEqual ? 'green' : 'yellow'
|
|
118
|
+
|
|
119
|
+
response[dep] = {
|
|
120
|
+
isEqual: isEqual,
|
|
121
|
+
package: packageVersion,
|
|
122
|
+
installed: installedVersion,
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
self.log(chalk[verb](`${dep}: ${packageVersion} = ${installedVersion}`));
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// self.log(chalk.blue.bold(`\nDev Dependencies:`));
|
|
129
|
+
// Object.keys(self.proj_packageJSON.devDependencies || {})
|
|
130
|
+
// .forEach((dep, i) => {
|
|
131
|
+
// self.log(chalk.blue(`${dep} @ ${self.proj_packageJSON.devDependencies[dep]}`));
|
|
132
|
+
// });
|
|
133
|
+
|
|
134
|
+
return response;
|
|
135
|
+
}
|
|
136
|
+
|
|
96
137
|
if (self.options.clean) {
|
|
97
138
|
const NPM_INSTALL_FLAG = self.options['--no-optional'] || self.options['-no-optional'] || self.options['no-optional'] ? '--no-optional' : ''
|
|
98
139
|
const NPM_CLEAN = `rm -fr node_modules && rm -fr package-lock.json && npm cache clean --force && npm install ${NPM_INSTALL_FLAG} && npm rb`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-power-user",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"description": "Easy tools for every Node.js developer!",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://itwcreativeworks.com",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"chalk": "^4.1.
|
|
32
|
+
"chalk": "^4.1.2",
|
|
33
33
|
"fs-jetpack": "^4.3.1",
|
|
34
|
-
"inquirer": "^8.
|
|
35
|
-
"json5": "^2.2.
|
|
34
|
+
"inquirer": "^8.2.4",
|
|
35
|
+
"json5": "^2.2.1",
|
|
36
36
|
"keychain": "^1.3.0",
|
|
37
37
|
"lodash": "^4.17.21",
|
|
38
38
|
"semver": "^7.3.7",
|
|
@@ -44,6 +44,6 @@
|
|
|
44
44
|
],
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"mocha": "^8.4.0",
|
|
47
|
-
"prepare-package": "^0.0.
|
|
47
|
+
"prepare-package": "^0.0.13"
|
|
48
48
|
}
|
|
49
|
-
}
|
|
49
|
+
}
|
package/src/index.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
// https://www.sitepoint.com/javascript-command-line-interface-cli-node-js/
|
|
6
6
|
// https://github.com/sitepoint-editors/ginit
|
|
7
|
-
|
|
8
7
|
const jetpack = require('fs-jetpack');
|
|
9
8
|
const chalk = require('chalk');
|
|
10
9
|
const _ = require('lodash');
|
|
@@ -13,13 +12,15 @@ const path = require('path');
|
|
|
13
12
|
const { spawn, exec } = require('child_process');
|
|
14
13
|
const argv = require('yargs').argv;
|
|
15
14
|
const JSON5 = require('json5');
|
|
15
|
+
const { isEqual } = require('lodash');
|
|
16
|
+
// const npm = require('npm');
|
|
16
17
|
|
|
17
18
|
function Main() {
|
|
18
19
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
Main.prototype.process = async function (args) {
|
|
22
|
-
|
|
23
|
+
const self = this;
|
|
23
24
|
args = args || process.argv
|
|
24
25
|
self.options = {};
|
|
25
26
|
self.argv = argv;
|
|
@@ -27,10 +28,7 @@ Main.prototype.process = async function (args) {
|
|
|
27
28
|
try {
|
|
28
29
|
self.npu_packageJSON = require('../package.json');
|
|
29
30
|
} catch (e) {
|
|
30
|
-
|
|
31
|
-
version: '0.0.0'
|
|
32
|
-
}
|
|
33
|
-
console.error(chalk.red(`This project does not contain a valid package.json file!: \n${e}`));
|
|
31
|
+
throw new Error(`NPU does not contain a valid package.json file!: \n${e}`);
|
|
34
32
|
}
|
|
35
33
|
|
|
36
34
|
try {
|
|
@@ -38,8 +36,14 @@ Main.prototype.process = async function (args) {
|
|
|
38
36
|
self.proj_packageJSONPath = path.resolve(self.proj_path, './package.json');
|
|
39
37
|
self.proj_packageJSON = require(self.proj_packageJSONPath);
|
|
40
38
|
} catch (e) {
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
self.proj_packageJSON = {
|
|
40
|
+
name: 'Unknown Name',
|
|
41
|
+
version: '0.0.0',
|
|
42
|
+
dependencies: {},
|
|
43
|
+
devDependencies: {},
|
|
44
|
+
peerDependencies: {},
|
|
45
|
+
}
|
|
46
|
+
console.error(chalk.red(`This project does not contain a valid package.json file!: \n${e}`));
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
if (Array.isArray(args)) {
|
|
@@ -64,11 +68,12 @@ Main.prototype.process = async function (args) {
|
|
|
64
68
|
|
|
65
69
|
if (self.options.pv || self.options['project-version'] || self.options.project) {
|
|
66
70
|
self.log(chalk.blue(`The current project (${chalk.bold(self.proj_packageJSON.name)}) is v${chalk.bold(self.proj_packageJSON.version)}`));
|
|
67
|
-
return self.proj_packageJSON.
|
|
71
|
+
return self.proj_packageJSON.version;
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
if (self.options.lp || self.options.listpackages || self.options['-lp'] || self.options['--listpackages']) {
|
|
71
75
|
self.log(chalk.blue.bold(`Dependencies:`));
|
|
76
|
+
|
|
72
77
|
Object.keys(self.proj_packageJSON.dependencies || {})
|
|
73
78
|
.forEach((dep, i) => {
|
|
74
79
|
self.log(chalk.blue(`${dep} @ ${self.proj_packageJSON.dependencies[dep]}`));
|
|
@@ -93,6 +98,42 @@ Main.prototype.process = async function (args) {
|
|
|
93
98
|
};
|
|
94
99
|
}
|
|
95
100
|
|
|
101
|
+
if (self.options.mm || self.options.matchmodules || self.options.match || self.options['-mm'] || self.options['--matchmodules'] || self.options['--match']) {
|
|
102
|
+
self.log(chalk.blue.bold(`Match:`));
|
|
103
|
+
|
|
104
|
+
const response = {};
|
|
105
|
+
const isEqualFn = require('semver/functions/eq')
|
|
106
|
+
const coerceFn = require('semver/functions/coerce')
|
|
107
|
+
|
|
108
|
+
Object.keys(self.proj_packageJSON.dependencies || {})
|
|
109
|
+
.forEach(async (dep, i) => {
|
|
110
|
+
const packageVersion = coerceFn(self.proj_packageJSON.dependencies[dep]);
|
|
111
|
+
const installedVersion = coerceFn(
|
|
112
|
+
(await asyncCommand(`npm list ${dep} --depth=0 | grep ${dep}`))
|
|
113
|
+
.split(' ')[1]
|
|
114
|
+
.split('@')[1]
|
|
115
|
+
);
|
|
116
|
+
const isEqual = isEqualFn(installedVersion, packageVersion);
|
|
117
|
+
const verb = isEqual ? 'green' : 'yellow'
|
|
118
|
+
|
|
119
|
+
response[dep] = {
|
|
120
|
+
isEqual: isEqual,
|
|
121
|
+
package: packageVersion,
|
|
122
|
+
installed: installedVersion,
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
self.log(chalk[verb](`${dep}: ${packageVersion} = ${installedVersion}`));
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// self.log(chalk.blue.bold(`\nDev Dependencies:`));
|
|
129
|
+
// Object.keys(self.proj_packageJSON.devDependencies || {})
|
|
130
|
+
// .forEach((dep, i) => {
|
|
131
|
+
// self.log(chalk.blue(`${dep} @ ${self.proj_packageJSON.devDependencies[dep]}`));
|
|
132
|
+
// });
|
|
133
|
+
|
|
134
|
+
return response;
|
|
135
|
+
}
|
|
136
|
+
|
|
96
137
|
if (self.options.clean) {
|
|
97
138
|
const NPM_INSTALL_FLAG = self.options['--no-optional'] || self.options['-no-optional'] || self.options['no-optional'] ? '--no-optional' : ''
|
|
98
139
|
const NPM_CLEAN = `rm -fr node_modules && rm -fr package-lock.json && npm cache clean --force && npm install ${NPM_INSTALL_FLAG} && npm rb`;
|