@ingenyus/swarm-wasp 1.0.3 → 1.2.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 +14 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.d.ts.map +1 -1
- package/dist/common/index.js +81 -0
- package/dist/common/wasp-compatibility.d.ts +10 -0
- package/dist/common/wasp-compatibility.d.ts.map +1 -0
- package/dist/common/wasp-compatibility.js +82 -0
- package/dist/generators/action/action-generator.d.ts.map +1 -1
- package/dist/generators/action/action-generator.js +102 -13
- package/dist/generators/action/index.js +102 -13
- package/dist/generators/action/schema.js +7 -0
- package/dist/generators/api/api-generator.d.ts.map +1 -1
- package/dist/generators/api/api-generator.js +104 -15
- package/dist/generators/api/index.js +104 -15
- package/dist/generators/api/schema.js +7 -0
- package/dist/generators/api-namespace/api-namespace-generator.d.ts.map +1 -1
- package/dist/generators/api-namespace/api-namespace-generator.js +104 -15
- package/dist/generators/api-namespace/index.js +104 -15
- package/dist/generators/api-namespace/schema.js +7 -0
- package/dist/generators/base/component-generator.base.js +101 -13
- package/dist/generators/base/index.js +101 -13
- package/dist/generators/base/operation-generator.base.js +101 -13
- package/dist/generators/base/wasp-generator.base.d.ts +5 -0
- package/dist/generators/base/wasp-generator.base.d.ts.map +1 -1
- package/dist/generators/base/wasp-generator.base.js +93 -6
- package/dist/generators/config/index.js +11 -4
- package/dist/generators/config/wasp-config-generator.js +11 -4
- package/dist/generators/crud/crud-generator.d.ts.map +1 -1
- package/dist/generators/crud/crud-generator.js +102 -13
- package/dist/generators/crud/index.js +102 -13
- package/dist/generators/crud/schema.js +7 -0
- package/dist/generators/feature/feature-generator.d.ts.map +1 -1
- package/dist/generators/feature/feature-generator.js +98 -10
- package/dist/generators/feature/index.js +98 -10
- package/dist/generators/feature/schema.js +7 -0
- package/dist/generators/index.js +112 -17
- package/dist/generators/job/index.js +102 -13
- package/dist/generators/job/job-generator.d.ts.map +1 -1
- package/dist/generators/job/job-generator.js +102 -13
- package/dist/generators/job/schema.js +7 -0
- package/dist/generators/query/index.js +102 -13
- package/dist/generators/query/query-generator.d.ts.map +1 -1
- package/dist/generators/query/query-generator.js +102 -13
- package/dist/generators/query/schema.js +7 -0
- package/dist/generators/route/index.js +102 -13
- package/dist/generators/route/route-generator.d.ts.map +1 -1
- package/dist/generators/route/route-generator.js +102 -13
- package/dist/generators/route/schema.js +7 -0
- package/dist/index.js +120 -25
- package/package.json +11 -6
package/dist/generators/index.js
CHANGED
|
@@ -396,22 +396,102 @@ var TemplateUtility = class {
|
|
|
396
396
|
}
|
|
397
397
|
};
|
|
398
398
|
|
|
399
|
+
// src/common/wasp-compatibility.ts
|
|
400
|
+
import { findPackageJson, getVersion } from "@ingenyus/swarm";
|
|
401
|
+
import { execSync } from "child_process";
|
|
402
|
+
import path4 from "path";
|
|
403
|
+
import { fileURLToPath } from "url";
|
|
404
|
+
import * as semver from "semver";
|
|
405
|
+
var cachedSupportedRange = null;
|
|
406
|
+
function getWaspSupportedRange() {
|
|
407
|
+
if (cachedSupportedRange) {
|
|
408
|
+
return cachedSupportedRange;
|
|
409
|
+
}
|
|
410
|
+
const currentFile = fileURLToPath(import.meta.url);
|
|
411
|
+
const currentDir = path4.dirname(currentFile);
|
|
412
|
+
const result = findPackageJson(currentDir, {
|
|
413
|
+
packageName: "@ingenyus/swarm-wasp"
|
|
414
|
+
});
|
|
415
|
+
if (!result) {
|
|
416
|
+
throw new Error(
|
|
417
|
+
"Unable to find package.json for @ingenyus/swarm-wasp. Wasp supported version range must be specified in swarm.wasp field."
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
const swarm = result.packageJson.swarm;
|
|
421
|
+
const waspRange = swarm?.wasp;
|
|
422
|
+
if (!waspRange) {
|
|
423
|
+
throw new Error(
|
|
424
|
+
`Wasp supported version range not found in package.json. Please specify swarm.wasp field in @ingenyus/swarm-wasp package.json (e.g., "swarm": { "wasp": ">=0.18.0 <0.20.0" }).`
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
cachedSupportedRange = waspRange;
|
|
428
|
+
return cachedSupportedRange;
|
|
429
|
+
}
|
|
430
|
+
function getInstalledWaspVersion(logger) {
|
|
431
|
+
try {
|
|
432
|
+
const output = execSync("wasp version", {
|
|
433
|
+
encoding: "utf8",
|
|
434
|
+
stdio: "pipe"
|
|
435
|
+
});
|
|
436
|
+
const firstLine = output.split("\n")[0]?.trim();
|
|
437
|
+
if (!firstLine) {
|
|
438
|
+
logger.error(
|
|
439
|
+
"Unable to parse Wasp version from command output. Expected version number on first line."
|
|
440
|
+
);
|
|
441
|
+
throw new Error("Unable to parse Wasp version from command output");
|
|
442
|
+
}
|
|
443
|
+
if (!semver.valid(firstLine)) {
|
|
444
|
+
logger.error(
|
|
445
|
+
`Invalid Wasp version format: "${firstLine}". Expected a valid semver version (e.g., "0.18.2").`
|
|
446
|
+
);
|
|
447
|
+
throw new Error("Invalid Wasp version format");
|
|
448
|
+
}
|
|
449
|
+
return firstLine;
|
|
450
|
+
} catch (error) {
|
|
451
|
+
if (error.code === "ENOENT" || error.message?.includes("wasp")) {
|
|
452
|
+
logger.error(
|
|
453
|
+
"Wasp CLI not found. Install using: curl -sSL https://get.wasp.sh/installer.sh | sh -s"
|
|
454
|
+
);
|
|
455
|
+
throw new Error("Wasp CLI not found");
|
|
456
|
+
}
|
|
457
|
+
throw new Error("Unable to determine installed Wasp version");
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
function isTestEnvironment() {
|
|
461
|
+
return process.env.NODE_ENV === "test" || process.env.VITEST === "true" || typeof process.env.VITEST !== "undefined";
|
|
462
|
+
}
|
|
463
|
+
function assertWaspCompatible(logger) {
|
|
464
|
+
if (isTestEnvironment()) {
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
const version = getInstalledWaspVersion(logger);
|
|
468
|
+
const supportedRange = getWaspSupportedRange();
|
|
469
|
+
if (!semver.satisfies(version, supportedRange)) {
|
|
470
|
+
const startDir = path4.dirname(fileURLToPath(import.meta.url));
|
|
471
|
+
const packageVersion = getVersion("@ingenyus/swarm-wasp", startDir);
|
|
472
|
+
logger.error(
|
|
473
|
+
`Incompatible Wasp version detected: ${version}. @ingenyus/swarm-wasp@${packageVersion} supports Wasp ${supportedRange}.`
|
|
474
|
+
);
|
|
475
|
+
throw new Error("Incompatible Wasp version");
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
399
479
|
// src/generators/base/component-generator.base.ts
|
|
400
480
|
import {
|
|
401
481
|
hasHelperMethodCall,
|
|
402
482
|
toKebabCase as toKebabCase2
|
|
403
483
|
} from "@ingenyus/swarm";
|
|
404
|
-
import
|
|
484
|
+
import path7 from "path";
|
|
405
485
|
|
|
406
486
|
// src/generators/feature/feature-generator.ts
|
|
407
487
|
import { handleFatalError as handleFatalError2 } from "@ingenyus/swarm";
|
|
408
|
-
import
|
|
488
|
+
import path6 from "path";
|
|
409
489
|
|
|
410
490
|
// src/generators/base/wasp-generator.base.ts
|
|
411
491
|
import {
|
|
412
492
|
GeneratorBase,
|
|
413
|
-
|
|
414
|
-
|
|
493
|
+
TemplateResolver,
|
|
494
|
+
getConfigManager
|
|
415
495
|
} from "@ingenyus/swarm";
|
|
416
496
|
|
|
417
497
|
// src/generators/config/wasp-config-generator.ts
|
|
@@ -420,14 +500,14 @@ import {
|
|
|
420
500
|
handleFatalError,
|
|
421
501
|
parseHelperMethodDefinition
|
|
422
502
|
} from "@ingenyus/swarm";
|
|
423
|
-
import
|
|
503
|
+
import path5 from "path";
|
|
424
504
|
var WaspConfigGenerator = class {
|
|
425
505
|
constructor(logger = getCLILogger(), fileSystem = realFileSystem) {
|
|
426
506
|
this.logger = logger;
|
|
427
507
|
this.fileSystem = fileSystem;
|
|
428
508
|
this.templateUtility = new TemplateUtility(fileSystem);
|
|
429
509
|
}
|
|
430
|
-
path =
|
|
510
|
+
path = path5;
|
|
431
511
|
templateUtility;
|
|
432
512
|
/**
|
|
433
513
|
* Gets the template path for feature config templates.
|
|
@@ -456,7 +536,7 @@ var WaspConfigGenerator = class {
|
|
|
456
536
|
this.logger.error(`Template not found: ${templatePath}`);
|
|
457
537
|
return;
|
|
458
538
|
}
|
|
459
|
-
const configFilePath =
|
|
539
|
+
const configFilePath = path5.join(featureDir, `feature.wasp.ts`);
|
|
460
540
|
if (this.fileSystem.existsSync(configFilePath)) {
|
|
461
541
|
this.logger.warn(`Feature config already exists: ${configFilePath}`);
|
|
462
542
|
return;
|
|
@@ -472,7 +552,7 @@ var WaspConfigGenerator = class {
|
|
|
472
552
|
*/
|
|
473
553
|
update(featurePath, declaration) {
|
|
474
554
|
const configDir = getFeatureDir(this.fileSystem, featurePath);
|
|
475
|
-
const configFilePath =
|
|
555
|
+
const configFilePath = path5.join(configDir, `feature.wasp.ts`);
|
|
476
556
|
if (!this.fileSystem.existsSync(configFilePath)) {
|
|
477
557
|
const templatePath = this.getTemplatePath("feature.wasp.eta");
|
|
478
558
|
if (!this.fileSystem.existsSync(templatePath)) {
|
|
@@ -868,6 +948,13 @@ var WaspGeneratorBase = class extends GeneratorBase {
|
|
|
868
948
|
this.templateUtility = new TemplateUtility(this.fileSystem);
|
|
869
949
|
this.templateResolver = new TemplateResolver(this.fileSystem);
|
|
870
950
|
}
|
|
951
|
+
/**
|
|
952
|
+
* Ensures that the installed Wasp version is compatible with this package.
|
|
953
|
+
* Should be called at the start of generator execution.
|
|
954
|
+
*/
|
|
955
|
+
ensureWaspCompatible() {
|
|
956
|
+
assertWaspCompatible(this.logger);
|
|
957
|
+
}
|
|
871
958
|
async loadConfig() {
|
|
872
959
|
if (this.configLoaded) return;
|
|
873
960
|
const configManager = getConfigManager();
|
|
@@ -984,21 +1071,22 @@ var FeatureGenerator = class extends WaspGeneratorBase {
|
|
|
984
1071
|
* @param target - The target path of the generated directory
|
|
985
1072
|
*/
|
|
986
1073
|
async generate(args) {
|
|
1074
|
+
this.ensureWaspCompatible();
|
|
987
1075
|
const { target } = args;
|
|
988
1076
|
const segments = validateFeaturePath(target);
|
|
989
1077
|
const normalisedPath = normaliseFeaturePath(target);
|
|
990
|
-
const sourceRoot =
|
|
1078
|
+
const sourceRoot = path6.join(findWaspRoot(this.fileSystem), "src");
|
|
991
1079
|
if (segments.length > 1) {
|
|
992
1080
|
const parentPath = segments.slice(0, -1).join("/");
|
|
993
1081
|
const parentNormalisedPath = normaliseFeaturePath(parentPath);
|
|
994
|
-
const parentFeatureDir =
|
|
1082
|
+
const parentFeatureDir = path6.join(sourceRoot, parentNormalisedPath);
|
|
995
1083
|
if (!this.fileSystem.existsSync(parentFeatureDir)) {
|
|
996
1084
|
handleFatalError2(
|
|
997
1085
|
`Parent feature '${parentPath}' does not exist. Please create it first.`
|
|
998
1086
|
);
|
|
999
1087
|
}
|
|
1000
1088
|
}
|
|
1001
|
-
const featureDir =
|
|
1089
|
+
const featureDir = path6.join(sourceRoot, normalisedPath);
|
|
1002
1090
|
this.fileSystem.mkdirSync(featureDir, { recursive: true });
|
|
1003
1091
|
this.configGenerator.generate(normalisedPath);
|
|
1004
1092
|
this.logger.success(`Generated feature: ${normalisedPath}`);
|
|
@@ -1033,7 +1121,7 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
1033
1121
|
const currentPath = pathSegments.join("/");
|
|
1034
1122
|
const featureName = pathSegments[pathSegments.length - 1];
|
|
1035
1123
|
const featureDir = getFeatureDir(this.fileSystem, currentPath);
|
|
1036
|
-
const configPath =
|
|
1124
|
+
const configPath = path7.join(featureDir, `feature.wasp.ts`);
|
|
1037
1125
|
if (this.fileSystem.existsSync(configPath)) {
|
|
1038
1126
|
return configPath;
|
|
1039
1127
|
}
|
|
@@ -1105,7 +1193,7 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
1105
1193
|
const featureDir = getFeatureDir(this.fileSystem, normalisedPath);
|
|
1106
1194
|
const typeKey = type.toLowerCase();
|
|
1107
1195
|
const typeDirectory = TYPE_DIRECTORIES[typeKey];
|
|
1108
|
-
const targetDirectory =
|
|
1196
|
+
const targetDirectory = path7.join(featureDir, typeDirectory);
|
|
1109
1197
|
const importDirectory = `@src/${normalisedPath}/${typeDirectory}`;
|
|
1110
1198
|
return { targetDirectory, importDirectory };
|
|
1111
1199
|
}
|
|
@@ -1471,6 +1559,7 @@ var ActionGenerator = class extends OperationGeneratorBase {
|
|
|
1471
1559
|
this.componentType,
|
|
1472
1560
|
operationName,
|
|
1473
1561
|
async () => {
|
|
1562
|
+
this.ensureWaspCompatible();
|
|
1474
1563
|
const configPath = this.validateFeatureConfig(feature);
|
|
1475
1564
|
const { targetDirectory: operationsDir, importDirectory } = this.ensureTargetDirectory(feature, operationType);
|
|
1476
1565
|
const importPath = `${importDirectory}/${operationName}`;
|
|
@@ -1565,6 +1654,7 @@ var ApiGenerator = class extends ComponentGeneratorBase {
|
|
|
1565
1654
|
async generate(args) {
|
|
1566
1655
|
const apiName = toCamelCase(args.name);
|
|
1567
1656
|
return this.handleGeneratorError(this.componentType, apiName, async () => {
|
|
1657
|
+
this.ensureWaspCompatible();
|
|
1568
1658
|
const configPath = this.validateFeatureConfig(args.feature);
|
|
1569
1659
|
const {
|
|
1570
1660
|
targetDirectory: apiTargetDirectory,
|
|
@@ -1611,7 +1701,7 @@ var ApiGenerator = class extends ComponentGeneratorBase {
|
|
|
1611
1701
|
force = false,
|
|
1612
1702
|
entities,
|
|
1613
1703
|
method,
|
|
1614
|
-
path:
|
|
1704
|
+
path: path9,
|
|
1615
1705
|
auth,
|
|
1616
1706
|
customMiddleware
|
|
1617
1707
|
} = args;
|
|
@@ -1621,7 +1711,7 @@ var ApiGenerator = class extends ComponentGeneratorBase {
|
|
|
1621
1711
|
feature,
|
|
1622
1712
|
Array.isArray(entities) ? entities : entities ? [entities] : [],
|
|
1623
1713
|
method,
|
|
1624
|
-
|
|
1714
|
+
path9,
|
|
1625
1715
|
apiFile,
|
|
1626
1716
|
auth,
|
|
1627
1717
|
importPath,
|
|
@@ -1677,7 +1767,7 @@ var ApiGenerator = class extends ComponentGeneratorBase {
|
|
|
1677
1767
|
|
|
1678
1768
|
// src/generators/api-namespace/api-namespace-generator.ts
|
|
1679
1769
|
import { toCamelCase as toCamelCase2 } from "@ingenyus/swarm";
|
|
1680
|
-
import
|
|
1770
|
+
import path8 from "path";
|
|
1681
1771
|
|
|
1682
1772
|
// src/generators/api-namespace/schema.ts
|
|
1683
1773
|
import { registerSchemaMetadata as registerSchemaMetadata4 } from "@ingenyus/swarm";
|
|
@@ -1714,12 +1804,13 @@ var ApiNamespaceGenerator = class extends ComponentGeneratorBase {
|
|
|
1714
1804
|
this.componentType,
|
|
1715
1805
|
namespaceName,
|
|
1716
1806
|
async () => {
|
|
1807
|
+
this.ensureWaspCompatible();
|
|
1717
1808
|
const configPath = this.validateFeatureConfig(feature);
|
|
1718
1809
|
const {
|
|
1719
1810
|
targetDirectory: apiTargetDirectory,
|
|
1720
1811
|
importDirectory: apiImportDirectory
|
|
1721
1812
|
} = this.ensureTargetDirectory(feature, "api");
|
|
1722
|
-
const middlewareTargetDirectory =
|
|
1813
|
+
const middlewareTargetDirectory = path8.join(
|
|
1723
1814
|
apiTargetDirectory,
|
|
1724
1815
|
"middleware"
|
|
1725
1816
|
);
|
|
@@ -1871,6 +1962,7 @@ var CrudGenerator = class extends OperationGeneratorBase {
|
|
|
1871
1962
|
const crudName = name || toCamelCase3(getPlural2(dataType));
|
|
1872
1963
|
const crudType = toPascalCase4(crudName);
|
|
1873
1964
|
return this.handleGeneratorError(this.componentType, crudName, async () => {
|
|
1965
|
+
this.ensureWaspCompatible();
|
|
1874
1966
|
const configPath = this.validateFeatureConfig(feature);
|
|
1875
1967
|
const { targetDirectory } = this.ensureTargetDirectory(
|
|
1876
1968
|
feature,
|
|
@@ -2119,6 +2211,7 @@ var JobGenerator = class extends ComponentGeneratorBase {
|
|
|
2119
2211
|
async generate(args) {
|
|
2120
2212
|
const jobName = toCamelCase4(args.name);
|
|
2121
2213
|
return this.handleGeneratorError(this.componentType, jobName, async () => {
|
|
2214
|
+
this.ensureWaspCompatible();
|
|
2122
2215
|
const configPath = this.validateFeatureConfig(args.feature);
|
|
2123
2216
|
const { targetDirectory } = this.ensureTargetDirectory(
|
|
2124
2217
|
args.feature,
|
|
@@ -2260,6 +2353,7 @@ var QueryGenerator = class extends OperationGeneratorBase {
|
|
|
2260
2353
|
this.componentType,
|
|
2261
2354
|
operationName,
|
|
2262
2355
|
async () => {
|
|
2356
|
+
this.ensureWaspCompatible();
|
|
2263
2357
|
const configPath = this.validateFeatureConfig(feature);
|
|
2264
2358
|
const { targetDirectory: operationsDir, importDirectory } = this.ensureTargetDirectory(feature, operationType);
|
|
2265
2359
|
const importPath = `${importDirectory}/${operationName}`;
|
|
@@ -2336,6 +2430,7 @@ var RouteGenerator = class extends ComponentGeneratorBase {
|
|
|
2336
2430
|
this.componentType,
|
|
2337
2431
|
routeName,
|
|
2338
2432
|
async () => {
|
|
2433
|
+
this.ensureWaspCompatible();
|
|
2339
2434
|
const configPath = this.validateFeatureConfig(feature);
|
|
2340
2435
|
const { targetDirectory } = this.ensureTargetDirectory(feature, "page");
|
|
2341
2436
|
const targetFile = `${targetDirectory}/${fileName}`;
|
|
@@ -224,22 +224,102 @@ var TemplateUtility = class {
|
|
|
224
224
|
}
|
|
225
225
|
};
|
|
226
226
|
|
|
227
|
+
// src/common/wasp-compatibility.ts
|
|
228
|
+
import { findPackageJson, getVersion } from "@ingenyus/swarm";
|
|
229
|
+
import { execSync } from "child_process";
|
|
230
|
+
import path4 from "path";
|
|
231
|
+
import { fileURLToPath } from "url";
|
|
232
|
+
import * as semver from "semver";
|
|
233
|
+
var cachedSupportedRange = null;
|
|
234
|
+
function getWaspSupportedRange() {
|
|
235
|
+
if (cachedSupportedRange) {
|
|
236
|
+
return cachedSupportedRange;
|
|
237
|
+
}
|
|
238
|
+
const currentFile = fileURLToPath(import.meta.url);
|
|
239
|
+
const currentDir = path4.dirname(currentFile);
|
|
240
|
+
const result = findPackageJson(currentDir, {
|
|
241
|
+
packageName: "@ingenyus/swarm-wasp"
|
|
242
|
+
});
|
|
243
|
+
if (!result) {
|
|
244
|
+
throw new Error(
|
|
245
|
+
"Unable to find package.json for @ingenyus/swarm-wasp. Wasp supported version range must be specified in swarm.wasp field."
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
const swarm = result.packageJson.swarm;
|
|
249
|
+
const waspRange = swarm?.wasp;
|
|
250
|
+
if (!waspRange) {
|
|
251
|
+
throw new Error(
|
|
252
|
+
`Wasp supported version range not found in package.json. Please specify swarm.wasp field in @ingenyus/swarm-wasp package.json (e.g., "swarm": { "wasp": ">=0.18.0 <0.20.0" }).`
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
cachedSupportedRange = waspRange;
|
|
256
|
+
return cachedSupportedRange;
|
|
257
|
+
}
|
|
258
|
+
function getInstalledWaspVersion(logger) {
|
|
259
|
+
try {
|
|
260
|
+
const output = execSync("wasp version", {
|
|
261
|
+
encoding: "utf8",
|
|
262
|
+
stdio: "pipe"
|
|
263
|
+
});
|
|
264
|
+
const firstLine = output.split("\n")[0]?.trim();
|
|
265
|
+
if (!firstLine) {
|
|
266
|
+
logger.error(
|
|
267
|
+
"Unable to parse Wasp version from command output. Expected version number on first line."
|
|
268
|
+
);
|
|
269
|
+
throw new Error("Unable to parse Wasp version from command output");
|
|
270
|
+
}
|
|
271
|
+
if (!semver.valid(firstLine)) {
|
|
272
|
+
logger.error(
|
|
273
|
+
`Invalid Wasp version format: "${firstLine}". Expected a valid semver version (e.g., "0.18.2").`
|
|
274
|
+
);
|
|
275
|
+
throw new Error("Invalid Wasp version format");
|
|
276
|
+
}
|
|
277
|
+
return firstLine;
|
|
278
|
+
} catch (error) {
|
|
279
|
+
if (error.code === "ENOENT" || error.message?.includes("wasp")) {
|
|
280
|
+
logger.error(
|
|
281
|
+
"Wasp CLI not found. Install using: curl -sSL https://get.wasp.sh/installer.sh | sh -s"
|
|
282
|
+
);
|
|
283
|
+
throw new Error("Wasp CLI not found");
|
|
284
|
+
}
|
|
285
|
+
throw new Error("Unable to determine installed Wasp version");
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function isTestEnvironment() {
|
|
289
|
+
return process.env.NODE_ENV === "test" || process.env.VITEST === "true" || typeof process.env.VITEST !== "undefined";
|
|
290
|
+
}
|
|
291
|
+
function assertWaspCompatible(logger) {
|
|
292
|
+
if (isTestEnvironment()) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
const version = getInstalledWaspVersion(logger);
|
|
296
|
+
const supportedRange = getWaspSupportedRange();
|
|
297
|
+
if (!semver.satisfies(version, supportedRange)) {
|
|
298
|
+
const startDir = path4.dirname(fileURLToPath(import.meta.url));
|
|
299
|
+
const packageVersion = getVersion("@ingenyus/swarm-wasp", startDir);
|
|
300
|
+
logger.error(
|
|
301
|
+
`Incompatible Wasp version detected: ${version}. @ingenyus/swarm-wasp@${packageVersion} supports Wasp ${supportedRange}.`
|
|
302
|
+
);
|
|
303
|
+
throw new Error("Incompatible Wasp version");
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
227
307
|
// src/generators/base/component-generator.base.ts
|
|
228
308
|
import {
|
|
229
309
|
hasHelperMethodCall,
|
|
230
310
|
toKebabCase as toKebabCase2
|
|
231
311
|
} from "@ingenyus/swarm";
|
|
232
|
-
import
|
|
312
|
+
import path7 from "path";
|
|
233
313
|
|
|
234
314
|
// src/generators/feature/feature-generator.ts
|
|
235
315
|
import { handleFatalError as handleFatalError2 } from "@ingenyus/swarm";
|
|
236
|
-
import
|
|
316
|
+
import path6 from "path";
|
|
237
317
|
|
|
238
318
|
// src/generators/base/wasp-generator.base.ts
|
|
239
319
|
import {
|
|
240
320
|
GeneratorBase,
|
|
241
|
-
|
|
242
|
-
|
|
321
|
+
TemplateResolver,
|
|
322
|
+
getConfigManager
|
|
243
323
|
} from "@ingenyus/swarm";
|
|
244
324
|
|
|
245
325
|
// src/generators/config/wasp-config-generator.ts
|
|
@@ -248,14 +328,14 @@ import {
|
|
|
248
328
|
handleFatalError,
|
|
249
329
|
parseHelperMethodDefinition
|
|
250
330
|
} from "@ingenyus/swarm";
|
|
251
|
-
import
|
|
331
|
+
import path5 from "path";
|
|
252
332
|
var WaspConfigGenerator = class {
|
|
253
333
|
constructor(logger = getCLILogger(), fileSystem = realFileSystem) {
|
|
254
334
|
this.logger = logger;
|
|
255
335
|
this.fileSystem = fileSystem;
|
|
256
336
|
this.templateUtility = new TemplateUtility(fileSystem);
|
|
257
337
|
}
|
|
258
|
-
path =
|
|
338
|
+
path = path5;
|
|
259
339
|
templateUtility;
|
|
260
340
|
/**
|
|
261
341
|
* Gets the template path for feature config templates.
|
|
@@ -284,7 +364,7 @@ var WaspConfigGenerator = class {
|
|
|
284
364
|
this.logger.error(`Template not found: ${templatePath}`);
|
|
285
365
|
return;
|
|
286
366
|
}
|
|
287
|
-
const configFilePath =
|
|
367
|
+
const configFilePath = path5.join(featureDir, `feature.wasp.ts`);
|
|
288
368
|
if (this.fileSystem.existsSync(configFilePath)) {
|
|
289
369
|
this.logger.warn(`Feature config already exists: ${configFilePath}`);
|
|
290
370
|
return;
|
|
@@ -300,7 +380,7 @@ var WaspConfigGenerator = class {
|
|
|
300
380
|
*/
|
|
301
381
|
update(featurePath, declaration) {
|
|
302
382
|
const configDir = getFeatureDir(this.fileSystem, featurePath);
|
|
303
|
-
const configFilePath =
|
|
383
|
+
const configFilePath = path5.join(configDir, `feature.wasp.ts`);
|
|
304
384
|
if (!this.fileSystem.existsSync(configFilePath)) {
|
|
305
385
|
const templatePath = this.getTemplatePath("feature.wasp.eta");
|
|
306
386
|
if (!this.fileSystem.existsSync(templatePath)) {
|
|
@@ -696,6 +776,13 @@ var WaspGeneratorBase = class extends GeneratorBase {
|
|
|
696
776
|
this.templateUtility = new TemplateUtility(this.fileSystem);
|
|
697
777
|
this.templateResolver = new TemplateResolver(this.fileSystem);
|
|
698
778
|
}
|
|
779
|
+
/**
|
|
780
|
+
* Ensures that the installed Wasp version is compatible with this package.
|
|
781
|
+
* Should be called at the start of generator execution.
|
|
782
|
+
*/
|
|
783
|
+
ensureWaspCompatible() {
|
|
784
|
+
assertWaspCompatible(this.logger);
|
|
785
|
+
}
|
|
699
786
|
async loadConfig() {
|
|
700
787
|
if (this.configLoaded) return;
|
|
701
788
|
const configManager = getConfigManager();
|
|
@@ -812,21 +899,22 @@ var FeatureGenerator = class extends WaspGeneratorBase {
|
|
|
812
899
|
* @param target - The target path of the generated directory
|
|
813
900
|
*/
|
|
814
901
|
async generate(args) {
|
|
902
|
+
this.ensureWaspCompatible();
|
|
815
903
|
const { target } = args;
|
|
816
904
|
const segments = validateFeaturePath(target);
|
|
817
905
|
const normalisedPath = normaliseFeaturePath(target);
|
|
818
|
-
const sourceRoot =
|
|
906
|
+
const sourceRoot = path6.join(findWaspRoot(this.fileSystem), "src");
|
|
819
907
|
if (segments.length > 1) {
|
|
820
908
|
const parentPath = segments.slice(0, -1).join("/");
|
|
821
909
|
const parentNormalisedPath = normaliseFeaturePath(parentPath);
|
|
822
|
-
const parentFeatureDir =
|
|
910
|
+
const parentFeatureDir = path6.join(sourceRoot, parentNormalisedPath);
|
|
823
911
|
if (!this.fileSystem.existsSync(parentFeatureDir)) {
|
|
824
912
|
handleFatalError2(
|
|
825
913
|
`Parent feature '${parentPath}' does not exist. Please create it first.`
|
|
826
914
|
);
|
|
827
915
|
}
|
|
828
916
|
}
|
|
829
|
-
const featureDir =
|
|
917
|
+
const featureDir = path6.join(sourceRoot, normalisedPath);
|
|
830
918
|
this.fileSystem.mkdirSync(featureDir, { recursive: true });
|
|
831
919
|
this.configGenerator.generate(normalisedPath);
|
|
832
920
|
this.logger.success(`Generated feature: ${normalisedPath}`);
|
|
@@ -861,7 +949,7 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
861
949
|
const currentPath = pathSegments.join("/");
|
|
862
950
|
const featureName = pathSegments[pathSegments.length - 1];
|
|
863
951
|
const featureDir = getFeatureDir(this.fileSystem, currentPath);
|
|
864
|
-
const configPath =
|
|
952
|
+
const configPath = path7.join(featureDir, `feature.wasp.ts`);
|
|
865
953
|
if (this.fileSystem.existsSync(configPath)) {
|
|
866
954
|
return configPath;
|
|
867
955
|
}
|
|
@@ -933,7 +1021,7 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
933
1021
|
const featureDir = getFeatureDir(this.fileSystem, normalisedPath);
|
|
934
1022
|
const typeKey = type.toLowerCase();
|
|
935
1023
|
const typeDirectory = TYPE_DIRECTORIES[typeKey];
|
|
936
|
-
const targetDirectory =
|
|
1024
|
+
const targetDirectory = path7.join(featureDir, typeDirectory);
|
|
937
1025
|
const importDirectory = `@src/${normalisedPath}/${typeDirectory}`;
|
|
938
1026
|
return { targetDirectory, importDirectory };
|
|
939
1027
|
}
|
|
@@ -1078,6 +1166,7 @@ var JobGenerator = class extends ComponentGeneratorBase {
|
|
|
1078
1166
|
async generate(args) {
|
|
1079
1167
|
const jobName = toCamelCase(args.name);
|
|
1080
1168
|
return this.handleGeneratorError(this.componentType, jobName, async () => {
|
|
1169
|
+
this.ensureWaspCompatible();
|
|
1081
1170
|
const configPath = this.validateFeatureConfig(args.feature);
|
|
1082
1171
|
const { targetDirectory } = this.ensureTargetDirectory(
|
|
1083
1172
|
args.feature,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"job-generator.d.ts","sourceRoot":"","sources":["../../../src/generators/job/job-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EACjB,GAAG,EAEJ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,qBAAa,YAAa,SAAQ,sBAAsB,CACtD,OAAO,MAAM,EACb,OAAO,YAAY,CAAC,GAAG,CACxB;IACC,SAAS,KAAK,aAAa,UAE1B;IAED,WAAW,SAA0B;IACrC,MAAM;;;;;;;qCAAU;gBAEJ,QAAQ,EAAE,iBAAiB;IAIjC,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"job-generator.d.ts","sourceRoot":"","sources":["../../../src/generators/job/job-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EACjB,GAAG,EAEJ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,qBAAa,YAAa,SAAQ,sBAAsB,CACtD,OAAO,MAAM,EACb,OAAO,YAAY,CAAC,GAAG,CACxB;IACC,SAAS,KAAK,aAAa,UAE1B;IAED,WAAW,SAA0B;IACrC,MAAM;;;;;;;qCAAU;gBAEJ,QAAQ,EAAE,iBAAiB;IAIjC,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;YAkBzC,eAAe;IA4B7B,OAAO,CAAC,gBAAgB;IA6BxB;;OAEG;IACH,aAAa,CACX,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAAE,EAClB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX,MAAM;CAUV"}
|