node-power-user 0.0.20 → 0.0.23
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 +56 -0
- package/package.json +6 -6
- package/src/index.js +56 -0
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 outdated`: 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
|
@@ -12,6 +12,10 @@ const path = require('path');
|
|
|
12
12
|
const { spawn, exec } = require('child_process');
|
|
13
13
|
const argv = require('yargs').argv;
|
|
14
14
|
const JSON5 = require('json5');
|
|
15
|
+
const { isEqual } = require('lodash');
|
|
16
|
+
const semverIsEqual = require('semver/functions/eq')
|
|
17
|
+
const semverCoerce = require('semver/functions/coerce')
|
|
18
|
+
// const npm = require('npm');
|
|
15
19
|
|
|
16
20
|
function Main() {
|
|
17
21
|
|
|
@@ -71,6 +75,7 @@ const self = this;
|
|
|
71
75
|
|
|
72
76
|
if (self.options.lp || self.options.listpackages || self.options['-lp'] || self.options['--listpackages']) {
|
|
73
77
|
self.log(chalk.blue.bold(`Dependencies:`));
|
|
78
|
+
|
|
74
79
|
Object.keys(self.proj_packageJSON.dependencies || {})
|
|
75
80
|
.forEach((dep, i) => {
|
|
76
81
|
self.log(chalk.blue(`${dep} @ ${self.proj_packageJSON.dependencies[dep]}`));
|
|
@@ -95,6 +100,41 @@ const self = this;
|
|
|
95
100
|
};
|
|
96
101
|
}
|
|
97
102
|
|
|
103
|
+
if (self.options.out || self.options.outdated || self.options.match || self.options['-o'] || self.options['--outdated'] || self.options['--match']) {
|
|
104
|
+
self.log(chalk.blue.bold(`Outdated:`));
|
|
105
|
+
self.log(chalk.green(`name: package = installed`));
|
|
106
|
+
|
|
107
|
+
const response = {};
|
|
108
|
+
|
|
109
|
+
Object.keys(self.proj_packageJSON.dependencies || {})
|
|
110
|
+
.forEach(async (dep, i) => {
|
|
111
|
+
const packageVersion = _coerce(self.proj_packageJSON.dependencies[dep]);
|
|
112
|
+
const installedVersion = _coerce(
|
|
113
|
+
(await asyncCommand(`npm list ${dep} --depth=0 | grep ${dep}`))
|
|
114
|
+
.split(' ')[1]
|
|
115
|
+
.split('@')[1]
|
|
116
|
+
);
|
|
117
|
+
const isEqual = _isEqual(installedVersion, packageVersion);
|
|
118
|
+
const verb = isEqual ? 'green' : 'yellow'
|
|
119
|
+
|
|
120
|
+
response[dep] = {
|
|
121
|
+
isEqual: isEqual,
|
|
122
|
+
package: packageVersion,
|
|
123
|
+
installed: installedVersion,
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
self.log(chalk[verb](`${dep}: ${packageVersion} = ${installedVersion}`));
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// self.log(chalk.blue.bold(`\nDev Dependencies:`));
|
|
130
|
+
// Object.keys(self.proj_packageJSON.devDependencies || {})
|
|
131
|
+
// .forEach((dep, i) => {
|
|
132
|
+
// self.log(chalk.blue(`${dep} @ ${self.proj_packageJSON.devDependencies[dep]}`));
|
|
133
|
+
// });
|
|
134
|
+
|
|
135
|
+
return response;
|
|
136
|
+
}
|
|
137
|
+
|
|
98
138
|
if (self.options.clean) {
|
|
99
139
|
const NPM_INSTALL_FLAG = self.options['--no-optional'] || self.options['-no-optional'] || self.options['no-optional'] ? '--no-optional' : ''
|
|
100
140
|
const NPM_CLEAN = `rm -fr node_modules && rm -fr package-lock.json && npm cache clean --force && npm install ${NPM_INSTALL_FLAG} && npm rb`;
|
|
@@ -171,3 +211,19 @@ async function asyncCommand(command) {
|
|
|
171
211
|
});
|
|
172
212
|
});
|
|
173
213
|
}
|
|
214
|
+
|
|
215
|
+
function _coerce(v) {
|
|
216
|
+
try {
|
|
217
|
+
return semverCoerce(v)
|
|
218
|
+
} catch (e) {
|
|
219
|
+
return '0.0.0'
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function _isEqual(v1, v2) {
|
|
224
|
+
try {
|
|
225
|
+
return semverIsEqual(v1, v2)
|
|
226
|
+
} catch (e) {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-power-user",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
4
|
"description": "Easy tools for every Node.js developer!",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"test": "npm run prepare && ./node_modules/mocha/bin/mocha test/ --recursive --timeout=10000",
|
|
13
13
|
"start": "npm run prepare && node -e 'new (require(`./dist/index.js`))().process()'",
|
|
14
|
-
"prepare": "node -e 'require(`prepare-package`)'"
|
|
14
|
+
"prepare": "node -e 'require(`prepare-package`)()'"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
@@ -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
34
|
"inquirer": "^8.2.4",
|
|
35
|
-
"json5": "^2.2.
|
|
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.16"
|
|
48
48
|
}
|
|
49
|
-
}
|
|
49
|
+
}
|
package/src/index.js
CHANGED
|
@@ -12,6 +12,10 @@ const path = require('path');
|
|
|
12
12
|
const { spawn, exec } = require('child_process');
|
|
13
13
|
const argv = require('yargs').argv;
|
|
14
14
|
const JSON5 = require('json5');
|
|
15
|
+
const { isEqual } = require('lodash');
|
|
16
|
+
const semverIsEqual = require('semver/functions/eq')
|
|
17
|
+
const semverCoerce = require('semver/functions/coerce')
|
|
18
|
+
// const npm = require('npm');
|
|
15
19
|
|
|
16
20
|
function Main() {
|
|
17
21
|
|
|
@@ -71,6 +75,7 @@ const self = this;
|
|
|
71
75
|
|
|
72
76
|
if (self.options.lp || self.options.listpackages || self.options['-lp'] || self.options['--listpackages']) {
|
|
73
77
|
self.log(chalk.blue.bold(`Dependencies:`));
|
|
78
|
+
|
|
74
79
|
Object.keys(self.proj_packageJSON.dependencies || {})
|
|
75
80
|
.forEach((dep, i) => {
|
|
76
81
|
self.log(chalk.blue(`${dep} @ ${self.proj_packageJSON.dependencies[dep]}`));
|
|
@@ -95,6 +100,41 @@ const self = this;
|
|
|
95
100
|
};
|
|
96
101
|
}
|
|
97
102
|
|
|
103
|
+
if (self.options.out || self.options.outdated || self.options.match || self.options['-o'] || self.options['--outdated'] || self.options['--match']) {
|
|
104
|
+
self.log(chalk.blue.bold(`Outdated:`));
|
|
105
|
+
self.log(chalk.green(`name: package = installed`));
|
|
106
|
+
|
|
107
|
+
const response = {};
|
|
108
|
+
|
|
109
|
+
Object.keys(self.proj_packageJSON.dependencies || {})
|
|
110
|
+
.forEach(async (dep, i) => {
|
|
111
|
+
const packageVersion = _coerce(self.proj_packageJSON.dependencies[dep]);
|
|
112
|
+
const installedVersion = _coerce(
|
|
113
|
+
(await asyncCommand(`npm list ${dep} --depth=0 | grep ${dep}`))
|
|
114
|
+
.split(' ')[1]
|
|
115
|
+
.split('@')[1]
|
|
116
|
+
);
|
|
117
|
+
const isEqual = _isEqual(installedVersion, packageVersion);
|
|
118
|
+
const verb = isEqual ? 'green' : 'yellow'
|
|
119
|
+
|
|
120
|
+
response[dep] = {
|
|
121
|
+
isEqual: isEqual,
|
|
122
|
+
package: packageVersion,
|
|
123
|
+
installed: installedVersion,
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
self.log(chalk[verb](`${dep}: ${packageVersion} = ${installedVersion}`));
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// self.log(chalk.blue.bold(`\nDev Dependencies:`));
|
|
130
|
+
// Object.keys(self.proj_packageJSON.devDependencies || {})
|
|
131
|
+
// .forEach((dep, i) => {
|
|
132
|
+
// self.log(chalk.blue(`${dep} @ ${self.proj_packageJSON.devDependencies[dep]}`));
|
|
133
|
+
// });
|
|
134
|
+
|
|
135
|
+
return response;
|
|
136
|
+
}
|
|
137
|
+
|
|
98
138
|
if (self.options.clean) {
|
|
99
139
|
const NPM_INSTALL_FLAG = self.options['--no-optional'] || self.options['-no-optional'] || self.options['no-optional'] ? '--no-optional' : ''
|
|
100
140
|
const NPM_CLEAN = `rm -fr node_modules && rm -fr package-lock.json && npm cache clean --force && npm install ${NPM_INSTALL_FLAG} && npm rb`;
|
|
@@ -171,3 +211,19 @@ async function asyncCommand(command) {
|
|
|
171
211
|
});
|
|
172
212
|
});
|
|
173
213
|
}
|
|
214
|
+
|
|
215
|
+
function _coerce(v) {
|
|
216
|
+
try {
|
|
217
|
+
return semverCoerce(v)
|
|
218
|
+
} catch (e) {
|
|
219
|
+
return '0.0.0'
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function _isEqual(v1, v2) {
|
|
224
|
+
try {
|
|
225
|
+
return semverIsEqual(v1, v2)
|
|
226
|
+
} catch (e) {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
}
|