Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
168d365
feat: create app folder and install dependencies
LexBorisoff Jan 14, 2025
8050e69
Merge branch 'dev' into feat/create-app
LexBorisoff Jan 15, 2025
815f466
ci: running CI Results only for pull requests
LexBorisoff Jan 15, 2025
5ec68b1
chore: updated package description, keywords, and removed bin commands
LexBorisoff Jan 15, 2025
6f5dc99
chore: renamed LICENSE file
LexBorisoff Jan 16, 2025
5c3fd29
feat: functionality to create app
LexBorisoff Jan 17, 2025
18af6b0
ci: added permissions to release jobs
LexBorisoff Jan 17, 2025
f248037
refactor: scripts contents
LexBorisoff Jan 17, 2025
5e10efa
refactor: creating all scripts in the bin folder
LexBorisoff Jan 18, 2025
7961de0
refactor: extracted hooks tree objects
LexBorisoff Jan 18, 2025
88cb353
refactor: exporting npmHooks as an object with dirHooks
LexBorisoff Jan 18, 2025
9cc54df
refactor: getting package name
LexBorisoff Jan 18, 2025
6d9d4fe
chore: small edits
LexBorisoff Jan 18, 2025
e593542
Merge pull request #3 from LexBorisoff/feat/create-app
LexBorisoff Jan 18, 2025
3587105
fix: fixed getPackageJson function by not using find-up package
LexBorisoff Jan 19, 2025
769c2dc
Merge pull request #4 from LexBorisoff/fix/get-package-script
LexBorisoff Jan 19, 2025
3efe356
fix(select-script): fixed filtering scripts in autocomplete when valu…
LexBorisoff Jan 19, 2025
93ac703
Merge pull request #5 from LexBorisoff/fix/select-script-autocomplete
LexBorisoff Jan 19, 2025
e64370b
feat: functionality to select a package manager when creating the app
LexBorisoff Jan 19, 2025
67b2943
refactor: created functions to work with config
LexBorisoff Jan 19, 2025
5c94f16
refactor: extracted useCoreHooks function
LexBorisoff Jan 19, 2025
893a257
feat(package manager): functionality to set and update a package manager
LexBorisoff Jan 19, 2025
c890edb
refactor(create app): refactored create-app files
LexBorisoff Jan 19, 2025
010a26c
feat(package manager): functionality to add other package managers to…
LexBorisoff Jan 19, 2025
cc8f844
fix(create app): keeping existing config file during app initialization
LexBorisoff Jan 19, 2025
d162814
feat(package manager): functionality to remove package managers from …
LexBorisoff Jan 20, 2025
fbde7a8
feat: option to match a script exactly
LexBorisoff Jan 20, 2025
fef90c6
ci: added pre-commit git hook
LexBorisoff Jan 20, 2025
467ca49
revert: deleted pre-commit git hook
LexBorisoff Jan 20, 2025
bb7a56b
feat(package manager): functionality to use or ignore package manager…
LexBorisoff Jan 20, 2025
0611475
fix(package manager): handling empty selection when removing package …
LexBorisoff Jan 21, 2025
574a871
feat: implemented --verbose option
LexBorisoff Jan 21, 2025
f564421
refactor(config): using CONFIG_FILE constant when updating config usi…
LexBorisoff Jan 21, 2025
97e2811
refactor: small edits
LexBorisoff Jan 21, 2025
410a1f2
Merge pull request #6 from LexBorisoff/feat/package-manager
LexBorisoff Jan 21, 2025
612e634
feat(package manager): improved suggestions when selecting and removi…
LexBorisoff Jan 21, 2025
d0a8ef5
chore: removed bash function script contents
LexBorisoff Jan 21, 2025
84304b6
refactor: changed dist link path to be at the root
LexBorisoff Jan 21, 2025
dc40594
Merge pull request #7 from LexBorisoff/feat/prompt-suggestions
LexBorisoff Jan 22, 2025
53c81ea
feat(package manager): removed functionality to add/remove package ma…
LexBorisoff Jan 22, 2025
432d8b6
refactor(select script): allowing to select other scripts when CLI ar…
LexBorisoff Jan 22, 2025
76eb7ab
refactor: removed ignorePackageManagerProp config setting
LexBorisoff Jan 23, 2025
d226932
fix(script contents): unsetting bash script variables in the correct …
LexBorisoff Jan 23, 2025
e3a67ed
feat: functionality to pass through arguments to the package script
LexBorisoff Jan 23, 2025
7ceec77
feat(create app): functionality to use existing config in createApp
LexBorisoff Jan 23, 2025
63e83c2
refactor: package manager as string in config
LexBorisoff Jan 24, 2025
af104c1
fix: fixed bug in createScriptFiles related to finding command files …
LexBorisoff Jan 24, 2025
f48811b
Merge pull request #8 from LexBorisoff/feat/default-package-managers
LexBorisoff Jan 24, 2025
991541c
Merge branch 'dev' into feat/pass-through-arguments
LexBorisoff Jan 24, 2025
7db6143
Merge pull request #9 from LexBorisoff/feat/pass-through-arguments
LexBorisoff Jan 24, 2025
6690135
Merge branch 'dev' into feat/using-config-on-app-initialize
LexBorisoff Jan 24, 2025
e47a002
Merge pull request #10 from LexBorisoff/feat/using-config-on-app-init…
LexBorisoff Jan 24, 2025
05bcc69
Merge branch 'dev' into refactor/config-package-manager
LexBorisoff Jan 24, 2025
68fafb2
revert: added back PackageJsonError error
LexBorisoff Jan 24, 2025
f7d3667
Merge pull request #11 from LexBorisoff/refactor/config-package-manager
LexBorisoff Jan 24, 2025
37ec0ed
refactor: refactored package manager CLI options
LexBorisoff Jan 24, 2025
48cf9da
refactor(create app): improved app initialize process with existing c…
LexBorisoff Jan 24, 2025
702c6e9
style: better variable names
LexBorisoff Jan 24, 2025
aa4bacd
Merge pull request #12 from LexBorisoff/refactor/package-manager-options
LexBorisoff Jan 24, 2025
69d905b
fix(config): handling and resetting incorrect config values
LexBorisoff Jan 24, 2025
f8e2737
build: upgraded @lexjs/prompts package
LexBorisoff Jan 24, 2025
b0648ae
docs: improved options help documentation
LexBorisoff Jan 24, 2025
4b924fb
feat(select script): functionality to run first matched script withou…
LexBorisoff Jan 24, 2025
10d814c
fix(select package manager): using select instead of autocomplete to …
LexBorisoff Jan 24, 2025
eb017ad
refactor(select script): improved select script flow
LexBorisoff Jan 24, 2025
7ae8877
fix(reset config): added fallback config when parsing config file data
LexBorisoff Jan 25, 2025
7705c9c
style: renamed SelectPmEnum
LexBorisoff Jan 25, 2025
2b758f5
Merge pull request #13 from LexBorisoff/fix/config-setup
LexBorisoff Jan 25, 2025
a14ca16
refactor(args): improved conflict handling
LexBorisoff Jan 25, 2025
1820317
Merge pull request #14 from LexBorisoff/feat/script-options
LexBorisoff Jan 25, 2025
bfbb70e
build: fixed eslint and prettier scripts in package.json
LexBorisoff Jan 25, 2025
d8e6ef2
feat(create app): functionality to add x permission to created script…
LexBorisoff Jan 25, 2025
ad06aaa
Merge pull request #15 from LexBorisoff/feat/permissions
LexBorisoff Jan 25, 2025
6902b3d
docs: added example gif file
LexBorisoff Jan 25, 2025
a488c92
docs: updated example gif file
LexBorisoff Jan 25, 2025
78d1118
docs: updated example gif file
LexBorisoff Jan 25, 2025
71d5a95
Merge branch 'dev' into readme
LexBorisoff Jan 25, 2025
435cf90
docs: finished readme
LexBorisoff Jan 26, 2025
01c0f1e
docs: updated gif links in readme to point to the main branch
LexBorisoff Jan 26, 2025
1e83a79
docs: updated readme
LexBorisoff Jan 26, 2025
2311fc3
feat: functionality to rename the command
LexBorisoff Jan 26, 2025
4cf9979
style: better variable names
LexBorisoff Jan 26, 2025
0d64337
Merge pull request #16 from LexBorisoff/feat/rename-command
LexBorisoff Jan 26, 2025
d137113
docs: updated readme
LexBorisoff Jan 26, 2025
e68f3e8
Merge pull request #17 from LexBorisoff/readme
LexBorisoff Jan 26, 2025
8ab78e5
fix(create app): adding version to package name to install during app…
LexBorisoff Jan 26, 2025
03a368e
fix(args): displaying package version
LexBorisoff Jan 26, 2025
652bc62
docs: updated readme
LexBorisoff Jan 26, 2025
99e445b
Merge pull request #19 from LexBorisoff/fix/install-core-library
LexBorisoff Jan 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,8 @@ jobs:
name: CI
uses: LexBorisoff/workflows/.github/workflows/ci.yml@main

