gulp-mu-gulp-api 0.3.12 → 0.4.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 (3) hide show
  1. package/README.md +82 -8
  2. package/package.json +5 -2
  3. package/src/index.mjs +71 -7
package/README.md CHANGED
@@ -37,6 +37,16 @@ The module is deliberately **dependency-free** and knows nothing about µGulp™
37
37
  npm install gulp-mu-gulp-api
38
38
  ```
39
39
 
40
+ ### 0.4.0
41
+
42
+ - **Added** `GetParameters()` / `GetParameter(id, fallback)` — values for the inputs a task declared with `µParameters`. µGulp asks for them once before the task body runs and passes them in as `MICROGULP_PARAMS` (JSON) plus one flat `MICROGULP_PARAM_<ID>` per parameter.
43
+ - Works outside µGulp too: set the same environment variables by hand (`MICROGULP_PARAM_TARGET=staging npx gulp DEPLOY`) or rely on the declared defaults.
44
+ - Related gulpfile metadata added by µGulp 0.7.0: `µParameters` (declarative inputs), `µKeyBinding` (dashboard shortcut), `µWatch` (file trigger). They are plain task properties — no API call needed.
45
+
46
+ ### 0.3.13
47
+
48
+ - **Updated** `PlaySignal` / `PlaySound` docs and CLI fallbacks for the µGulp sound schema (`taskSuccess`, `taskFailed`, `requestAlert`, …). Legacy presets `success` / `error` / `attention` remain valid.
49
+
40
50
  ### 0.3.12
41
51
 
42
52
  - **Added** `RegisterDashboardFont({ id, file, family?, usage? })` — registers a workspace font for µGulp dashboard **task icons** and/or **run-log** typography. `usage`: `'task-icons'` (default), `'log'`, or `'all'`. Call at gulpfile load time; the scan worker forwards the registry to the engine.
@@ -123,8 +133,8 @@ export async function BUILD_THEME() {
123
133
  progress.Done();
124
134
 
125
135
  // sound + speech (rendered by the dashboard, configured in its settings)
126
- PlaySignal('success'); // preset: success | error | attention
127
- PlaySound('success'); // named atlas sample
136
+ PlaySignal('success'); // preset taskSuccess (also error→taskFailed, attention→requestAlert)
137
+ PlaySound('taskSuccess'); // named atlas sample (see MicroGulpSoundSchema.md)
128
138
  PlaySound('engine', { loop: true }); // loop until StopSound('engine')
129
139
  StopSound('engine');
130
140
  Speak('Theme build finished.');
@@ -165,8 +175,8 @@ let values = await RequestForm({
165
175
  | `GetLid()` / `SetLid(lid?)` | Active language id; `SetLid` clears to automatic when omitted |
166
176
  | `ReportProgress(value, label?)` | Report progress `0..1` to the task progress bar |
167
177
  | `CreateProgress(label?)` | Reporter object with `Update(value, stepLabel?)` and `Done()` |
168
- | `PlaySignal(signal?)` | Preset acoustic signal: `'success'` \| `'error'` \| `'attention'` (default) |
169
- | `PlaySound(sample, options?)` | Named sample from the dashboard sound atlas; `options.loop` repeats until `StopSound` |
178
+ | `PlaySignal(signal?)` | Preset or schema name; presets: `'success'`→`taskSuccess`, `'error'`→`taskFailed`, `'attention'`→`requestAlert` |
179
+ | `PlaySound(sample, options?)` | Named sample from the dashboard sound atlas (e.g. `taskStart`, `requestInfo`); `options.loop` repeats until `StopSound` |
170
180
  | `StopSound(sample)` | Stops a looping sample started with `PlaySound(sample, { loop: true })` |
171
181
  | `RegisterDashboardFont(spec)` | Registers a workspace font for dashboard task icons / run-log (`id`, `file`, optional `family` / `usage`: `task-icons`\|`log`\|`all`) |
172
182
  | `GetRegisteredDashboardFonts()` | Snapshot of fonts registered in this process (scan worker / tests) |
@@ -180,6 +190,33 @@ let values = await RequestForm({
180
190
  | `RequestFontInput(options)` | Font selection (`options`: font list) |
181
191
  | `RequestSelectInput(options)` | Single selection from a fixed option list |
182
192
  | `RequestMultiSelectInput(options)` | Multi selection (checkbox group), always resolves to a `string[]` |
193
+ | `GetParameters()` | Values of the task's declared `µParameters` (map id → typed value) |
194
+ | `GetParameter(id, fallback?)` | Single declared parameter value, with an env fallback |
195
+
196
+ ### Declared task parameters (`µParameters`)
197
+
198
+ Instead of asking inside the task body, declare the inputs once and read them at the top of the task. µGulp shows one form before the run, remembers the answers for the next run and passes the values in as environment:
199
+
200
+ ```javascript
201
+ import { GetParameters, Log } from 'gulp-mu-gulp-api';
202
+
203
+ export async function DEPLOY() {
204
+ let { target, tag, dryRun } = GetParameters();
205
+ Log('Deploying <tag/> to <target/><context="task log"/>', { tag, target });
206
+ }
207
+ DEPLOY.µParameters = [
208
+ { id: 'target', type: 'select', options: ['staging', 'production'], default: 'staging' },
209
+ { id: 'tag', type: 'text', required: true, pattern: '^v\\d+\\.\\d+' },
210
+ { id: 'dryRun', type: 'boolean', default: true },
211
+ { id: 'token', type: 'password' }, // never stored, never logged
212
+ ];
213
+ ```
214
+
215
+ The declaration uses the same field types as `RequestForm` plus the `boolean` shorthand (a single checkbox). `id` must be env-var safe. Values arrive as `MICROGULP_PARAMS` (JSON) and `MICROGULP_PARAM_<ID>`, so shell steps in the task can read them as well — and running the gulpfile through the plain gulp CLI works by setting those variables yourself:
216
+
217
+ ```bash
218
+ MICROGULP_PARAM_TARGET=staging npx gulp DEPLOY
219
+ ```
183
220
 
184
221
  ### Localized task metadata (`.i18xRegister()` + placeholders)
185
222
 
@@ -310,6 +347,16 @@ Das Modul ist bewusst **abhängigkeitsfrei** und kennt keine µGulp™-Interna:
310
347
  npm install gulp-mu-gulp-api
311
348
  ```
