einsteinjs 0.1.2 → 0.1.4

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 CHANGED
@@ -1,34 +1,82 @@
1
1
  # EinsteinJS
2
2
 
3
- A type-safe snippet registry and compiler for VSCode and Cursor.
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.
4
6
 
5
7
  ## Installation
6
8
 
9
+ Using Bun:
10
+
7
11
  ```bash
8
12
  bun add einsteinjs
9
13
  ```
10
14
 
15
+ Using npm:
16
+
17
+ ```bash
18
+ npm install einsteinjs
19
+ ```
20
+
11
21
  ## Usage
12
22
 
13
23
  ```ts
14
- import { registry, build } from "einsteinjs"
24
+ import { registry, defineConfig } from "einsteinjs"
15
25
 
16
26
  const rfc = registry
17
- .it("React Functional Component")
18
- .scope(["typescriptreact"])
19
- .prefix("rfc")
20
- .body([
21
- "export default function ${1:Component}() {",
22
- " return <div>$0</div>",
23
- "}"
24
- ])
25
- .tag(["react"])
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
+ }
26
78
  ```
27
79
 
28
- ## Features
80
+ ## License
29
81
 
30
- - Type-safe API
31
- - Duplicate prefix validation
32
- - Duplicate name validation
33
- - VSCode-compatible output
34
- - Extensible compiler architecture
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
- scope: Scope[];
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.
@@ -61,7 +97,18 @@ interface Config {
61
97
  */
62
98
  declare function defineConfig(config: Config): Config;
63
99
 
64
- declare function build(config: Config): Promise<void>;
100
+ /**
101
+ * API pública.
102
+ *
103
+ * Permite:
104
+ *
105
+ * await build(
106
+ * tsx,
107
+ * jsx,
108
+ * html
109
+ * )
110
+ */
111
+ declare function build(...configs: Config[]): Promise<void>;
65
112
 
66
113
  /**
67
114
  * API pública:
package/dist/index.js CHANGED
@@ -13,13 +13,27 @@ function compileSnippet(snippet) {
13
13
  return {
14
14
  [snippet.name]: {
15
15
  /**
16
- * VSCode espera string.
17
- * Nós trabalhamos com array
18
- * e convertemos somente aqui.
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,17 +14594,17 @@ 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
14590
- async function build(config2) {
14591
- const snippets = config2.snippets.map(
14592
- (snippet) => snippet.build()
14593
- );
14606
+ async function buildConfig(config2) {
14607
+ const snippets = config2.snippets.map((snippet) => snippet.build());
14594
14608
  for (const snippet of snippets) {
14595
14609
  snippetSchema.parse(snippet);
14596
14610
  }
@@ -14601,11 +14615,10 @@ async function build(config2) {
14601
14615
  await mkdir(outputDir, {
14602
14616
  recursive: true
14603
14617
  });
14604
- await writeFile(
14605
- config2.output,
14606
- JSON.stringify(json2, null, 2),
14607
- "utf-8"
14608
- );
14618
+ await writeFile(config2.output, JSON.stringify(json2, null, 4), "utf-8");
14619
+ }
14620
+ async function build(...configs) {
14621
+ await Promise.all(configs.map(buildConfig));
14609
14622
  }
14610
14623
 
14611
14624
  // src/define-config.ts
@@ -14619,7 +14632,12 @@ var SnippetBuilder = class {
14619
14632
  * Partial permite criar o objeto aos poucos.
14620
14633
  */
14621
14634
  snippet = {
14622
- tags: []
14635
+ tags: [],
14636
+ /**
14637
+ * Por padrão o snippet
14638
+ * NÃO é template.
14639
+ */
14640
+ isFileTemplate: false
14623
14641
  };
14624
14642
  /**
14625
14643
  * Nome do snippet.
@@ -14652,6 +14670,23 @@ var SnippetBuilder = class {
14652
14670
  this.snippet.body = body;
14653
14671
  return this;
14654
14672
  }
14673
+ describe(description) {
14674
+ this.snippet.description = description;
14675
+ return this;
14676
+ }
14677
+ /**
14678
+ * Define se é um template de arquivo.
14679
+ *
14680
+ * Ex:
14681
+ *
14682
+ * .template()
14683
+ * .template(true)
14684
+ * .template(false)
14685
+ */
14686
+ template(isFileTemplate = true) {
14687
+ this.snippet.isFileTemplate = isFileTemplate;
14688
+ return this;
14689
+ }
14655
14690
  /**
14656
14691
  * Tags para futuras features:
14657
14692
  * documentação, filtros, busca etc.
package/package.json CHANGED
@@ -1,29 +1,30 @@
1
1
  {
2
- "name": "einsteinjs",
3
- "version": "0.1.2",
4
- "type": "module",
5
- "main": "./dist/index.js",
6
- "types": "./dist/index.d.ts",
7
- "files": [
8
- "dist"
9
- ],
10
- "exports": {
11
- ".": {
12
- "import": "./dist/index.js",
13
- "types": "./dist/index.d.ts"
2
+ "name": "einsteinjs",
3
+ "version": "0.1.4",
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
+ }