gulp-mu-gulp-api 0.3.13 → 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 +66 -0
  2. package/package.json +5 -2
  3. package/src/index.mjs +58 -0
package/README.md CHANGED
@@ -37,6 +37,12 @@ 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
+
40
46
  ### 0.3.13
41
47
 
42
48
  - **Updated** `PlaySignal` / `PlaySound` docs and CLI fallbacks for the µGulp sound schema (`taskSuccess`, `taskFailed`, `requestAlert`, …). Legacy presets `success` / `error` / `attention` remain valid.
@@ -184,6 +190,33 @@ let values = await RequestForm({
184
190
  | `RequestFontInput(options)` | Font selection (`options`: font list) |
185
191
  | `RequestSelectInput(options)` | Single selection from a fixed option list |
186
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
+ ```
187
220
 
188
221
  ### Localized task metadata (`.i18xRegister()` + placeholders)
189
222
 
@@ -314,6 +347,12 @@ Das Modul ist bewusst **abhängigkeitsfrei** und kennt keine µGulp™-Interna:
314
347
  npm install gulp-mu-gulp-api
315
348
  ```
316
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
+
317
356
  ### 0.3.13
318
357
 
319
358
  - **Aktualisiert** `PlaySignal` / `PlaySound` für das µGulp-Sound-Schema (`taskSuccess`, `taskFailed`, `requestAlert`, …). Legacy-Presets `success` / `error` / `attention` bleiben gültig.
@@ -461,6 +500,33 @@ let values = await RequestForm({
461
500
  | `RequestFontInput(options)` | Schriftart-Auswahl (`options`: Font-Liste) |
462
501
  | `RequestSelectInput(options)` | Einzelauswahl aus fester Optionsliste |
463
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
+ ```
464
530
 
465
531
  ### Lokalisierte Task-Metadaten (`.i18xRegister()` + Platzhalter)
466
532
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gulp-mu-gulp-api",
3
- "version": "0.3.13",
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
@@ -855,6 +855,62 @@ export function ClearRegisteredDashboardFonts() {
855
855
  registeredDashboardFonts.clear();
856
856
  }
857
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
+
858
914
  export default {
859
915
  IsMicroGulp,
860
916
  IsµGulp,
@@ -862,6 +918,8 @@ export default {
862
918
  RegisterDashboardFont,
863
919
  GetRegisteredDashboardFonts,
864
920
  ClearRegisteredDashboardFonts,
921
+ GetParameters,
922
+ GetParameter,
865
923
  ReportProgress,
866
924
  CreateProgress,
867
925
  PlaySignal,