as-soon 0.1.0 → 0.1.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 +139 -0
- package/dist/cli.js +6 -2
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
- package/src/cli.ts +6 -2
package/README.md
CHANGED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# as-soon
|
|
2
|
+
|
|
3
|
+
A lightweight file watcher that executes commands as soon as files change.
|
|
4
|
+
|
|
5
|
+
## What is as-soon?
|
|
6
|
+
|
|
7
|
+
`as-soon` is a command-line tool that watches specified files or directories and automatically executes a command whenever changes are detected. It's perfect for development workflows where you need to rebuild, test, or restart processes whenever your code changes.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Simple and fast** - Watch files and execute commands with minimal configuration
|
|
12
|
+
- **Flexible watching** - Watch specific directories or the current working directory
|
|
13
|
+
- **Debounced execution** - Commands are debounced (200ms) to avoid excessive runs during rapid file changes
|
|
14
|
+
- **File creation support** - Can watch for files that don't exist yet and automatically start watching them once created
|
|
15
|
+
- **Environment variables** - Loads environment variables from `.env` files automatically
|
|
16
|
+
- **Directory recreation handling** - Automatically re-subscribes when watched directories are deleted and recreated
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install -g as-soon
|
|
22
|
+
# or
|
|
23
|
+
pnpm add -g as-soon
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or use it locally in your project:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install -D as-soon
|
|
30
|
+
# or
|
|
31
|
+
pnpm add -D as-soon
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
### Basic Usage
|
|
37
|
+
|
|
38
|
+
Watch the current directory and execute a command on any file change:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
as-soon command
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Watch Specific Directories
|
|
45
|
+
|
|
46
|
+
Use the `-w` flag to watch specific directories:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
as-soon -w src -w public pnpm build
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Watch Specific Files
|
|
53
|
+
|
|
54
|
+
You can also watch specific files:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
as-soon -w package.json -w tsconfig.json pnpm build
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Pass Arguments to Commands
|
|
61
|
+
|
|
62
|
+
Any arguments after the command are passed through:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
as-soon pnpm test -- --watch
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Multiple Watch Paths
|
|
69
|
+
|
|
70
|
+
Watch multiple directories:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
as-soon -w src -w test pnpm build
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## How It Works
|
|
77
|
+
|
|
78
|
+
1. **Initial Execution**: The command runs immediately when you start as-soon
|
|
79
|
+
2. **File Watching**: It watches the specified directories (or current directory by default)
|
|
80
|
+
3. **Change Detection**: When files are added, modified, or deleted, it detects the changes
|
|
81
|
+
4. **Debounced Execution**: After a 200ms debounce period, the command executes again
|
|
82
|
+
5. **Continuous Watching**: The process continues until you stop it (Ctrl+C)
|
|
83
|
+
|
|
84
|
+
## Examples
|
|
85
|
+
|
|
86
|
+
### Development Workflow
|
|
87
|
+
|
|
88
|
+
Watch your source files and rebuild on changes:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
as-soon -w src pnpm build
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Test Runner
|
|
95
|
+
|
|
96
|
+
Run tests whenever test files change:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
as-soon -w test pnpm test
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Type Checking
|
|
103
|
+
|
|
104
|
+
Run TypeScript type checking on file changes:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
as-soon -w src tsc --noEmit
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Multiple Workspaces
|
|
111
|
+
|
|
112
|
+
Watch multiple directories in a monorepo:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
as-soon -w packages/app/src -w packages/lib/src pnpm build
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Watch Non-Existent Files
|
|
119
|
+
|
|
120
|
+
You can even watch for files that don't exist yet:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
as-soon -w ./config/dev.ts pnpm build
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
This is useful for configuration files that might be created later.
|
|
127
|
+
|
|
128
|
+
## Command-Line Options
|
|
129
|
+
|
|
130
|
+
- `-w <path>` - Specify a directory or file to watch (can be used multiple times)
|
|
131
|
+
- All other arguments are treated as the command to execute
|
|
132
|
+
|
|
133
|
+
## Environment Variables
|
|
134
|
+
|
|
135
|
+
as-soon automatically loads environment variables from `.env` files using `ldenv`.
|
|
136
|
+
|
|
137
|
+
## License
|
|
138
|
+
|
|
139
|
+
MIT
|
package/dist/cli.js
CHANGED
|
@@ -10,7 +10,6 @@ function error(msg) {
|
|
|
10
10
|
console.error(msg);
|
|
11
11
|
process.exit(1);
|
|
12
12
|
}
|
|
13
|
-
let deploymentContext = 'localhost';
|
|
14
13
|
let argToConsume;
|
|
15
14
|
let command;
|
|
16
15
|
let commandArgs;
|
|
@@ -45,7 +44,12 @@ if (!command) {
|
|
|
45
44
|
}
|
|
46
45
|
const commandToUse = command;
|
|
47
46
|
console.log(`"${commandToUse} ${commandArgs?.join(' ') || ''}"`);
|
|
48
|
-
|
|
47
|
+
if (options['mode'] || options['m']) {
|
|
48
|
+
loadEnv({ mode: options['mode'][0] || options['m'][0] });
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
loadEnv();
|
|
52
|
+
}
|
|
49
53
|
function _execute() {
|
|
50
54
|
try {
|
|
51
55
|
execFileSync(commandToUse, commandArgs, { stdio: ['inherit', 'inherit', 'inherit'] });
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAC3C,OAAO,OAA4B,MAAM,iBAAiB,CAAC;AAC3D,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAC,QAAQ,EAAC,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAE9B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAEnC,SAAS,KAAK,CAAC,GAAW;IACzB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC;AAED,IAAI,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAC3C,OAAO,OAA4B,MAAM,iBAAiB,CAAC;AAC3D,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAC,QAAQ,EAAC,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAE9B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAEnC,SAAS,KAAK,CAAC,GAAW;IACzB,OAAO,CAAC,KAAK,CAAC,GAAG,C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O,EAAE,CAAC;YAC9B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAExB,OAAO,CAAC,GAAG,CAAC,oBAAoB,MAAM,EAAE,CAAC,CAAC;YAC1C,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;QACtD,CAAC;IACF,CAAC;SAAM,CAAC;QACP,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QAC7C,OAAO,CAAC,GAAG,CAAC,gCAAgC,MAAM,EAAE,CAAC,CAAC;QACtD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzB,CAAC;AACF,CAAC;AACD,IAAI,EAAE,CAAC"}
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -13,7 +13,6 @@ function error(msg: string) {
|
|
|
13
13
|
process.exit(1);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
let deploymentContext = 'localhost';
|
|
17
16
|
let argToConsume;
|
|
18
17
|
let command: string | undefined;
|
|
19
18
|
let commandArgs: string[] | undefined;
|
|
@@ -47,7 +46,12 @@ const commandToUse = command!;
|
|
|
47
46
|
|
|
48
47
|
console.log(`"${commandToUse} ${commandArgs?.join(' ') || ''}"`);
|
|
49
48
|
|
|
50
|
-
|
|
49
|
+
if (options['mode'] || options['m']) {
|
|
50
|
+
loadEnv({mode: options['mode'][0] || options['m'][0]});
|
|
51
|
+
} else {
|
|
52
|
+
loadEnv();
|
|
53
|
+
}
|
|
54
|
+
|
|
51
55
|
|
|
52
56
|
function _execute() {
|
|
53
57
|
try {
|