@smapiot/pilet-template-angular 0.15.1 → 0.15.2-beta.4952

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.
Files changed (2) hide show
  1. package/lib/index.js +323 -304
  2. package/package.json +3 -3
package/lib/index.js CHANGED
@@ -140,6 +140,229 @@ var require_io = __commonJS({
140
140
  }
141
141
  });
142
142
 
143
+ // ../../packages/template-utils/lib/log.js
144
+ var require_log = __commonJS({
145
+ "../../packages/template-utils/lib/log.js"(exports) {
146
+ "use strict";
147
+ Object.defineProperty(exports, "__esModule", { value: true });
148
+ exports.log = exports.setLogLevel = void 0;
149
+ var logLevel = "warn";
150
+ function setLogLevel(level) {
151
+ logLevel = level;
152
+ }
153
+ exports.setLogLevel = setLogLevel;
154
+ function log(level, message) {
155
+ if (level === "error") {
156
+ if (logLevel !== "disabled") {
157
+ console.error(`[template] ${message}`);
158
+ }
159
+ } else if (level === "warn") {
160
+ if (logLevel !== "error" && logLevel !== "disabled") {
161
+ console.warn(`[template] ${message}`);
162
+ }
163
+ } else if (level === "info") {
164
+ if (logLevel === "verbose" || logLevel === "info") {
165
+ console.info(`[template] ${message}`);
166
+ }
167
+ } else if (level === "verbose") {
168
+ if (logLevel === "verbose") {
169
+ console.log(`[template] ${message}`);
170
+ }
171
+ }
172
+ }
173
+ exports.log = log;
174
+ }
175
+ });
176
+
177
+ // ../../packages/template-utils/lib/version.js
178
+ var require_version = __commonJS({
179
+ "../../packages/template-utils/lib/version.js"(exports) {
180
+ "use strict";
181
+ Object.defineProperty(exports, "__esModule", { value: true });
182
+ exports.checkVersion = void 0;
183
+ var log_1 = require_log();
184
+ var semver = /^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;
185
+ var acceptsAll = ["*", "x", ">=0"];
186
+ var operatorResMap = {
187
+ ">": [1],
188
+ ">=": [0, 1],
189
+ "=": [0],
190
+ "<=": [-1, 0],
191
+ "<": [-1]
192
+ };
193
+ function indexOrEnd(str, q) {
194
+ return str.indexOf(q) === -1 ? str.length : str.indexOf(q);
195
+ }
196
+ function splitVersion(v) {
197
+ var c = v.replace(/^v/, "").replace(/\+.*$/, "");
198
+ var patchIndex = indexOrEnd(c, "-");
199
+ var arr = c.substring(0, patchIndex).split(".");
200
+ arr.push(c.substring(patchIndex + 1));
201
+ return arr;
202
+ }
203
+ function parseSegment(v) {
204
+ var n = parseInt(v, 10);
205
+ return isNaN(n) ? v : n;
206
+ }
207
+ function validateAndParse(v) {
208
+ const match = v.match(semver);
209
+ match.shift();
210
+ return match;
211
+ }
212
+ function compareStrings(a, b) {
213
+ const ap = parseSegment(a);
214
+ const bp = parseSegment(b);
215
+ if (ap > bp) {
216
+ return 1;
217
+ } else if (ap < bp) {
218
+ return -1;
219
+ } else {
220
+ return 0;
221
+ }
222
+ }
223
+ function compareSegments(a, b) {
224
+ for (let i = 0; i < 2; i++) {
225
+ const r = compareStrings(a[i] || "0", b[i] || "0");
226
+ if (r !== 0) {
227
+ return r;
228
+ }
229
+ }
230
+ return 0;
231
+ }
232
+ function compareVersions(v1, v2) {
233
+ const s1 = splitVersion(v1);
234
+ const s2 = splitVersion(v2);
235
+ const len = Math.max(s1.length - 1, s2.length - 1);
236
+ for (let i = 0; i < len; i++) {
237
+ const n1 = parseInt(s1[i] || "0", 10);
238
+ const n2 = parseInt(s2[i] || "0", 10);
239
+ if (n1 > n2) {
240
+ return 1;
241
+ } else if (n2 > n1) {
242
+ return -1;
243
+ }
244
+ }
245
+ const sp1 = s1[s1.length - 1];
246
+ const sp2 = s2[s2.length - 1];
247
+ if (sp1 && sp2) {
248
+ const p1 = sp1.split(".").map(parseSegment);
249
+ const p2 = sp2.split(".").map(parseSegment);
250
+ const len2 = Math.max(p1.length, p2.length);
251
+ for (let i = 0; i < len2; i++) {
252
+ if (p1[i] === void 0 || typeof p2[i] === "string" && typeof p1[i] === "number") {
253
+ return -1;
254
+ } else if (p2[i] === void 0 || typeof p1[i] === "string" && typeof p2[i] === "number") {
255
+ return 1;
256
+ } else if (p1[i] > p2[i]) {
257
+ return 1;
258
+ } else if (p2[i] > p1[i]) {
259
+ return -1;
260
+ }
261
+ }
262
+ } else if (sp1 || sp2) {
263
+ return sp1 ? -1 : 1;
264
+ }
265
+ return 0;
266
+ }
267
+ function compare(v1, v2, operator) {
268
+ const res = compareVersions(v1, v2);
269
+ return operatorResMap[operator].indexOf(res) > -1;
270
+ }
271
+ function satisfies(v, r) {
272
+ if (!acceptsAll.includes(r)) {
273
+ const match = r.match(/^([<>=~^]+)/);
274
+ const op = match ? match[1] : "=";
275
+ if (op !== "^" && op !== "~") {
276
+ return compare(v, r, op);
277
+ }
278
+ const [v1, v2, v3] = validateAndParse(v);
279
+ const [m1, m2, m3] = validateAndParse(r);
280
+ if (compareStrings(v1, m1) !== 0) {
281
+ return false;
282
+ } else if (op === "^") {
283
+ return compareSegments([v2, v3], [m2, m3]) >= 0;
284
+ } else if (compareStrings(v2, m2) !== 0) {
285
+ return false;
286
+ }
287
+ return compareStrings(v3, m3) >= 0;
288
+ }
289
+ return true;
290
+ }
291
+ function normalize(version) {
292
+ const dash = version.indexOf("-");
293
+ if (dash !== -1) {
294
+ return version.substring(0, dash);
295
+ }
296
+ return version;
297
+ }
298
+ function checkVersion(desired, actual) {
299
+ const normActual = normalize(actual);
300
+ const normDesired = normalize(desired);
301
+ if (!satisfies(normActual, normDesired)) {
302
+ (0, log_1.log)("warn", `The template was made for "piral-cli" version "${desired}" but was used with "${actual}".`);
303
+ }
304
+ }
305
+ exports.checkVersion = checkVersion;
306
+ }
307
+ });
308
+
309
+ // ../../packages/template-utils/lib/parent.js
310
+ var require_parent = __commonJS({
311
+ "../../packages/template-utils/lib/parent.js"(exports) {
312
+ "use strict";
313
+ Object.defineProperty(exports, "__esModule", { value: true });
314
+ exports.configure = exports.LogLevels = exports.ForceOverwrite = void 0;
315
+ var path_1 = require("path");
316
+ var log_1 = require_log();
317
+ var version_1 = require_version();
318
+ var ForceOverwrite;
319
+ (function(ForceOverwrite2) {
320
+ ForceOverwrite2[ForceOverwrite2["no"] = 0] = "no";
321
+ ForceOverwrite2[ForceOverwrite2["prompt"] = 1] = "prompt";
322
+ ForceOverwrite2[ForceOverwrite2["yes"] = 2] = "yes";
323
+ })(ForceOverwrite = exports.ForceOverwrite || (exports.ForceOverwrite = {}));
324
+ var LogLevels;
325
+ (function(LogLevels2) {
326
+ LogLevels2[LogLevels2["disabled"] = 0] = "disabled";
327
+ LogLevels2[LogLevels2["error"] = 1] = "error";
328
+ LogLevels2[LogLevels2["warning"] = 2] = "warning";
329
+ LogLevels2[LogLevels2["info"] = 3] = "info";
330
+ LogLevels2[LogLevels2["verbose"] = 4] = "verbose";
331
+ LogLevels2[LogLevels2["debug"] = 5] = "debug";
332
+ })(LogLevels = exports.LogLevels || (exports.LogLevels = {}));
333
+ function configure(root2, details) {
334
+ var _a, _b;
335
+ if (details) {
336
+ const packageJsonPath = (0, path_1.resolve)(root2, "package.json");
337
+ const templateProject = require(packageJsonPath);
338
+ const desiredVersion = (_b = (_a = templateProject.engines) === null || _a === void 0 ? void 0 : _a.piral) !== null && _b !== void 0 ? _b : "*";
339
+ switch (details.logLevel) {
340
+ case LogLevels.disabled:
341
+ (0, log_1.setLogLevel)("disabled");
342
+ break;
343
+ case LogLevels.error:
344
+ (0, log_1.setLogLevel)("error");
345
+ break;
346
+ case LogLevels.warning:
347
+ (0, log_1.setLogLevel)("warn");
348
+ break;
349
+ case LogLevels.info:
350
+ (0, log_1.setLogLevel)("info");
351
+ break;
352
+ case LogLevels.verbose:
353
+ case LogLevels.debug:
354
+ (0, log_1.setLogLevel)("verbose");
355
+ break;
356
+ }
357
+ (0, version_1.checkVersion)(desiredVersion, details.cliVersion);
358
+ } else {
359
+ (0, log_1.log)("warn", `The used version of the "piral-cli" is outdated. The templating may still work - if not you should use a more recent version of the "piral-cli".`);
360
+ }
361
+ }
362
+ exports.configure = configure;
363
+ }
364
+ });
365
+
143
366
  // ../../node_modules/ejs/lib/utils.js
