sudo-npm 1.0.0

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 (2) hide show
  1. package/index.ts +41 -0
  2. package/package.json +18 -0
package/index.ts ADDED
@@ -0,0 +1,41 @@
1
+ import shell from "shelljs"
2
+ import { ConsoleXtra } from "console-xtra"
3
+
4
+ const konsole = ConsoleXtra()
5
+
6
+ function optJoin<T>(a: T, separator: string = " "){
7
+ if (Array.isArray(a)){
8
+ return a.join(separator)
9
+ } else {
10
+ return a
11
+ }
12
+ }
13
+
14
+ function checkIfSuccess(Ss: shell.ShellString, message?: string | string[]){
15
+ if (Ss.code !== 0){
16
+ konsole.error("ERROR: Install failed, exiting...")
17
+ } else {
18
+ konsole.success(optJoin(message))
19
+ }
20
+ shell.exit()
21
+ }
22
+
23
+ export function install(packages: string[] | string){
24
+ const a = shell.exec(`sudo npm i ${optJoin(packages)}`)
25
+ checkIfSuccess(a, `Success installing ${optJoin(packages)}!`)
26
+ }
27
+
28
+ export function uninstall(packages: string[] | string){
29
+ const a = shell.exec(`sudo npm uninstall ${optJoin(packages)}`)
30
+ checkIfSuccess(a, `Success uninstalling ${optJoin(packages)}!`)
31
+ }
32
+
33
+ export function execute(commands: string | string[]){
34
+ if (Array.isArray(commands)){
35
+ for (let command of commands){
36
+ checkIfSuccess(shell.exec(`sudo npm ${command}`), `Success running ${command}!`)
37
+ }
38
+ } else {
39
+ checkIfSuccess(shell.exec(`sudo npm ${commands}`), `Success running ${commands}!`)
40
+ }
41
+ }
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "sudo-npm",
3
+ "version": "1.0.0",
4
+ "description": "NPM but it runs as root.",
5
+ "main": "index.ts",
6
+ "keywords": [],
7
+ "author": "",
8
+ "license": "MIT",
9
+ "type": "module",
10
+ "dependencies": {
11
+ "@types/shelljs": "^0.10.0",
12
+ "console-xtra": "^1.0.0",
13
+ "shelljs": "^0.10.0"
14
+ },
15
+ "scripts": {
16
+ "test": "echo \"Error: no test specified\" && exit 1"
17
+ }
18
+ }