312
349
 
350
+ ### 0.4.0
351
+
352
+ - **Neu** `GetParameters()` / `GetParameter(id, fallback)` — Werte für die Eingaben, die ein Task per `µParameters` deklariert hat. µGulp fragt sie einmal vor dem Task-Rumpf ab und übergibt sie als `MICROGULP_PARAMS` (JSON) plus je Parameter ein flaches `MICROGULP_PARAM_<ID>`.
353
+ - Funktioniert auch ohne µGulp: dieselben Umgebungsvariablen von Hand setzen (`MICROGULP_PARAM_TARGET=staging npx gulp DEPLOY`) oder die deklarierten Defaults nutzen.
354
+ - Ergänzende Gulpfile-Metadaten aus µGulp 0.7.0: `µParameters` (deklarative Eingaben), `µKeyBinding` (Dashboard-Kürzel), `µWatch` (Datei-Trigger). Reine Task-Eigenschaften — kein API-Aufruf nötig.
355
+
356
+ ### 0.3.13
357
+
358
+ - **Aktualisiert** `PlaySignal` / `PlaySound` für das µGulp-Sound-Schema (`taskSuccess`, `taskFailed`, `requestAlert`, …). Legacy-Presets `success` / `error` / `attention` bleiben gültig.
359
+
313
360
  ### 0.3.12
314
361
 