144
367
  var require_utils = __commonJS({
145
368
  "../../node_modules/ejs/lib/utils.js"(exports) {
@@ -818,37 +1041,96 @@ var require_ejs = __commonJS({
818
1041
  }
819
1042
  });
820
1043
 
821
- // ../../packages/template-utils/lib/log.js
822
- var require_log = __commonJS({
823
- "../../packages/template-utils/lib/log.js"(exports) {
1044
+ // ../../packages/template-utils/lib/utils.js
1045
+ var require_utils2 = __commonJS({
1046
+ "../../packages/template-utils/lib/utils.js"(exports) {
824
1047
  "use strict";
825
1048
  Object.defineProperty(exports, "__esModule", { value: true });
826
- exports.log = exports.setLogLevel = void 0;
827
- var logLevel = "warn";
828
- function setLogLevel(level) {
829
- logLevel = level;
1049
+ exports.getLanguageExtension = exports.getPlugins = exports.getPiralInstance = exports.getPackageJsonWithSource = exports.makeRelative = void 0;
1050
+ var path_1 = require("path");
1051
+ var fs_1 = require("fs");
1052
+ var log_1 = require_log();
1053
+ function makeRelative(path, root2) {
1054
+ const relPath = (0, path_1.isAbsolute)(path) ? (0, path_1.relative)(root2, path) : path;
1055
+ return relPath.replaceAll(path_1.sep, path_1.posix.sep);
830
1056
  }
831
- exports.setLogLevel = setLogLevel;
832
- function log(level, message) {
833
- if (level === "error") {
834
- if (logLevel !== "disabled") {
835
- console.error(`[template] ${message}`);
836
- }
837
- } else if (level === "warn") {
838
- if (logLevel !== "error" && logLevel !== "disabled") {
839
- console.warn(`[template] ${message}`);
840
- }
841
- } else if (level === "info") {
842
- if (logLevel === "verbose" || logLevel === "info") {
843
- console.info(`[template] ${message}`);
844
- }
845
- } else if (level === "verbose") {
846
- if (logLevel === "verbose") {
847
- console.log(`[template] ${message}`);
848
- }
849
- }
1057
+ exports.makeRelative = makeRelative;
1058
+ function getPackageJsonWithSource(root2, targetDir, fileName) {
1059
+ const path = makeRelative(path_1.posix.join(targetDir, fileName), root2);
1060
+ (0, log_1.log)("verbose", `Adding "source" to package.json: "${path}"`);
1061
+ return {
1062
+ languages: ["ts", "js"],
1063
+ name: "package.json",
1064
+ content: JSON.stringify({ source: path }),
1065
+ target: "<root>/package.json"
1066
+ };
850
1067
  }
851
- exports.log = log;
1068
+ exports.getPackageJsonWithSource = getPackageJsonWithSource;
1069
+ function getPiralInstance2(root2, sourceName) {
1070
+ try {
1071
+ const packageJsonPath = require.resolve(`${sourceName}/package.json`, {
1072
+ paths: [root2]
1073
+ });
1074
+ (0, log_1.log)("verbose", `Found package JSON in "${packageJsonPath}"`);
1075
+ const sourcePath = (0, path_1.dirname)(packageJsonPath);
1076
+ const details = require(packageJsonPath);
1077
+ const types = details.types || details.typings;
1078
+ (0, log_1.log)("verbose", `Looking for types in "${types}"`);
1079
+ const typingsPath = types !== void 0 ? (0, path_1.resolve)(sourcePath, types) : void 0;
1080
+ const app = details.app;
1081
+ (0, log_1.log)("verbose", `Looking for types in "${app}"`);
1082
+ const appPath = app !== void 0 ? (0, path_1.resolve)(sourcePath, app) : void 0;
1083
+ return {
1084
+ sourceName,
1085
+ sourcePath,
1086
+ details,
1087
+ appPath,
1088
+ typingsPath
1089
+ };
1090
+ } catch (ex) {
1091
+ (0, log_1.log)("error", `Error when getting Piral instance: ${ex}`);
1092
+ }
1093
+ return void 0;
1094
+ }
1095
+ exports.getPiralInstance = getPiralInstance2;
1096
+ function getPlugins(root2, sourceName) {
1097
+ const plugins = {};
1098
+ (0, log_1.log)("verbose", `Getting the plugins of "${sourceName}/package.json" ...`);
1099
+ const piralInstance = getPiralInstance2(root2, sourceName);
1100
+ const typingsPath = piralInstance === null || piralInstance === void 0 ? void 0 : piralInstance.typingsPath;
1101
+ if (typingsPath) {
1102
+ (0, log_1.log)("verbose", `Reading file in "${typingsPath}"`);
1103
+ const typing = (0, fs_1.readFileSync)(typingsPath, "utf8");
1104
+ const match = /export interface PiletCustomApi extends (.*?) \{/g.exec(typing);
1105
+ if (!match) {
1106
+ (0, log_1.log)("verbose", `No Piral instance plugins have been found`);
1107
+ return [];
1108
+ }
1109
+ const apis = match[1].split(", ");
1110
+ (0, log_1.log)("verbose", `Found Piral instance plugins "${match[1]}"`);
1111
+ for (const api of apis) {
1112
+ const pluginMatch = /^Pilet(.*)Api$/.exec(api);
1113
+ if (pluginMatch) {
1114
+ const name = pluginMatch[1].toLowerCase();
1115
+ plugins[name] = true;
1116
+ } else {
1117
+ (0, log_1.log)("warn", `Could not find plugin for Pilet API "${api}"`);
1118
+ }
1119
+ }
1120
+ }
1121
+ return plugins;
1122
+ }
1123
+ exports.getPlugins = getPlugins;
1124
+ function getLanguageExtension(language, isJsx = true) {
1125
+ switch (language) {
1126
+ case "js":
1127
+ return isJsx ? ".jsx" : ".js";
1128
+ case "ts":
1129
+ default:
1130
+ return isJsx ? ".tsx" : ".ts";
1131
+ }
1132
+ }
1133
+ exports.getLanguageExtension = getLanguageExtension;
852
1134
  }
853
1135
  });
854
1136
 
@@ -884,10 +1166,11 @@ var require_template = __commonJS({
884
1166
  });
885
1167
  };
886
1168
  Object.defineProperty(exports, "__esModule", { value: true });
887
- exports.getFileFromTemplate = void 0;
1169
+ exports.getFileFromTemplate = exports.normalizeData = void 0;
888
1170
  var path_1 = require("path");
889
1171
  var ejs_1 = require_ejs();
890
1172
  var log_1 = require_log();
1173
+ var utils_1 = require_utils2();
891
1174
  var findVariable = /<(\w+)>/g;
892
1175
  function replaceVariables(str, data) {
893
1176
  let match = findVariable.exec(str);
@@ -919,11 +1202,16 @@ var require_template = __commonJS({
919
1202
  });
920
1203
  });
921
1204
  }
1205
+ function normalizeData(data) {
1206
+ data.src = (0, utils_1.makeRelative)(replaceVariables(data.src, data), data.root);
1207
+ data.mocks = (0, utils_1.makeRelative)(replaceVariables(data.mocks, data), data.root);
1208
+ return data;
1209
+ }
1210
+ exports.normalizeData = normalizeData;
922
1211
  function getFileFromTemplate(sourceDir, source, data) {
923
1212
  return __awaiter(this, void 0, void 0, function* () {
924
1213
  let { target, name, content } = source;
925
- const absPath = replaceVariables(target, data);
926
- const path = (0, path_1.isAbsolute)(absPath) ? (0, path_1.relative)(data.projectRoot, absPath) : absPath;
1214
+ const path = (0, utils_1.makeRelative)(replaceVariables(target, data), data.projectRoot);
927
1215
  if (!content) {
928
1216
  (0, log_1.log)("verbose", `Return template "${name}" with path "${path}" (from "${target}")`);
929
1217
  content = yield fillTemplate(sourceDir, name, data);
@@ -940,275 +1228,6 @@ var require_template = __commonJS({
940
1228
  }
941
1229
  });
942
1230
 
943
- // ../../packages/template-utils/lib/version.js
944
- var require_version = __commonJS({
945
- "../../packages/template-utils/lib/version.js"(exports) {
946
- "use strict";
947
- Object.defineProperty(exports, "__esModule", { value: true });
948
- exports.checkVersion = void 0;
949
- var log_1 = require_log();
950
- var semver = /^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;
951
- var acceptsAll = ["*", "x", ">=0"];
952
- var operatorResMap = {
953
- ">": [1],
954
- ">=": [0, 1],
955
- "=": [0],
956
- "<=": [-1, 0],
957
- "<": [-1]
958
- };
959
- function indexOrEnd(str, q) {
960
- return str.indexOf(q) === -1 ? str.length : str.indexOf(q);
961
- }
962
- function splitVersion(v) {
963
- var c = v.replace(/^v/, "").replace(/\+.*$/, "");
964
- var patchIndex = indexOrEnd(c, "-");
965
- var arr = c.substring(0, patchIndex).split(".");
966
- arr.push(c.substring(patchIndex + 1));
967
- return arr;
968
- }
969
- function parseSegment(v) {
970
- var n = parseInt(v, 10);
971
- return isNaN(n) ? v : n;
972
- }
973
- function validateAndParse(v) {
974
- const match = v.match(semver);
975
- match.shift();
976
- return match;
977
- }
978
- function compareStrings(a, b) {
979
- const ap = parseSegment(a);
980
- const bp = parseSegment(b);
981
- if (ap > bp) {
982
- return 1;
983
- } else if (ap < bp) {
984
- return -1;
985
- } else {
986
- return 0;
987
- }
988
- }
989
- function compareSegments(a, b) {
990
- for (let i = 0; i < 2; i++) {
991
- const r = compareStrings(a[i] || "0", b[i] || "0");
992
- if (r !== 0) {
993
- return r;
994
- }
995
- }
996
- return 0;
997
- }
998
- function compareVersions(v1, v2) {
999
- const s1 = splitVersion(v1);
1000
- const s2 = splitVersion(v2);
1001
- const len = Math.max(s1.length - 1, s2.length - 1);
1002
- for (let i = 0; i < len; i++) {
1003
- const n1 = parseInt(s1[i] || "0", 10);
1004
- const n2 = parseInt(s2[i] || "0", 10);
1005
- if (n1 > n2) {
1006
- return 1;
1007
- } else if (n2 > n1) {
1008
- return -1;
1009
- }
1010
- }
1011
- const sp1 = s1[s1.length - 1];
1012
- const sp2 = s2[s2.length - 1];
1013
- if (sp1 && sp2) {
1014
- const p1 = sp1.split(".").map(parseSegment);
1015
- const p2 = sp2.split(".").map(parseSegment);
1016
- const len2 = Math.max(p1.length, p2.length);
1017
- for (let i = 0; i < len2; i++) {
1018
- if (p1[i] === void 0 || typeof p2[i] === "string" && typeof p1[i] === "number") {
1019
- return -1;
1020
- } else if (p2[i] === void 0 || typeof p1[i] === "string" && typeof p2[i] === "number") {
1021
- return 1;
1022
- } else if (p1[i] > p2[i]) {
1023
- return 1;
1024
- } else if (p2[i] > p1[i]) {
1025
- return -1;
1026
- }
1027
- }
1028
- } else if (sp1 || sp2) {
1029
- return sp1 ? -1 : 1;
1030
- }
1031
- return 0;
1032
- }
1033
- function compare(v1, v2, operator) {
1034
- const res = compareVersions(v1, v2);
1035
- return operatorResMap[operator].indexOf(res) > -1;
1036
- }
1037
- function satisfies(v, r) {
1038
- if (!acceptsAll.includes(r)) {
1039
- const match = r.match(/^([<>=~^]+)/);
1040
- const op = match ? match[1] : "=";
1041
- if (op !== "^" && op !== "~") {
1042
- return compare(v, r, op);
1043
- }
1044
- const [v1, v2, v3] = validateAndParse(v);
1045
- const [m1, m2, m3] = validateAndParse(r);
1046
- if (compareStrings(v1, m1) !== 0) {
1047
- return false;
1048
- } else if (op === "^") {
1049
- return compareSegments([v2, v3], [m2, m3]) >= 0;
1050
- } else if (compareStrings(v2, m2) !== 0) {
1051
- return false;
1052
- }
1053
- return compareStrings(v3, m3) >= 0;
1054
- }
1055
- return true;
1056
- }
1057
- function checkVersion(desired, actual) {
1058
- if (!satisfies(actual, desired)) {
1059
- (0, log_1.log)("warn", `The template was made for "piral-cli" version "${desired}" but was used with "${actual}".`);
1060
- }
1061
- }
1062
- exports.checkVersion = checkVersion;
1063
- }
1064
- });
1065
-
1066
- // ../../packages/template-utils/lib/parent.js
1067
- var require_parent = __commonJS({
1068
- "../../packages/template-utils/lib/parent.js"(exports) {
1069
- "use strict";
1070
- Object.defineProperty(exports, "__esModule", { value: true });
1071
- exports.configure = exports.LogLevels = exports.ForceOverwrite = void 0;
1072
- var path_1 = require("path");
1073
- var log_1 = require_log();
1074
- var version_1 = require_version();
1075
- var ForceOverwrite;
1076
- (function(ForceOverwrite2) {
1077
- ForceOverwrite2[ForceOverwrite2["no"] = 0] = "no";
1078
- ForceOverwrite2[ForceOverwrite2["prompt"] = 1] = "prompt";
1079
- ForceOverwrite2[ForceOverwrite2["yes"] = 2] = "yes";
1080
- })(ForceOverwrite = exports.ForceOverwrite || (exports.ForceOverwrite = {}));
1081
- var LogLevels;
1082
- (function(LogLevels2) {
1083
- LogLevels2[LogLevels2["disabled"] = 0] = "disabled";
1084
- LogLevels2[LogLevels2["error"] = 1] = "error";
1085
- LogLevels2[LogLevels2["warning"] = 2] = "warning";
1086
- LogLevels2[LogLevels2["info"] = 3] = "info";
1087
- LogLevels2[LogLevels2["verbose"] = 4] = "verbose";
1088
- LogLevels2[LogLevels2["debug"] = 5] = "debug";
1089
- })(LogLevels = exports.LogLevels || (exports.LogLevels = {}));
1090
- function configure(root2, details) {
1091
- var _a, _b;
1092
- if (details) {
1093
- const packageJsonPath = (0, path_1.resolve)(root2, "package.json");
1094
- const templateProject = require(packageJsonPath);
1095
- const desiredVersion = (_b = (_a = templateProject.engines) === null || _a === void 0 ? void 0 : _a.piral) !== null && _b !== void 0 ? _b : "*";
1096
- switch (details.logLevel) {
1097
- case LogLevels.disabled:
1098
- (0, log_1.setLogLevel)("disabled");
1099
- break;
1100
- case LogLevels.error:
1101
- (0, log_1.setLogLevel)("error");
1102
- break;
1103
- case LogLevels.warning:
1104
- (0, log_1.setLogLevel)("warn");
1105
- break;
1106
- case LogLevels.info:
1107
- (0, log_1.setLogLevel)("info");
1108
- break;
1109
- case LogLevels.verbose:
1110
- case LogLevels.debug:
1111
- (0, log_1.setLogLevel)("verbose");
1112
- break;
1113
- }
1114
- (0, version_1.checkVersion)(desiredVersion, details.cliVersion);
1115
- } else {
1116
- (0, log_1.log)("warn", `The used version of the "piral-cli" is outdated. The templating may still work - if not you should use a more recent version of the "piral-cli".`);
1117
- }
1118
- }
1119
- exports.configure = configure;
1120
- }
1121
- });
1122
-
1123
- // ../../packages/template-utils/lib/utils.js
1124
- var require_utils2 = __commonJS({
1125
- "../../packages/template-utils/lib/utils.js"(exports) {
1126
- "use strict";
1127
- Object.defineProperty(exports, "__esModule", { value: true });
1128
- exports.getLanguageExtension = exports.getPlugins = exports.getPiralInstance = exports.getPackageJsonWithSource = void 0;
1129
- var path_1 = require("path");
1130
- var fs_1 = require("fs");
1131
- var log_1 = require_log();
1132
- function getPackageJsonWithSource(root2, targetDir, fileName) {
1133
- const absPath = path_1.posix.join(targetDir, fileName);
1134
- const path = (0, path_1.isAbsolute)(absPath) ? (0, path_1.relative)(root2, absPath) : absPath;
1135
- (0, log_1.log)("verbose", `Adding "source" to package.json: "${path}"`);
1136
- return {
1137
- languages: ["ts", "js"],
1138
- name: "package.json",
1139
- content: JSON.stringify({ source: path }),
1140
- target: "<root>/package.json"
1141
- };
1142
- }
1143
- exports.getPackageJsonWithSource = getPackageJsonWithSource;
1144
- function getPiralInstance2(root2, sourceName) {
1145
- try {
1146
- const packageJsonPath = require.resolve(`${sourceName}/package.json`, {
1147
- paths: [root2]
1148
- });
1149
- (0, log_1.log)("verbose", `Found package JSON in "${packageJsonPath}"`);
1150
- const sourcePath = (0, path_1.dirname)(packageJsonPath);
1151
- const details = require(packageJsonPath);
1152
- const types = details.types || details.typings;
1153
- (0, log_1.log)("verbose", `Looking for types in "${types}"`);
1154
- const typingsPath = types !== void 0 ? (0, path_1.resolve)(sourcePath, types) : void 0;
1155
- const app = details.app;
1156
- (0, log_1.log)("verbose", `Looking for types in "${app}"`);
1157
- const appPath = app !== void 0 ? (0, path_1.resolve)(sourcePath, app) : void 0;
1158
- return {
1159
- sourceName,
1160
- sourcePath,
1161
- details,
1162
- appPath,
1163
- typingsPath
1164
- };
1165
- } catch (ex) {
1166
- (0, log_1.log)("error", `Error when getting Piral instance: ${ex}`);
1167
- }
1168
- return void 0;
1169
- }
1170
- exports.getPiralInstance = getPiralInstance2;
1171
- function getPlugins(root2, sourceName) {
1172
- const plugins = {};
1173
- (0, log_1.log)("verbose", `Getting the plugins of "${sourceName}/package.json" ...`);
1174
- const piralInstance = getPiralInstance2(root2, sourceName);
1175
- const typingsPath = piralInstance === null || piralInstance === void 0 ? void 0 : piralInstance.typingsPath;
1176
- if (typingsPath) {
1177
- (0, log_1.log)("verbose", `Reading file in "${typingsPath}"`);
1178
- const typing = (0, fs_1.readFileSync)(typingsPath, "utf8");
1179
- const match = /export interface PiletCustomApi extends (.*?) \{/g.exec(typing);
1180
- if (!match) {
1181
- (0, log_1.log)("verbose", `No Piral instance plugins have been found`);
1182
- return [];
1183
- }
1184
- const apis = match[1].split(", ");
1185
- (0, log_1.log)("verbose", `Found Piral instance plugins "${match[1]}"`);
1186
- for (const api of apis) {
1187
- const pluginMatch = /^Pilet(.*)Api$/.exec(api);
1188
- if (pluginMatch) {
1189
- const name = pluginMatch[1].toLowerCase();
1190
- plugins[name] = true;
1191
- } else {
1192
- (0, log_1.log)("warn", `Could not find plugin for Pilet API "${api}"`);
1193
- }
1194
- }
1195
- }
1196
- return plugins;
1197
- }
1198
- exports.getPlugins = getPlugins;
1199
- function getLanguageExtension(language, isJsx = true) {
1200
- switch (language) {
1201
- case "js":
1202
- return isJsx ? ".jsx" : ".js";
1203
- case "ts":
1204
- default:
1205
- return isJsx ? ".tsx" : ".ts";
1206
- }
1207
- }
1208
- exports.getLanguageExtension = getLanguageExtension;
1209
- }
1210
- });
1211
-
1212
1231
  // ../../packages/template-utils/lib/factory.js
1213
1232
  var require_factory = __commonJS({
1214
1233
  "../../packages/template-utils/lib/factory.js"(exports) {
@@ -1244,8 +1263,8 @@ var require_factory = __commonJS({
1244
1263
  exports.createPiralTemplateFactory = exports.createPiletTemplateFactory = void 0;
1245
1264
  var path_1 = require("path");
1246
1265
  var io_1 = require_io();
1247
- var template_1 = require_template();
1248
1266
  var parent_1 = require_parent();
1267
+ var template_1 = require_template();
1249
1268
  var utils_1 = require_utils2();
1250
1269
  function createPiletTemplateFactory2(templateRoot, getAllSources, defaultArgs = {}) {
1251
1270
  const sourceDir = (0, path_1.resolve)(templateRoot, "templates");
@@ -1255,7 +1274,7 @@ var require_factory = __commonJS({
1255
1274
  const { language = "ts", sourceName, src = "<root>/src", plugins = (0, utils_1.getPlugins)(projectRoot, sourceName), mocks = "<src>/mocks" } = allArgs;
1256
1275
  const allSources = getAllSources(projectRoot, allArgs, details);
1257
1276
  const sources = allSources.filter((m) => m.languages.includes(language));
1258
- const data = Object.assign(Object.assign({}, allArgs), {
1277
+ const data = (0, template_1.normalizeData)(Object.assign(Object.assign({}, allArgs), {
1259
1278
  language,
1260
1279
  plugins,
1261
1280
  projectRoot,
@@ -1264,7 +1283,7 @@ var require_factory = __commonJS({
1264
1283
  extension: (0, utils_1.getLanguageExtension)(language),
1265
1284
  src,
1266
1285
  mocks
1267
- });
1286
+ }));
1268
1287
  const defaultSource = (0, utils_1.getPackageJsonWithSource)(data.projectRoot, data.src, `index${data.extension}`);
1269
1288
  const files = yield Promise.all([...sources, defaultSource].map((source) => (0, template_1.getFileFromTemplate)(sourceDir, source, data)));
1270
1289
  return (0, io_1.mergeFiles)(files);
@@ -1279,7 +1298,7 @@ var require_factory = __commonJS({
1279
1298
  const { language = "ts", packageName = "piral", mocks = "<src>/mocks", src = "<root>/src", title = "My Piral Instance", reactVersion = 17, plugins = [] } = allArgs;
1280
1299
  const allSources = getAllSources(projectRoot, allArgs, details);
1281
1300
  const sources = allSources.filter((m) => m.languages.includes(language) && m.frameworks.includes(packageName));
1282
- const data = Object.assign(Object.assign({}, allArgs), {
1301
+ const data = (0, template_1.normalizeData)(Object.assign(Object.assign({}, allArgs), {
1283
1302
  title,
1284
1303
  language,
1285
1304
  plugins,
@@ -1290,7 +1309,7 @@ var require_factory = __commonJS({
1290
1309
  extension: (0, utils_1.getLanguageExtension)(language, packageName !== "piral-base"),
1291
1310
  src,
1292
1311
  mocks
1293
- });
1312
+ }));
1294
1313
  const files = yield Promise.all(sources.map((source) => (0, template_1.getFileFromTemplate)(sourceDir, source, data)));
1295
1314
  return (0, io_1.mergeFiles)(files);
1296
1315
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smapiot/pilet-template-angular",
3
- "version": "0.15.1",
3
+ "version": "0.15.2-beta.4952",
4
4
  "description": "Official scaffolding template for pilets: 'angular'.",
5
5
  "keywords": [
6
6
  "piral-cli",
@@ -54,7 +54,7 @@
54
54
  "test": "echo \"Error: run tests from root\" && exit 1"
55
55
  },
56
56
  "devDependencies": {
57
- "@smapiot/template-utils": "^0.15.1"
57
+ "@smapiot/template-utils": "0.15.2-beta.4952"
58
58
  },
59
- "gitHead": "39215a41e828687ea1bd7632d294ae088690b69f"
59
+ "gitHead": "712a6b4ef4891de3b9e3922f6a798ffe4c6f07d5"
60
60
  }