node-power-user 0.0.5 → 0.0.9
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 -1
- package/bin/npu +1 -1
- package/dist/cli.js +111 -0
- package/package.json +14 -10
- package/src/cli.js +2 -1
- package/src/prepare.js +7 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<a href="https://cdn.itwcreativeworks.com/assets/itw-creative-works/images/logo/itw-creative-works-brandmark-black-x.svg">
|
|
3
|
-
<img src="https://cdn.itwcreativeworks.com/assets/itw-creative-works/images/logo/itw-creative-works-brandmark-black-x.svg">
|
|
3
|
+
<img src="https://cdn.itwcreativeworks.com/assets/itw-creative-works/images/logo/itw-creative-works-brandmark-black-x.svg" width="100px">
|
|
4
4
|
</a>
|
|
5
5
|
</p>
|
|
6
6
|
|
package/bin/npu
CHANGED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// CLI GUIDE:
|
|
2
|
+
// https://www.twilio.com/blog/how-to-build-a-cli-with-node-js
|
|
3
|
+
// https://www.npmjs.com/package/@dkundel/create-project
|
|
4
|
+
|
|
5
|
+
// https://www.sitepoint.com/javascript-command-line-interface-cli-node-js/
|
|
6
|
+
// https://github.com/sitepoint-editors/ginit
|
|
7
|
+
|
|
8
|
+
const jetpack = require('fs-jetpack');
|
|
9
|
+
const chalk = require('chalk');
|
|
10
|
+
const _ = require('lodash');
|
|
11
|
+
const inquirer = require('inquirer');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
const { spawn, exec } = require('child_process');
|
|
14
|
+
const argv = require('yargs').argv;
|
|
15
|
+
const JSON5 = require('json5');
|
|
16
|
+
|
|
17
|
+
function Main() {}
|
|
18
|
+
|
|
19
|
+
Main.prototype.process = async function (args) {
|
|
20
|
+
let self = this;
|
|
21
|
+
self.options = {};
|
|
22
|
+
self.argv = argv;
|
|
23
|
+
self.npu_packageJSON = require('../package.json');
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
self.proj_path = process.cwd();
|
|
27
|
+
self.proj_packageJSONPath = path.resolve(self.proj_path, './package.json');
|
|
28
|
+
self.proj_packageJSON = require(self.proj_packageJSONPath);
|
|
29
|
+
} catch (e) {
|
|
30
|
+
console.error(chalk.red(`Could not read package.json: ${e}`));
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
for (var i = 0; i < args.length; i++) {
|
|
35
|
+
self.options[args[i]] = true;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (self.options.v || self.options.version || self.options['-v'] || self.options['-version']) {
|
|
39
|
+
return console.log(chalk.blue(`Node Power User is v${chalk.bold(self.npu_packageJSON.version)}`));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (self.options.pv || self.options['project-version'] || self.options.project) {
|
|
43
|
+
return console.log(chalk.blue(`The current project (${chalk.bold(self.proj_packageJSON.name)}) is v${chalk.bold(self.proj_packageJSON.version)}`));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (self.options.clean) {
|
|
47
|
+
const NPM_INSTALL_FLAG = self.options['--no-optional'] || self.options['-no-optional'] || self.options['no-optional'] ? '--no-optional' : ''
|
|
48
|
+
const NPM_CLEAN = `rm -fr node_modules && rm -fr package-lock.json && npm cache clean --force && npm install ${NPM_INSTALL_FLAG} && npm rb`;
|
|
49
|
+
console.log(chalk.blue(`Running: ${NPM_CLEAN}...`));
|
|
50
|
+
return await asyncCommand(NPM_CLEAN)
|
|
51
|
+
.then(r => {
|
|
52
|
+
console.log(chalk.green(`Finished cleaning`));
|
|
53
|
+
})
|
|
54
|
+
.catch(e => {
|
|
55
|
+
console.log(chalk.green(`Error cleaning: ${e}`));
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (self.options.bump) {
|
|
60
|
+
return bump(self);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
module.exports = Main;
|
|
67
|
+
|
|
68
|
+
function bump(self) {
|
|
69
|
+
const semver = require('semver');
|
|
70
|
+
let level = '';
|
|
71
|
+
const version = self.proj_packageJSON.version;
|
|
72
|
+
// let version = '3.1.0-beta.0';
|
|
73
|
+
let newVersion = [semver.major(version), semver.minor(version), semver.patch(version)];
|
|
74
|
+
let newVersionPost = version.split('-')[1];
|
|
75
|
+
let newVersionString = '';
|
|
76
|
+
|
|
77
|
+
if (self.options.break || self.options.breaking || self.options.major || self.options['3']) {
|
|
78
|
+
level = 'breaking';
|
|
79
|
+
newVersion[0]++;
|
|
80
|
+
newVersion[1] = 0;
|
|
81
|
+
newVersion[2] = 0;
|
|
82
|
+
} else if (self.options.feature || self.options.features || self.options.med || self.options.medium || self.options['2']) {
|
|
83
|
+
level = 'feature';
|
|
84
|
+
newVersion[1]++;
|
|
85
|
+
newVersion[2] = 0;
|
|
86
|
+
} else {
|
|
87
|
+
level = 'patch';
|
|
88
|
+
newVersion[2]++;
|
|
89
|
+
}
|
|
90
|
+
newVersionString = newVersion.join('.') + (newVersionPost ? `-${newVersionPost}` : '');
|
|
91
|
+
|
|
92
|
+
self.proj_packageJSON.version = newVersionString;
|
|
93
|
+
|
|
94
|
+
jetpack.write(self.proj_packageJSONPath, self.proj_packageJSON);
|
|
95
|
+
|
|
96
|
+
console.log(chalk.blue(`Bumped package.json from ${chalk.bold(version)} to ${chalk.bold(newVersionString)}`));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
async function asyncCommand(command) {
|
|
101
|
+
return new Promise(function(resolve, reject) {
|
|
102
|
+
let cmd = exec(command, function (error, stdout, stderr) {
|
|
103
|
+
if (error) {
|
|
104
|
+
console.error(error);
|
|
105
|
+
return reject(error);
|
|
106
|
+
} else {
|
|
107
|
+
return resolve(stdout);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-power-user",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "
|
|
3
|
+
"version": "0.0.9",
|
|
4
|
+
"description": "Easy tools for every Node.js developer!",
|
|
5
|
+
"main": "dist/cli.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"npu": "
|
|
8
|
-
"node-power-user": "
|
|
9
|
-
"nodepoweruser": "
|
|
7
|
+
"npu": "bin/npu",
|
|
8
|
+
"node-power-user": "bin/npu",
|
|
9
|
+
"nodepoweruser": "bin/npu"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
13
|
-
"start": "node ./src/cli.js"
|
|
13
|
+
"start": "node ./src/cli.js",
|
|
14
|
+
"prepare": "node ./src/prepare.js"
|
|
14
15
|
},
|
|
15
16
|
"repository": {
|
|
16
17
|
"type": "git",
|
|
@@ -29,9 +30,9 @@
|
|
|
29
30
|
"homepage": "https://itwcreativeworks.com",
|
|
30
31
|
"dependencies": {
|
|
31
32
|
"chalk": "^4.1.0",
|
|
32
|
-
"fs-jetpack": "^4.1.0",
|
|
33
33
|
"inquirer": "^8.0.0",
|
|
34
34
|
"json5": "^2.2.0",
|
|
35
|
+
"keychain": "^1.3.0",
|
|
35
36
|
"lodash": "^4.17.21",
|
|
36
37
|
"semver": "^7.3.5",
|
|
37
38
|
"yargs": "^16.2.0"
|
|
@@ -39,5 +40,8 @@
|
|
|
39
40
|
"files": [
|
|
40
41
|
"bin/",
|
|
41
42
|
"src/"
|
|
42
|
-
]
|
|
43
|
-
|
|
43
|
+
],
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"fs-jetpack": "^4.3.1"
|
|
46
|
+
}
|
|
47
|
+
}
|
package/src/cli.js
CHANGED
|
@@ -44,7 +44,8 @@ Main.prototype.process = async function (args) {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
if (self.options.clean) {
|
|
47
|
-
const
|
|
47
|
+
const NPM_INSTALL_FLAG = self.options['--no-optional'] || self.options['-no-optional'] || self.options['no-optional'] ? '--no-optional' : ''
|
|
48
|
+
const NPM_CLEAN = `rm -fr node_modules && rm -fr package-lock.json && npm cache clean --force && npm install ${NPM_INSTALL_FLAG} && npm rb`;
|
|
48
49
|
console.log(chalk.blue(`Running: ${NPM_CLEAN}...`));
|
|
49
50
|
return await asyncCommand(NPM_CLEAN)
|
|
50
51
|
.then(r => {
|