@caleuche/core 0.1.2 → 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/LICENSE +22 -0
- package/README.md +13 -0
- package/dist/index.cjs.js +73 -9
- package/package.json +54 -53
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Brandon Miller
|
|
4
|
+
Copyright (c) 2025 Gerardo Lecaros
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -40,6 +40,19 @@ const output: CompileOutput = compileSample(sample, { name: "World" }, options);
|
|
|
40
40
|
// output.items will contain the generated files
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
+
### Template Built-ins
|
|
44
|
+
|
|
45
|
+
For use in authoring templates. All functions described below are ingested by Caleuche when compiling code files.
|
|
46
|
+
|
|
47
|
+
#### Universal
|
|
48
|
+
|
|
49
|
+
- `<language>.valueOrEnvironment(useEnvironmentVariable: boolean, variableName: string, environmentVariable: string, value: string)` Generates code to assign a variable from a specified environment variable `environmentVariable` at runtime or from a provided value `value`.
|
|
50
|
+
|
|
51
|
+
#### Language Specific
|
|
52
|
+
- `go.includes(...items: string | {module: string; condition?: boolean})` Generates go import statement from list of dependencies. Exclude a dependency by setting condition to false.
|
|
53
|
+
|
|
54
|
+
- `csharp.usings(...items: string | {namespace: string; condition?: boolean})` Generates C# using statements from a list of namespaces. Exclude a namespace by setting condition to false.
|
|
55
|
+
|
|
43
56
|
## API
|
|
44
57
|
|
|
45
58
|
### Types
|
package/dist/index.cjs.js
CHANGED
|
@@ -2,28 +2,40 @@
|
|
|
2
2
|
|
|
3
3
|
var _ = require('lodash');
|
|
4
4
|
|
|
5
|
+
function formatError(variableName, environmentVariable) {
|
|
6
|
+
if (variableName.trim() !== "") {
|
|
7
|
+
return new Error(`No value provided for variable "${variableName}" or environment variable.`);
|
|
8
|
+
}
|
|
9
|
+
else if (environmentVariable.trim() !== "") {
|
|
10
|
+
return new Error(`No value provided for environment variable "${environmentVariable}".`);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return new Error("No value provided for variable or environment variable.");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
5
17
|
function usings(...items) {
|
|
6
18
|
return items
|
|
7
19
|
.filter((u) => typeof u === "string" || u.condition)
|
|
8
20
|
.map((u) => `using ${typeof u === "string" ? u : u.namespace};`)
|
|
9
21
|
.join("\n");
|
|
10
22
|
}
|
|
11
|
-
function valueOrEnvironment$
|
|
23
|
+
function valueOrEnvironment$4(useEnvironmentVariable, variableName, environmentVariable, value) {
|
|
12
24
|
if (useEnvironmentVariable && environmentVariable) {
|
|
13
|
-
return `var ${variableName} = Environment.GetEnvironmentVariable("${environmentVariable}") ?? throw new InvalidOperationException("${environmentVariable} environment variable is not set.")
|
|
25
|
+
return `var ${variableName} = Environment.GetEnvironmentVariable("${environmentVariable}") ?? throw new InvalidOperationException("${environmentVariable} environment variable is not set.");`;
|
|
14
26
|
}
|
|
15
27
|
else if (value) {
|
|
16
28
|
return `const string ${variableName} = "${value}";`;
|
|
17
29
|
}
|
|
18
30
|
else {
|
|
19
|
-
throw
|
|
31
|
+
throw formatError(variableName, environmentVariable);
|
|
20
32
|
}
|
|
21
33
|
}
|
|
22
34
|
|
|
23
35
|
var csharp = /*#__PURE__*/Object.freeze({
|
|
24
36
|
__proto__: null,
|
|
25
37
|
usings: usings,
|
|
26
|
-
valueOrEnvironment: valueOrEnvironment$
|
|
38
|
+
valueOrEnvironment: valueOrEnvironment$4
|
|
27
39
|
});
|
|
28
40
|
|
|
29
41
|
function includes(...items) {
|
|
@@ -47,7 +59,7 @@ function includes(...items) {
|
|
|
47
59
|
imports += "\n)";
|
|
48
60
|
return imports;
|
|
49
61
|
}
|
|
50
|
-
function valueOrEnvironment$
|
|
62
|
+
function valueOrEnvironment$3(useEnvironmentVariable, variableName, environmentVariable, value, indentationLevel = 1) {
|
|
51
63
|
if (!variableName) {
|
|
52
64
|
throw new Error("Variable name must be provided.");
|
|
53
65
|
}
|
|
@@ -63,17 +75,17 @@ function valueOrEnvironment$1(useEnvironmentVariable, variableName, environmentV
|
|
|
63
75
|
return `const ${variableName} = "${value}"`;
|
|
64
76
|
}
|
|
65
77
|
else {
|
|
66
|
-
throw
|
|
78
|
+
throw formatError(variableName, environmentVariable);
|
|
67
79
|
}
|
|
68
80
|
}
|
|
69
81
|
|
|
70
82
|
var go = /*#__PURE__*/Object.freeze({
|
|
71
83
|
__proto__: null,
|
|
72
84
|
includes: includes,
|
|
73
|
-
valueOrEnvironment: valueOrEnvironment$
|
|
85
|
+
valueOrEnvironment: valueOrEnvironment$3
|
|
74
86
|
});
|
|
75
87
|
|
|
76
|
-
function valueOrEnvironment(useEnvironmentVariable, variableName, environmentVariable, value, indentationLevel = 0) {
|
|
88
|
+
function valueOrEnvironment$2(useEnvironmentVariable, variableName, environmentVariable, value, indentationLevel = 0) {
|
|
77
89
|
if (!variableName) {
|
|
78
90
|
throw new Error("Variable name must be provided.");
|
|
79
91
|
}
|
|
@@ -87,11 +99,61 @@ function valueOrEnvironment(useEnvironmentVariable, variableName, environmentVar
|
|
|
87
99
|
return `${variableName} = "${value}"`;
|
|
88
100
|
}
|
|
89
101
|
else {
|
|
90
|
-
throw
|
|
102
|
+
throw formatError(variableName, environmentVariable);
|
|
91
103
|
}
|
|
92
104
|
}
|
|
93
105
|
|
|
94
106
|
var python = /*#__PURE__*/Object.freeze({
|
|
107
|
+
__proto__: null,
|
|
108
|
+
valueOrEnvironment: valueOrEnvironment$2
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
function valueOrEnvironment$1(useEnvironmentVariable, variableName, environmentVariable, value, indentationLevel = 1) {
|
|
112
|
+
if (!variableName) {
|
|
113
|
+
throw new Error("Variable name must be provided.");
|
|
114
|
+
}
|
|
115
|
+
const indent = " ".repeat(indentationLevel);
|
|
116
|
+
if (useEnvironmentVariable && environmentVariable) {
|
|
117
|
+
return (`String ${variableName} = System.getenv("${environmentVariable}");\n` +
|
|
118
|
+
`${indent}if (${variableName} == null || ${variableName}.isEmpty()) {\n` +
|
|
119
|
+
`${indent} System.out.println("Please set the ${environmentVariable} environment variable.");\n` +
|
|
120
|
+
`${indent} System.exit(1);\n` +
|
|
121
|
+
`${indent}}`);
|
|
122
|
+
}
|
|
123
|
+
else if (value) {
|
|
124
|
+
return `String ${variableName} = "${value}";`;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
throw formatError(variableName, environmentVariable);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
var java = /*#__PURE__*/Object.freeze({
|
|
132
|
+
__proto__: null,
|
|
133
|
+
valueOrEnvironment: valueOrEnvironment$1
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
function valueOrEnvironment(useEnvironmentVariable, variableName, environmentVariable, value, indentationLevel = 0) {
|
|
137
|
+
if (!variableName) {
|
|
138
|
+
throw new Error("Variable name must be provided.");
|
|
139
|
+
}
|
|
140
|
+
const indent = " ".repeat(indentationLevel);
|
|
141
|
+
if (useEnvironmentVariable && environmentVariable) {
|
|
142
|
+
return (`const ${variableName} = process.env["${environmentVariable}"];\n` +
|
|
143
|
+
`${indent}if (!${variableName}) {\n` +
|
|
144
|
+
`${indent} console.error("Please set the ${environmentVariable} environment variable.");\n` +
|
|
145
|
+
`${indent} process.exit(1);\n` +
|
|
146
|
+
`${indent}}`);
|
|
147
|
+
}
|
|
148
|
+
else if (value) {
|
|
149
|
+
return `const ${variableName} = "${value}";`;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
throw formatError(variableName, environmentVariable);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
var javascript = /*#__PURE__*/Object.freeze({
|
|
95
157
|
__proto__: null,
|
|
96
158
|
valueOrEnvironment: valueOrEnvironment
|
|
97
159
|
});
|
|
@@ -200,6 +262,8 @@ function compileSample(sample, input, options) {
|
|
|
200
262
|
csharp: csharp,
|
|
201
263
|
go: go,
|
|
202
264
|
python: python,
|
|
265
|
+
java: java,
|
|
266
|
+
javascript: javascript,
|
|
203
267
|
},
|
|
204
268
|
});
|
|
205
269
|
const targetFileName = getTargetFileName(sample);
|
package/package.json
CHANGED
|
@@ -1,53 +1,54 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@caleuche/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"main": "dist/index.cjs.js",
|
|
5
|
-
"exports": {
|
|
6
|
-
".": {
|
|
7
|
-
"types": "./dist/types/index.d.ts",
|
|
8
|
-
"import": "./dist/index.esm.js",
|
|
9
|
-
"require": "./dist/index.cjs.js"
|
|
10
|
-
},
|
|
11
|
-
"./package.json": "./package.json"
|
|
12
|
-
},
|
|
13
|
-
"types": "dist/types/index.d.ts",
|
|
14
|
-
"scripts": {
|
|
15
|
-
"build": "rollup -c",
|
|
16
|
-
"build:watch": "rollup -c -w",
|
|
17
|
-
"build:clean": "rimraf dist && rollup -c",
|
|
18
|
-
"build:clean:watch": "rimraf dist && rollup -c -w",
|
|
19
|
-
"clean": "rimraf dist",
|
|
20
|
-
"format": "prettier --write .",
|
|
21
|
-
"
|
|
22
|
-
},
|
|
23
|
-
"author": "",
|
|
24
|
-
"license": "MIT",
|
|
25
|
-
"description": "",
|
|
26
|
-
"repository": {
|
|
27
|
-
"type": "git",
|
|
28
|
-
"url": "https://github.com/brandor64/caleuche"
|
|
29
|
-
},
|
|
30
|
-
"dependencies": {
|
|
31
|
-
"lodash": "^4.17.21",
|
|
32
|
-
"tslib": "^2.8.1"
|
|
33
|
-
},
|
|
34
|
-
"devDependencies": {
|
|
35
|
-
"@rollup/plugin-commonjs": "^28.0.3",
|
|
36
|
-
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
37
|
-
"@rollup/plugin-typescript": "^12.1.2",
|
|
38
|
-
"@types/lodash": "^4.17.17",
|
|
39
|
-
"prettier": "^3.5.3",
|
|
40
|
-
"rimraf": "^6.0.1",
|
|
41
|
-
"rollup": "^4.42.0",
|
|
42
|
-
"typescript": "^5.8.3"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"./project-templates/
|
|
47
|
-
"./project-templates/
|
|
48
|
-
"./project-templates/
|
|
49
|
-
"./project-templates/
|
|
50
|
-
"./project-templates/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@caleuche/core",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"main": "dist/index.cjs.js",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/types/index.d.ts",
|
|
8
|
+
"import": "./dist/index.esm.js",
|
|
9
|
+
"require": "./dist/index.cjs.js"
|
|
10
|
+
},
|
|
11
|
+
"./package.json": "./package.json"
|
|
12
|
+
},
|
|
13
|
+
"types": "dist/types/index.d.ts",
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "rollup -c",
|
|
16
|
+
"build:watch": "rollup -c -w",
|
|
17
|
+
"build:clean": "rimraf dist && rollup -c",
|
|
18
|
+
"build:clean:watch": "rimraf dist && rollup -c -w",
|
|
19
|
+
"clean": "rimraf dist",
|
|
20
|
+
"format": "prettier --write .",
|
|
21
|
+
"test": "vitest run"
|
|
22
|
+
},
|
|
23
|
+
"author": "",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"description": "",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/brandor64/caleuche"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"lodash": "^4.17.21",
|
|
32
|
+
"tslib": "^2.8.1"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@rollup/plugin-commonjs": "^28.0.3",
|
|
36
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
37
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
38
|
+
"@types/lodash": "^4.17.17",
|
|
39
|
+
"prettier": "^3.5.3",
|
|
40
|
+
"rimraf": "^6.0.1",
|
|
41
|
+
"rollup": "^4.42.0",
|
|
42
|
+
"typescript": "^5.8.3",
|
|
43
|
+
"vitest": "^3.2.3"
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"./project-templates/Sample.csproj.template",
|
|
47
|
+
"./project-templates/go.mod.template",
|
|
48
|
+
"./project-templates/package.json.template",
|
|
49
|
+
"./project-templates/pom.xml.template",
|
|
50
|
+
"./project-templates/requirements.txt.template",
|
|
51
|
+
"./project-templates/Sample.csproj.template"
|
|
52
|
+
],
|
|
53
|
+
"bin": {}
|
|
54
|
+
}
|