ci-results:
results:
name: CI Results
if: github.event_name == 'push'
needs: ci
uses: LexBorisoff/workflows/.github/workflows/ci-results.yml@main
with:
ci-result: ${{ needs.ci.result }}

ci-results-pr:
name: CI Results - Pull Request
if: github.event_name == 'pull_request'
needs: ci
uses: LexBorisoff/workflows/.github/workflows/ci-results.yml@main
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@ concurrency:
jobs:
release:
name: Release
permissions:
contents: write
pull-requests: write
issues: write
id-token: write
uses: LexBorisoff/workflows/.github/workflows/release.yml@main
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

sync-dev:
name: Sync main to dev
permissions:
contents: write
uses: LexBorisoff/workflows/.github/workflows/sync-dev.yml@main
secrets:
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
File renamed without changes.
224 changes: 224 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
# `package-scripts`

![Build](https://img.shields.io/github/actions/workflow/status/LexBorisoff/package-scripts/release.yml)
![NPM Version](https://img.shields.io/npm/v/package-scripts)

CLI to interactively select and run package scripts using any package manager.

- [Installation](#installation)
- [Usage](#usage)
- [Arguments](#arguments)
- [Bypassing the selection prompt](#bypassing-the-selection-prompt)
- [Running the first matched script](#running-the-first-matched-script)
- [Pass-through arguments](#pass-through-arguments)
- [Package Manager](#package-manager)
- [Default package manager](#default-package-manager)
- [Project's package manager](#projects-package-manager)

## Installation

**Step 1**. Run the following command using **_npx_** from any directory.

```bash
npx package-scripts
```

**Step 2**. Follow the prompts to set up the command name and select your default package manager.

**Step 3**. Once the installation process is complete, add the following lines to your shell configuration file.

- For POSIX-compatible shells like bash or zsh

```bash
# ~/.bashrc or ~/.zshrc

if test -d ~/.package-scripts/bin; then
export PATH=~/.package-scripts/bin:$PATH
fi
```

- For PowerShell

```powershell
# C:\Program Files\PowerShell\7\profile.ps1

if (Test-Path -Path "$env:HOMEPATH\.package-scripts\bin") {
$env:Path = "$env:HOMEPATH\.package-scripts\bin;$env:Path"
}
```

> 💡 To get the path of your PowerShell configuration file, type `$PROFILE.` and tab through the available options to choose the necessary profile.

**Step 4**. Restart your shell. The command should now be available.

### How it works

The installation process creates a `~/.package-scripts` directory where it installs the **_core library_** and creates a **_shell script_** that acts as the program's main entry point. The script's directory (`bin`) is added to your PATH, making the script accessible from anywhere in your shell. By giving the script a name that you prefer (or sticking to the default), you control how to invoke the program.

### Renaming the command

You can rename the command later by providing the `--rename` option with the new command name. If the name is not provided, you will be prompted to enter one.

```bash
scripts --rename <new-name>
```

> 📚 All following examples will assume the command name is `scripts`

## Usage

To interactively select and run a script in your current project, run the command you created during the installation. Calling without any arguments or options will display all scripts (except for lifecycle scripts). You can type in the selection menu to filter down your search.

For example:

```bash
scripts
```

```json
{
"scripts": {
"prepack": "npm run build",
"build": "npm run compile",
"prebuild": "npm run ci && rimraf ./dist",
"ci": "npm run check-style && npm run check-build",
"check-style": "npm run format:check && npm run lint",
"check-build": "npm run compile -- --noEmit",
"format": "prettier --write \"*.{js,cjs,mjs,ts,cts,mts}\" \"{src,test}/**/*.ts\"",
"format:check": "prettier --check \"*.{js,cjs,mjs,ts,cts,mts}\" \"{src,test}/**/*.ts\"",
"lint": "eslint \"{src,test}/**/*.{js,ts}\"",
"lint:fix": "npm run lint -- --fix",
"style": "npm run format && npm run lint:fix",
"compile": "tsc -p tsconfig.json",
"prepare": "husky"
}
}
```

<img src="https://github.com/LexBorisoff/package-scripts/blob/main/media/usage.gif?raw=true" alt="usage example" width="1000" />

### Arguments

Supplying command arguments will filter the initial list of displayed scripts. However, you are not limited to the suggested list - you can still type in the prompt menu and select a different script.

For example:

```bash
scripts arg1 arg2 ...
```

### Bypassing the selection prompt

There are cases when the CLI will run a matched script without displaying the selection prompt.

- When a single argument is provided that matches a script **_exactly_** even if there are other scripts containing that argument in their names.
- When a single script is matched based on the provided arguments.

> 💡 The `--select` option can override this behavior and force the display of the selection menu.

For example:

```json
{
"scripts": {
"build": "npm run compile",
"prebuild": "npm run ci && rimraf ./dist",
"check-build": "npm run compile -- --noEmit"
}
}
```

```bash
scripts build
```

> 👆 runs the `build` script (exact match)

```bash
scripts build check
```

> 👆 runs the `check-build` script

### Running the first matched script

If there are multiple matched scripts, the `--first` option can be used to run the first script without displaying the selection prompt.

For example:

```json
{
"scripts": {
"check-style": "npm run format:check && npm run lint",
"check-build": "npm run compile -- --noEmit",
"format:check": "prettier --check \"*.{js,cjs,mjs,ts,cts,mts}\" \"{src,test}/**/*.ts\""
}
}
```

```bash
scripts check --first
```

> 👆 runs the `check-style` script

### Pass-through arguments

To pass arguments directly to the underlying script, provide them after the double-dash `--`. All arguments passed after `--` will be treated as pass-through arguments.

> ⚠️ If double-dash is not working in your shell, you can also use triple-dash `---`.

For example:

```json
{
"scripts": {
"hello": "echo hello"
}
}
```

```bash
scripts hello -- world
```

<img src="https://github.com/LexBorisoff/package-scripts/blob/main/media/hello-world-1.gif?raw=true" alt="usage example" width="1000" />

Passing arguments to the script also works with the selection prompt:

<img src="https://github.com/LexBorisoff/package-scripts/blob/main/media/hello-world-2.gif?raw=true" alt="usage example" width="1000" />

## Package Manager

The CLI allows you to run scripts by using one of the following package managers:

- npm
- pnpm
- yarn
- bun

> 💡 Use the `--which` option to view which package manager is currently being used.

### Default package manager

To set the default package manager for all projects, provide the `--default` option with a package manager name. If no name is provided, you will be prompted to select one.

For example:

```bash
scripts --default pnpm
```

### Project's package manager

Some projects include a `packageManager` property in their `package.json`. The CLI honors it and will run scripts using this property instead of your default package manager.

You can override this behavior by supplying the package manager that you want to use as a _**flag**_. It will be applied for the _**current script run**_ only and not override the project's package manager completely.

For example, if the project defines that it uses _**yarn**_, you can run a script with _**pnpm**_ as follows:

```bash
scripts --pnpm [SCRIPT]
```

> 💡 If there is no `packageManager` property in `package.json`, you can still use this pattern to override your default package manager.
Binary file added media/hello-world-1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/hello-world-2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/usage.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading