lscripts 1.1.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 (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +27 -0
  3. package/lscripts.js +54 -0
  4. package/package.json +34 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Jules Fournier
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # lscripts
2
+
3
+ Command to list all the scripts in your `package.json`. Pick easely wich one you want to run and lscripts handles the rest !
4
+
5
+ ![demo](https://github.com/julesfrn/lscripts/blob/main/demo.gif?raw=true)
6
+
7
+ ## Install
8
+
9
+ With your favourite package manager you can install the package globaly using the git repo web URL.
10
+
11
+ ``` bash
12
+ # using npm
13
+ npm install -g lscripts
14
+
15
+ # using yarn
16
+ yarn global add lscripts
17
+ ```
18
+
19
+ ## Use
20
+
21
+ Simply run:
22
+ ``` bash
23
+ lscripts
24
+ ```
25
+
26
+ You can then pick the script you want to copy to your clipboard using `Up` or `Down` keyes or by searching for the name of the script or the command its supposed to run and pressing `Enter`.
27
+ The script you chose will then be ran using your package manager. It determines the package manager you are using checking if you have a `package-lock` or a `yarn-lock` file in your project to copy the proper command to your clipboard.
package/lscripts.js ADDED
@@ -0,0 +1,54 @@
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 } from 'process'
7
+ import { spawn } from 'child_process'
8
+
9
+ const getPackageManagerEngine = () => {
10
+ if (fs.existsSync('./package-lock.json')) return 'npm'
11
+ if (fs.existsSync('./yarn.lock')) return 'yarn'
12
+ return null
13
+ }
14
+
15
+ const runner = getPackageManagerEngine()
16
+
17
+ if (!runner) {
18
+ console.log('Please install your dependencies before using lscripts.')
19
+ console.log('lscripts uses the lock file to determine which package manager you are using.')
20
+ console.log('lscripts is currently only compatible with npm and yarn.')
21
+ exit(1)
22
+ }
23
+
24
+ const scripts = Object.entries(JSON.parse(fs.readFileSync('./package.json')).scripts)
25
+
26
+ const regex = /^(.+) - /
27
+
28
+ const source = async (_, input) => {
29
+ return scripts.reduce((acc, [name, command]) => {
30
+ const script = `${name} - "${command}"`
31
+ if (script.includes(input) || input === undefined) acc.push(script)
32
+ return acc
33
+ }, [])
34
+ }
35
+
36
+ inquirer.registerPrompt('autocomplete', inquirerPrompt)
37
+ inquirer.prompt({
38
+ type: 'autocomplete',
39
+ name: 'script',
40
+ message: 'What script do you want to copy to your clipboard ?',
41
+ emptyText: `Sorry, I couldn't find the script you are looking for...`,
42
+ searchText: 'Looking for the script...',
43
+ pageSize: scripts.length,
44
+ source
45
+ }).then(({ script }) => {
46
+ const child = spawn(runner, ['run', script.match(regex)[1]], {
47
+ stdio: 'inherit',
48
+ shell: true
49
+ })
50
+
51
+ child.on('exit', (code) => {
52
+ process.exit(code);
53
+ })
54
+ })
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "type": "module",
3
+ "name": "lscripts",
4
+ "version": "1.1.0",
5
+ "description": "lscripts is a command tool that allows you to list and choose a script from your package.json easely.",
6
+ "main": "lscripts.js",
7
+ "bin": {
8
+ "lscripts": "lscripts.js"
9
+ },
10
+ "files": [
11
+ "lscripts.js",
12
+ "package.json"
13
+ ],
14
+ "scripts": {
15
+ "test": "echo \"Error: no test specified\" && exit 1"
16
+ },
17
+ "author": "@julesfrn",
18
+ "license": "MIT",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/julesfrn/lscripts.git"
22
+ },
23
+ "keywords": [
24
+ "lscripts",
25
+ "cli"
26
+ ],
27
+ "dependencies": {
28
+ "inquirer": "^9.1.4",
29
+ "inquirer-autocomplete-prompt": "^3.0.0"
30
+ },
31
+ "devDependencies": {
32
+ "semantic-release": "^24.2.7"
33
+ }
34
+ }