gulp-mu-gulp-api 0.3.13 → 0.4.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 +76 -0
- package/package.json +5 -2
- package/src/i18x-engine.mjs +4 -1
- package/src/i18x.mjs +2 -0
- package/src/index.mjs +62 -2
package/README.md
CHANGED
|
@@ -37,6 +37,17 @@ 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.1
|
|
41
|
+
|
|
42
|
+
- **Fixed** a placeholder with an unknown named format rendered as an empty string instead of its value — gulp lifecycle lines lost their duration (`Finished 'task' after`). The raw value is kept when the format is missing.
|
|
43
|
+
- **Fixed** `SetLid()` kept the dictionary of the previous language cached, so a language switch inside a running worker could still translate with stale texts.
|
|
44
|
+
|
|
45
|
+
### 0.4.0
|
|
46
|
+
|
|
47
|
+
- **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.
|
|
48
|
+
- Works outside µGulp too: set the same environment variables by hand (`MICROGULP_PARAM_TARGET=staging npx gulp DEPLOY`) or rely on the declared defaults.
|
|
49
|
+
- 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.
|
|
50
|
+
|
|
40
51
|
### 0.3.13
|
|
41
52
|
|
|
42
53
|
- **Updated** `PlaySignal` / `PlaySound` docs and CLI fallbacks for the µGulp sound schema (`taskSuccess`, `taskFailed`, `requestAlert`, …). Legacy presets `success` / `error` / `attention` remain valid.
|
|
@@ -184,6 +195,33 @@ let values = await RequestForm({
|
|
|
184
195
|
| `RequestFontInput(options)` | Font selection (`options`: font list) |
|
|
185
196
|
| `RequestSelectInput(options)` | Single selection from a fixed option list |
|
|
186
197
|
| `RequestMultiSelectInput(options)` | Multi selection (checkbox group), always resolves to a `string[]` |
|
|
198
|
+
| `GetParameters()` | Values of the task's declared `µParameters` (map id → typed value) |
|
|
199
|
+
| `GetParameter(id, fallback?)` | Single declared parameter value, with an env fallback |
|
|
200
|
+
|
|
201
|
+
### Declared task parameters (`µParameters`)
|
|
202
|
+
|
|
203
|
+
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:
|
|
204
|
+
|
|
205
|
+
```javascript
|
|
206
|
+
import { GetParameters, Log } from 'gulp-mu-gulp-api';
|
|
207
|
+
|
|
208
|
+
export async function DEPLOY() {
|
|
209
|
+
let { target, tag, dryRun } = GetParameters();
|
|
210
|
+
Log('Deploying <tag/> to <target/><context="task log"/>', { tag, target });
|
|
211
|
+
}
|
|
212
|
+
DEPLOY.µParameters = [
|
|
213
|
+
{ id: 'target', type: 'select', options: ['staging', 'production'], default: 'staging' },
|
|
214
|
+
{ id: 'tag', type: 'text', required: true, pattern: '^v\\d+\\.\\d+' },
|
|
215
|
+
{ id: 'dryRun', type: 'boolean', default: true },
|
|
216
|
+
{ id: 'token', type: 'password' }, // never stored, never logged
|
|
217
|
+
];
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
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:
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
MICROGULP_PARAM_TARGET=staging npx gulp DEPLOY
|
|
224
|
+
```
|
|
187
225
|
|
|
188
226
|
### Localized task metadata (`.i18xRegister()` + placeholders)
|
|
189
227
|
|
|
@@ -314,6 +352,17 @@ Das Modul ist bewusst **abhängigkeitsfrei** und kennt keine µGulp™-Interna:
|
|
|
314
352
|
npm install gulp-mu-gulp-api
|
|
315
353
|
```
|
|
316
354
|
|
|
355
|
+
### 0.4.1
|
|
356
|
+
|
|
357
|
+
- **Behoben** Ein Platzhalter mit unbekanntem benanntem Format wurde als leerer Text gerendert statt mit seinem Wert — den Gulp-Lifecycle-Zeilen fehlte dadurch die Dauer (`Finished 'task' after`). Fehlt das Format, bleibt der Rohwert erhalten.
|
|
358
|
+
- **Behoben** `SetLid()` behielt das Wörterbuch der vorherigen Sprache im Cache; ein Sprachwechsel im laufenden Worker konnte weiter mit veralteten Texten übersetzen.
|
|
359
|
+
|
|
360
|
+
### 0.4.0
|
|
361
|
+
|
|
362
|
+
- **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>`.
|
|
363
|
+
- Funktioniert auch ohne µGulp: dieselben Umgebungsvariablen von Hand setzen (`MICROGULP_PARAM_TARGET=staging npx gulp DEPLOY`) oder die deklarierten Defaults nutzen.
|
|
364
|
+
- 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.
|
|
365
|
+
|
|
317
366
|
### 0.3.13
|
|
318
367
|
|
|
319
368
|
- **Aktualisiert** `PlaySignal` / `PlaySound` für das µGulp-Sound-Schema (`taskSuccess`, `taskFailed`, `requestAlert`, …). Legacy-Presets `success` / `error` / `attention` bleiben gültig.
|
|
@@ -461,6 +510,33 @@ let values = await RequestForm({
|
|
|
461
510
|
| `RequestFontInput(options)` | Schriftart-Auswahl (`options`: Font-Liste) |
|
|
462
511
|
| `RequestSelectInput(options)` | Einzelauswahl aus fester Optionsliste |
|
|
463
512
|
| `RequestMultiSelectInput(options)` | Mehrfachauswahl (Checkbox-Gruppe), löst immer mit `string[]` auf |
|
|
513
|
+
| `GetParameters()` | Werte der per `µParameters` deklarierten Task-Eingaben (Map id → typisierter Wert) |
|
|
514
|
+
| `GetParameter(id, fallback?)` | Einzelner deklarierter Parameterwert, mit Env-Fallback |
|
|
515
|
+
|
|
516
|
+
### Deklarierte Task-Parameter (`µParameters`)
|
|
517
|
+
|
|
518
|
+
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:
|
|
519
|
+
|
|
520
|
+
```javascript
|
|
521
|
+
import { GetParameters, Log } from 'gulp-mu-gulp-api';
|
|
522
|
+
|
|
523
|
+
export async function DEPLOY() {
|
|
524
|
+
let { target, tag, dryRun } = GetParameters();
|
|
525
|
+
Log('Deploying <tag/> to <target/><context="task log"/>', { tag, target });
|
|
526
|
+
}
|
|
527
|
+
DEPLOY.µParameters = [
|
|
528
|
+
{ id: 'target', type: 'select', options: ['staging', 'production'], default: 'staging' },
|
|
529
|
+
{ id: 'tag', type: 'text', required: true, pattern: '^v\\d+\\.\\d+' },
|
|
530
|
+
{ id: 'dryRun', type: 'boolean', default: true },
|
|
531
|
+
{ id: 'token', type: 'password' }, // wird nie gespeichert oder geloggt
|
|
532
|
+
];
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
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:
|
|
536
|
+
|
|
537
|
+
```bash
|
|
538
|
+
MICROGULP_PARAM_TARGET=staging npx gulp DEPLOY
|
|
539
|
+
```
|
|
464
540
|
|
|
465
541
|
### Lokalisierte Task-Metadaten (`.i18xRegister()` + Platzhalter)
|
|
466
542
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gulp-mu-gulp-api",
|
|
3
|
-
"version": "0.
|
|
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.1",
|
|
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/i18x-engine.mjs
CHANGED
|
@@ -627,7 +627,10 @@ export function Trans(_text, _placeholders, _ctx) {
|
|
|
627
627
|
let subContext = localFormats ? { ...ctx, formats: { ...(ctx.formats ?? {}), ...localFormats } } : ctx;
|
|
628
628
|
value = FormatValue(Number(value) || 0, attrValue, subContext);
|
|
629
629
|
} else {
|
|
630
|
-
|
|
630
|
+
// Missing named format must not swallow the placeholder (e.g.
|
|
631
|
+
// gulp lifecycle "after <duration format="progressDuration"/>"
|
|
632
|
+
// would otherwise render as "Finished 'task' after ").
|
|
633
|
+
value = value === undefined || value === null ? '' : String(value);
|
|
631
634
|
}
|
|
632
635
|
} else if (attrKey === 'enumeration') {
|
|
633
636
|
let options = attrValue.split('|');
|
package/src/i18x.mjs
CHANGED
|
@@ -195,8 +195,10 @@ export function GetLid() {
|
|
|
195
195
|
*/
|
|
196
196
|
export function SetLid(_lid) {
|
|
197
197
|
activeLid = _lid ? _BestAvailableLid(_lid, _AvailableLids()) : null;
|
|
198
|
+
dictionaryCache.clear();
|
|
198
199
|
formatDefinitionCache.clear();
|
|
199
200
|
formatRegistryCache.clear();
|
|
201
|
+
availableLids = null;
|
|
200
202
|
}
|
|
201
203
|
|
|
202
204
|
/** Loads and caches `<dir>/<lid>.json`; a missing/broken file yields source text. */
|
package/src/index.mjs
CHANGED
|
@@ -386,9 +386,11 @@ export function Speak(_text, _options) {
|
|
|
386
386
|
* { value, label?, checked?, disabled? }.
|
|
387
387
|
*
|
|
388
388
|
* Validation rules: { required?, minLength?, pattern?, minSelected? } —
|
|
389
|
-
* checks run
|
|
389
|
+
* checks run in the webview; required / minSelected also keep the submit
|
|
390
|
+
* button disabled until the form is valid. Multi-select `required` means
|
|
391
|
+
* at least one option.
|
|
390
392
|
*
|
|
391
|
-
* @param {object} _form { title
|
|
393
|
+
* @param {object} _form { title?, submitLabel?, fields: [...] }
|
|
392
394
|
* @returns {Promise<object>} map fieldId -> value
|
|
393
395
|
*/
|
|
394
396
|
export async function RequestForm(_form) {
|
|
@@ -855,6 +857,62 @@ export function ClearRegisteredDashboardFonts() {
|
|
|
855
857
|
registeredDashboardFonts.clear();
|
|
856
858
|
}
|
|
857
859
|
|
|
860
|
+
// -------------------------------------------------
|
|
861
|
+
// declared task parameters (µParameters)
|
|
862
|
+
// -------------------------------------------------
|
|
863
|
+
|
|
864
|
+
/**
|
|
865
|
+
* Values for the parameters a task declared with `µParameters`. µGulp collects
|
|
866
|
+
* them once before the task body runs (dashboard form, remembered defaults or
|
|
867
|
+
* values handed in by a repeat run) and passes them in as environment, so this
|
|
868
|
+
* works from any npm package in the pipeline.
|
|
869
|
+
*
|
|
870
|
+
* Outside µGulp the same values can be supplied by hand:
|
|
871
|
+
* `MICROGULP_PARAMS='{"target":"staging"}' npx gulp DEPLOY` — or per parameter
|
|
872
|
+
* with `MICROGULP_PARAM_TARGET=staging`.
|
|
873
|
+
*
|
|
874
|
+
* @returns {Record<string, any>} typed values (strings, numbers, booleans, string lists)
|
|
875
|
+
*
|
|
876
|
+
* @example
|
|
877
|
+
* export async function DEPLOY() {
|
|
878
|
+
* let { target, dryRun } = GetParameters();
|
|
879
|
+
* Log('Deploying to <target/><context="task log"/>', { target });
|
|
880
|
+
* }
|
|
881
|
+
* DEPLOY.µParameters = [
|
|
882
|
+
* { id: 'target', type: 'select', options: ['staging', 'production'], default: 'staging' },
|
|
883
|
+
* { id: 'dryRun', type: 'boolean', default: true },
|
|
884
|
+
* ];
|
|
885
|
+
*/
|
|
886
|
+
export function GetParameters() {
|
|
887
|
+
let raw = process.env.MICROGULP_PARAMS;
|
|
888
|
+
if (!raw) return {};
|
|
889
|
+
try {
|
|
890
|
+
let parsed = JSON.parse(raw);
|
|
891
|
+
if (parsed == null || typeof parsed !== 'object' || Array.isArray(parsed)) return {};
|
|
892
|
+
return parsed;
|
|
893
|
+
} catch {
|
|
894
|
+
return {};
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
/**
|
|
899
|
+
* Single declared parameter value.
|
|
900
|
+
*
|
|
901
|
+
* @param {string} _id parameter id as declared in µParameters
|
|
902
|
+
* @param {any} [_fallback] returned when the parameter was not answered
|
|
903
|
+
* @returns {any}
|
|
904
|
+
*/
|
|
905
|
+
export function GetParameter(_id, _fallback) {
|
|
906
|
+
let values = GetParameters();
|
|
907
|
+
if (Object.hasOwn(values, _id) && values[_id] != null && values[_id] !== '') {
|
|
908
|
+
return values[_id];
|
|
909
|
+
}
|
|
910
|
+
// Flat per-parameter env fallback for CLI runs and shell steps.
|
|
911
|
+
let flat = process.env['MICROGULP_PARAM_' + String(_id).toUpperCase()];
|
|
912
|
+
if (flat != null && flat !== '') return flat;
|
|
913
|
+
return _fallback;
|
|
914
|
+
}
|
|
915
|
+
|
|
858
916
|
export default {
|
|
859
917
|
IsMicroGulp,
|
|
860
918
|
IsµGulp,
|
|
@@ -862,6 +920,8 @@ export default {
|
|
|
862
920
|
RegisterDashboardFont,
|
|
863
921
|
GetRegisteredDashboardFonts,
|
|
864
922
|
ClearRegisteredDashboardFonts,
|
|
923
|
+
GetParameters,
|
|
924
|
+
GetParameter,
|
|
865
925
|
ReportProgress,
|
|
866
926
|
CreateProgress,
|
|
867
927
|
PlaySignal,
|