@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,12 +1,12 @@
|
|
|
1
1
|
// src/generators/base/component-generator.base.ts
|
|
2
2
|
import {
|
|
3
|
+
GeneratorRuntime,
|
|
3
4
|
hasHelperMethodCall,
|
|
4
|
-
logger as singletonLogger4,
|
|
5
5
|
toCamelCase,
|
|
6
6
|
toKebabCase as toKebabCase2,
|
|
7
7
|
validateFeaturePath as validateFeaturePath3
|
|
8
8
|
} from "@ingenyus/swarm";
|
|
9
|
-
import
|
|
9
|
+
import path6 from "path";
|
|
10
10
|
|
|
11
11
|
// src/common/filesystem.ts
|
|
12
12
|
import { toPascalCase, validateFeaturePath } from "@ingenyus/swarm";
|
|
@@ -79,16 +79,12 @@ function getFeatureDir(fileSystem, featureName) {
|
|
|
79
79
|
return path.join(waspRoot, "src", normalisedPath);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
// src/common/plugin.ts
|
|
83
|
-
import path2 from "path";
|
|
84
|
-
import { fileURLToPath } from "url";
|
|
85
|
-
|
|
86
82
|
// src/common/prisma.ts
|
|
87
83
|
import {
|
|
88
84
|
getSchema
|
|
89
85
|
} from "@mrleebo/prisma-ast";
|
|
90
86
|
import fs2 from "fs";
|
|
91
|
-
import
|
|
87
|
+
import path2 from "path";
|
|
92
88
|
|
|
93
89
|
// src/common/schemas.ts
|
|
94
90
|
import { commandRegistry } from "@ingenyus/swarm";
|
|
@@ -145,7 +141,7 @@ var commonSchemas = {
|
|
|
145
141
|
// src/common/templates.ts
|
|
146
142
|
import { toKebabCase } from "@ingenyus/swarm";
|
|
147
143
|
import { Eta } from "eta";
|
|
148
|
-
import
|
|
144
|
+
import path3 from "path";
|
|
149
145
|
var TemplateUtility = class {
|
|
150
146
|
constructor(fileSystem) {
|
|
151
147
|
this.fileSystem = fileSystem;
|
|
@@ -153,14 +149,14 @@ var TemplateUtility = class {
|
|
|
153
149
|
processTemplate(templatePath, replacements) {
|
|
154
150
|
const declarations = Object.keys(replacements).map((key) => `${key}=it.${key}`).join(", ");
|
|
155
151
|
const functionHeader = declarations ? `const ${declarations};` : void 0;
|
|
156
|
-
const templateDir =
|
|
152
|
+
const templateDir = path3.dirname(templatePath);
|
|
157
153
|
const eta = new Eta({
|
|
158
154
|
autoTrim: false,
|
|
159
155
|
autoEscape: false,
|
|
160
156
|
views: templateDir,
|
|
161
157
|
functionHeader
|
|
162
158
|
});
|
|
163
|
-
const templateName =
|
|
159
|
+
const templateName = path3.basename(templatePath).replace(/\.eta$/, "");
|
|
164
160
|
if (this.fileSystem.existsSync(templatePath)) {
|
|
165
161
|
return eta.render(templateName, replacements);
|
|
166
162
|
} else {
|
|
@@ -178,11 +174,11 @@ var TemplateUtility = class {
|
|
|
178
174
|
resolveTemplatePath(relativePath, generatorName, currentFileUrl) {
|
|
179
175
|
const generatorDirName = toKebabCase(generatorName);
|
|
180
176
|
const currentFilePath = new URL(currentFileUrl).pathname;
|
|
181
|
-
const currentFileDir =
|
|
182
|
-
const currentFileName =
|
|
177
|
+
const currentFileDir = path3.dirname(currentFilePath);
|
|
178
|
+
const currentFileName = path3.basename(currentFilePath);
|
|
183
179
|
const isInstalledPackage = currentFileDir.includes("node_modules") && currentFileDir.endsWith("/dist") && currentFileName === "index.js";
|
|
184
|
-
const startDir = isInstalledPackage ? currentFileDir :
|
|
185
|
-
return
|
|
180
|
+
const startDir = isInstalledPackage ? currentFileDir : path3.dirname(path3.dirname(currentFileDir));
|
|
181
|
+
return path3.join(
|
|
186
182
|
startDir,
|
|
187
183
|
"generators",
|
|
188
184
|
generatorDirName,
|
|
@@ -193,17 +189,12 @@ var TemplateUtility = class {
|
|
|
193
189
|
};
|
|
194
190
|
|
|
195
191
|
// src/generators/feature/feature-generator.ts
|
|
196
|
-
import {
|
|
197
|
-
|
|
198
|
-
logger as singletonLogger3,
|
|
199
|
-
validateFeaturePath as validateFeaturePath2
|
|
200
|
-
} from "@ingenyus/swarm";
|
|
201
|
-
import path6 from "path";
|
|
192
|
+
import { handleFatalError as handleFatalError2, validateFeaturePath as validateFeaturePath2 } from "@ingenyus/swarm";
|
|
193
|
+
import path5 from "path";
|
|
202
194
|
|
|
203
195
|
// src/generators/base/wasp-generator.base.ts
|
|
204
196
|
import {
|
|
205
197
|
GeneratorBase,
|
|
206
|
-
logger as singletonLogger2,
|
|
207
198
|
SwarmConfigManager,
|
|
208
199
|
TemplateResolver
|
|
209
200
|
} from "@ingenyus/swarm";
|
|
@@ -214,14 +205,14 @@ import {
|
|
|
214
205
|
parseHelperMethodDefinition,
|
|
215
206
|
logger as singletonLogger
|
|
216
207
|
} from "@ingenyus/swarm";
|
|
217
|
-
import
|
|
208
|
+
import path4 from "path";
|
|
218
209
|
var WaspConfigGenerator = class {
|
|
219
210
|
constructor(logger = singletonLogger, fileSystem = realFileSystem) {
|
|
220
211
|
this.logger = logger;
|
|
221
212
|
this.fileSystem = fileSystem;
|
|
222
213
|
this.templateUtility = new TemplateUtility(fileSystem);
|
|
223
214
|
}
|
|
224
|
-
path =
|
|
215
|
+
path = path4;
|
|
225
216
|
templateUtility;
|
|
226
217
|
/**
|
|
227
218
|
* Gets the template path for feature config templates.
|
|
@@ -250,7 +241,7 @@ var WaspConfigGenerator = class {
|
|
|
250
241
|
this.logger.error(`Template not found: ${templatePath}`);
|
|
251
242
|
return;
|
|
252
243
|
}
|
|
253
|
-
const configFilePath =
|
|
244
|
+
const configFilePath = path4.join(featureDir, `feature.wasp.ts`);
|
|
254
245
|
if (this.fileSystem.existsSync(configFilePath)) {
|
|
255
246
|
this.logger.warn(`Feature config already exists: ${configFilePath}`);
|
|
256
247
|
return;
|
|
@@ -266,7 +257,7 @@ var WaspConfigGenerator = class {
|
|
|
266
257
|
*/
|
|
267
258
|
update(featurePath, declaration) {
|
|
268
259
|
const configDir = getFeatureDir(this.fileSystem, featurePath);
|
|
269
|
-
const configFilePath =
|
|
260
|
+
const configFilePath = path4.join(configDir, `feature.wasp.ts`);
|
|
270
261
|
if (!this.fileSystem.existsSync(configFilePath)) {
|
|
271
262
|
const templatePath = this.getTemplatePath("feature.wasp.eta");
|
|
272
263
|
if (!this.fileSystem.existsSync(templatePath)) {
|
|
@@ -646,14 +637,6 @@ var WaspConfigGenerator = class {
|
|
|
646
637
|
|
|
647
638
|
// src/generators/base/wasp-generator.base.ts
|
|
648
639
|
var WaspGeneratorBase = class extends GeneratorBase {
|
|
649
|
-
constructor(fileSystem = realFileSystem, logger = singletonLogger2) {
|
|
650
|
-
super(fileSystem, logger);
|
|
651
|
-
this.fileSystem = fileSystem;
|
|
652
|
-
this.logger = logger;
|
|
653
|
-
this.configGenerator = new WaspConfigGenerator(logger, fileSystem);
|
|
654
|
-
this.templateUtility = new TemplateUtility(fileSystem);
|
|
655
|
-
this.templateResolver = new TemplateResolver(fileSystem);
|
|
656
|
-
}
|
|
657
640
|
configGenerator;
|
|
658
641
|
templateUtility;
|
|
659
642
|
templateResolver;
|
|
@@ -661,6 +644,15 @@ var WaspGeneratorBase = class extends GeneratorBase {
|
|
|
661
644
|
configLoaded = false;
|
|
662
645
|
// Plugin name from swarm.config.json
|
|
663
646
|
pluginName = PLUGIN_NAME;
|
|
647
|
+
constructor() {
|
|
648
|
+
super();
|
|
649
|
+
this.configGenerator = new WaspConfigGenerator(
|
|
650
|
+
this.logger,
|
|
651
|
+
this.fileSystem
|
|
652
|
+
);
|
|
653
|
+
this.templateUtility = new TemplateUtility(this.fileSystem);
|
|
654
|
+
this.templateResolver = new TemplateResolver(this.fileSystem);
|
|
655
|
+
}
|
|
664
656
|
async loadSwarmConfig() {
|
|
665
657
|
if (this.configLoaded) return;
|
|
666
658
|
const configManager = new SwarmConfigManager();
|
|
@@ -711,7 +703,7 @@ var WaspGeneratorBase = class extends GeneratorBase {
|
|
|
711
703
|
}
|
|
712
704
|
/**
|
|
713
705
|
* Generic existence check with force flag handling
|
|
714
|
-
* Consolidates the pattern used in both file and config checks
|
|
706
|
+
* Consolidates the pattern used in both file and config existence checks
|
|
715
707
|
*/
|
|
716
708
|
checkExistence(exists, itemDescription, force, errorMessage) {
|
|
717
709
|
if (exists && !force) {
|
|
@@ -751,16 +743,14 @@ var schema = z2.object({
|
|
|
751
743
|
|
|
752
744
|
// src/generators/feature/feature-generator.ts
|
|
753
745
|
var FeatureGenerator = class extends WaspGeneratorBase {
|
|
754
|
-
constructor(logger = singletonLogger3, fileSystem = realFileSystem) {
|
|
755
|
-
super(fileSystem, logger);
|
|
756
|
-
this.logger = logger;
|
|
757
|
-
this.fileSystem = fileSystem;
|
|
758
|
-
this.name = "feature";
|
|
759
|
-
this.description = "Generates a feature directory containing a Wasp configuration file";
|
|
760
|
-
}
|
|
761
746
|
name;
|
|
762
747
|
description;
|
|
763
748
|
schema = schema;
|
|
749
|
+
constructor() {
|
|
750
|
+
super();
|
|
751
|
+
this.name = "feature";
|
|
752
|
+
this.description = "Generates a feature directory containing a Wasp configuration file";
|
|
753
|
+
}
|
|
764
754
|
getDefaultTemplatePath(templateName) {
|
|
765
755
|
return this.templateUtility.resolveTemplatePath(
|
|
766
756
|
templateName,
|
|
@@ -776,18 +766,18 @@ var FeatureGenerator = class extends WaspGeneratorBase {
|
|
|
776
766
|
const { target } = args;
|
|
777
767
|
const segments = validateFeaturePath2(target);
|
|
778
768
|
const normalisedPath = normaliseFeaturePath(target);
|
|
779
|
-
const sourceRoot =
|
|
769
|
+
const sourceRoot = path5.join(findWaspRoot(this.fileSystem), "src");
|
|
780
770
|
if (segments.length > 1) {
|
|
781
771
|
const parentPath = segments.slice(0, -1).join("/");
|
|
782
772
|
const parentNormalisedPath = normaliseFeaturePath(parentPath);
|
|
783
|
-
const parentFeatureDir =
|
|
773
|
+
const parentFeatureDir = path5.join(sourceRoot, parentNormalisedPath);
|
|
784
774
|
if (!this.fileSystem.existsSync(parentFeatureDir)) {
|
|
785
775
|
handleFatalError2(
|
|
786
776
|
`Parent feature '${parentPath}' does not exist. Please create it first.`
|
|
787
777
|
);
|
|
788
778
|
}
|
|
789
779
|
}
|
|
790
|
-
const featureDir =
|
|
780
|
+
const featureDir = path5.join(sourceRoot, normalisedPath);
|
|
791
781
|
this.fileSystem.mkdirSync(featureDir, { recursive: true });
|
|
792
782
|
this.configGenerator.generate(normalisedPath);
|
|
793
783
|
this.logger.success(`Generated feature: ${normalisedPath}`);
|
|
@@ -796,13 +786,6 @@ var FeatureGenerator = class extends WaspGeneratorBase {
|
|
|
796
786
|
|
|
797
787
|
// src/generators/base/component-generator.base.ts
|
|
798
788
|
var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
799
|
-
constructor(logger = singletonLogger4, fileSystem = realFileSystem, featureDirectoryGenerator = new FeatureGenerator(logger, fileSystem)) {
|
|
800
|
-
super(fileSystem, logger);
|
|
801
|
-
this.logger = logger;
|
|
802
|
-
this.fileSystem = fileSystem;
|
|
803
|
-
this.featureDirectoryGenerator = featureDirectoryGenerator;
|
|
804
|
-
this.featureDirectoryGenerator = featureDirectoryGenerator;
|
|
805
|
-
}
|
|
806
789
|
getDefaultTemplatePath(templateName) {
|
|
807
790
|
return this.templateUtility.resolveTemplatePath(
|
|
808
791
|
templateName,
|
|
@@ -810,6 +793,17 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
810
793
|
import.meta.url
|
|
811
794
|
);
|
|
812
795
|
}
|
|
796
|
+
featureDirectoryGenerator;
|
|
797
|
+
constructor() {
|
|
798
|
+
super();
|
|
799
|
+
const runtime = GeneratorRuntime.current();
|
|
800
|
+
if (runtime.featureGeneratorFactory) {
|
|
801
|
+
const factoryResult = runtime.featureGeneratorFactory(runtime);
|
|
802
|
+
this.featureDirectoryGenerator = factoryResult;
|
|
803
|
+
} else {
|
|
804
|
+
this.featureDirectoryGenerator = new FeatureGenerator();
|
|
805
|
+
}
|
|
806
|
+
}
|
|
813
807
|
get name() {
|
|
814
808
|
return toKebabCase2(this.componentType);
|
|
815
809
|
}
|
|
@@ -824,7 +818,7 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
824
818
|
const currentPath = pathSegments.join("/");
|
|
825
819
|
const featureName = pathSegments[pathSegments.length - 1];
|
|
826
820
|
const featureDir = getFeatureDir(this.fileSystem, currentPath);
|
|
827
|
-
const configPath =
|
|
821
|
+
const configPath = path6.join(featureDir, `feature.wasp.ts`);
|
|
828
822
|
if (this.fileSystem.existsSync(configPath)) {
|
|
829
823
|
return configPath;
|
|
830
824
|
}
|
|
@@ -886,18 +880,17 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
886
880
|
}
|
|
887
881
|
/**
|
|
888
882
|
* Gets the appropriate directory for a feature based on its path.
|
|
889
|
-
* @param fileSystem - The filesystem abstraction
|
|
890
883
|
* @param featurePath - The full feature path
|
|
891
884
|
* @param type - The type of file being generated
|
|
892
885
|
* @returns The target directory and import path
|
|
893
886
|
*/
|
|
894
|
-
getFeatureTargetDir(
|
|
887
|
+
getFeatureTargetDir(featurePath, type) {
|
|
895
888
|
validateFeaturePath3(featurePath);
|
|
896
889
|
const normalisedPath = normaliseFeaturePath(featurePath);
|
|
897
|
-
const featureDir = getFeatureDir(fileSystem, normalisedPath);
|
|
890
|
+
const featureDir = getFeatureDir(this.fileSystem, normalisedPath);
|
|
898
891
|
const typeKey = type.toLowerCase();
|
|
899
892
|
const typeDirectory = TYPE_DIRECTORIES[typeKey];
|
|
900
|
-
const targetDirectory =
|
|
893
|
+
const targetDirectory = path6.join(featureDir, typeDirectory);
|
|
901
894
|
const importDirectory = `@src/${normalisedPath}/${typeDirectory}`;
|
|
902
895
|
return { targetDirectory, importDirectory };
|
|
903
896
|
}
|
|
@@ -906,7 +899,6 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
906
899
|
*/
|
|
907
900
|
ensureTargetDirectory(featurePath, type) {
|
|
908
901
|
const { targetDirectory, importDirectory } = this.getFeatureTargetDir(
|
|
909
|
-
this.fileSystem,
|
|
910
902
|
featurePath,
|
|
911
903
|
type
|
|
912
904
|
);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// src/generators/base/component-generator.base.ts
|
|
2
2
|
import {
|
|
3
|
+
GeneratorRuntime,
|
|
3
4
|
hasHelperMethodCall,
|
|
4
|
-
logger as singletonLogger4,
|
|
5
5
|
toCamelCase,
|
|
6
6
|
toKebabCase as toKebabCase2,
|
|
7
7
|
validateFeaturePath as validateFeaturePath3
|
|
8
8
|
} from "@ingenyus/swarm";
|
|
9
|
-
import
|
|
9
|
+
import path6 from "path";
|
|
10
10
|
|
|
11
11
|
// src/common/filesystem.ts
|
|
12
12
|
import { toPascalCase, validateFeaturePath } from "@ingenyus/swarm";
|
|
@@ -107,19 +107,15 @@ function getFeatureImportPath(featurePath) {
|
|
|
107
107
|
return segments.join("/");
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
// src/common/plugin.ts
|
|
111
|
-
import path2 from "path";
|
|
112
|
-
import { fileURLToPath } from "url";
|
|
113
|
-
|
|
114
110
|
// src/common/prisma.ts
|
|
115
111
|
import {
|
|
116
112
|
getSchema
|
|
117
113
|
} from "@mrleebo/prisma-ast";
|
|
118
114
|
import fs2 from "fs";
|
|
119
|
-
import
|
|
115
|
+
import path2 from "path";
|
|
120
116
|
async function getEntityMetadata(modelName) {
|
|
121
117
|
try {
|
|
122
|
-
const schemaPath =
|
|
118
|
+
const schemaPath = path2.join(process.cwd(), "schema.prisma");
|
|
123
119
|
const schemaContent = fs2.readFileSync(schemaPath, "utf8");
|
|
124
120
|
const schema2 = getSchema(schemaContent);
|
|
125
121
|
const model = schema2.list?.find(
|
|
@@ -294,7 +290,7 @@ var commonSchemas = {
|
|
|
294
290
|
// src/common/templates.ts
|
|
295
291
|
import { toKebabCase } from "@ingenyus/swarm";
|
|
296
292
|
import { Eta } from "eta";
|
|
297
|
-
import
|
|
293
|
+
import path3 from "path";
|
|
298
294
|
var TemplateUtility = class {
|
|
299
295
|
constructor(fileSystem) {
|
|
300
296
|
this.fileSystem = fileSystem;
|
|
@@ -302,14 +298,14 @@ var TemplateUtility = class {
|
|
|
302
298
|
processTemplate(templatePath, replacements) {
|
|
303
299
|
const declarations = Object.keys(replacements).map((key) => `${key}=it.${key}`).join(", ");
|
|
304
300
|
const functionHeader = declarations ? `const ${declarations};` : void 0;
|
|
305
|
-
const templateDir =
|
|
301
|
+
const templateDir = path3.dirname(templatePath);
|
|
306
302
|
const eta = new Eta({
|
|
307
303
|
autoTrim: false,
|
|
308
304
|
autoEscape: false,
|
|
309
305
|
views: templateDir,
|
|
310
306
|
functionHeader
|
|
311
307
|
});
|
|
312
|
-
const templateName =
|
|
308
|
+
const templateName = path3.basename(templatePath).replace(/\.eta$/, "");
|
|
313
309
|
if (this.fileSystem.existsSync(templatePath)) {
|
|
314
310
|
return eta.render(templateName, replacements);
|
|
315
311
|
} else {
|
|
@@ -327,11 +323,11 @@ var TemplateUtility = class {
|
|
|
327
323
|
resolveTemplatePath(relativePath, generatorName, currentFileUrl) {
|
|
328
324
|
const generatorDirName = toKebabCase(generatorName);
|
|
329
325
|
const currentFilePath = new URL(currentFileUrl).pathname;
|
|
330
|
-
const currentFileDir =
|
|
331
|
-
const currentFileName =
|
|
326
|
+
const currentFileDir = path3.dirname(currentFilePath);
|
|
327
|
+
const currentFileName = path3.basename(currentFilePath);
|
|
332
328
|
const isInstalledPackage = currentFileDir.includes("node_modules") && currentFileDir.endsWith("/dist") && currentFileName === "index.js";
|
|
333
|
-
const startDir = isInstalledPackage ? currentFileDir :
|
|
334
|
-
return
|
|
329
|
+
const startDir = isInstalledPackage ? currentFileDir : path3.dirname(path3.dirname(currentFileDir));
|
|
330
|
+
return path3.join(
|
|
335
331
|
startDir,
|
|
336
332
|
"generators",
|
|
337
333
|
generatorDirName,
|
|
@@ -342,17 +338,12 @@ var TemplateUtility = class {
|
|
|
342
338
|
};
|
|
343
339
|
|
|
344
340
|
// src/generators/feature/feature-generator.ts
|
|
345
|
-
import {
|
|
346
|
-
|
|
347
|
-
logger as singletonLogger3,
|
|
348
|
-
validateFeaturePath as validateFeaturePath2
|
|
349
|
-
} from "@ingenyus/swarm";
|
|
350
|
-
import path6 from "path";
|
|
341
|
+
import { handleFatalError as handleFatalError2, validateFeaturePath as validateFeaturePath2 } from "@ingenyus/swarm";
|
|
342
|
+
import path5 from "path";
|
|
351
343
|
|
|
352
344
|
// src/generators/base/wasp-generator.base.ts
|
|
353
345
|
import {
|
|
354
346
|
GeneratorBase,
|
|
355
|
-
logger as singletonLogger2,
|
|
356
347
|
SwarmConfigManager,
|
|
357
348
|
TemplateResolver
|
|
358
349
|
} from "@ingenyus/swarm";
|
|
@@ -363,14 +354,14 @@ import {
|
|
|
363
354
|
parseHelperMethodDefinition,
|
|
364
355
|
logger as singletonLogger
|
|
365
356
|
} from "@ingenyus/swarm";
|
|
366
|
-
import
|
|
357
|
+
import path4 from "path";
|
|
367
358
|
var WaspConfigGenerator = class {
|
|
368
359
|
constructor(logger = singletonLogger, fileSystem = realFileSystem) {
|
|
369
360
|
this.logger = logger;
|
|
370
361
|
this.fileSystem = fileSystem;
|
|
371
362
|
this.templateUtility = new TemplateUtility(fileSystem);
|
|
372
363
|
}
|
|
373
|
-
path =
|
|
364
|
+
path = path4;
|
|
374
365
|
templateUtility;
|
|
375
366
|
/**
|
|
376
367
|
* Gets the template path for feature config templates.
|
|
@@ -399,7 +390,7 @@ var WaspConfigGenerator = class {
|
|
|
399
390
|
this.logger.error(`Template not found: ${templatePath}`);
|
|
400
391
|
return;
|
|
401
392
|
}
|
|
402
|
-
const configFilePath =
|
|
393
|
+
const configFilePath = path4.join(featureDir, `feature.wasp.ts`);
|
|
403
394
|
if (this.fileSystem.existsSync(configFilePath)) {
|
|
404
395
|
this.logger.warn(`Feature config already exists: ${configFilePath}`);
|
|
405
396
|
return;
|
|
@@ -415,7 +406,7 @@ var WaspConfigGenerator = class {
|
|
|
415
406
|
*/
|
|
416
407
|
update(featurePath, declaration) {
|
|
417
408
|
const configDir = getFeatureDir(this.fileSystem, featurePath);
|
|
418
|
-
const configFilePath =
|
|
409
|
+
const configFilePath = path4.join(configDir, `feature.wasp.ts`);
|
|
419
410
|
if (!this.fileSystem.existsSync(configFilePath)) {
|
|
420
411
|
const templatePath = this.getTemplatePath("feature.wasp.eta");
|
|
421
412
|
if (!this.fileSystem.existsSync(templatePath)) {
|
|
@@ -795,14 +786,6 @@ var WaspConfigGenerator = class {
|
|
|
795
786
|
|
|
796
787
|
// src/generators/base/wasp-generator.base.ts
|
|
797
788
|
var WaspGeneratorBase = class extends GeneratorBase {
|
|
798
|
-
constructor(fileSystem = realFileSystem, logger = singletonLogger2) {
|
|
799
|
-
super(fileSystem, logger);
|
|
800
|
-
this.fileSystem = fileSystem;
|
|
801
|
-
this.logger = logger;
|
|
802
|
-
this.configGenerator = new WaspConfigGenerator(logger, fileSystem);
|
|
803
|
-
this.templateUtility = new TemplateUtility(fileSystem);
|
|
804
|
-
this.templateResolver = new TemplateResolver(fileSystem);
|
|
805
|
-
}
|
|
806
789
|
configGenerator;
|
|
807
790
|
templateUtility;
|
|
808
791
|
templateResolver;
|
|
@@ -810,6 +793,15 @@ var WaspGeneratorBase = class extends GeneratorBase {
|
|
|
810
793
|
configLoaded = false;
|
|
811
794
|
// Plugin name from swarm.config.json
|
|
812
795
|
pluginName = PLUGIN_NAME;
|
|
796
|
+
constructor() {
|
|
797
|
+
super();
|
|
798
|
+
this.configGenerator = new WaspConfigGenerator(
|
|
799
|
+
this.logger,
|
|
800
|
+
this.fileSystem
|
|
801
|
+
);
|
|
802
|
+
this.templateUtility = new TemplateUtility(this.fileSystem);
|
|
803
|
+
this.templateResolver = new TemplateResolver(this.fileSystem);
|
|
804
|
+
}
|
|
813
805
|
async loadSwarmConfig() {
|
|
814
806
|
if (this.configLoaded) return;
|
|
815
807
|
const configManager = new SwarmConfigManager();
|
|
@@ -860,7 +852,7 @@ var WaspGeneratorBase = class extends GeneratorBase {
|
|
|
860
852
|
}
|
|
861
853
|
/**
|
|
862
854
|
* Generic existence check with force flag handling
|
|
863
|
-
* Consolidates the pattern used in both file and config checks
|
|
855
|
+
* Consolidates the pattern used in both file and config existence checks
|
|
864
856
|
*/
|
|
865
857
|
checkExistence(exists, itemDescription, force, errorMessage) {
|
|
866
858
|
if (exists && !force) {
|
|
@@ -900,16 +892,14 @@ var schema = z2.object({
|
|
|
900
892
|
|
|
901
893
|
// src/generators/feature/feature-generator.ts
|
|
902
894
|
var FeatureGenerator = class extends WaspGeneratorBase {
|
|
903
|
-
constructor(logger = singletonLogger3, fileSystem = realFileSystem) {
|
|
904
|
-
super(fileSystem, logger);
|
|
905
|
-
this.logger = logger;
|
|
906
|
-
this.fileSystem = fileSystem;
|
|
907
|
-
this.name = "feature";
|
|
908
|
-
this.description = "Generates a feature directory containing a Wasp configuration file";
|
|
909
|
-
}
|
|
910
895
|
name;
|
|
911
896
|
description;
|
|
912
897
|
schema = schema;
|
|
898
|
+
constructor() {
|
|
899
|
+
super();
|
|
900
|
+
this.name = "feature";
|
|
901
|
+
this.description = "Generates a feature directory containing a Wasp configuration file";
|
|
902
|
+
}
|
|
913
903
|
getDefaultTemplatePath(templateName) {
|
|
914
904
|
return this.templateUtility.resolveTemplatePath(
|
|
915
905
|
templateName,
|
|
@@ -925,18 +915,18 @@ var FeatureGenerator = class extends WaspGeneratorBase {
|
|
|
925
915
|
const { target } = args;
|
|
926
916
|
const segments = validateFeaturePath2(target);
|
|
927
917
|
const normalisedPath = normaliseFeaturePath(target);
|
|
928
|
-
const sourceRoot =
|
|
918
|
+
const sourceRoot = path5.join(findWaspRoot(this.fileSystem), "src");
|
|
929
919
|
if (segments.length > 1) {
|
|
930
920
|
const parentPath = segments.slice(0, -1).join("/");
|
|
931
921
|
const parentNormalisedPath = normaliseFeaturePath(parentPath);
|
|
932
|
-
const parentFeatureDir =
|
|
922
|
+
const parentFeatureDir = path5.join(sourceRoot, parentNormalisedPath);
|
|
933
923
|
if (!this.fileSystem.existsSync(parentFeatureDir)) {
|
|
934
924
|
handleFatalError2(
|
|
935
925
|
`Parent feature '${parentPath}' does not exist. Please create it first.`
|
|
936
926
|
);
|
|
937
927
|
}
|
|
938
928
|
}
|
|
939
|
-
const featureDir =
|
|
929
|
+
const featureDir = path5.join(sourceRoot, normalisedPath);
|
|
940
930
|
this.fileSystem.mkdirSync(featureDir, { recursive: true });
|
|
941
931
|
this.configGenerator.generate(normalisedPath);
|
|
942
932
|
this.logger.success(`Generated feature: ${normalisedPath}`);
|
|
@@ -945,13 +935,6 @@ var FeatureGenerator = class extends WaspGeneratorBase {
|
|
|
945
935
|
|
|
946
936
|
// src/generators/base/component-generator.base.ts
|
|
947
937
|
var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
948
|
-
constructor(logger = singletonLogger4, fileSystem = realFileSystem, featureDirectoryGenerator = new FeatureGenerator(logger, fileSystem)) {
|
|
949
|
-
super(fileSystem, logger);
|
|
950
|
-
this.logger = logger;
|
|
951
|
-
this.fileSystem = fileSystem;
|
|
952
|
-
this.featureDirectoryGenerator = featureDirectoryGenerator;
|
|
953
|
-
this.featureDirectoryGenerator = featureDirectoryGenerator;
|
|
954
|
-
}
|
|
955
938
|
getDefaultTemplatePath(templateName) {
|
|
956
939
|
return this.templateUtility.resolveTemplatePath(
|
|
957
940
|
templateName,
|
|
@@ -959,6 +942,17 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
959
942
|
import.meta.url
|
|
960
943
|
);
|
|
961
944
|
}
|
|
945
|
+
featureDirectoryGenerator;
|
|
946
|
+
constructor() {
|
|
947
|
+
super();
|
|
948
|
+
const runtime = GeneratorRuntime.current();
|
|
949
|
+
if (runtime.featureGeneratorFactory) {
|
|
950
|
+
const factoryResult = runtime.featureGeneratorFactory(runtime);
|
|
951
|
+
this.featureDirectoryGenerator = factoryResult;
|
|
952
|
+
} else {
|
|
953
|
+
this.featureDirectoryGenerator = new FeatureGenerator();
|
|
954
|
+
}
|
|
955
|
+
}
|
|
962
956
|
get name() {
|
|
963
957
|
return toKebabCase2(this.componentType);
|
|
964
958
|
}
|
|
@@ -973,7 +967,7 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
973
967
|
const currentPath = pathSegments.join("/");
|
|
974
968
|
const featureName = pathSegments[pathSegments.length - 1];
|
|
975
969
|
const featureDir = getFeatureDir(this.fileSystem, currentPath);
|
|
976
|
-
const configPath =
|
|
970
|
+
const configPath = path6.join(featureDir, `feature.wasp.ts`);
|
|
977
971
|
if (this.fileSystem.existsSync(configPath)) {
|
|
978
972
|
return configPath;
|
|
979
973
|
}
|
|
@@ -1035,18 +1029,17 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
1035
1029
|
}
|
|
1036
1030
|
/**
|
|
1037
1031
|
* Gets the appropriate directory for a feature based on its path.
|
|
1038
|
-
* @param fileSystem - The filesystem abstraction
|
|
1039
1032
|
* @param featurePath - The full feature path
|
|
1040
1033
|
* @param type - The type of file being generated
|
|
1041
1034
|
* @returns The target directory and import path
|
|
1042
1035
|
*/
|
|
1043
|
-
getFeatureTargetDir(
|
|
1036
|
+
getFeatureTargetDir(featurePath, type) {
|
|
1044
1037
|
validateFeaturePath3(featurePath);
|
|
1045
1038
|
const normalisedPath = normaliseFeaturePath(featurePath);
|
|
1046
|
-
const featureDir = getFeatureDir(fileSystem, normalisedPath);
|
|
1039
|
+
const featureDir = getFeatureDir(this.fileSystem, normalisedPath);
|
|
1047
1040
|
const typeKey = type.toLowerCase();
|
|
1048
1041
|
const typeDirectory = TYPE_DIRECTORIES[typeKey];
|
|
1049
|
-
const targetDirectory =
|
|
1042
|
+
const targetDirectory = path6.join(featureDir, typeDirectory);
|
|
1050
1043
|
const importDirectory = `@src/${normalisedPath}/${typeDirectory}`;
|
|
1051
1044
|
return { targetDirectory, importDirectory };
|
|
1052
1045
|
}
|
|
@@ -1055,7 +1048,6 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
1055
1048
|
*/
|
|
1056
1049
|
ensureTargetDirectory(featurePath, type) {
|
|
1057
1050
|
const { targetDirectory, importDirectory } = this.getFeatureTargetDir(
|
|
1058
|
-
this.fileSystem,
|
|
1059
1051
|
featurePath,
|
|
1060
1052
|
type
|
|
1061
1053
|
);
|