315
362
  - **Neu** `RegisterDashboardFont({ id, file, family?, usage? })` — registriert einen Workspace-Font für **Task-Icons** und/oder die **Run-Log**-Typografie im µGulp-Dashboard. `usage`: `'task-icons'` (Default), `'log'` oder `'all'`. Aufruf beim Laden des Gulpfiles; der Scan-Worker reicht die Registry an die Engine weiter.
@@ -396,8 +443,8 @@ export async function BUILD_THEME() {
396
443
  progress.Done();
397
444
 
398
445
  // sound + speech (rendered by the dashboard, configured in its settings)
399
- PlaySignal('success'); // preset: success | error | attention
400
- PlaySound('success'); // named atlas sample
446
+ PlaySignal('success'); // preset taskSuccess (also error→taskFailed, attention→requestAlert)
447
+ PlaySound('taskSuccess'); // named atlas sample (see MicroGulpSoundSchema.md)
401
448
  PlaySound('engine', { loop: true }); // loop until StopSound('engine')
402
449
  StopSound('engine');
403
450
  Speak('Theme build finished.');
@@ -438,8 +485,8 @@ let values = await RequestForm({
438
485
  | `GetLid()` / `SetLid(lid?)` | Aktive Sprach-ID; `SetLid` ohne Argument = automatische Auflösung |
439
486
  | `ReportProgress(value, label?)` | Fortschritt `0..1` an die Task-Progressbar melden |
440
487
  | `CreateProgress(label?)` | Reporter-Objekt mit `Update(value, stepLabel?)` und `Done()` |
441
- | `PlaySignal(signal?)` | Vorgabe-Signal: `'success'` \| `'error'` \| `'attention'` (Default) |
442
- | `PlaySound(sample, options?)` | Benanntes Sample aus dem Sound-Atlas; `options.loop` wiederholt bis `StopSound` |
488
+ | `PlaySignal(signal?)` | Vorgabe oder Schema-Name; Presets: `'success'`→`taskSuccess`, `'error'`→`taskFailed`, `'attention'`→`requestAlert` |
489
+ | `PlaySound(sample, options?)` | Benanntes Sample aus dem Sound-Atlas (z. B. `taskStart`, `requestInfo`); `options.loop` wiederholt bis `StopSound` |
443
490
  | `StopSound(sample)` | Stoppt eine Schleife von `PlaySound(sample, { loop: true })` |
444
491
  | `RegisterDashboardFont(spec)` | Registriert einen Workspace-Font für Dashboard-Task-Icons / Run-Log (`id`, `file`, optional `family` / `usage`: `task-icons`\|`log`\|`all`) |
445
492
  | `GetRegisteredDashboardFonts()` | Snapshot der in diesem Prozess registrierten Fonts (Scan-Worker / Tests) |
@@ -453,6 +500,33 @@ let values = await RequestForm({
453
500
  | `RequestFontInput(options)` | Schriftart-Auswahl (`options`: Font-Liste) |
454
501
  | `RequestSelectInput(options)` | Einzelauswahl aus fester Optionsliste |
455
502
  | `RequestMultiSelectInput(options)` | Mehrfachauswahl (Checkbox-Gruppe), löst immer mit `string[]` auf |
503
+ | `GetParameters()` | Werte der per `µParameters` deklarierten Task-Eingaben (Map id → typisierter Wert) |
504
+ | `GetParameter(id, fallback?)` | Einzelner deklarierter Parameterwert, mit Env-Fallback |
505
+
506
+ ### Deklarierte Task-Parameter (`µParameters`)
507
+
508
+ Statt im Task-Rumpf zu fragen, werden die Eingaben einmal deklariert und am Task-Anfang gelesen. µGulp zeigt vor dem Lauf ein Formular, merkt die Antworten für den nächsten Lauf und übergibt die Werte als Umgebung:
509
+
510
+ ```javascript
511
+ import { GetParameters, Log } from 'gulp-mu-gulp-api';
512
+
513
+ export async function DEPLOY() {
514
+ let { target, tag, dryRun } = GetParameters();
515
+ Log('Deploying <tag/> to <target/><context="task log"/>', { tag, target });
516
+ }
517
+ DEPLOY.µParameters = [
518
+ { id: 'target', type: 'select', options: ['staging', 'production'], default: 'staging' },
519
+ { id: 'tag', type: 'text', required: true, pattern: '^v\\d+\\.\\d+' },
520
+ { id: 'dryRun', type: 'boolean', default: true },
521
+ { id: 'token', type: 'password' }, // wird nie gespeichert oder geloggt
522
+ ];
523
+ ```
524
+
525
+ Die Deklaration nutzt die Feldtypen von `RequestForm` plus die Kurzform `boolean` (eine einzelne Checkbox). `id` muss als Umgebungsvariablenname taugen. Die Werte kommen als `MICROGULP_PARAMS` (JSON) und `MICROGULP_PARAM_<ID>` an — auch Shell-Schritte im Task können sie lesen, und unter der reinen gulp-CLI setzt man sie einfach selbst:
526
+
527
+ ```bash
528
+ MICROGULP_PARAM_TARGET=staging npx gulp DEPLOY
529
+ ```
456
530
 
457
531
  ### Lokalisierte Task-Metadaten (`.i18xRegister()` + Platzhalter)
458
532
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gulp-mu-gulp-api",
3
- "version": "0.3.12",
4
- "description": "Public task API for the µGulp orchestrator: progress reporting, sound signals, speech output, localized console output (i18x) and interactive UI inputs (text, password, number, textarea, color, font, select, radio, multi-select checkbox, range slider, date/time, file) from within gulp tasks — with graceful CLI fallbacks when running without µGulp.",
3
+ "version": "0.4.0",
4
+ "description": "Public task API for the µGulp orchestrator: progress reporting, declared task parameters, sound signals, speech output, localized console output (i18x) and interactive UI inputs (text, password, number, textarea, color, font, select, radio, multi-select checkbox, range slider, date/time, file) from within gulp tasks — with graceful CLI fallbacks when running without µGulp.",
5
5
  "type": "module",
6
6
  "main": "src/index.mjs",
7
7
  "exports": {
@@ -28,6 +28,9 @@
28
28
  "prompt",
29
29
  "multiselect",
30
30
  "form",
31
+ "parameters",
32
+ "watch",
33
+ "keybinding",
31
34
  "task-api"
32
35
  ],
33
36
  "license": "MIT",
package/src/index.mjs CHANGED
@@ -287,29 +287,35 @@ export function LogChart(_spec) {
287
287
  /**
288
288
  * Plays an acoustic signal in the µGulp dashboard (WebAudio, respects the
289
289
  * dashboard audio settings: mute/volume). CLI fallback: terminal bell for
290
- * 'attention' and 'error' on a TTY, silent otherwise.
290
+ * 'attention' / 'error' (and their schema aliases) on a TTY, silent otherwise.
291
291
  *
292
- * @param {'success'|'error'|'attention'} [_signal]
292
+ * Presets map to atlas samples: `success`→`taskSuccess`, `error`→`taskFailed`,
293
+ * `attention`→`requestAlert`. New schema names (`taskStart`, `requestInfo`, …)
294
+ * are also accepted.
295
+ *
296
+ * @param {string} [_signal]
293
297
  */
294
298
  export function PlaySignal(_signal = 'attention') {
295
299
  if (IsMicroGulp()) {
296
300
  process.send({ type: 'sound', signal: _signal });
297
301
  return;
298
302
  }
299
- if (process.stdout.isTTY && (_signal === 'attention' || _signal === 'error')) {
303
+ let key = String(_signal ?? '').trim();
304
+ if (process.stdout.isTTY && (key === 'attention' || key === 'error' || key === 'requestAlert' || key === 'taskFailed')) {
300
305
  process.stdout.write('\u0007');
301
306
  }
302
307
  }
303
308
 
304
309
  /**
305
310
  * Plays a named sample from the dashboard sound atlas (µAU). Sample names match
306
- * the files bundled with µGulp (`success`, `error`, `attention`, or custom
307
- * atlas entries in the consumer skin). When `loop` is true the sample repeats
308
- * until `StopSound(sample)` is called.
311
+ * the files bundled with µGulp (see `dev/docs/MicroGulpSoundSchema.md`), e.g.
312
+ * `taskSuccess`, `taskFailed`, `requestAlert`, or custom atlas entries in a
313
+ * consumer theme pack. When `loop` is true the sample repeats until
314
+ * `StopSound(sample)` is called.
309
315
  *
310
316
  * CLI fallback: logs `[sound] <name>` on a TTY, silent otherwise.
311
317
  *
312
- * @param {string} _sample atlas sample name (e.g. `'success'`)
318
+ * @param {string} _sample atlas sample name (e.g. `'taskSuccess'`)
313
319
  * @param {object} [_options]
314
320
  * @param {boolean} [_options.loop] repeat until stopped (default `false`)
315
321
  */
@@ -849,6 +855,62 @@ export function ClearRegisteredDashboardFonts() {
849
855
  registeredDashboardFonts.clear();
850
856
  }
851
857
 
858
+ // -------------------------------------------------
859
+ // declared task parameters (µParameters)
860
+ // -------------------------------------------------
861
+
862
+ /**
863
+ * Values for the parameters a task declared with `µParameters`. µGulp collects
864
+ * them once before the task body runs (dashboard form, remembered defaults or
865
+ * values handed in by a repeat run) and passes them in as environment, so this
866
+ * works from any npm package in the pipeline.
867
+ *
868
+ * Outside µGulp the same values can be supplied by hand:
869
+ * `MICROGULP_PARAMS='{"target":"staging"}' npx gulp DEPLOY` — or per parameter
870
+ * with `MICROGULP_PARAM_TARGET=staging`.
871
+ *
872
+ * @returns {Record<string, any>} typed values (strings, numbers, booleans, string lists)
873
+ *
874
+ * @example
875
+ * export async function DEPLOY() {
876
+ * let { target, dryRun } = GetParameters();
877
+ * Log('Deploying to <target/><context="task log"/>', { target });
878
+ * }
879
+ * DEPLOY.µParameters = [
880
+ * { id: 'target', type: 'select', options: ['staging', 'production'], default: 'staging' },
881
+ * { id: 'dryRun', type: 'boolean', default: true },
882
+ * ];
883
+ */
884
+ export function GetParameters() {
885
+ let raw = process.env.MICROGULP_PARAMS;
886
+ if (!raw) return {};
887
+ try {
888
+ let parsed = JSON.parse(raw);
889
+ if (parsed == null || typeof parsed !== 'object' || Array.isArray(parsed)) return {};
890
+ return parsed;
891
+ } catch {
892
+ return {};
893
+ }
894
+ }
895
+
896
+ /**
897
+ * Single declared parameter value.
898
+ *
899
+ * @param {string} _id parameter id as declared in µParameters
900
+ * @param {any} [_fallback] returned when the parameter was not answered
901
+ * @returns {any}
902
+ */
903
+ export function GetParameter(_id, _fallback) {
904
+ let values = GetParameters();
905
+ if (Object.hasOwn(values, _id) && values[_id] != null && values[_id] !== '') {
906
+ return values[_id];
907
+ }
908
+ // Flat per-parameter env fallback for CLI runs and shell steps.
909
+ let flat = process.env['MICROGULP_PARAM_' + String(_id).toUpperCase()];
910
+ if (flat != null && flat !== '') return flat;
911
+ return _fallback;
912
+ }
913
+
852
914
  export default {
853
915
  IsMicroGulp,
854
916
  IsµGulp,
@@ -856,6 +918,8 @@ export default {
856
918
  RegisterDashboardFont,
857
919
  GetRegisteredDashboardFonts,
858
920
  ClearRegisteredDashboardFonts,
921
+ GetParameters,
922
+ GetParameter,
859
923
  ReportProgress,
860
924
  CreateProgress,
861
925
  PlaySignal,