@ingenyus/swarm-wasp 0.2.0 → 0.2.2
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/dist/.tsbuildinfo +1 -1
- package/dist/common/index.d.ts +0 -1
- package/dist/common/index.d.ts.map +1 -1
- package/dist/common/index.js +9 -34
- package/dist/generators/action/action-generator.js +50 -58
- package/dist/generators/action/index.js +50 -58
- package/dist/generators/action/schema.js +1 -5
- package/dist/generators/api/api-generator.js +51 -59
- package/dist/generators/api/index.js +51 -59
- package/dist/generators/api/schema.js +1 -5
- package/dist/generators/api-namespace/api-namespace-generator.js +51 -59
- package/dist/generators/api-namespace/index.js +51 -59
- package/dist/generators/api-namespace/schema.js +1 -5
- package/dist/generators/base/component-generator.base.d.ts +4 -7
- package/dist/generators/base/component-generator.base.d.ts.map +1 -1
- package/dist/generators/base/component-generator.base.js +49 -57
- package/dist/generators/base/index.js +50 -58
- package/dist/generators/base/operation-generator.base.js +50 -58
- package/dist/generators/base/wasp-generator.base.d.ts +3 -5
- package/dist/generators/base/wasp-generator.base.d.ts.map +1 -1
- package/dist/generators/base/wasp-generator.base.js +22 -26
- package/dist/generators/config/index.js +12 -16
- package/dist/generators/config/wasp-config-generator.js +12 -16
- package/dist/generators/crud/crud-generator.js +50 -58
- package/dist/generators/crud/index.js +50 -58
- package/dist/generators/crud/schema.js +1 -5
- package/dist/generators/feature/feature-generator.d.ts +2 -4
- package/dist/generators/feature/feature-generator.d.ts.map +1 -1
- package/dist/generators/feature/feature-generator.js +32 -42
- package/dist/generators/feature/index.js +32 -42
- package/dist/generators/feature/schema.js +1 -5
- package/dist/generators/index.js +54 -62
- package/dist/generators/job/index.js +49 -57
- package/dist/generators/job/job-generator.js +49 -57
- package/dist/generators/job/schema.js +1 -5
- package/dist/generators/query/index.js +50 -58
- package/dist/generators/query/query-generator.js +50 -58
- package/dist/generators/query/schema.js +1 -5
- package/dist/generators/route/index.js +49 -57
- package/dist/generators/route/route-generator.js +49 -57
- package/dist/generators/route/schema.js +1 -5
- package/dist/index.js +60 -90
- package/dist/plugins/wasp.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/common/plugin.d.ts +0 -2
- package/dist/common/plugin.d.ts.map +0 -1
- package/dist/common/plugin.js +0 -41
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/generators/api-namespace/api-namespace-generator.ts
|
|
2
2
|
import { toCamelCase as toCamelCase2 } from "@ingenyus/swarm";
|
|
3
|
-
import
|
|
3
|
+
import path7 from "path";
|
|
4
4
|
|
|
5
5
|
// src/types/constants.ts
|
|
6
6
|
var PLUGIN_NAME = "wasp";
|
|
@@ -30,13 +30,13 @@ var CONFIG_TYPES = {
|
|
|
30
30
|
|
|
31
31
|
// src/generators/base/component-generator.base.ts
|
|
32
32
|
import {
|
|
33
|
+
GeneratorRuntime,
|
|
33
34
|
hasHelperMethodCall,
|
|
34
|
-
logger as singletonLogger4,
|
|
35
35
|
toCamelCase,
|
|
36
36
|
toKebabCase as toKebabCase2,
|
|
37
37
|
validateFeaturePath as validateFeaturePath3
|
|
38
38
|
} from "@ingenyus/swarm";
|
|
39
|
-
import
|
|
39
|
+
import path6 from "path";
|
|
40
40
|
|
|
41
41
|
// src/common/filesystem.ts
|
|
42
42
|
import { toPascalCase, validateFeaturePath } from "@ingenyus/swarm";
|
|
@@ -90,16 +90,12 @@ function getFeatureDir(fileSystem, featureName) {
|
|
|
90
90
|
return path.join(waspRoot, "src", normalisedPath);
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
// src/common/plugin.ts
|
|
94
|
-
import path2 from "path";
|
|
95
|
-
import { fileURLToPath } from "url";
|
|
96
|
-
|
|
97
93
|
// src/common/prisma.ts
|
|
98
94
|
import {
|
|
99
95
|
getSchema
|
|
100
96
|
} from "@mrleebo/prisma-ast";
|
|
101
97
|
import fs2 from "fs";
|
|
102
|
-
import
|
|
98
|
+
import path2 from "path";
|
|
103
99
|
|
|
104
100
|
// src/common/schemas.ts
|
|
105
101
|
import { commandRegistry } from "@ingenyus/swarm";
|
|
@@ -156,7 +152,7 @@ var commonSchemas = {
|
|
|
156
152
|
// src/common/templates.ts
|
|
157
153
|
import { toKebabCase } from "@ingenyus/swarm";
|
|
158
154
|
import { Eta } from "eta";
|
|
159
|
-
import
|
|
155
|
+
import path3 from "path";
|
|
160
156
|
var TemplateUtility = class {
|
|
161
157
|
constructor(fileSystem) {
|
|
162
158
|
this.fileSystem = fileSystem;
|
|
@@ -164,14 +160,14 @@ var TemplateUtility = class {
|
|
|
164
160
|
processTemplate(templatePath, replacements) {
|
|
165
161
|
const declarations = Object.keys(replacements).map((key) => `${key}=it.${key}`).join(", ");
|
|
166
162
|
const functionHeader = declarations ? `const ${declarations};` : void 0;
|
|
167
|
-
const templateDir =
|
|
163
|
+
const templateDir = path3.dirname(templatePath);
|
|
168
164
|
const eta = new Eta({
|
|
169
165
|
autoTrim: false,
|
|
170
166
|
autoEscape: false,
|
|
171
167
|
views: templateDir,
|
|
172
168
|
functionHeader
|
|
173
169
|
});
|
|
174
|
-
const templateName =
|
|
170
|
+
const templateName = path3.basename(templatePath).replace(/\.eta$/, "");
|
|
175
171
|
if (this.fileSystem.existsSync(templatePath)) {
|
|
176
172
|
return eta.render(templateName, replacements);
|
|
177
173
|
} else {
|
|
@@ -189,11 +185,11 @@ var TemplateUtility = class {
|
|
|
189
185
|
resolveTemplatePath(relativePath, generatorName, currentFileUrl) {
|
|
190
186
|
const generatorDirName = toKebabCase(generatorName);
|
|
191
187
|
const currentFilePath = new URL(currentFileUrl).pathname;
|
|
192
|
-
const currentFileDir =
|
|
193
|
-
const currentFileName =
|
|
188
|
+
const currentFileDir = path3.dirname(currentFilePath);
|
|
189
|
+
const currentFileName = path3.basename(currentFilePath);
|
|
194
190
|
const isInstalledPackage = currentFileDir.includes("node_modules") && currentFileDir.endsWith("/dist") && currentFileName === "index.js";
|
|
195
|
-
const startDir = isInstalledPackage ? currentFileDir :
|
|
196
|
-
return
|
|
191
|
+
const startDir = isInstalledPackage ? currentFileDir : path3.dirname(path3.dirname(currentFileDir));
|
|
192
|
+
return path3.join(
|
|
197
193
|
startDir,
|
|
198
194
|
"generators",
|
|
199
195
|
generatorDirName,
|
|
@@ -204,17 +200,12 @@ var TemplateUtility = class {
|
|
|
204
200
|
};
|
|
205
201
|
|
|
206
202
|
// src/generators/feature/feature-generator.ts
|
|
207
|
-
import {
|
|
208
|
-
|
|
209
|
-
logger as singletonLogger3,
|
|
210
|
-
validateFeaturePath as validateFeaturePath2
|
|
211
|
-
} from "@ingenyus/swarm";
|
|
212
|
-
import path6 from "path";
|
|
203
|
+
import { handleFatalError as handleFatalError2, validateFeaturePath as validateFeaturePath2 } from "@ingenyus/swarm";
|
|
204
|
+
import path5 from "path";
|
|
213
205
|
|
|
214
206
|
// src/generators/base/wasp-generator.base.ts
|
|
215
207
|
import {
|
|
216
208
|
GeneratorBase,
|
|
217
|
-
logger as singletonLogger2,
|
|
218
209
|
SwarmConfigManager,
|
|
219
210
|
TemplateResolver
|
|
220
211
|
} from "@ingenyus/swarm";
|
|
@@ -225,14 +216,14 @@ import {
|
|
|
225
216
|
parseHelperMethodDefinition,
|
|
226
217
|
logger as singletonLogger
|
|
227
218
|
} from "@ingenyus/swarm";
|
|
228
|
-
import
|
|
219
|
+
import path4 from "path";
|
|
229
220
|
var WaspConfigGenerator = class {
|
|
230
221
|
constructor(logger = singletonLogger, fileSystem = realFileSystem) {
|
|
231
222
|
this.logger = logger;
|
|
232
223
|
this.fileSystem = fileSystem;
|
|
233
224
|
this.templateUtility = new TemplateUtility(fileSystem);
|
|
234
225
|
}
|
|
235
|
-
path =
|
|
226
|
+
path = path4;
|
|
236
227
|
templateUtility;
|
|
237
228
|
/**
|
|
238
229
|
* Gets the template path for feature config templates.
|
|
@@ -261,7 +252,7 @@ var WaspConfigGenerator = class {
|
|
|
261
252
|
this.logger.error(`Template not found: ${templatePath}`);
|
|
262
253
|
return;
|
|
263
254
|
}
|
|
264
|
-
const configFilePath =
|
|
255
|
+
const configFilePath = path4.join(featureDir, `feature.wasp.ts`);
|
|
265
256
|
if (this.fileSystem.existsSync(configFilePath)) {
|
|
266
257
|
this.logger.warn(`Feature config already exists: ${configFilePath}`);
|
|
267
258
|
return;
|
|
@@ -277,7 +268,7 @@ var WaspConfigGenerator = class {
|
|
|
277
268
|
*/
|
|
278
269
|
update(featurePath, declaration) {
|
|
279
270
|
const configDir = getFeatureDir(this.fileSystem, featurePath);
|
|
280
|
-
const configFilePath =
|
|
271
|
+
const configFilePath = path4.join(configDir, `feature.wasp.ts`);
|
|
281
272
|
if (!this.fileSystem.existsSync(configFilePath)) {
|
|
282
273
|
const templatePath = this.getTemplatePath("feature.wasp.eta");
|
|
283
274
|
if (!this.fileSystem.existsSync(templatePath)) {
|
|
@@ -657,14 +648,6 @@ var WaspConfigGenerator = class {
|
|
|
657
648
|
|
|
658
649
|
// src/generators/base/wasp-generator.base.ts
|
|
659
650
|
var WaspGeneratorBase = class extends GeneratorBase {
|
|
660
|
-
constructor(fileSystem = realFileSystem, logger = singletonLogger2) {
|
|
661
|
-
super(fileSystem, logger);
|
|
662
|
-
this.fileSystem = fileSystem;
|
|
663
|
-
this.logger = logger;
|
|
664
|
-
this.configGenerator = new WaspConfigGenerator(logger, fileSystem);
|
|
665
|
-
this.templateUtility = new TemplateUtility(fileSystem);
|
|
666
|
-
this.templateResolver = new TemplateResolver(fileSystem);
|
|
667
|
-
}
|
|
668
651
|
configGenerator;
|
|
669
652
|
templateUtility;
|
|
670
653
|
templateResolver;
|
|
@@ -672,6 +655,15 @@ var WaspGeneratorBase = class extends GeneratorBase {
|
|
|
672
655
|
configLoaded = false;
|
|
673
656
|
// Plugin name from swarm.config.json
|
|
674
657
|
pluginName = PLUGIN_NAME;
|
|
658
|
+
constructor() {
|
|
659
|
+
super();
|
|
660
|
+
this.configGenerator = new WaspConfigGenerator(
|
|
661
|
+
this.logger,
|
|
662
|
+
this.fileSystem
|
|
663
|
+
);
|
|
664
|
+
this.templateUtility = new TemplateUtility(this.fileSystem);
|
|
665
|
+
this.templateResolver = new TemplateResolver(this.fileSystem);
|
|
666
|
+
}
|
|
675
667
|
async loadSwarmConfig() {
|
|
676
668
|
if (this.configLoaded) return;
|
|
677
669
|
const configManager = new SwarmConfigManager();
|
|
@@ -722,7 +714,7 @@ var WaspGeneratorBase = class extends GeneratorBase {
|
|
|
722
714
|
}
|
|
723
715
|
/**
|
|
724
716
|
* Generic existence check with force flag handling
|
|
725
|
-
* Consolidates the pattern used in both file and config checks
|
|
717
|
+
* Consolidates the pattern used in both file and config existence checks
|
|
726
718
|
*/
|
|
727
719
|
checkExistence(exists, itemDescription, force, errorMessage) {
|
|
728
720
|
if (exists && !force) {
|
|
@@ -762,16 +754,14 @@ var schema = z2.object({
|
|
|
762
754
|
|
|
763
755
|
// src/generators/feature/feature-generator.ts
|
|
764
756
|
var FeatureGenerator = class extends WaspGeneratorBase {
|
|
765
|
-
constructor(logger = singletonLogger3, fileSystem = realFileSystem) {
|
|
766
|
-
super(fileSystem, logger);
|
|
767
|
-
this.logger = logger;
|
|
768
|
-
this.fileSystem = fileSystem;
|
|
769
|
-
this.name = "feature";
|
|
770
|
-
this.description = "Generates a feature directory containing a Wasp configuration file";
|
|
771
|
-
}
|
|
772
757
|
name;
|
|
773
758
|
description;
|
|
774
759
|
schema = schema;
|
|
760
|
+
constructor() {
|
|
761
|
+
super();
|
|
762
|
+
this.name = "feature";
|
|
763
|
+
this.description = "Generates a feature directory containing a Wasp configuration file";
|
|
764
|
+
}
|
|
775
765
|
getDefaultTemplatePath(templateName) {
|
|
776
766
|
return this.templateUtility.resolveTemplatePath(
|
|
777
767
|
templateName,
|
|
@@ -787,18 +777,18 @@ var FeatureGenerator = class extends WaspGeneratorBase {
|
|
|
787
777
|
const { target } = args;
|
|
788
778
|
const segments = validateFeaturePath2(target);
|
|
789
779
|
const normalisedPath = normaliseFeaturePath(target);
|
|
790
|
-
const sourceRoot =
|
|
780
|
+
const sourceRoot = path5.join(findWaspRoot(this.fileSystem), "src");
|
|
791
781
|
if (segments.length > 1) {
|
|
792
782
|
const parentPath = segments.slice(0, -1).join("/");
|
|
793
783
|
const parentNormalisedPath = normaliseFeaturePath(parentPath);
|
|
794
|
-
const parentFeatureDir =
|
|
784
|
+
const parentFeatureDir = path5.join(sourceRoot, parentNormalisedPath);
|
|
795
785
|
if (!this.fileSystem.existsSync(parentFeatureDir)) {
|
|
796
786
|
handleFatalError2(
|
|
797
787
|
`Parent feature '${parentPath}' does not exist. Please create it first.`
|
|
798
788
|
);
|
|
799
789
|
}
|
|
800
790
|
}
|
|
801
|
-
const featureDir =
|
|
791
|
+
const featureDir = path5.join(sourceRoot, normalisedPath);
|
|
802
792
|
this.fileSystem.mkdirSync(featureDir, { recursive: true });
|
|
803
793
|
this.configGenerator.generate(normalisedPath);
|
|
804
794
|
this.logger.success(`Generated feature: ${normalisedPath}`);
|
|
@@ -807,13 +797,6 @@ var FeatureGenerator = class extends WaspGeneratorBase {
|
|
|
807
797
|
|
|
808
798
|
// src/generators/base/component-generator.base.ts
|
|
809
799
|
var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
810
|
-
constructor(logger = singletonLogger4, fileSystem = realFileSystem, featureDirectoryGenerator = new FeatureGenerator(logger, fileSystem)) {
|
|
811
|
-
super(fileSystem, logger);
|
|
812
|
-
this.logger = logger;
|
|
813
|
-
this.fileSystem = fileSystem;
|
|
814
|
-
this.featureDirectoryGenerator = featureDirectoryGenerator;
|
|
815
|
-
this.featureDirectoryGenerator = featureDirectoryGenerator;
|
|
816
|
-
}
|
|
817
800
|
getDefaultTemplatePath(templateName) {
|
|
818
801
|
return this.templateUtility.resolveTemplatePath(
|
|
819
802
|
templateName,
|
|
@@ -821,6 +804,17 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
821
804
|
import.meta.url
|
|
822
805
|
);
|
|
823
806
|
}
|
|
807
|
+
featureDirectoryGenerator;
|
|
808
|
+
constructor() {
|
|
809
|
+
super();
|
|
810
|
+
const runtime = GeneratorRuntime.current();
|
|
811
|
+
if (runtime.featureGeneratorFactory) {
|
|
812
|
+
const factoryResult = runtime.featureGeneratorFactory(runtime);
|
|
813
|
+
this.featureDirectoryGenerator = factoryResult;
|
|
814
|
+
} else {
|
|
815
|
+
this.featureDirectoryGenerator = new FeatureGenerator();
|
|
816
|
+
}
|
|
817
|
+
}
|
|
824
818
|
get name() {
|
|
825
819
|
return toKebabCase2(this.componentType);
|
|
826
820
|
}
|
|
@@ -835,7 +829,7 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
835
829
|
const currentPath = pathSegments.join("/");
|
|
836
830
|
const featureName = pathSegments[pathSegments.length - 1];
|
|
837
831
|
const featureDir = getFeatureDir(this.fileSystem, currentPath);
|
|
838
|
-
const configPath =
|
|
832
|
+
const configPath = path6.join(featureDir, `feature.wasp.ts`);
|
|
839
833
|
if (this.fileSystem.existsSync(configPath)) {
|
|
840
834
|
return configPath;
|
|
841
835
|
}
|
|
@@ -897,18 +891,17 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
897
891
|
}
|
|
898
892
|
/**
|
|
899
893
|
* Gets the appropriate directory for a feature based on its path.
|
|
900
|
-
* @param fileSystem - The filesystem abstraction
|
|
901
894
|
* @param featurePath - The full feature path
|
|
902
895
|
* @param type - The type of file being generated
|
|
903
896
|
* @returns The target directory and import path
|
|
904
897
|
*/
|
|
905
|
-
getFeatureTargetDir(
|
|
898
|
+
getFeatureTargetDir(featurePath, type) {
|
|
906
899
|
validateFeaturePath3(featurePath);
|
|
907
900
|
const normalisedPath = normaliseFeaturePath(featurePath);
|
|
908
|
-
const featureDir = getFeatureDir(fileSystem, normalisedPath);
|
|
901
|
+
const featureDir = getFeatureDir(this.fileSystem, normalisedPath);
|
|
909
902
|
const typeKey = type.toLowerCase();
|
|
910
903
|
const typeDirectory = TYPE_DIRECTORIES[typeKey];
|
|
911
|
-
const targetDirectory =
|
|
904
|
+
const targetDirectory = path6.join(featureDir, typeDirectory);
|
|
912
905
|
const importDirectory = `@src/${normalisedPath}/${typeDirectory}`;
|
|
913
906
|
return { targetDirectory, importDirectory };
|
|
914
907
|
}
|
|
@@ -917,7 +910,6 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
917
910
|
*/
|
|
918
911
|
ensureTargetDirectory(featurePath, type) {
|
|
919
912
|
const { targetDirectory, importDirectory } = this.getFeatureTargetDir(
|
|
920
|
-
this.fileSystem,
|
|
921
913
|
featurePath,
|
|
922
914
|
type
|
|
923
915
|
);
|
|
@@ -996,7 +988,7 @@ var ApiNamespaceGenerator = class extends ComponentGeneratorBase {
|
|
|
996
988
|
}
|
|
997
989
|
async updateConfigFile(namespaceName, importDirectory, namespacePath, args, configFilePath) {
|
|
998
990
|
const { force = false } = args;
|
|
999
|
-
const importPath =
|
|
991
|
+
const importPath = path7.join(importDirectory, namespaceName);
|
|
1000
992
|
const definition = await this.getDefinition(
|
|
1001
993
|
namespaceName,
|
|
1002
994
|
importPath,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/generators/api-namespace/api-namespace-generator.ts
|
|
2
2
|
import { toCamelCase as toCamelCase2 } from "@ingenyus/swarm";
|
|
3
|
-
import
|
|
3
|
+
import path7 from "path";
|
|
4
4
|
|
|
5
5
|
// src/types/constants.ts
|
|
6
6
|
var PLUGIN_NAME = "wasp";
|
|
@@ -30,13 +30,13 @@ var CONFIG_TYPES = {
|
|
|
30
30
|
|
|
31
31
|
// src/generators/base/component-generator.base.ts
|
|
32
32
|
import {
|
|
33
|
+
GeneratorRuntime,
|
|
33
34
|
hasHelperMethodCall,
|
|
34
|
-
logger as singletonLogger4,
|
|
35
35
|
toCamelCase,
|
|
36
36
|
toKebabCase as toKebabCase2,
|
|
37
37
|
validateFeaturePath as validateFeaturePath3
|
|
38
38
|
} from "@ingenyus/swarm";
|
|
39
|
-
import
|
|
39
|
+
import path6 from "path";
|
|
40
40
|
|
|
41
41
|
// src/common/filesystem.ts
|
|
42
42
|
import { toPascalCase, validateFeaturePath } from "@ingenyus/swarm";
|
|
@@ -90,16 +90,12 @@ function getFeatureDir(fileSystem, featureName) {
|
|
|
90
90
|
return path.join(waspRoot, "src", normalisedPath);
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
// src/common/plugin.ts
|
|
94
|
-
import path2 from "path";
|
|
95
|
-
import { fileURLToPath } from "url";
|
|
96
|
-
|
|
97
93
|
// src/common/prisma.ts
|
|
98
94
|
import {
|
|
99
95
|
getSchema
|
|
100
96
|
} from "@mrleebo/prisma-ast";
|
|
101
97
|
import fs2 from "fs";
|
|
102
|
-
import
|
|
98
|
+
import path2 from "path";
|
|
103
99
|
|
|
104
100
|
// src/common/schemas.ts
|
|
105
101
|
import { commandRegistry } from "@ingenyus/swarm";
|
|
@@ -156,7 +152,7 @@ var commonSchemas = {
|
|
|
156
152
|
// src/common/templates.ts
|
|
157
153
|
import { toKebabCase } from "@ingenyus/swarm";
|
|
158
154
|
import { Eta } from "eta";
|
|
159
|
-
import
|
|
155
|
+
import path3 from "path";
|
|
160
156
|
var TemplateUtility = class {
|
|
161
157
|
constructor(fileSystem) {
|
|
162
158
|
this.fileSystem = fileSystem;
|
|
@@ -164,14 +160,14 @@ var TemplateUtility = class {
|
|
|
164
160
|
processTemplate(templatePath, replacements) {
|
|
165
161
|
const declarations = Object.keys(replacements).map((key) => `${key}=it.${key}`).join(", ");
|
|
166
162
|
const functionHeader = declarations ? `const ${declarations};` : void 0;
|
|
167
|
-
const templateDir =
|
|
163
|
+
const templateDir = path3.dirname(templatePath);
|
|
168
164
|
const eta = new Eta({
|
|
169
165
|
autoTrim: false,
|
|
170
166
|
autoEscape: false,
|
|
171
167
|
views: templateDir,
|
|
172
168
|
functionHeader
|
|
173
169
|
});
|
|
174
|
-
const templateName =
|
|
170
|
+
const templateName = path3.basename(templatePath).replace(/\.eta$/, "");
|
|
175
171
|
if (this.fileSystem.existsSync(templatePath)) {
|
|
176
172
|
return eta.render(templateName, replacements);
|
|
177
173
|
} else {
|
|
@@ -189,11 +185,11 @@ var TemplateUtility = class {
|
|
|
189
185
|
resolveTemplatePath(relativePath, generatorName, currentFileUrl) {
|
|
190
186
|
const generatorDirName = toKebabCase(generatorName);
|
|
191
187
|
const currentFilePath = new URL(currentFileUrl).pathname;
|
|
192
|
-
const currentFileDir =
|
|
193
|
-
const currentFileName =
|
|
188
|
+
const currentFileDir = path3.dirname(currentFilePath);
|
|
189
|
+
const currentFileName = path3.basename(currentFilePath);
|
|
194
190
|
const isInstalledPackage = currentFileDir.includes("node_modules") && currentFileDir.endsWith("/dist") && currentFileName === "index.js";
|
|
195
|
-
const startDir = isInstalledPackage ? currentFileDir :
|
|
196
|
-
return
|
|
191
|
+
const startDir = isInstalledPackage ? currentFileDir : path3.dirname(path3.dirname(currentFileDir));
|
|
192
|
+
return path3.join(
|
|
197
193
|
startDir,
|
|
198
194
|
"generators",
|
|
199
195
|
generatorDirName,
|
|
@@ -204,17 +200,12 @@ var TemplateUtility = class {
|
|
|
204
200
|
};
|
|
205
201
|
|
|
206
202
|
// src/generators/feature/feature-generator.ts
|
|
207
|
-
import {
|
|
208
|
-
|
|
209
|
-
logger as singletonLogger3,
|
|
210
|
-
validateFeaturePath as validateFeaturePath2
|
|
211
|
-
} from "@ingenyus/swarm";
|
|
212
|
-
import path6 from "path";
|
|
203
|
+
import { handleFatalError as handleFatalError2, validateFeaturePath as validateFeaturePath2 } from "@ingenyus/swarm";
|
|
204
|
+
import path5 from "path";
|
|
213
205
|
|
|
214
206
|
// src/generators/base/wasp-generator.base.ts
|
|
215
207
|
import {
|
|
216
208
|
GeneratorBase,
|
|
217
|
-
logger as singletonLogger2,
|
|
218
209
|
SwarmConfigManager,
|
|
219
210
|
TemplateResolver
|
|
220
211
|
} from "@ingenyus/swarm";
|
|
@@ -225,14 +216,14 @@ import {
|
|
|
225
216
|
parseHelperMethodDefinition,
|
|
226
217
|
logger as singletonLogger
|
|
227
218
|
} from "@ingenyus/swarm";
|
|
228
|
-
import
|
|
219
|
+
import path4 from "path";
|
|
229
220
|
var WaspConfigGenerator = class {
|
|
230
221
|
constructor(logger = singletonLogger, fileSystem = realFileSystem) {
|
|
231
222
|
this.logger = logger;
|
|
232
223
|
this.fileSystem = fileSystem;
|
|
233
224
|
this.templateUtility = new TemplateUtility(fileSystem);
|
|
234
225
|
}
|
|
235
|
-
path =
|
|
226
|
+
path = path4;
|
|
236
227
|
templateUtility;
|
|
237
228
|
/**
|
|
238
229
|
* Gets the template path for feature config templates.
|
|
@@ -261,7 +252,7 @@ var WaspConfigGenerator = class {
|
|
|
261
252
|
this.logger.error(`Template not found: ${templatePath}`);
|
|
262
253
|
return;
|
|
263
254
|
}
|
|
264
|
-
const configFilePath =
|
|
255
|
+
const configFilePath = path4.join(featureDir, `feature.wasp.ts`);
|
|
265
256
|
if (this.fileSystem.existsSync(configFilePath)) {
|
|
266
257
|
this.logger.warn(`Feature config already exists: ${configFilePath}`);
|
|
267
258
|
return;
|
|
@@ -277,7 +268,7 @@ var WaspConfigGenerator = class {
|
|
|
277
268
|
*/
|
|
278
269
|
update(featurePath, declaration) {
|
|
279
270
|
const configDir = getFeatureDir(this.fileSystem, featurePath);
|
|
280
|
-
const configFilePath =
|
|
271
|
+
const configFilePath = path4.join(configDir, `feature.wasp.ts`);
|
|
281
272
|
if (!this.fileSystem.existsSync(configFilePath)) {
|
|
282
273
|
const templatePath = this.getTemplatePath("feature.wasp.eta");
|
|
283
274
|
if (!this.fileSystem.existsSync(templatePath)) {
|
|
@@ -657,14 +648,6 @@ var WaspConfigGenerator = class {
|
|
|
657
648
|
|
|
658
649
|
// src/generators/base/wasp-generator.base.ts
|
|
659
650
|
var WaspGeneratorBase = class extends GeneratorBase {
|
|
660
|
-
constructor(fileSystem = realFileSystem, logger = singletonLogger2) {
|
|
661
|
-
super(fileSystem, logger);
|
|
662
|
-
this.fileSystem = fileSystem;
|
|
663
|
-
this.logger = logger;
|
|
664
|
-
this.configGenerator = new WaspConfigGenerator(logger, fileSystem);
|
|
665
|
-
this.templateUtility = new TemplateUtility(fileSystem);
|
|
666
|
-
this.templateResolver = new TemplateResolver(fileSystem);
|
|
667
|
-
}
|
|
668
651
|
configGenerator;
|
|
669
652
|
templateUtility;
|
|
670
653
|
templateResolver;
|
|
@@ -672,6 +655,15 @@ var WaspGeneratorBase = class extends GeneratorBase {
|
|
|
672
655
|
configLoaded = false;
|
|
673
656
|
// Plugin name from swarm.config.json
|
|
674
657
|
pluginName = PLUGIN_NAME;
|
|
658
|
+
constructor() {
|
|
659
|
+
super();
|
|
660
|
+
this.configGenerator = new WaspConfigGenerator(
|
|
661
|
+
this.logger,
|
|
662
|
+
this.fileSystem
|
|
663
|
+
);
|
|
664
|
+
this.templateUtility = new TemplateUtility(this.fileSystem);
|
|
665
|
+
this.templateResolver = new TemplateResolver(this.fileSystem);
|
|
666
|
+
}
|
|
675
667
|
async loadSwarmConfig() {
|
|
676
668
|
if (this.configLoaded) return;
|
|
677
669
|
const configManager = new SwarmConfigManager();
|
|
@@ -722,7 +714,7 @@ var WaspGeneratorBase = class extends GeneratorBase {
|
|
|
722
714
|
}
|
|
723
715
|
/**
|
|
724
716
|
* Generic existence check with force flag handling
|
|
725
|
-
* Consolidates the pattern used in both file and config checks
|
|
717
|
+
* Consolidates the pattern used in both file and config existence checks
|
|
726
718
|
*/
|
|
727
719
|
checkExistence(exists, itemDescription, force, errorMessage) {
|
|
728
720
|
if (exists && !force) {
|
|
@@ -762,16 +754,14 @@ var schema = z2.object({
|
|
|
762
754
|
|
|
763
755
|
// src/generators/feature/feature-generator.ts
|
|
764
756
|
var FeatureGenerator = class extends WaspGeneratorBase {
|
|
765
|
-
constructor(logger = singletonLogger3, fileSystem = realFileSystem) {
|
|
766
|
-
super(fileSystem, logger);
|
|
767
|
-
this.logger = logger;
|
|
768
|
-
this.fileSystem = fileSystem;
|
|
769
|
-
this.name = "feature";
|
|
770
|
-
this.description = "Generates a feature directory containing a Wasp configuration file";
|
|
771
|
-
}
|
|
772
757
|
name;
|
|
773
758
|
description;
|
|
774
759
|
schema = schema;
|
|
760
|
+
constructor() {
|
|
761
|
+
super();
|
|
762
|
+
this.name = "feature";
|
|
763
|
+
this.description = "Generates a feature directory containing a Wasp configuration file";
|
|
764
|
+
}
|
|
775
765
|
getDefaultTemplatePath(templateName) {
|
|
776
766
|
return this.templateUtility.resolveTemplatePath(
|
|
777
767
|
templateName,
|
|
@@ -787,18 +777,18 @@ var FeatureGenerator = class extends WaspGeneratorBase {
|
|
|
787
777
|
const { target } = args;
|
|
788
778
|
const segments = validateFeaturePath2(target);
|
|
789
779
|
const normalisedPath = normaliseFeaturePath(target);
|
|
790
|
-
const sourceRoot =
|
|
780
|
+
const sourceRoot = path5.join(findWaspRoot(this.fileSystem), "src");
|
|
791
781
|
if (segments.length > 1) {
|
|
792
782
|
const parentPath = segments.slice(0, -1).join("/");
|
|
793
783
|
const parentNormalisedPath = normaliseFeaturePath(parentPath);
|
|
794
|
-
const parentFeatureDir =
|
|
784
|
+
const parentFeatureDir = path5.join(sourceRoot, parentNormalisedPath);
|
|
795
785
|
if (!this.fileSystem.existsSync(parentFeatureDir)) {
|
|
796
786
|
handleFatalError2(
|
|
797
787
|
`Parent feature '${parentPath}' does not exist. Please create it first.`
|
|
798
788
|
);
|
|
799
789
|
}
|
|
800
790
|
}
|
|
801
|
-
const featureDir =
|
|
791
|
+
const featureDir = path5.join(sourceRoot, normalisedPath);
|
|
802
792
|
this.fileSystem.mkdirSync(featureDir, { recursive: true });
|
|
803
793
|
this.configGenerator.generate(normalisedPath);
|
|
804
794
|
this.logger.success(`Generated feature: ${normalisedPath}`);
|
|
@@ -807,13 +797,6 @@ var FeatureGenerator = class extends WaspGeneratorBase {
|
|
|
807
797
|
|
|
808
798
|
// src/generators/base/component-generator.base.ts
|
|
809
799
|
var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
810
|
-
constructor(logger = singletonLogger4, fileSystem = realFileSystem, featureDirectoryGenerator = new FeatureGenerator(logger, fileSystem)) {
|
|
811
|
-
super(fileSystem, logger);
|
|
812
|
-
this.logger = logger;
|
|
813
|
-
this.fileSystem = fileSystem;
|
|
814
|
-
this.featureDirectoryGenerator = featureDirectoryGenerator;
|
|
815
|
-
this.featureDirectoryGenerator = featureDirectoryGenerator;
|
|
816
|
-
}
|
|
817
800
|
getDefaultTemplatePath(templateName) {
|
|
818
801
|
return this.templateUtility.resolveTemplatePath(
|
|
819
802
|
templateName,
|
|
@@ -821,6 +804,17 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
821
804
|
import.meta.url
|
|
822
805
|
);
|
|
823
806
|
}
|
|
807
|
+
featureDirectoryGenerator;
|
|
808
|
+
constructor() {
|
|
809
|
+
super();
|
|
810
|
+
const runtime = GeneratorRuntime.current();
|
|
811
|
+
if (runtime.featureGeneratorFactory) {
|
|
812
|
+
const factoryResult = runtime.featureGeneratorFactory(runtime);
|
|
813
|
+
this.featureDirectoryGenerator = factoryResult;
|
|
814
|
+
} else {
|
|
815
|
+
this.featureDirectoryGenerator = new FeatureGenerator();
|
|
816
|
+
}
|
|
817
|
+
}
|
|
824
818
|
get name() {
|
|
825
819
|
return toKebabCase2(this.componentType);
|
|
826
820
|
}
|
|
@@ -835,7 +829,7 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
835
829
|
const currentPath = pathSegments.join("/");
|
|
836
830
|
const featureName = pathSegments[pathSegments.length - 1];
|
|
837
831
|
const featureDir = getFeatureDir(this.fileSystem, currentPath);
|
|
838
|
-
const configPath =
|
|
832
|
+
const configPath = path6.join(featureDir, `feature.wasp.ts`);
|
|
839
833
|
if (this.fileSystem.existsSync(configPath)) {
|
|
840
834
|
return configPath;
|
|
841
835
|
}
|
|
@@ -897,18 +891,17 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
897
891
|
}
|
|
898
892
|
/**
|
|
899
893
|
* Gets the appropriate directory for a feature based on its path.
|
|
900
|
-
* @param fileSystem - The filesystem abstraction
|
|
901
894
|
* @param featurePath - The full feature path
|
|
902
895
|
* @param type - The type of file being generated
|
|
903
896
|
* @returns The target directory and import path
|
|
904
897
|
*/
|
|
905
|
-
getFeatureTargetDir(
|
|
898
|
+
getFeatureTargetDir(featurePath, type) {
|
|
906
899
|
validateFeaturePath3(featurePath);
|
|
907
900
|
const normalisedPath = normaliseFeaturePath(featurePath);
|
|
908
|
-
const featureDir = getFeatureDir(fileSystem, normalisedPath);
|
|
901
|
+
const featureDir = getFeatureDir(this.fileSystem, normalisedPath);
|
|
909
902
|
const typeKey = type.toLowerCase();
|
|
910
903
|
const typeDirectory = TYPE_DIRECTORIES[typeKey];
|
|
911
|
-
const targetDirectory =
|
|
904
|
+
const targetDirectory = path6.join(featureDir, typeDirectory);
|
|
912
905
|
const importDirectory = `@src/${normalisedPath}/${typeDirectory}`;
|
|
913
906
|
return { targetDirectory, importDirectory };
|
|
914
907
|
}
|
|
@@ -917,7 +910,6 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
917
910
|
*/
|
|
918
911
|
ensureTargetDirectory(featurePath, type) {
|
|
919
912
|
const { targetDirectory, importDirectory } = this.getFeatureTargetDir(
|
|
920
|
-
this.fileSystem,
|
|
921
913
|
featurePath,
|
|
922
914
|
type
|
|
923
915
|
);
|
|
@@ -996,7 +988,7 @@ var ApiNamespaceGenerator = class extends ComponentGeneratorBase {
|
|
|
996
988
|
}
|
|
997
989
|
async updateConfigFile(namespaceName, importDirectory, namespacePath, args, configFilePath) {
|
|
998
990
|
const { force = false } = args;
|
|
999
|
-
const importPath =
|
|
991
|
+
const importPath = path7.join(importDirectory, namespaceName);
|
|
1000
992
|
const definition = await this.getDefinition(
|
|
1001
993
|
namespaceName,
|
|
1002
994
|
importPath,
|
|
@@ -14,16 +14,12 @@ var realFileSystem = {
|
|
|
14
14
|
statSync: fs.statSync
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
// src/common/plugin.ts
|
|
18
|
-
import path from "path";
|
|
19
|
-
import { fileURLToPath } from "url";
|
|
20
|
-
|
|
21
17
|
// src/common/prisma.ts
|
|
22
18
|
import {
|
|
23
19
|
getSchema
|
|
24
20
|
} from "@mrleebo/prisma-ast";
|
|
25
21
|
import fs2 from "fs";
|
|
26
|
-
import
|
|
22
|
+
import path from "path";
|
|
27
23
|
|
|
28
24
|
// src/common/schemas.ts
|
|
29
25
|
import { commandRegistry } from "@ingenyus/swarm";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SwarmGenerator } from '@ingenyus/swarm';
|
|
2
2
|
import { ZodType } from 'zod';
|
|
3
3
|
import { ConfigType } from '../../types';
|
|
4
4
|
import { schema as featureSchema } from '../feature/schema';
|
|
@@ -7,12 +7,10 @@ import { WaspGeneratorBase } from './wasp-generator.base';
|
|
|
7
7
|
* Abstract base class for all Wasp component generators
|
|
8
8
|
*/
|
|
9
9
|
export declare abstract class ComponentGeneratorBase<S extends ZodType, TConfig extends ConfigType> extends WaspGeneratorBase<S> {
|
|
10
|
-
logger: Logger;
|
|
11
|
-
fileSystem: FileSystem;
|
|
12
|
-
protected featureDirectoryGenerator: SwarmGenerator<typeof featureSchema>;
|
|
13
10
|
protected abstract componentType: TConfig;
|
|
14
11
|
protected getDefaultTemplatePath(templateName: string): string;
|
|
15
|
-
|
|
12
|
+
protected featureDirectoryGenerator: SwarmGenerator<typeof featureSchema>;
|
|
13
|
+
constructor();
|
|
16
14
|
get name(): string;
|
|
17
15
|
/**
|
|
18
16
|
* Validates that the feature config file exists in the target or ancestor directories
|
|
@@ -33,12 +31,11 @@ export declare abstract class ComponentGeneratorBase<S extends ZodType, TConfig
|
|
|
33
31
|
protected updateConfigWithCheck(configPath: string, methodName: string, entityName: string, definition: string, featurePath: string, force: boolean): void;
|
|
34
32
|
/**
|
|
35
33
|
* Gets the appropriate directory for a feature based on its path.
|
|
36
|
-
* @param fileSystem - The filesystem abstraction
|
|
37
34
|
* @param featurePath - The full feature path
|
|
38
35
|
* @param type - The type of file being generated
|
|
39
36
|
* @returns The target directory and import path
|
|
40
37
|
*/
|
|
41
|
-
protected getFeatureTargetDir(
|
|
38
|
+
protected getFeatureTargetDir(featurePath: string, type: string): {
|
|
42
39
|
targetDirectory: string;
|
|
43
40
|
importDirectory: string;
|
|
44
41
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-generator.base.d.ts","sourceRoot":"","sources":["../../../src/generators/base/component-generator.base.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"component-generator.base.d.ts","sourceRoot":"","sources":["../../../src/generators/base/component-generator.base.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,cAAc,EAIf,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAM9B,OAAO,EAAE,UAAU,EAAoB,MAAM,aAAa,CAAC;AAE3D,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D;;GAEG;AACH,8BAAsB,sBAAsB,CAC1C,CAAC,SAAS,OAAO,EACjB,OAAO,SAAS,UAAU,CAC1B,SAAQ,iBAAiB,CAAC,CAAC,CAAC;IAC5B,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;IAE1C,SAAS,CAAC,sBAAsB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;IAQ9D,SAAS,CAAC,yBAAyB,EAAE,cAAc,CAAC,OAAO,aAAa,CAAC,CAAC;;IAmB1E,IAAW,IAAI,IAAI,MAAM,CAExB;IAED;;OAEG;IACH,SAAS,CAAC,qBAAqB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;IA4B5D;;OAEG;IACH,SAAS,CAAC,iBAAiB,CACzB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,OAAO,GACb,OAAO;IAgBV;;OAEG;IACH,SAAS,CAAC,mBAAmB,CAC3B,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,OAAO,EACrB,UAAU,EAAE,MAAM,GACjB,IAAI;IAOP;;;OAGG;IACH,SAAS,CAAC,qBAAqB,CAC7B,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,OAAO,GACb,IAAI;IAmBP;;;;;OAKG;IACH,SAAS,CAAC,mBAAmB,CAC3B,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,GACX;QAAE,eAAe,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE;IAavD;;OAEG;IACH,SAAS,CAAC,qBAAqB,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;;;;IAWjE;;OAEG;cACa,sBAAsB,CACpC,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,IAAI,CAAC;CAcjB"}
|