go-dev 0.3.1 → 0.3.2

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 CHANGED
@@ -70,13 +70,30 @@ You can combine multiple keyword flag blocks for different services or specific
70
70
  npx go-dev <preset_name> [--<serviceArgsKeyword> <service_name>[:<command_index>] [args...] ] [...]
71
71
  ```
72
72
 
73
- Example:
73
+ **How Arguments are Applied to `cmd` Service Commands:**
74
74
 
75
- Consider an `api` service with two parallel commands: `api:0` (main server) and `api:1` (TypeScript compiler watch).
75
+ When arguments are passed to a `cmd` type service command, `go-dev` processes them in a special way:
76
+
77
+ 1. **Placeholder Substitution:**
78
+ * The command array (e.g., `[npx, tsx, ./src/$arg.ts]`) is scanned for the special placeholder `$arg`.
79
+ * Each occurrence of `$arg` is replaced, in order, by an argument from the `[args...]` provided on the command line.
80
+ * Example: A command `[npx, tsx, ./src/$arg.ts]` with extra arguments `[index, -w]` will become `[npx, tsx, ./src/index.ts, -w]`.
81
+
82
+ 2. **Escaped Placeholders:**
83
+ * If you need a literal `$arg` in your command that should *not* be substituted, escape it with a backslash: `\$arg`.
84
+ * Example: A command `[echo, \$arg]` with no extra arguments will result in `[echo, $arg]`.
85
+
86
+ 3. **Remaining Arguments:**
87
+ * Any arguments from `[args...]` that were *not* used to substitute an `$arg` placeholder will be **appended** to the end of the command array.
88
+ * Example: A command `[echo, $arg, fixed]` with extra arguments `[first, second, third]` will become `[echo, first, fixed, second, third]`. Here, `first` replaces `$arg`, and `second`, `third` are appended.
89
+
90
+ **Full Example:**
91
+
92
+ Consider an `api` service with two parallel commands: `api:0` (main server, using `$arg`) and `api:1` (TypeScript compiler watch).
76
93
 
77
94
  ```bash
78
95
  npx go-dev all \
79
- --args-for api:0 --host 0.0.0.0 --port 8081 \
96
+ --args-for api:0 main-entrypoint --host 0.0.0.0 --port 8081 \
80
97
  --args-for api:1 --pretty --diagnostics \
81
98
  --args-for frontend --log-level verbose
82
99
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "go-dev",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "main": "src/index.js",
5
5
  "bin": {
6
6
  "go-dev": "bin/go-dev"
package/src/config.js CHANGED
@@ -112,8 +112,6 @@ function loadConfig(configPath) {
112
112
  const configContent = fs.readFileSync(configPath, 'utf8');
113
113
  const config = yaml.load(configContent);
114
114
 
115
- console.log(config.services.api.modes);
116
-
117
115
  const { error, value } = configSchema.validate(config);
118
116
 
119
117
  if (error) {
@@ -60,13 +60,52 @@ class CmdService extends BaseService {
60
60
  const useProcessIndex = cmdArgs.length > 1;
61
61
  const exitedProcess = Array.from({ length: cmdArgs.length });
62
62
  for (let index = 0; index < cmdArgs.length; index++) {
63
- const command = cmdArgs[index];
63
+ const [command, ...args] = cmdArgs[index];
64
64
 
65
- const extraArgs = this.extraArgs?.[index] ?? [];
65
+ const extraArgs = (this.extraArgs?.[index] ?? []).slice();
66
+
67
+ const finalArgs = args.map(arg => {
68
+ const regex = /(\\*)\$arg/g;
69
+
70
+ let indexesToReplace = [];
71
+ while (true) {
72
+ const match = regex.exec(arg);
73
+ if (match == null) {
74
+ break;
75
+ }
76
+
77
+ const backslashes = match[1];
78
+
79
+ const startIndex = match.index + backslashes.length;
80
+
81
+ if (backslashes.length % 2 === 1) {
82
+ indexesToReplace.unshift({
83
+ startIndex: startIndex - 1,
84
+ endIndex: startIndex + 5,
85
+ replacement: '$arg',
86
+ });
87
+ continue;
88
+ }
89
+
90
+ const replacement = extraArgs.shift() ?? '';
91
+ indexesToReplace.unshift({
92
+ startIndex,
93
+ endIndex: startIndex + 4,
94
+ replacement,
95
+ });
96
+ }
97
+
98
+ indexesToReplace.forEach(({ startIndex, endIndex, replacement }) => {
99
+ console.log({ replacement, start: arg.slice(0, startIndex) });
100
+ arg = arg.slice(0, startIndex) + replacement + arg.slice(endIndex);
101
+ });
102
+
103
+ return arg;
104
+ }).concat(extraArgs);
66
105
 
67
106
  const process = CmdService._processManager.startManagedProcess(
68
- command[0],
69
- command.slice(1).concat(extraArgs),
107
+ command,
108
+ finalArgs,
70
109
  { cwd: directory[index] },
71
110
  (useProcessIndex ?
72
111
  `${this.prefix}${index}:` :