@loopress/cli 0.2.0 → 0.3.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.
- package/README.md +14 -14
- package/dist/commands/snippets/pull.js +1 -0
- package/dist/commands/snippets/push.d.ts +2 -0
- package/dist/commands/snippets/push.js +35 -13
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ $ npm install -g @loopress/cli
|
|
|
20
20
|
$ lps COMMAND
|
|
21
21
|
running command...
|
|
22
22
|
$ lps (--version)
|
|
23
|
-
@loopress/cli/0.
|
|
23
|
+
@loopress/cli/0.3.0 linux-x64 node-v24.16.0
|
|
24
24
|
$ lps --help [COMMAND]
|
|
25
25
|
USAGE
|
|
26
26
|
$ lps COMMAND
|
|
@@ -89,7 +89,7 @@ EXAMPLES
|
|
|
89
89
|
$ lps login
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
-
_See code: [src/commands/login.ts](https://github.com/loopress/loopress/blob/v0.
|
|
92
|
+
_See code: [src/commands/login.ts](https://github.com/loopress/loopress/blob/v0.3.0/src/commands/login.ts)_
|
|
93
93
|
|
|
94
94
|
## `lps logout`
|
|
95
95
|
|
|
@@ -106,7 +106,7 @@ EXAMPLES
|
|
|
106
106
|
$ lps logout
|
|
107
107
|
```
|
|
108
108
|
|
|
109
|
-
_See code: [src/commands/logout.ts](https://github.com/loopress/loopress/blob/v0.
|
|
109
|
+
_See code: [src/commands/logout.ts](https://github.com/loopress/loopress/blob/v0.3.0/src/commands/logout.ts)_
|
|
110
110
|
|
|
111
111
|
## `lps plugins`
|
|
112
112
|
|
|
@@ -413,7 +413,7 @@ EXAMPLES
|
|
|
413
413
|
$ lps project config
|
|
414
414
|
```
|
|
415
415
|
|
|
416
|
-
_See code: [src/commands/project/config.ts](https://github.com/loopress/loopress/blob/v0.
|
|
416
|
+
_See code: [src/commands/project/config.ts](https://github.com/loopress/loopress/blob/v0.3.0/src/commands/project/config.ts)_
|
|
417
417
|
|
|
418
418
|
## `lps project list`
|
|
419
419
|
|
|
@@ -430,7 +430,7 @@ EXAMPLES
|
|
|
430
430
|
$ lps project list
|
|
431
431
|
```
|
|
432
432
|
|
|
433
|
-
_See code: [src/commands/project/list.ts](https://github.com/loopress/loopress/blob/v0.
|
|
433
|
+
_See code: [src/commands/project/list.ts](https://github.com/loopress/loopress/blob/v0.3.0/src/commands/project/list.ts)_
|
|
434
434
|
|
|
435
435
|
## `lps project remove`
|
|
436
436
|
|
|
@@ -447,7 +447,7 @@ EXAMPLES
|
|
|
447
447
|
$ lps project remove
|
|
448
448
|
```
|
|
449
449
|
|
|
450
|
-
_See code: [src/commands/project/remove.ts](https://github.com/loopress/loopress/blob/v0.
|
|
450
|
+
_See code: [src/commands/project/remove.ts](https://github.com/loopress/loopress/blob/v0.3.0/src/commands/project/remove.ts)_
|
|
451
451
|
|
|
452
452
|
## `lps project remove-env`
|
|
453
453
|
|
|
@@ -464,7 +464,7 @@ EXAMPLES
|
|
|
464
464
|
$ lps project remove-env
|
|
465
465
|
```
|
|
466
466
|
|
|
467
|
-
_See code: [src/commands/project/remove-env.ts](https://github.com/loopress/loopress/blob/v0.
|
|
467
|
+
_See code: [src/commands/project/remove-env.ts](https://github.com/loopress/loopress/blob/v0.3.0/src/commands/project/remove-env.ts)_
|
|
468
468
|
|
|
469
469
|
## `lps project switch`
|
|
470
470
|
|
|
@@ -481,7 +481,7 @@ EXAMPLES
|
|
|
481
481
|
$ lps project switch
|
|
482
482
|
```
|
|
483
483
|
|
|
484
|
-
_See code: [src/commands/project/switch.ts](https://github.com/loopress/loopress/blob/v0.
|
|
484
|
+
_See code: [src/commands/project/switch.ts](https://github.com/loopress/loopress/blob/v0.3.0/src/commands/project/switch.ts)_
|
|
485
485
|
|
|
486
486
|
## `lps project switch-env`
|
|
487
487
|
|
|
@@ -498,7 +498,7 @@ EXAMPLES
|
|
|
498
498
|
$ lps project switch-env
|
|
499
499
|
```
|
|
500
500
|
|
|
501
|
-
_See code: [src/commands/project/switch-env.ts](https://github.com/loopress/loopress/blob/v0.
|
|
501
|
+
_See code: [src/commands/project/switch-env.ts](https://github.com/loopress/loopress/blob/v0.3.0/src/commands/project/switch-env.ts)_
|
|
502
502
|
|
|
503
503
|
## `lps snippets list`
|
|
504
504
|
|
|
@@ -529,7 +529,7 @@ EXAMPLES
|
|
|
529
529
|
$ lps snippets list --plugin wpcode
|
|
530
530
|
```
|
|
531
531
|
|
|
532
|
-
_See code: [src/commands/snippets/list.ts](https://github.com/loopress/loopress/blob/v0.
|
|
532
|
+
_See code: [src/commands/snippets/list.ts](https://github.com/loopress/loopress/blob/v0.3.0/src/commands/snippets/list.ts)_
|
|
533
533
|
|
|
534
534
|
## `lps snippets pull [PATH]`
|
|
535
535
|
|
|
@@ -565,7 +565,7 @@ EXAMPLES
|
|
|
565
565
|
$ lps snippets pull --plugin wpcode
|
|
566
566
|
```
|
|
567
567
|
|
|
568
|
-
_See code: [src/commands/snippets/pull.ts](https://github.com/loopress/loopress/blob/v0.
|
|
568
|
+
_See code: [src/commands/snippets/pull.ts](https://github.com/loopress/loopress/blob/v0.3.0/src/commands/snippets/pull.ts)_
|
|
569
569
|
|
|
570
570
|
## `lps snippets push [PATH]`
|
|
571
571
|
|
|
@@ -601,7 +601,7 @@ EXAMPLES
|
|
|
601
601
|
$ lps snippets push --plugin wpcode
|
|
602
602
|
```
|
|
603
603
|
|
|
604
|
-
_See code: [src/commands/snippets/push.ts](https://github.com/loopress/loopress/blob/v0.
|
|
604
|
+
_See code: [src/commands/snippets/push.ts](https://github.com/loopress/loopress/blob/v0.3.0/src/commands/snippets/push.ts)_
|
|
605
605
|
|
|
606
606
|
## `lps styles pull`
|
|
607
607
|
|
|
@@ -628,7 +628,7 @@ EXAMPLES
|
|
|
628
628
|
$ lps styles pull --url http://example.com
|
|
629
629
|
```
|
|
630
630
|
|
|
631
|
-
_See code: [src/commands/styles/pull.ts](https://github.com/loopress/loopress/blob/v0.
|
|
631
|
+
_See code: [src/commands/styles/pull.ts](https://github.com/loopress/loopress/blob/v0.3.0/src/commands/styles/pull.ts)_
|
|
632
632
|
|
|
633
633
|
## `lps styles push`
|
|
634
634
|
|
|
@@ -655,5 +655,5 @@ EXAMPLES
|
|
|
655
655
|
$ lps styles push --url http://example.com
|
|
656
656
|
```
|
|
657
657
|
|
|
658
|
-
_See code: [src/commands/styles/push.ts](https://github.com/loopress/loopress/blob/v0.
|
|
658
|
+
_See code: [src/commands/styles/push.ts](https://github.com/loopress/loopress/blob/v0.3.0/src/commands/styles/push.ts)_
|
|
659
659
|
<!-- commandsstop -->
|
|
@@ -13,6 +13,7 @@ const EXTENSIONS = {
|
|
|
13
13
|
const sanitize = (value) => value.replaceAll(/\s*\n\s*/g, ' ').trim();
|
|
14
14
|
function buildMetaLines(snippet) {
|
|
15
15
|
return [
|
|
16
|
+
`id: ${snippet.id}`,
|
|
16
17
|
`name: ${sanitize(snippet.name)}`,
|
|
17
18
|
...(snippet.description ? [`description: ${sanitize(snippet.description)}`] : []),
|
|
18
19
|
`type: ${snippet.type}`,
|
|
@@ -13,6 +13,8 @@ export default class Push extends LoopressCommand {
|
|
|
13
13
|
user: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
14
|
};
|
|
15
15
|
run(): Promise<void>;
|
|
16
|
+
private injectIdIntoFile;
|
|
16
17
|
private loadSnippets;
|
|
18
|
+
private parseMetaFromContent;
|
|
17
19
|
private pushSnippet;
|
|
18
20
|
}
|
|
@@ -45,6 +45,20 @@ export default class Push extends LoopressCommand {
|
|
|
45
45
|
this.error(error.message);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
+
async injectIdIntoFile(filePath, content, id) {
|
|
49
|
+
const fs = await import('node:fs/promises');
|
|
50
|
+
let updated;
|
|
51
|
+
if (content.includes('/**')) {
|
|
52
|
+
updated = content.replace('/**', `/**\n * id: ${id}`);
|
|
53
|
+
}
|
|
54
|
+
else if (content.includes('<!--')) {
|
|
55
|
+
updated = content.replace('<!--', `<!--\n id: ${id}`);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
await fs.writeFile(filePath, updated);
|
|
61
|
+
}
|
|
48
62
|
async loadSnippets(path) {
|
|
49
63
|
const fs = await import('node:fs/promises');
|
|
50
64
|
const snippets = [];
|
|
@@ -54,9 +68,11 @@ export default class Push extends LoopressCommand {
|
|
|
54
68
|
if (file.endsWith('.php')) {
|
|
55
69
|
const filePath = `${path}/${file}`;
|
|
56
70
|
const content = await fs.readFile(filePath, 'utf8');
|
|
71
|
+
const meta = this.parseMetaFromContent(content);
|
|
57
72
|
snippets.push({
|
|
58
73
|
code: content,
|
|
59
|
-
|
|
74
|
+
id: meta.id,
|
|
75
|
+
name: meta.name ?? file.replace('.php', ''),
|
|
60
76
|
path: filePath,
|
|
61
77
|
});
|
|
62
78
|
}
|
|
@@ -67,6 +83,14 @@ export default class Push extends LoopressCommand {
|
|
|
67
83
|
}
|
|
68
84
|
return snippets;
|
|
69
85
|
}
|
|
86
|
+
parseMetaFromContent(content) {
|
|
87
|
+
const idMatch = content.match(/[\s*]*id:\s*(\d+)/);
|
|
88
|
+
const nameMatch = content.match(/[\s*]*name:\s*(.+)/);
|
|
89
|
+
return {
|
|
90
|
+
id: idMatch ? Number(idMatch[1]) : undefined,
|
|
91
|
+
name: nameMatch ? nameMatch[1].trim() : undefined,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
70
94
|
async pushSnippet(snippet, url, headers, dryRun, adapter) {
|
|
71
95
|
if (dryRun) {
|
|
72
96
|
this.log(`📝 [DRY RUN] Would push snippet: ${snippet.name}`);
|
|
@@ -75,20 +99,18 @@ export default class Push extends LoopressCommand {
|
|
|
75
99
|
}
|
|
76
100
|
try {
|
|
77
101
|
const endpoint = adapter.endpoint(url);
|
|
78
|
-
const remoteList = await got.get(endpoint, { headers }).json();
|
|
79
|
-
const existing = remoteList
|
|
80
|
-
.map((r) => adapter.fromRemote(r))
|
|
81
|
-
.find((s) => s.name === snippet.name);
|
|
82
102
|
const payload = adapter.toPayload(snippet.name, snippet.code, snippet.path);
|
|
83
|
-
if (
|
|
84
|
-
this.log(`🔄 Updating
|
|
85
|
-
await got.put(`${endpoint}/${
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
this.log(`➕ Creating new snippet: ${snippet.name}`);
|
|
89
|
-
await got.post(endpoint, { headers, json: payload });
|
|
103
|
+
if (snippet.id) {
|
|
104
|
+
this.log(`🔄 Updating snippet by id (${snippet.id}): ${snippet.name}`);
|
|
105
|
+
await got.put(`${endpoint}/${snippet.id}`, { headers, json: payload });
|
|
106
|
+
this.log(`✅ Updated: ${snippet.name}`);
|
|
107
|
+
return;
|
|
90
108
|
}
|
|
91
|
-
this.log(
|
|
109
|
+
this.log(`➕ Creating new snippet: ${snippet.name}`);
|
|
110
|
+
const response = await got.post(endpoint, { headers, json: payload }).json();
|
|
111
|
+
const created = adapter.fromRemote(response);
|
|
112
|
+
await this.injectIdIntoFile(snippet.path, snippet.code, created.id);
|
|
113
|
+
this.log(`✅ Created: ${snippet.name} (id: ${created.id})`);
|
|
92
114
|
}
|
|
93
115
|
catch (error) {
|
|
94
116
|
this.error(`❌ Error pushing snippet ${snippet.name}: ${error.message}`);
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED