command-cmd 1.0.6 → 1.0.10
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/cmd.js +133 -13
- package/doc.md +32 -5
- package/docPTBR.md +24 -4
- package/package.json +1 -1
package/cmd.js
CHANGED
|
@@ -35,6 +35,12 @@ const DOC_TEMPLATE_MAP = Object.freeze({
|
|
|
35
35
|
target: 'docPTBR.md',
|
|
36
36
|
isMapDoc: false
|
|
37
37
|
}),
|
|
38
|
+
doc_html: Object.freeze({
|
|
39
|
+
key: 'doc_html',
|
|
40
|
+
source: 'doc.html',
|
|
41
|
+
target: 'doc.html',
|
|
42
|
+
isMapDoc: false
|
|
43
|
+
}),
|
|
38
44
|
map_en: Object.freeze({
|
|
39
45
|
key: 'map_en',
|
|
40
46
|
source: 'map.md',
|
|
@@ -50,6 +56,7 @@ const DOC_TEMPLATE_MAP = Object.freeze({
|
|
|
50
56
|
});
|
|
51
57
|
|
|
52
58
|
const DOC_TEMPLATES = Object.freeze(Object.values(DOC_TEMPLATE_MAP));
|
|
59
|
+
const DOC_HTML_MARKDOWN_PLACEHOLDER = '__DOC_MARKDOWN_BUNDLE__';
|
|
53
60
|
|
|
54
61
|
const ACTION_ALIASES = Object.freeze({
|
|
55
62
|
skip_ads: 'skip_ads',
|
|
@@ -370,10 +377,6 @@ export async function maper(enabled) {
|
|
|
370
377
|
pollPosition();
|
|
371
378
|
maperInterval = setInterval(pollPosition, MAPER_POLL_INTERVAL);
|
|
372
379
|
|
|
373
|
-
if (typeof maperInterval.unref === 'function') {
|
|
374
|
-
maperInterval.unref();
|
|
375
|
-
}
|
|
376
|
-
|
|
377
380
|
return { active: true, pollInterval: MAPER_POLL_INTERVAL };
|
|
378
381
|
}
|
|
379
382
|
|
|
@@ -429,15 +432,7 @@ export async function initDoc(options = {}) {
|
|
|
429
432
|
continue;
|
|
430
433
|
}
|
|
431
434
|
|
|
432
|
-
|
|
433
|
-
try {
|
|
434
|
-
content = await readFile(sourcePath, 'utf8');
|
|
435
|
-
} catch (error) {
|
|
436
|
-
if (error && error.code === 'ENOENT') {
|
|
437
|
-
throw new Error(`doc_template_not_found:${template.source}`);
|
|
438
|
-
}
|
|
439
|
-
throw error;
|
|
440
|
-
}
|
|
435
|
+
const content = await loadDocTemplateContent(template, sourcePath);
|
|
441
436
|
|
|
442
437
|
await writeFile(targetPath, content, 'utf8');
|
|
443
438
|
|
|
@@ -457,6 +452,59 @@ export async function initDoc(options = {}) {
|
|
|
457
452
|
};
|
|
458
453
|
}
|
|
459
454
|
|
|
455
|
+
async function loadDocTemplateContent(template, sourcePath) {
|
|
456
|
+
let content;
|
|
457
|
+
try {
|
|
458
|
+
content = await readFile(sourcePath, 'utf8');
|
|
459
|
+
} catch (error) {
|
|
460
|
+
if (error && error.code === 'ENOENT') {
|
|
461
|
+
throw new Error(`doc_template_not_found:${template.source}`);
|
|
462
|
+
}
|
|
463
|
+
throw error;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
if (template.key !== DOC_TEMPLATE_MAP.doc_html.key) {
|
|
467
|
+
return content;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
const markdownBundle = await loadDocMarkdownBundle();
|
|
471
|
+
const serialized = JSON.stringify(markdownBundle)
|
|
472
|
+
.replace(/</g, '\\u003c')
|
|
473
|
+
.replace(/>/g, '\\u003e')
|
|
474
|
+
.replace(/&/g, '\\u0026');
|
|
475
|
+
|
|
476
|
+
if (content.includes(DOC_HTML_MARKDOWN_PLACEHOLDER)) {
|
|
477
|
+
return content.replace(DOC_HTML_MARKDOWN_PLACEHOLDER, serialized);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
return content;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
async function loadDocMarkdownBundle() {
|
|
484
|
+
const templates = [
|
|
485
|
+
DOC_TEMPLATE_MAP.doc_en,
|
|
486
|
+
DOC_TEMPLATE_MAP.doc_ptbr,
|
|
487
|
+
DOC_TEMPLATE_MAP.map_en,
|
|
488
|
+
DOC_TEMPLATE_MAP.map_ptbr
|
|
489
|
+
];
|
|
490
|
+
|
|
491
|
+
const bundle = {};
|
|
492
|
+
|
|
493
|
+
for (const template of templates) {
|
|
494
|
+
const sourcePath = resolvePath(MODULE_DIR, template.source);
|
|
495
|
+
try {
|
|
496
|
+
bundle[template.key] = await readFile(sourcePath, 'utf8');
|
|
497
|
+
} catch (error) {
|
|
498
|
+
if (error && error.code === 'ENOENT') {
|
|
499
|
+
throw new Error(`doc_template_not_found:${template.source}`);
|
|
500
|
+
}
|
|
501
|
+
throw error;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
return bundle;
|
|
506
|
+
}
|
|
507
|
+
|
|
460
508
|
export async function cursor(input, options = {}) {
|
|
461
509
|
const commands = normalizeCursorInput(input);
|
|
462
510
|
if (commands.length === 0) {
|
|
@@ -591,6 +639,67 @@ export async function cursor(input, options = {}) {
|
|
|
591
639
|
};
|
|
592
640
|
}
|
|
593
641
|
|
|
642
|
+
export async function cursorSequential(input, intervalMs = 3000, options = {}) {
|
|
643
|
+
const commands = normalizeCursorInput(input);
|
|
644
|
+
const parsedInterval = toNonNegativeInteger(intervalMs);
|
|
645
|
+
|
|
646
|
+
if (parsedInterval === null) {
|
|
647
|
+
throw new Error('cursor_sequential_requires_non_negative_interval_ms');
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
if (commands.length === 0) {
|
|
651
|
+
return {
|
|
652
|
+
executed: [],
|
|
653
|
+
skipped: [{ reason: 'no_commands' }],
|
|
654
|
+
totalCommands: 0,
|
|
655
|
+
totalExecutions: 0,
|
|
656
|
+
intervalMs: parsedInterval
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
if (commands.length === 1) {
|
|
661
|
+
const singleResult = await cursor(commands[0], options);
|
|
662
|
+
return {
|
|
663
|
+
...singleResult,
|
|
664
|
+
intervalMs: parsedInterval
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
const executed = [];
|
|
669
|
+
const skipped = [];
|
|
670
|
+
|
|
671
|
+
for (let commandIndex = 0; commandIndex < commands.length; commandIndex++) {
|
|
672
|
+
const command = commands[commandIndex];
|
|
673
|
+
const result = await cursor(command, options);
|
|
674
|
+
|
|
675
|
+
for (const entry of result.executed) {
|
|
676
|
+
executed.push({
|
|
677
|
+
...entry,
|
|
678
|
+
commandIndex
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
for (const entry of result.skipped) {
|
|
683
|
+
skipped.push({
|
|
684
|
+
...entry,
|
|
685
|
+
commandIndex
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
if (commandIndex < commands.length - 1 && parsedInterval > 0) {
|
|
690
|
+
await sleep(parsedInterval);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
return {
|
|
695
|
+
executed,
|
|
696
|
+
skipped,
|
|
697
|
+
totalCommands: commands.length,
|
|
698
|
+
totalExecutions: executed.length,
|
|
699
|
+
intervalMs: parsedInterval
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
|
|
594
703
|
function createCursorRuntime(options) {
|
|
595
704
|
const config = buildCursorConfig(options);
|
|
596
705
|
let mapStorePromise;
|
|
@@ -1482,6 +1591,17 @@ function resolveDocTemplateByName(value) {
|
|
|
1482
1591
|
return DOC_TEMPLATE_MAP.doc_ptbr;
|
|
1483
1592
|
}
|
|
1484
1593
|
|
|
1594
|
+
if (
|
|
1595
|
+
token === 'doc_html' ||
|
|
1596
|
+
token === 'dochtml' ||
|
|
1597
|
+
token === 'html' ||
|
|
1598
|
+
token === 'docs_html' ||
|
|
1599
|
+
token === 'documentation_html' ||
|
|
1600
|
+
token === 'documentacao_html'
|
|
1601
|
+
) {
|
|
1602
|
+
return DOC_TEMPLATE_MAP.doc_html;
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1485
1605
|
if (
|
|
1486
1606
|
token === 'map' ||
|
|
1487
1607
|
token === 'map_en' ||
|
package/doc.md
CHANGED
|
@@ -7,6 +7,7 @@ Exported functions:
|
|
|
7
7
|
- `cmd`
|
|
8
8
|
- `extractFirstCommand`
|
|
9
9
|
- `cursor`
|
|
10
|
+
- `cursorSequential`
|
|
10
11
|
- `initMap`
|
|
11
12
|
- `initDoc`
|
|
12
13
|
- `maper`
|
|
@@ -20,7 +21,15 @@ npm install command-cmd
|
|
|
20
21
|
## Import
|
|
21
22
|
|
|
22
23
|
```js
|
|
23
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
cmd,
|
|
26
|
+
extractFirstCommand,
|
|
27
|
+
cursor,
|
|
28
|
+
cursorSequential,
|
|
29
|
+
initMap,
|
|
30
|
+
initDoc,
|
|
31
|
+
maper
|
|
32
|
+
} from 'command-cmd';
|
|
24
33
|
```
|
|
25
34
|
|
|
26
35
|
## 1) `cmd(message)`
|
|
@@ -111,7 +120,24 @@ Accepted object keys:
|
|
|
111
120
|
- `seq` or `sequencia`
|
|
112
121
|
- `extra`
|
|
113
122
|
|
|
114
|
-
## 4) `
|
|
123
|
+
## 4) `cursorSequential(input, intervalMs = 3000, options?)`
|
|
124
|
+
|
|
125
|
+
Runs commands sequentially with a fixed delay between each command block.
|
|
126
|
+
|
|
127
|
+
- uses the same input format as `cursor`
|
|
128
|
+
- if input has 2+ commands, it executes them in written order
|
|
129
|
+
- default interval is `3000` ms (3 seconds)
|
|
130
|
+
|
|
131
|
+
Example:
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
await cursorSequential(
|
|
135
|
+
'[open_app, command: chrome][close_app, command: chrome]',
|
|
136
|
+
3000
|
|
137
|
+
);
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## 5) `initMap(options?)`
|
|
115
141
|
|
|
116
142
|
Creates (or loads/merges) `map.json` explicitly.
|
|
117
143
|
|
|
@@ -132,7 +158,7 @@ Optional keys:
|
|
|
132
158
|
- `skipAdsPoint`
|
|
133
159
|
- `persistMerged` (writes merged defaults even when map already exists)
|
|
134
160
|
|
|
135
|
-
##
|
|
161
|
+
## 6) `initDoc(options?)`
|
|
136
162
|
|
|
137
163
|
Creates documentation files from package templates.
|
|
138
164
|
|
|
@@ -140,6 +166,7 @@ By default it writes in current working directory:
|
|
|
140
166
|
|
|
141
167
|
- `doc.md`
|
|
142
168
|
- `docPTBR.md`
|
|
169
|
+
- `doc.html`
|
|
143
170
|
- `map.md`
|
|
144
171
|
- `mapPTBR.md`
|
|
145
172
|
|
|
@@ -155,9 +182,9 @@ Optional keys:
|
|
|
155
182
|
- `outputDir` (alias: `dir`, `path`)
|
|
156
183
|
- `overwrite`
|
|
157
184
|
- `includeMapDocs`
|
|
158
|
-
- `files` (e.g. `['doc', 'docPTBR', 'map', 'mapPTBR']`)
|
|
185
|
+
- `files` (e.g. `['doc', 'docPTBR', 'docHtml', 'map', 'mapPTBR']`)
|
|
159
186
|
|
|
160
|
-
##
|
|
187
|
+
## 7) `maper(enabled)`
|
|
161
188
|
|
|
162
189
|
Turns terminal mouse position mapping on/off.
|
|
163
190
|
|
package/docPTBR.md
CHANGED
|
@@ -7,6 +7,7 @@ Funcoes exportadas:
|
|
|
7
7
|
- `cmd`
|
|
8
8
|
- `extractFirstCommand`
|
|
9
9
|
- `cursor`
|
|
10
|
+
- `cursorSequential`
|
|
10
11
|
- `initMap`
|
|
11
12
|
- `initDoc`
|
|
12
13
|
- `maper`
|
|
@@ -24,6 +25,7 @@ import {
|
|
|
24
25
|
cmd as extrairComandos,
|
|
25
26
|
extractFirstCommand as extrairPrimeiroComando,
|
|
26
27
|
cursor as executarCursor,
|
|
28
|
+
cursorSequential as executarCursorSequencial,
|
|
27
29
|
initMap as iniciarMap,
|
|
28
30
|
initDoc as iniciarDoc,
|
|
29
31
|
maper
|
|
@@ -118,7 +120,24 @@ Campos aceitos no objeto:
|
|
|
118
120
|
- `seq` ou `sequencia`
|
|
119
121
|
- `extra`
|
|
120
122
|
|
|
121
|
-
## 4) `
|
|
123
|
+
## 4) `cursorSequential(input, intervalMs = 3000, options?)`
|
|
124
|
+
|
|
125
|
+
Executa comandos de forma sequencial com intervalo fixo entre cada bloco de comando.
|
|
126
|
+
|
|
127
|
+
- usa o mesmo formato de entrada do `cursor`
|
|
128
|
+
- se a string tiver 2+ comandos, executa na ordem em que foram escritos
|
|
129
|
+
- intervalo padrao de `3000` ms (3 segundos)
|
|
130
|
+
|
|
131
|
+
Exemplo:
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
await executarCursorSequencial(
|
|
135
|
+
'[abrir_app, comando: chrome][fechar_app, comando: chrome]',
|
|
136
|
+
3000
|
|
137
|
+
);
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## 5) `initMap(options?)`
|
|
122
141
|
|
|
123
142
|
Cria (ou carrega/mescla) o `map.json` de forma explicita.
|
|
124
143
|
|
|
@@ -139,7 +158,7 @@ Campos opcionais:
|
|
|
139
158
|
- `skipAdsPoint`
|
|
140
159
|
- `persistMerged` (salva defaults mesclados mesmo se o map ja existir)
|
|
141
160
|
|
|
142
|
-
##
|
|
161
|
+
## 6) `initDoc(options?)`
|
|
143
162
|
|
|
144
163
|
Cria os arquivos de documentacao usando os templates do pacote.
|
|
145
164
|
|
|
@@ -147,6 +166,7 @@ Por padrao, escreve no diretório atual:
|
|
|
147
166
|
|
|
148
167
|
- `doc.md`
|
|
149
168
|
- `docPTBR.md`
|
|
169
|
+
- `doc.html`
|
|
150
170
|
- `map.md`
|
|
151
171
|
- `mapPTBR.md`
|
|
152
172
|
|
|
@@ -162,9 +182,9 @@ Campos opcionais:
|
|
|
162
182
|
- `outputDir` (alias: `dir`, `path`)
|
|
163
183
|
- `overwrite`
|
|
164
184
|
- `includeMapDocs`
|
|
165
|
-
- `files` (ex.: `['doc', 'docPTBR', 'map', 'mapPTBR']`)
|
|
185
|
+
- `files` (ex.: `['doc', 'docPTBR', 'docHtml', 'map', 'mapPTBR']`)
|
|
166
186
|
|
|
167
|
-
##
|
|
187
|
+
## 7) `maper(enabled)`
|
|
168
188
|
|
|
169
189
|
Liga/desliga o mapeador de posicao do mouse no terminal.
|
|
170
190
|
|