@caleuche/core 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 +13 -0
- package/dist/index.cjs.js +49 -11
- package/package.json +1 -1
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,13 +2,25 @@
|
|
|
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
25
|
return `var ${variableName} = Environment.GetEnvironmentVariable("${environmentVariable}") ?? throw new InvalidOperationException("${environmentVariable} environment variable is not set.");`;
|
|
14
26
|
}
|
|
@@ -16,14 +28,14 @@ function valueOrEnvironment$3(useEnvironmentVariable, variableName, environmentV
|
|
|
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$2(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$
|
|
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,16 +99,16 @@ function valueOrEnvironment$1(useEnvironmentVariable, variableName, environmentV
|
|
|
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({
|
|
95
107
|
__proto__: null,
|
|
96
|
-
valueOrEnvironment: valueOrEnvironment$
|
|
108
|
+
valueOrEnvironment: valueOrEnvironment$2
|
|
97
109
|
});
|
|
98
110
|
|
|
99
|
-
function valueOrEnvironment(useEnvironmentVariable, variableName, environmentVariable, value, indentationLevel = 1) {
|
|
111
|
+
function valueOrEnvironment$1(useEnvironmentVariable, variableName, environmentVariable, value, indentationLevel = 1) {
|
|
100
112
|
if (!variableName) {
|
|
101
113
|
throw new Error("Variable name must be provided.");
|
|
102
114
|
}
|
|
@@ -112,11 +124,36 @@ function valueOrEnvironment(useEnvironmentVariable, variableName, environmentVar
|
|
|
112
124
|
return `String ${variableName} = "${value}";`;
|
|
113
125
|
}
|
|
114
126
|
else {
|
|
115
|
-
throw
|
|
127
|
+
throw formatError(variableName, environmentVariable);
|
|
116
128
|
}
|
|
117
129
|
}
|
|
118
130
|
|
|
119
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({
|
|
120
157
|
__proto__: null,
|
|
121
158
|
valueOrEnvironment: valueOrEnvironment
|
|
122
159
|
});
|
|
@@ -226,6 +263,7 @@ function compileSample(sample, input, options) {
|
|
|
226
263
|
go: go,
|
|
227
264
|
python: python,
|
|
228
265
|
java: java,
|
|
266
|
+
javascript: javascript,
|
|
229
267
|
},
|
|
230
268
|
});
|
|
231
269
|
const targetFileName = getTargetFileName(sample);
|