Skip to content

Commit 182b190

Browse files
authored
Document npm:* commands (#213)
1 parent d139fe8 commit 182b190

File tree

2 files changed

+107
-32
lines changed

2 files changed

+107
-32
lines changed

console/asset-compilation.md

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -107,37 +107,8 @@ BundleManager::instance()->registerBundle('tailwind', [
107107
]);
108108
```
109109

110-
### Run a package script
110+
### NPM Utilities
111111

112-
```bash
113-
php artisan npm:run <package> <script> [-f|--production] [-- <extra script args>]
114-
```
115-
116-
The `npm:run` command allows you to quickly run scripts defined in the `package.json` file of a Mix package.
117-
118-
```json5
119-
// package.json
120-
{
121-
// ...
122-
"scripts": {
123-
"scriptName": "script to execute"
124-
}
125-
// ...
126-
}
127-
```
128-
129-
This can be useful for running arbitrary scripts that augment the capabilities of your plugin or theme, such as executing unit tests, making customised builds and much more. Note that scripts will run with the working directory set to the root folder of the package, not the root folder of the entire project that the `artisan` command normally executes within.
130-
131-
By default, all package scripts are run in "development" mode. If you wish to run a script in "production" mode, add the `-f` or `--production` flag to the command.
132-
133-
If you wish to pass extra arguments or options to your script, you can add `--` to the end of the command. Any arguments or options added after the `--` argument are interpreted as arguments and options to be sent to the script itself.
134-
135-
### Update Node dependencies
136-
137-
```bash
138-
php artisan npm:update [-p <package name>] [--npm <path to npm>]
139-
```
140-
141-
The `npm:update` command will update Node dependencies for all registered packages.
112+
Winter offers `npm` utilities that simplify and improve your development experience. These utilities are all accessible via the `artisan` interface.
142113

143-
This allows you to keep dependencies up to date, especially in the case of security fixes or breaking updates from your Node dependencies.
114+
Full documentation of the [`npm` utilities can be found here](./asset-node-utilities.md)

console/asset-node-utilities.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Asset Compilation - NPM Utilities
2+
3+
## Introduction
4+
5+
Winter supports running `npm` commands within the context of your packages, i.e. allowing you to update a specific plugins dependencies or allowing you to execute a themes npm script.
6+
7+
### Requirements
8+
9+
The following assumes you have a compatible version of `npm` installed (>= v7.0), and you have already configured your packages as described in the [Asset Compilation](./asset-compilation.md) guide.
10+
11+
### Install Node dependencies
12+
13+
```bash
14+
php artisan npm:install <?package name> <dependencies[]>
15+
```
16+
17+
The `npm:install` command will install Node dependencies. You are able to target a package to install the dependency into as the first option.
18+
19+
```bash
20+
php artisan npm:install acme.plugin is-odd
21+
```
22+
23+
Multiple packages can be installed in a single command by appending the desired packages to the end of the command.
24+
25+
```bash
26+
php artisan npm:install acme.plugin is-odd is-even
27+
```
28+
29+
If you wish for the dependencies to be installed within devDependencies, you can pass the `--dev` flag.
30+
31+
```bash
32+
php artisan npm:install acme.plugin is-odd is-even --dev
33+
```
34+
35+
Alternatively, if you wish to install dependencies to your projects root, you may omit the `package name` from the command.
36+
37+
```bash
38+
php artisan npm:install is-odd is-even
39+
```
40+
41+
### Update Node dependencies
42+
43+
```bash
44+
php artisan npm:update <?package name> <dependencies[]>
45+
```
46+
47+
The `npm:update` command will update Node dependencies. You are able to target a package to update the dependency into as the first option.
48+
49+
```bash
50+
php artisan npm:update acme.plugin
51+
```
52+
53+
If you want to update a specific dependency, simply provide it at the end of the command.
54+
55+
```bash
56+
php artisan npm:update acme.plugin is-odd
57+
```
58+
59+
To tell `npm` to also save the version update to your package's `package.json` in addition to the lock file, provide the `--save` flag
60+
61+
```bash
62+
php artisan npm:update acme.plugin --save
63+
```
64+
65+
To update dependencies of your projects root `package.json`, omit the package from the command.
66+
67+
```bash
68+
php artisan npm:update is-odd
69+
```
70+
71+
### Run a package script
72+
73+
```bash
74+
php artisan npm:run <package> <script> [-f|--production] [-- <extra script args>]
75+
```
76+
77+
If your packages `package.json` implements `scripts`, you can execute them via the `npm:run` command. The following assumes you already have scripts configured.
78+
79+
```json5
80+
// package.json
81+
{
82+
// ...
83+
"scripts": {
84+
"scriptName": "script to execute"
85+
}
86+
// ...
87+
}
88+
```
89+
90+
The following will run the `test` script from within the `acme.plugin` package.
91+
92+
```bash
93+
php artisan npm:run acme.plugin test
94+
```
95+
96+
You are also able to pass custom arguments to the script via adding `--` followed by your arguments.
97+
98+
```bash
99+
php artisan npm:run acme.plugin test -- --custom-arg --example=1
100+
```
101+
102+
This can be useful for running arbitrary scripts that augment the capabilities of your plugin or theme, such as executing unit tests, making customised builds and much more. Note that scripts will run with the working directory set to the root folder of the package, not the root folder of the entire project that the `artisan` command normally executes within.
103+
104+
By default, all package scripts are run in "development" mode. If you wish to run a script in "production" mode, add the `-f` or `--production` flag to the command.

0 commit comments

Comments
 (0)