lscripts 1.4.1 → 1.5.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.
- package/README.md +12 -4
- package/package.json +13 -9
- package/lscripts.js +0 -135
package/README.md
CHANGED
|
@@ -6,14 +6,15 @@ Command to list all the scripts in your `package.json`. Pick easely wich one you
|
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Install the lscripts globally using your package manager you like.
|
|
10
10
|
|
|
11
11
|
``` bash
|
|
12
12
|
# using npm
|
|
13
13
|
npm install -g lscripts
|
|
14
|
-
|
|
15
14
|
# using yarn
|
|
16
15
|
yarn global add lscripts
|
|
16
|
+
# using pnpm
|
|
17
|
+
pnpm add -g lscripts
|
|
17
18
|
```
|
|
18
19
|
|
|
19
20
|
## Use
|
|
@@ -23,5 +24,12 @@ Simply run:
|
|
|
23
24
|
lscripts
|
|
24
25
|
```
|
|
25
26
|
|
|
26
|
-
You can then pick the script you want to
|
|
27
|
-
|
|
27
|
+
You can then pick the script you want to run using `Up` or `Down` keyes or by searching for the name of the script or the command its supposed to run and pressing `Enter`.
|
|
28
|
+
|
|
29
|
+
The script you chose will then be ran using your package manager. It determines the package manager you are using by checking what kind of lock file is present in your project. For now lscripts is compatible with `npm`, `yarn` and `pnpm`.
|
|
30
|
+
|
|
31
|
+
## Opitonal flags
|
|
32
|
+
|
|
33
|
+
- `--copy, -c`: This flag allows you to copy the script you pick to your clipboard instead of letting lscripts running it directly for you.
|
|
34
|
+
- `--version -v`: Displays the version of the package you are using.
|
|
35
|
+
- `--help -h`: Displays a help message.
|
package/package.json
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
{
|
|
2
|
-
"type": "
|
|
2
|
+
"type": "commonjs",
|
|
3
3
|
"name": "lscripts",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.5.0",
|
|
5
5
|
"description": "lscripts is a command tool that allows you to list and choose a script from your package.json easely.",
|
|
6
|
-
"main": "
|
|
6
|
+
"main": "./dist/main.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
"require": "./dist/main.js"
|
|
9
|
+
},
|
|
7
10
|
"bin": {
|
|
8
|
-
"lscripts": "
|
|
11
|
+
"lscripts": "./dist/main.js"
|
|
9
12
|
},
|
|
10
13
|
"files": [
|
|
11
|
-
"
|
|
14
|
+
"dist/*",
|
|
12
15
|
"package.json"
|
|
13
16
|
],
|
|
14
17
|
"scripts": {
|
|
18
|
+
"build": "tsc -p tsconfig.json",
|
|
15
19
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
16
20
|
"prepare": "husky"
|
|
17
21
|
},
|
|
@@ -26,14 +30,14 @@
|
|
|
26
30
|
"cli"
|
|
27
31
|
],
|
|
28
32
|
"dependencies": {
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"inquirer-autocomplete-prompt": "^3.0.0"
|
|
33
|
+
"@inquirer/search": "^3.1.1",
|
|
34
|
+
"clipboardy": "^4.0.0"
|
|
32
35
|
},
|
|
33
36
|
"devDependencies": {
|
|
34
37
|
"@commitlint/cli": "^19.8.1",
|
|
35
38
|
"@commitlint/config-conventional": "^19.8.1",
|
|
36
39
|
"husky": "^9.1.7",
|
|
37
|
-
"semantic-release": "^24.2.7"
|
|
40
|
+
"semantic-release": "^24.2.7",
|
|
41
|
+
"typescript": "^5.9.2"
|
|
38
42
|
}
|
|
39
43
|
}
|
package/lscripts.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import inquirer from 'inquirer'
|
|
4
|
-
import inquirerPrompt from 'inquirer-autocomplete-prompt'
|
|
5
|
-
import fs from 'fs'
|
|
6
|
-
import { exit, argv } from 'process'
|
|
7
|
-
import { spawn } from 'child_process'
|
|
8
|
-
import clipboard from 'clipboardy'
|
|
9
|
-
import lscriptsPackageJson from './package.json' with { type: "json" }
|
|
10
|
-
|
|
11
|
-
const rootDir = '/'
|
|
12
|
-
|
|
13
|
-
let isCopyModeEnabled = false
|
|
14
|
-
const useCopyMode = () => {
|
|
15
|
-
isCopyModeEnabled = true
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const displayHelpMessage = () => {
|
|
19
|
-
console.log(`Usage: lscripts [option]
|
|
20
|
-
Simply list and run a script form the package.json of your current node project.
|
|
21
|
-
|
|
22
|
-
option alias description
|
|
23
|
-
----------- ------- -----------------------------------------------------------------
|
|
24
|
-
--copy -c Enables copy mode: when you pick your script, it will be copied
|
|
25
|
-
to your clipboard instead of being ran immediately
|
|
26
|
-
--version -v Displays your installed version of lscripts
|
|
27
|
-
--help -h Displays this help message
|
|
28
|
-
|
|
29
|
-
You can only pass one argument at a time to lscripts command.`)
|
|
30
|
-
exit(0)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const displayVersion = () => {
|
|
34
|
-
console.log(`You are currently using lscripts version ${lscriptsPackageJson.version}`)
|
|
35
|
-
exit(0)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const possibleFlags = [
|
|
39
|
-
{ flags: ['--copy', '-c'], callback: useCopyMode },
|
|
40
|
-
{ flags: ['--help', '-h'], callback: displayHelpMessage },
|
|
41
|
-
{ flags: ['--version', '-v'], callback: displayVersion }
|
|
42
|
-
]
|
|
43
|
-
|
|
44
|
-
const parseArguments = () => {
|
|
45
|
-
if (argv.length < 3) return
|
|
46
|
-
if (argv.length > 3) {
|
|
47
|
-
console.log('You can only pass one argument at a time to lscripts.')
|
|
48
|
-
console.log(`Run 'lscripts --help' for more information.`)
|
|
49
|
-
return exit(1)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const arg = argv[2]
|
|
53
|
-
const flag = possibleFlags.find(({ flags }) => flags.includes(arg))
|
|
54
|
-
|
|
55
|
-
if (!flag) {
|
|
56
|
-
console.log(`Unkown argument "${arg}".`)
|
|
57
|
-
console.log(`Run 'lscripts --help' for more information.`)
|
|
58
|
-
return exit(1)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
flag.callback()
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const findPackageJsonInWorkingDirOrParent = (currentDir = './') => {
|
|
65
|
-
if (fs.existsSync(`${currentDir}package.json`)) return JSON.parse(fs.readFileSync(`${currentDir}package.json`))
|
|
66
|
-
if (fs.realpathSync(currentDir) === rootDir) return null
|
|
67
|
-
return findPackageJsonInWorkingDirOrParent(`${currentDir}../`)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const getScriptsFromPackageJson = (packageJson) => Object.entries(packageJson.scripts)
|
|
71
|
-
|
|
72
|
-
const getPackageManagerEngine = (currentDir = './') => {
|
|
73
|
-
if (fs.existsSync(`${currentDir}package-lock.json`)) return 'npm'
|
|
74
|
-
if (fs.existsSync(`${currentDir}yarn.lock`)) return 'yarn'
|
|
75
|
-
if (fs.existsSync(`${currentDir}pnpm-lock.yaml`)) return 'pnpm'
|
|
76
|
-
if (fs.realpathSync(currentDir) === rootDir) return null
|
|
77
|
-
return getPackageManagerEngine((`${currentDir}../`))
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
parseArguments()
|
|
81
|
-
|
|
82
|
-
const packageJson = findPackageJsonInWorkingDirOrParent()
|
|
83
|
-
|
|
84
|
-
if (!packageJson) {
|
|
85
|
-
console.log('No package.json was found in current directory or parent directories.')
|
|
86
|
-
console.log('Make sure you are in a NodeJS project before running lscripts.')
|
|
87
|
-
exit(1)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const scripts = getScriptsFromPackageJson(packageJson)
|
|
91
|
-
|
|
92
|
-
const runner = getPackageManagerEngine()
|
|
93
|
-
|
|
94
|
-
if (!runner) {
|
|
95
|
-
console.log('Please install your dependencies before using lscripts.')
|
|
96
|
-
console.log('lscripts uses the lock file to determine which package manager you are using.')
|
|
97
|
-
console.log('lscripts is currently only compatible with npm, yarn and pnpm.')
|
|
98
|
-
exit(1)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const regex = /^(.+) - /
|
|
102
|
-
|
|
103
|
-
const source = async (_, input) => {
|
|
104
|
-
return scripts.reduce((acc, [name, command]) => {
|
|
105
|
-
const script = `${name} - "${command}"`
|
|
106
|
-
if (script.includes(input) || input === undefined) acc.push(script)
|
|
107
|
-
return acc
|
|
108
|
-
}, [])
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
inquirer.registerPrompt('autocomplete', inquirerPrompt)
|
|
112
|
-
inquirer.prompt({
|
|
113
|
-
type: 'autocomplete',
|
|
114
|
-
name: 'script',
|
|
115
|
-
message: isCopyModeEnabled
|
|
116
|
-
? 'What script do you want to copy to your clipboard ?'
|
|
117
|
-
: 'What script do you want to run ?',
|
|
118
|
-
emptyText: `Sorry, I couldn't find the script you are looking for...`,
|
|
119
|
-
searchText: 'Looking for the script...',
|
|
120
|
-
pageSize: scripts.length,
|
|
121
|
-
source
|
|
122
|
-
}).then(({ script }) => {
|
|
123
|
-
const command = `${runner} run ${script.match(regex)[1]}`
|
|
124
|
-
|
|
125
|
-
if (isCopyModeEnabled) {
|
|
126
|
-
clipboard.writeSync(command)
|
|
127
|
-
console.log('✅ Command copied to your clipboard!')
|
|
128
|
-
console.log('You can paste it and run it!')
|
|
129
|
-
return
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
console.log(`🚀 ${command}`)
|
|
133
|
-
spawn(command, { stdio: 'inherit', shell: true })
|
|
134
|
-
.on('exit', process.exit)
|
|
135
|
-
})
|