einsteinjs 0.1.1 → 0.1.3
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 +82 -0
- package/dist/index.d.ts +37 -1
- package/dist/index.js +44 -6
- package/package.json +28 -27
package/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# EinsteinJS
|
|
2
|
+
|
|
3
|
+
A type-safe snippet registry and compiler for VSCode, Cursor, and editors based on VSCode.
|
|
4
|
+
|
|
5
|
+
Define snippets using an expressive DSL while EinsteinJS handles validation, compilation and JSON generation automatically.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Using Bun:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bun add einsteinjs
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Using npm:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install einsteinjs
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { registry, defineConfig } from "einsteinjs"
|
|
25
|
+
|
|
26
|
+
const rfc = registry
|
|
27
|
+
.it("React Functional Component")
|
|
28
|
+
.describe("Creates a React functional component")
|
|
29
|
+
.scope(["typescriptreact"])
|
|
30
|
+
.prefix("rfc")
|
|
31
|
+
.body([
|
|
32
|
+
"export default function ${1:Component}() {",
|
|
33
|
+
" return <div>$0</div>",
|
|
34
|
+
"}"
|
|
35
|
+
])
|
|
36
|
+
.template()
|
|
37
|
+
.tag(["react", "tsx"])
|
|
38
|
+
|
|
39
|
+
export default defineConfig({
|
|
40
|
+
output: "./dist/react.json",
|
|
41
|
+
|
|
42
|
+
snippets: [rfc]
|
|
43
|
+
})
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Build your snippets:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import config from "./snippets.config"
|
|
50
|
+
|
|
51
|
+
import { build } from "einsteinjs"
|
|
52
|
+
|
|
53
|
+
await build(config)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Run:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
bun run build.ts
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Generated output:
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"React Functional Component": {
|
|
67
|
+
"scope": "typescriptreact",
|
|
68
|
+
"prefix": "rfc",
|
|
69
|
+
"body": [
|
|
70
|
+
"export default function ${1:Component}() {",
|
|
71
|
+
" return <div>$0</div>",
|
|
72
|
+
"}"
|
|
73
|
+
],
|
|
74
|
+
"description": "Creates a React functional component",
|
|
75
|
+
"isFileTemplate": true
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## License
|
|
81
|
+
|
|
82
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,35 @@
|
|
|
1
1
|
type Scope = 'typescriptreact' | 'javascriptreact' | 'typescript' | 'javascript' | 'html' | 'json';
|
|
2
2
|
interface Snippet {
|
|
3
|
+
/**
|
|
4
|
+
* Nome do snippet.
|
|
5
|
+
*
|
|
6
|
+
* Será usado como chave no JSON final.
|
|
7
|
+
*/
|
|
3
8
|
name: string;
|
|
4
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Descrição exibida pelo VSCode.
|
|
11
|
+
*/
|
|
12
|
+
description?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Escopos do VSCode.
|
|
15
|
+
*/
|
|
16
|
+
scope: string[];
|
|
17
|
+
/**
|
|
18
|
+
* Prefixo digitado pelo usuário.
|
|
19
|
+
*/
|
|
5
20
|
prefix: string;
|
|
21
|
+
/**
|
|
22
|
+
* Corpo do snippet.
|
|
23
|
+
*/
|
|
6
24
|
body: string[];
|
|
25
|
+
/**
|
|
26
|
+
* Tags para documentação futura.
|
|
27
|
+
*/
|
|
7
28
|
tags: string[];
|
|
29
|
+
/**
|
|
30
|
+
* Define se o snippet é um template de arquivo.
|
|
31
|
+
*/
|
|
32
|
+
isFileTemplate: boolean;
|
|
8
33
|
}
|
|
9
34
|
|
|
10
35
|
/**
|
|
@@ -41,6 +66,17 @@ declare class SnippetBuilder {
|
|
|
41
66
|
* Corpo do snippet.
|
|
42
67
|
*/
|
|
43
68
|
body(body: string[]): this;
|
|
69
|
+
describe(description: string): this;
|
|
70
|
+
/**
|
|
71
|
+
* Define se é um template de arquivo.
|
|
72
|
+
*
|
|
73
|
+
* Ex:
|
|
74
|
+
*
|
|
75
|
+
* .template()
|
|
76
|
+
* .template(true)
|
|
77
|
+
* .template(false)
|
|
78
|
+
*/
|
|
79
|
+
template(isFileTemplate?: boolean): this;
|
|
44
80
|
/**
|
|
45
81
|
* Tags para futuras features:
|
|
46
82
|
* documentação, filtros, busca etc.
|
package/dist/index.js
CHANGED
|
@@ -13,13 +13,27 @@ function compileSnippet(snippet) {
|
|
|
13
13
|
return {
|
|
14
14
|
[snippet.name]: {
|
|
15
15
|
/**
|
|
16
|
-
* VSCode espera
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* O VSCode espera:
|
|
17
|
+
*
|
|
18
|
+
* "typescriptreact,typescript"
|
|
19
19
|
*/
|
|
20
20
|
scope: snippet.scope.join(","),
|
|
21
21
|
prefix: snippet.prefix,
|
|
22
|
-
body: snippet.body
|
|
22
|
+
body: snippet.body,
|
|
23
|
+
/**
|
|
24
|
+
* A DSL usa:
|
|
25
|
+
* .describe()
|
|
26
|
+
* mas o VSCode espera:
|
|
27
|
+
* description
|
|
28
|
+
*/
|
|
29
|
+
description: snippet.description,
|
|
30
|
+
/**
|
|
31
|
+
* A DSL usa:
|
|
32
|
+
* .template()
|
|
33
|
+
* mas o VSCode espera:
|
|
34
|
+
* isFileTemplate
|
|
35
|
+
*/
|
|
36
|
+
isFileTemplate: snippet.isFileTemplate
|
|
23
37
|
}
|
|
24
38
|
};
|
|
25
39
|
}
|
|
@@ -14580,10 +14594,12 @@ config(en_default());
|
|
|
14580
14594
|
// src/schemas/snippet.schema.ts
|
|
14581
14595
|
var snippetSchema = external_exports.object({
|
|
14582
14596
|
name: external_exports.string().min(1),
|
|
14597
|
+
description: external_exports.string().optional(),
|
|
14583
14598
|
scope: external_exports.array(external_exports.string()).min(1),
|
|
14584
14599
|
prefix: external_exports.string().min(1),
|
|
14585
14600
|
body: external_exports.array(external_exports.string()).min(1),
|
|
14586
|
-
tags: external_exports.array(external_exports.string())
|
|
14601
|
+
tags: external_exports.array(external_exports.string()),
|
|
14602
|
+
isFileTemplate: external_exports.boolean()
|
|
14587
14603
|
});
|
|
14588
14604
|
|
|
14589
14605
|
// src/build.ts
|
|
@@ -14619,7 +14635,12 @@ var SnippetBuilder = class {
|
|
|
14619
14635
|
* Partial permite criar o objeto aos poucos.
|
|
14620
14636
|
*/
|
|
14621
14637
|
snippet = {
|
|
14622
|
-
tags: []
|
|
14638
|
+
tags: [],
|
|
14639
|
+
/**
|
|
14640
|
+
* Por padrão o snippet
|
|
14641
|
+
* NÃO é template.
|
|
14642
|
+
*/
|
|
14643
|
+
isFileTemplate: false
|
|
14623
14644
|
};
|
|
14624
14645
|
/**
|
|
14625
14646
|
* Nome do snippet.
|
|
@@ -14652,6 +14673,23 @@ var SnippetBuilder = class {
|
|
|
14652
14673
|
this.snippet.body = body;
|
|
14653
14674
|
return this;
|
|
14654
14675
|
}
|
|
14676
|
+
describe(description) {
|
|
14677
|
+
this.snippet.description = description;
|
|
14678
|
+
return this;
|
|
14679
|
+
}
|
|
14680
|
+
/**
|
|
14681
|
+
* Define se é um template de arquivo.
|
|
14682
|
+
*
|
|
14683
|
+
* Ex:
|
|
14684
|
+
*
|
|
14685
|
+
* .template()
|
|
14686
|
+
* .template(true)
|
|
14687
|
+
* .template(false)
|
|
14688
|
+
*/
|
|
14689
|
+
template(isFileTemplate = true) {
|
|
14690
|
+
this.snippet.isFileTemplate = isFileTemplate;
|
|
14691
|
+
return this;
|
|
14692
|
+
}
|
|
14655
14693
|
/**
|
|
14656
14694
|
* Tags para futuras features:
|
|
14657
14695
|
* documentação, filtros, busca etc.
|
package/package.json
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
"name": "einsteinjs",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "A type-safe snippet registry and compiler for VSCode and Cursor.",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsup src/index.ts --format esm --dts",
|
|
19
|
+
"prepublishOnly": "bun run build"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"tsup": "^8.5.1"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"oxfmt": "^0.54.0",
|
|
26
|
+
"oxlint": "^1.69.0",
|
|
27
|
+
"typescript": "^5.9.3",
|
|
28
|
+
"zod": "^4.4.3"
|
|
14
29
|
}
|
|
15
|
-
|
|
16
|
-
"scripts": {
|
|
17
|
-
"build": "tsup src/index.ts --format esm --dts",
|
|
18
|
-
"prepublishOnly": "bun run build"
|
|
19
|
-
},
|
|
20
|
-
"devDependencies": {
|
|
21
|
-
"oxfmt": "^0.54.0",
|
|
22
|
-
"oxlint": "^1.69.0",
|
|
23
|
-
"typescript": "^5.9.2",
|
|
24
|
-
"zod": "^4.4.3"
|
|
25
|
-
},
|
|
26
|
-
"dependencies": {
|
|
27
|
-
"tsup": "^8.5.1"
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
+
}
|