scriptpal 1.2.2 → 1.3.1
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 +21 -2
- package/bin/index.js +90 -31
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ A simple npm script palette for lazy people who want a quick way to look through
|
|
|
8
8
|
|
|
9
9
|
- keyboard navigation
|
|
10
10
|
- autocompletion
|
|
11
|
-
-
|
|
11
|
+
- fuzzy finding
|
|
12
12
|
|
|
13
13
|
<p align="center">
|
|
14
14
|
<img width="580" src="assets/demo.gif" alt="Demo">
|
|
@@ -22,7 +22,7 @@ Install globally
|
|
|
22
22
|
npm install -g scriptpal
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
##
|
|
25
|
+
## Usage 🏁
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
28
|
scriptpal
|
|
@@ -33,3 +33,22 @@ Usage with npx
|
|
|
33
33
|
```bash
|
|
34
34
|
npx scriptpal
|
|
35
35
|
```
|
|
36
|
+
|
|
37
|
+
## API 🤖
|
|
38
|
+
|
|
39
|
+
- `--nowelcome`, `-n` Omit welcome message
|
|
40
|
+
- `--last`, `-l` Run previous command
|
|
41
|
+
- `--version`, `-v` Version number
|
|
42
|
+
- `--clipboard`, `-c` Copy command to clipboard
|
|
43
|
+
- `--help` Help me 🙏
|
|
44
|
+
|
|
45
|
+
## Examples
|
|
46
|
+
|
|
47
|
+
- `$ scriptpal --nowelcome`
|
|
48
|
+
- `$ npx scriptpal`
|
|
49
|
+
- `$ scriptpal --last --preset="emoji"`
|
|
50
|
+
|
|
51
|
+
## You might also like...
|
|
52
|
+
|
|
53
|
+
- [CommitPal](https://github.com/zeropoly/commitpal): A delightful CLI tool for building complex commit messages
|
|
54
|
+
- [Enquirer](https://github.com/enquirer/enquirer): Stylish, intuitive and user-friendly prompts
|
package/bin/index.js
CHANGED
|
@@ -1,82 +1,141 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
|
-
const { spawnSync } = require(
|
|
5
|
-
const { AutoComplete, Snippet } = require("enquirer");
|
|
4
|
+
const { spawnSync } = require("child_process");
|
|
5
|
+
const { AutoComplete, Snippet, Confirm } = require("enquirer");
|
|
6
6
|
const clipboardy = require("clipboardy");
|
|
7
7
|
const meow = require("meow");
|
|
8
|
+
const Conf = require("conf");
|
|
9
|
+
const chalk = require("chalk");
|
|
8
10
|
|
|
9
11
|
const welcome = require("./welcome");
|
|
10
12
|
const { getPackageJson, hasFile } = require("./file-manager");
|
|
11
13
|
|
|
12
|
-
async
|
|
13
|
-
|
|
14
|
+
const promptShouldRerunPrevious = async (previous) => {
|
|
15
|
+
const previousCommand = `${previous.script} ${
|
|
16
|
+
previous.parameters || ""
|
|
17
|
+
}`.trim();
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
return await new Confirm({
|
|
20
|
+
message: `Would you like to rerun the previous command?\n${chalk.greenBright(
|
|
21
|
+
previousCommand
|
|
22
|
+
)}`,
|
|
23
|
+
}).run();
|
|
24
|
+
};
|
|
16
25
|
|
|
26
|
+
const promptGetCommand = async (choices) => {
|
|
17
27
|
const script = await new AutoComplete({
|
|
18
|
-
name: "flavor",
|
|
19
28
|
message: "Which script would you like to run? 🤷♂️",
|
|
20
29
|
limit: 18,
|
|
21
|
-
choices
|
|
30
|
+
choices,
|
|
22
31
|
}).run();
|
|
23
32
|
|
|
24
|
-
const {
|
|
25
|
-
|
|
26
|
-
|
|
33
|
+
const {
|
|
34
|
+
values: { parameters },
|
|
35
|
+
} = await new Snippet({
|
|
36
|
+
message: "Would you like to add parameters?",
|
|
27
37
|
required: false,
|
|
28
|
-
fields: [
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
fields: [
|
|
39
|
+
{
|
|
40
|
+
name: "parameters",
|
|
41
|
+
message: "parameters",
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
template: `${script} \${parameters}`,
|
|
33
45
|
}).run();
|
|
34
46
|
|
|
47
|
+
return {
|
|
48
|
+
script,
|
|
49
|
+
parameters,
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
async function main(input, flags) {
|
|
54
|
+
if (!flags.nowelcome) welcome();
|
|
55
|
+
|
|
56
|
+
const packageJson = getPackageJson();
|
|
57
|
+
const choices = Object.keys(packageJson.scripts);
|
|
58
|
+
|
|
59
|
+
const config = new Conf();
|
|
60
|
+
const previous = config.get(`${process.cwd()}.previous`);
|
|
61
|
+
|
|
62
|
+
let shouldRerunPrevious = false;
|
|
63
|
+
|
|
64
|
+
if (!previous && flags.last) {
|
|
65
|
+
console.log("Previous command not found, continuing...\n");
|
|
66
|
+
} else if (previous && !flags.last) {
|
|
67
|
+
shouldRerunPrevious = await promptShouldRerunPrevious(previous);
|
|
68
|
+
} else {
|
|
69
|
+
shouldRerunPrevious = true;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const { script, parameters } =
|
|
73
|
+
(previous || flags.last) && shouldRerunPrevious
|
|
74
|
+
? previous
|
|
75
|
+
: await promptGetCommand(choices);
|
|
76
|
+
|
|
35
77
|
const isYarn = hasFile("yarn.lock");
|
|
36
78
|
const packageManager = isYarn ? "yarn" : "npm";
|
|
37
|
-
let args = !isYarn ? [
|
|
79
|
+
let args = !isYarn ? ["run", script] : [script];
|
|
38
80
|
|
|
39
81
|
args = parameters ? [...args, parameters] : args;
|
|
40
82
|
|
|
41
83
|
if (flags.clipboard) {
|
|
42
|
-
await clipboardy.write(`${packageManager} ${args.join(
|
|
84
|
+
await clipboardy.write(`${packageManager} ${args.join(" ")}`);
|
|
43
85
|
console.log("Copied to clipboard 👉 📋");
|
|
44
|
-
|
|
45
|
-
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const spawn = spawnSync(packageManager, args, { stdio: "inherit" });
|
|
46
90
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return 1;
|
|
50
|
-
}
|
|
91
|
+
if (spawn.error) {
|
|
92
|
+
throw new Error(spawn.error);
|
|
51
93
|
}
|
|
94
|
+
|
|
95
|
+
config.set(`${process.cwd()}.previous`, { script, parameters });
|
|
52
96
|
}
|
|
53
97
|
|
|
54
|
-
const cli = meow(
|
|
98
|
+
const cli = meow(
|
|
99
|
+
`
|
|
55
100
|
Usage
|
|
56
101
|
$ scriptpal
|
|
57
102
|
|
|
58
103
|
Options
|
|
104
|
+
--last, -l Run previous command
|
|
105
|
+
--clipboard, -c Copy command to clipboard
|
|
59
106
|
--nowelcome, -n Omit welcome message
|
|
107
|
+
--version Version number
|
|
60
108
|
--help Help me
|
|
61
|
-
--version, -v Version number
|
|
62
|
-
--clipboard, -c Copy command to clipboard
|
|
63
109
|
|
|
64
110
|
Examples
|
|
65
111
|
$ scriptpal --nowelcome
|
|
66
112
|
$ npx scriptpal
|
|
113
|
+
$ scriptpal --last --preset="emoji"
|
|
67
114
|
`,
|
|
68
115
|
{
|
|
69
116
|
flags: {
|
|
70
117
|
nowelcome: {
|
|
71
118
|
type: "boolean",
|
|
72
|
-
alias: "n"
|
|
119
|
+
alias: "n",
|
|
73
120
|
},
|
|
74
121
|
clipboard: {
|
|
75
122
|
type: "boolean",
|
|
76
|
-
alias: "c"
|
|
77
|
-
}
|
|
78
|
-
|
|
123
|
+
alias: "c",
|
|
124
|
+
},
|
|
125
|
+
last: {
|
|
126
|
+
type: "boolean",
|
|
127
|
+
alias: "l",
|
|
128
|
+
},
|
|
129
|
+
},
|
|
79
130
|
}
|
|
80
131
|
);
|
|
81
132
|
|
|
82
|
-
|
|
133
|
+
(async () => {
|
|
134
|
+
try {
|
|
135
|
+
await main(cli.input[0], cli.flags);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
console.error(chalk.red(error));
|
|
138
|
+
console.log(error);
|
|
139
|
+
process.exit(1);
|
|
140
|
+
}
|
|
141
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scriptpal",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "A simple npm script palette for lazy people (like me)",
|
|
5
5
|
"main": "./bin/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"start": "node ./bin/index",
|
|
11
|
-
"test": "echo \"Error: no test specified\"
|
|
11
|
+
"test": "echo \"Error: no test specified\""
|
|
12
12
|
},
|
|
13
13
|
"author": "Daniel Del Core",
|
|
14
14
|
"repository": {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"chalk": "^3.0.0",
|
|
31
31
|
"clipboardy": "^2.1.0",
|
|
32
|
+
"conf": "^6.2.1",
|
|
32
33
|
"enquirer": "^2.3.2",
|
|
33
34
|
"find-config": "^1.0.0",
|
|
34
35
|
"gradient-string": "^1.2.0",
|