@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
|
@@ -90,16 +90,12 @@ function getRouteNameFromPath(routePath) {
|
|
|
90
90
|
return `${toPascalCase(cleanSegment)}Page`;
|
|
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,
|
|
@@ -205,26 +201,21 @@ var TemplateUtility = class {
|
|
|
205
201
|
|
|
206
202
|
// src/generators/base/component-generator.base.ts
|
|
207
203
|
import {
|
|
204
|
+
GeneratorRuntime,
|
|
208
205
|
hasHelperMethodCall,
|
|
209
|
-
logger as singletonLogger4,
|
|
210
206
|
toCamelCase,
|
|
211
207
|
toKebabCase as toKebabCase2,
|
|
212
208
|
validateFeaturePath as validateFeaturePath3
|
|
213
209
|
} from "@ingenyus/swarm";
|
|
214
|
-
import
|
|
210
|
+
import path6 from "path";
|
|
215
211
|
|
|
216
212
|
// src/generators/feature/feature-generator.ts
|
|
217
|
-
import {
|
|
218
|
-
|
|
219
|
-
logger as singletonLogger3,
|
|
220
|
-
validateFeaturePath as validateFeaturePath2
|
|
221
|
-
} from "@ingenyus/swarm";
|
|
222
|
-
import path6 from "path";
|
|
213
|
+
import { handleFatalError as handleFatalError2, validateFeaturePath as validateFeaturePath2 } from "@ingenyus/swarm";
|
|
214
|
+
import path5 from "path";
|
|
223
215
|
|
|
224
216
|
// src/generators/base/wasp-generator.base.ts
|
|
225
217
|
import {
|
|
226
218
|
GeneratorBase,
|
|
227
|
-
logger as singletonLogger2,
|
|
228
219
|
SwarmConfigManager,
|
|
229
220
|
TemplateResolver
|
|
230
221
|
} from "@ingenyus/swarm";
|
|
@@ -235,14 +226,14 @@ import {
|
|
|
235
226
|
parseHelperMethodDefinition,
|
|
236
227
|
logger as singletonLogger
|
|
237
228
|
} from "@ingenyus/swarm";
|
|
238
|
-
import
|
|
229
|
+
import path4 from "path";
|
|
239
230
|
var WaspConfigGenerator = class {
|
|
240
231
|
constructor(logger = singletonLogger, fileSystem = realFileSystem) {
|
|
241
232
|
this.logger = logger;
|
|
242
233
|
this.fileSystem = fileSystem;
|
|
243
234
|
this.templateUtility = new TemplateUtility(fileSystem);
|
|
244
235
|
}
|
|
245
|
-
path =
|
|
236
|
+
path = path4;
|
|
246
237
|
templateUtility;
|
|
247
238
|
/**
|
|
248
239
|
* Gets the template path for feature config templates.
|
|
@@ -271,7 +262,7 @@ var WaspConfigGenerator = class {
|
|
|
271
262
|
this.logger.error(`Template not found: ${templatePath}`);
|
|
272
263
|
return;
|
|
273
264
|
}
|
|
274
|
-
const configFilePath =
|
|
265
|
+
const configFilePath = path4.join(featureDir, `feature.wasp.ts`);
|
|
275
266
|
if (this.fileSystem.existsSync(configFilePath)) {
|
|
276
267
|
this.logger.warn(`Feature config already exists: ${configFilePath}`);
|
|
277
268
|
return;
|
|
@@ -287,7 +278,7 @@ var WaspConfigGenerator = class {
|
|
|
287
278
|
*/
|
|
288
279
|
update(featurePath, declaration) {
|
|
289
280
|
const configDir = getFeatureDir(this.fileSystem, featurePath);
|
|
290
|
-
const configFilePath =
|
|
281
|
+
const configFilePath = path4.join(configDir, `feature.wasp.ts`);
|
|
291
282
|
if (!this.fileSystem.existsSync(configFilePath)) {
|
|
292
283
|
const templatePath = this.getTemplatePath("feature.wasp.eta");
|
|
293
284
|
if (!this.fileSystem.existsSync(templatePath)) {
|
|
@@ -667,14 +658,6 @@ var WaspConfigGenerator = class {
|
|
|
667
658
|
|
|
668
659
|
// src/generators/base/wasp-generator.base.ts
|
|
669
660
|
var WaspGeneratorBase = class extends GeneratorBase {
|
|
670
|
-
constructor(fileSystem = realFileSystem, logger = singletonLogger2) {
|
|
671
|
-
super(fileSystem, logger);
|
|
672
|
-
this.fileSystem = fileSystem;
|
|
673
|
-
this.logger = logger;
|
|
674
|
-
this.configGenerator = new WaspConfigGenerator(logger, fileSystem);
|
|
675
|
-
this.templateUtility = new TemplateUtility(fileSystem);
|
|
676
|
-
this.templateResolver = new TemplateResolver(fileSystem);
|
|
677
|
-
}
|
|
678
661
|
configGenerator;
|
|
679
662
|
templateUtility;
|
|
680
663
|
templateResolver;
|
|
@@ -682,6 +665,15 @@ var WaspGeneratorBase = class extends GeneratorBase {
|
|
|
682
665
|
configLoaded = false;
|
|
683
666
|
// Plugin name from swarm.config.json
|
|
684
667
|
pluginName = PLUGIN_NAME;
|
|
668
|
+
constructor() {
|
|
669
|
+
super();
|
|
670
|
+
this.configGenerator = new WaspConfigGenerator(
|
|
671
|
+
this.logger,
|
|
672
|
+
this.fileSystem
|
|
673
|
+
);
|
|
674
|
+
this.templateUtility = new TemplateUtility(this.fileSystem);
|
|
675
|
+
this.templateResolver = new TemplateResolver(this.fileSystem);
|
|
676
|
+
}
|
|
685
677
|
async loadSwarmConfig() {
|
|
686
678
|
if (this.configLoaded) return;
|
|
687
679
|
const configManager = new SwarmConfigManager();
|
|
@@ -732,7 +724,7 @@ var WaspGeneratorBase = class extends GeneratorBase {
|
|
|
732
724
|
}
|
|
733
725
|
/**
|
|
734
726
|
* Generic existence check with force flag handling
|
|
735
|
-
* Consolidates the pattern used in both file and config checks
|
|
727
|
+
* Consolidates the pattern used in both file and config existence checks
|
|
736
728
|
*/
|
|
737
729
|
checkExistence(exists, itemDescription, force, errorMessage) {
|
|
738
730
|
if (exists && !force) {
|
|
@@ -772,16 +764,14 @@ var schema = z2.object({
|
|
|
772
764
|
|
|
773
765
|
// src/generators/feature/feature-generator.ts
|
|
774
766
|
var FeatureGenerator = class extends WaspGeneratorBase {
|
|
775
|
-
constructor(logger = singletonLogger3, fileSystem = realFileSystem) {
|
|
776
|
-
super(fileSystem, logger);
|
|
777
|
-
this.logger = logger;
|
|
778
|
-
this.fileSystem = fileSystem;
|
|
779
|
-
this.name = "feature";
|
|
780
|
-
this.description = "Generates a feature directory containing a Wasp configuration file";
|
|
781
|
-
}
|
|
782
767
|
name;
|
|
783
768
|
description;
|
|
784
769
|
schema = schema;
|
|
770
|
+
constructor() {
|
|
771
|
+
super();
|
|
772
|
+
this.name = "feature";
|
|
773
|
+
this.description = "Generates a feature directory containing a Wasp configuration file";
|
|
774
|
+
}
|
|
785
775
|
getDefaultTemplatePath(templateName) {
|
|
786
776
|
return this.templateUtility.resolveTemplatePath(
|
|
787
777
|
templateName,
|
|
@@ -797,18 +787,18 @@ var FeatureGenerator = class extends WaspGeneratorBase {
|
|
|
797
787
|
const { target } = args;
|
|
798
788
|
const segments = validateFeaturePath2(target);
|
|
799
789
|
const normalisedPath = normaliseFeaturePath(target);
|
|
800
|
-
const sourceRoot =
|
|
790
|
+
const sourceRoot = path5.join(findWaspRoot(this.fileSystem), "src");
|
|
801
791
|
if (segments.length > 1) {
|
|
802
792
|
const parentPath = segments.slice(0, -1).join("/");
|
|
803
793
|
const parentNormalisedPath = normaliseFeaturePath(parentPath);
|
|
804
|
-
const parentFeatureDir =
|
|
794
|
+
const parentFeatureDir = path5.join(sourceRoot, parentNormalisedPath);
|
|
805
795
|
if (!this.fileSystem.existsSync(parentFeatureDir)) {
|
|
806
796
|
handleFatalError2(
|
|
807
797
|
`Parent feature '${parentPath}' does not exist. Please create it first.`
|
|
808
798
|
);
|
|
809
799
|
}
|
|
810
800
|
}
|
|
811
|
-
const featureDir =
|
|
801
|
+
const featureDir = path5.join(sourceRoot, normalisedPath);
|
|
812
802
|
this.fileSystem.mkdirSync(featureDir, { recursive: true });
|
|
813
803
|
this.configGenerator.generate(normalisedPath);
|
|
814
804
|
this.logger.success(`Generated feature: ${normalisedPath}`);
|
|
@@ -817,13 +807,6 @@ var FeatureGenerator = class extends WaspGeneratorBase {
|
|
|
817
807
|
|
|
818
808
|
// src/generators/base/component-generator.base.ts
|
|
819
809
|
var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
820
|
-
constructor(logger = singletonLogger4, fileSystem = realFileSystem, featureDirectoryGenerator = new FeatureGenerator(logger, fileSystem)) {
|
|
821
|
-
super(fileSystem, logger);
|
|
822
|
-
this.logger = logger;
|
|
823
|
-
this.fileSystem = fileSystem;
|
|
824
|
-
this.featureDirectoryGenerator = featureDirectoryGenerator;
|
|
825
|
-
this.featureDirectoryGenerator = featureDirectoryGenerator;
|
|
826
|
-
}
|
|
827
810
|
getDefaultTemplatePath(templateName) {
|
|
828
811
|
return this.templateUtility.resolveTemplatePath(
|
|
829
812
|
templateName,
|
|
@@ -831,6 +814,17 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
831
814
|
import.meta.url
|
|
832
815
|
);
|
|
833
816
|
}
|
|
817
|
+
featureDirectoryGenerator;
|
|
818
|
+
constructor() {
|
|
819
|
+
super();
|
|
820
|
+
const runtime = GeneratorRuntime.current();
|
|
821
|
+
if (runtime.featureGeneratorFactory) {
|
|
822
|
+
const factoryResult = runtime.featureGeneratorFactory(runtime);
|
|
823
|
+
this.featureDirectoryGenerator = factoryResult;
|
|
824
|
+
} else {
|
|
825
|
+
this.featureDirectoryGenerator = new FeatureGenerator();
|
|
826
|
+
}
|
|
827
|
+
}
|
|
834
828
|
get name() {
|
|
835
829
|
return toKebabCase2(this.componentType);
|
|
836
830
|
}
|
|
@@ -845,7 +839,7 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
845
839
|
const currentPath = pathSegments.join("/");
|
|
846
840
|
const featureName = pathSegments[pathSegments.length - 1];
|
|
847
841
|
const featureDir = getFeatureDir(this.fileSystem, currentPath);
|
|
848
|
-
const configPath =
|
|
842
|
+
const configPath = path6.join(featureDir, `feature.wasp.ts`);
|
|
849
843
|
if (this.fileSystem.existsSync(configPath)) {
|
|
850
844
|
return configPath;
|
|
851
845
|
}
|
|
@@ -907,18 +901,17 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
907
901
|
}
|
|
908
902
|
/**
|
|
909
903
|
* Gets the appropriate directory for a feature based on its path.
|
|
910
|
-
* @param fileSystem - The filesystem abstraction
|
|
911
904
|
* @param featurePath - The full feature path
|
|
912
905
|
* @param type - The type of file being generated
|
|
913
906
|
* @returns The target directory and import path
|
|
914
907
|
*/
|
|
915
|
-
getFeatureTargetDir(
|
|
908
|
+
getFeatureTargetDir(featurePath, type) {
|
|
916
909
|
validateFeaturePath3(featurePath);
|
|
917
910
|
const normalisedPath = normaliseFeaturePath(featurePath);
|
|
918
|
-
const featureDir = getFeatureDir(fileSystem, normalisedPath);
|
|
911
|
+
const featureDir = getFeatureDir(this.fileSystem, normalisedPath);
|
|
919
912
|
const typeKey = type.toLowerCase();
|
|
920
913
|
const typeDirectory = TYPE_DIRECTORIES[typeKey];
|
|
921
|
-
const targetDirectory =
|
|
914
|
+
const targetDirectory = path6.join(featureDir, typeDirectory);
|
|
922
915
|
const importDirectory = `@src/${normalisedPath}/${typeDirectory}`;
|
|
923
916
|
return { targetDirectory, importDirectory };
|
|
924
917
|
}
|
|
@@ -927,7 +920,6 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
927
920
|
*/
|
|
928
921
|
ensureTargetDirectory(featurePath, type) {
|
|
929
922
|
const { targetDirectory, importDirectory } = this.getFeatureTargetDir(
|
|
930
|
-
this.fileSystem,
|
|
931
923
|
featurePath,
|
|
932
924
|
type
|
|
933
925
|
);
|
|
@@ -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";
|
package/dist/index.js
CHANGED
|
@@ -59,13 +59,13 @@ var CONFIG_TYPES = {
|
|
|
59
59
|
|
|
60
60
|
// src/generators/base/component-generator.base.ts
|
|
61
61
|
import {
|
|
62
|
+
GeneratorRuntime,
|
|
62
63
|
hasHelperMethodCall,
|
|
63
|
-
logger as singletonLogger4,
|
|
64
64
|
toCamelCase,
|
|
65
65
|
toKebabCase as toKebabCase2,
|
|
66
66
|
validateFeaturePath as validateFeaturePath3
|
|
67
67
|
} from "@ingenyus/swarm";
|
|
68
|
-
import
|
|
68
|
+
import path6 from "path";
|
|
69
69
|
|
|
70
70
|
// src/common/filesystem.ts
|
|
71
71
|
import { toPascalCase, validateFeaturePath } from "@ingenyus/swarm";
|
|
@@ -143,39 +143,15 @@ function getRouteNameFromPath(routePath) {
|
|
|
143
143
|
return `${toPascalCase(cleanSegment)}Page`;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
// src/common/plugin.ts
|
|
147
|
-
import path2 from "path";
|
|
148
|
-
import { fileURLToPath } from "url";
|
|
149
|
-
function getPluginVersion() {
|
|
150
|
-
const __dirname = path2.dirname(fileURLToPath(import.meta.url));
|
|
151
|
-
let currentDir = __dirname;
|
|
152
|
-
while (currentDir !== path2.dirname(currentDir)) {
|
|
153
|
-
const packageJsonPath = path2.join(currentDir, "package.json");
|
|
154
|
-
if (realFileSystem.existsSync(packageJsonPath)) {
|
|
155
|
-
try {
|
|
156
|
-
const packageJson = JSON.parse(
|
|
157
|
-
realFileSystem.readFileSync(packageJsonPath, "utf8")
|
|
158
|
-
);
|
|
159
|
-
if (packageJson.name === "@ingenyus/swarm-wasp") {
|
|
160
|
-
return packageJson.version;
|
|
161
|
-
}
|
|
162
|
-
} catch (e) {
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
currentDir = path2.dirname(currentDir);
|
|
166
|
-
}
|
|
167
|
-
return "0.1.0";
|
|
168
|
-
}
|
|
169
|
-
|
|
170
146
|
// src/common/prisma.ts
|
|
171
147
|
import {
|
|
172
148
|
getSchema
|
|
173
149
|
} from "@mrleebo/prisma-ast";
|
|
174
150
|
import fs2 from "fs";
|
|
175
|
-
import
|
|
151
|
+
import path2 from "path";
|
|
176
152
|
async function getEntityMetadata(modelName) {
|
|
177
153
|
try {
|
|
178
|
-
const schemaPath =
|
|
154
|
+
const schemaPath = path2.join(process.cwd(), "schema.prisma");
|
|
179
155
|
const schemaContent = fs2.readFileSync(schemaPath, "utf8");
|
|
180
156
|
const schema9 = getSchema(schemaContent);
|
|
181
157
|
const model = schema9.list?.find(
|
|
@@ -350,7 +326,7 @@ var commonSchemas = {
|
|
|
350
326
|
// src/common/templates.ts
|
|
351
327
|
import { toKebabCase } from "@ingenyus/swarm";
|
|
352
328
|
import { Eta } from "eta";
|
|
353
|
-
import
|
|
329
|
+
import path3 from "path";
|
|
354
330
|
var TemplateUtility = class {
|
|
355
331
|
constructor(fileSystem) {
|
|
356
332
|
this.fileSystem = fileSystem;
|
|
@@ -358,14 +334,14 @@ var TemplateUtility = class {
|
|
|
358
334
|
processTemplate(templatePath, replacements) {
|
|
359
335
|
const declarations = Object.keys(replacements).map((key) => `${key}=it.${key}`).join(", ");
|
|
360
336
|
const functionHeader = declarations ? `const ${declarations};` : void 0;
|
|
361
|
-
const templateDir =
|
|
337
|
+
const templateDir = path3.dirname(templatePath);
|
|
362
338
|
const eta = new Eta({
|
|
363
339
|
autoTrim: false,
|
|
364
340
|
autoEscape: false,
|
|
365
341
|
views: templateDir,
|
|
366
342
|
functionHeader
|
|
367
343
|
});
|
|
368
|
-
const templateName =
|
|
344
|
+
const templateName = path3.basename(templatePath).replace(/\.eta$/, "");
|
|
369
345
|
if (this.fileSystem.existsSync(templatePath)) {
|
|
370
346
|
return eta.render(templateName, replacements);
|
|
371
347
|
} else {
|
|
@@ -383,11 +359,11 @@ var TemplateUtility = class {
|
|
|
383
359
|
resolveTemplatePath(relativePath, generatorName, currentFileUrl) {
|
|
384
360
|
const generatorDirName = toKebabCase(generatorName);
|
|
385
361
|
const currentFilePath = new URL(currentFileUrl).pathname;
|
|
386
|
-
const currentFileDir =
|
|
387
|
-
const currentFileName =
|
|
362
|
+
const currentFileDir = path3.dirname(currentFilePath);
|
|
363
|
+
const currentFileName = path3.basename(currentFilePath);
|
|
388
364
|
const isInstalledPackage = currentFileDir.includes("node_modules") && currentFileDir.endsWith("/dist") && currentFileName === "index.js";
|
|
389
|
-
const startDir = isInstalledPackage ? currentFileDir :
|
|
390
|
-
return
|
|
365
|
+
const startDir = isInstalledPackage ? currentFileDir : path3.dirname(path3.dirname(currentFileDir));
|
|
366
|
+
return path3.join(
|
|
391
367
|
startDir,
|
|
392
368
|
"generators",
|
|
393
369
|
generatorDirName,
|
|
@@ -398,17 +374,12 @@ var TemplateUtility = class {
|
|
|
398
374
|
};
|
|
399
375
|
|
|
400
376
|
// src/generators/feature/feature-generator.ts
|
|
401
|
-
import {
|
|
402
|
-
|
|
403
|
-
logger as singletonLogger3,
|
|
404
|
-
validateFeaturePath as validateFeaturePath2
|
|
405
|
-
} from "@ingenyus/swarm";
|
|
406
|
-
import path6 from "path";
|
|
377
|
+
import { handleFatalError as handleFatalError2, validateFeaturePath as validateFeaturePath2 } from "@ingenyus/swarm";
|
|
378
|
+
import path5 from "path";
|
|
407
379
|
|
|
408
380
|
// src/generators/base/wasp-generator.base.ts
|
|
409
381
|
import {
|
|
410
382
|
GeneratorBase,
|
|
411
|
-
logger as singletonLogger2,
|
|
412
383
|
SwarmConfigManager,
|
|
413
384
|
TemplateResolver
|
|
414
385
|
} from "@ingenyus/swarm";
|
|
@@ -419,14 +390,14 @@ import {
|
|
|
419
390
|
parseHelperMethodDefinition,
|
|
420
391
|
logger as singletonLogger
|
|
421
392
|
} from "@ingenyus/swarm";
|
|
422
|
-
import
|
|
393
|
+
import path4 from "path";
|
|
423
394
|
var WaspConfigGenerator = class {
|
|
424
395
|
constructor(logger = singletonLogger, fileSystem = realFileSystem) {
|
|
425
396
|
this.logger = logger;
|
|
426
397
|
this.fileSystem = fileSystem;
|
|
427
398
|
this.templateUtility = new TemplateUtility(fileSystem);
|
|
428
399
|
}
|
|
429
|
-
path =
|
|
400
|
+
path = path4;
|
|
430
401
|
templateUtility;
|
|
431
402
|
/**
|
|
432
403
|
* Gets the template path for feature config templates.
|
|
@@ -455,7 +426,7 @@ var WaspConfigGenerator = class {
|
|
|
455
426
|
this.logger.error(`Template not found: ${templatePath}`);
|
|
456
427
|
return;
|
|
457
428
|
}
|
|
458
|
-
const configFilePath =
|
|
429
|
+
const configFilePath = path4.join(featureDir, `feature.wasp.ts`);
|
|
459
430
|
if (this.fileSystem.existsSync(configFilePath)) {
|
|
460
431
|
this.logger.warn(`Feature config already exists: ${configFilePath}`);
|
|
461
432
|
return;
|
|
@@ -471,7 +442,7 @@ var WaspConfigGenerator = class {
|
|
|
471
442
|
*/
|
|
472
443
|
update(featurePath, declaration) {
|
|
473
444
|
const configDir = getFeatureDir(this.fileSystem, featurePath);
|
|
474
|
-
const configFilePath =
|
|
445
|
+
const configFilePath = path4.join(configDir, `feature.wasp.ts`);
|
|
475
446
|
if (!this.fileSystem.existsSync(configFilePath)) {
|
|
476
447
|
const templatePath = this.getTemplatePath("feature.wasp.eta");
|
|
477
448
|
if (!this.fileSystem.existsSync(templatePath)) {
|
|
@@ -851,14 +822,6 @@ var WaspConfigGenerator = class {
|
|
|
851
822
|
|
|
852
823
|
// src/generators/base/wasp-generator.base.ts
|
|
853
824
|
var WaspGeneratorBase = class extends GeneratorBase {
|
|
854
|
-
constructor(fileSystem = realFileSystem, logger = singletonLogger2) {
|
|
855
|
-
super(fileSystem, logger);
|
|
856
|
-
this.fileSystem = fileSystem;
|
|
857
|
-
this.logger = logger;
|
|
858
|
-
this.configGenerator = new WaspConfigGenerator(logger, fileSystem);
|
|
859
|
-
this.templateUtility = new TemplateUtility(fileSystem);
|
|
860
|
-
this.templateResolver = new TemplateResolver(fileSystem);
|
|
861
|
-
}
|
|
862
825
|
configGenerator;
|
|
863
826
|
templateUtility;
|
|
864
827
|
templateResolver;
|
|
@@ -866,6 +829,15 @@ var WaspGeneratorBase = class extends GeneratorBase {
|
|
|
866
829
|
configLoaded = false;
|
|
867
830
|
// Plugin name from swarm.config.json
|
|
868
831
|
pluginName = PLUGIN_NAME;
|
|
832
|
+
constructor() {
|
|
833
|
+
super();
|
|
834
|
+
this.configGenerator = new WaspConfigGenerator(
|
|
835
|
+
this.logger,
|
|
836
|
+
this.fileSystem
|
|
837
|
+
);
|
|
838
|
+
this.templateUtility = new TemplateUtility(this.fileSystem);
|
|
839
|
+
this.templateResolver = new TemplateResolver(this.fileSystem);
|
|
840
|
+
}
|
|
869
841
|
async loadSwarmConfig() {
|
|
870
842
|
if (this.configLoaded) return;
|
|
871
843
|
const configManager = new SwarmConfigManager();
|
|
@@ -916,7 +888,7 @@ var WaspGeneratorBase = class extends GeneratorBase {
|
|
|
916
888
|
}
|
|
917
889
|
/**
|
|
918
890
|
* Generic existence check with force flag handling
|
|
919
|
-
* Consolidates the pattern used in both file and config checks
|
|
891
|
+
* Consolidates the pattern used in both file and config existence checks
|
|
920
892
|
*/
|
|
921
893
|
checkExistence(exists, itemDescription, force, errorMessage) {
|
|
922
894
|
if (exists && !force) {
|
|
@@ -956,16 +928,14 @@ var schema = z2.object({
|
|
|
956
928
|
|
|
957
929
|
// src/generators/feature/feature-generator.ts
|
|
958
930
|
var FeatureGenerator = class extends WaspGeneratorBase {
|
|
959
|
-
constructor(logger = singletonLogger3, fileSystem = realFileSystem) {
|
|
960
|
-
super(fileSystem, logger);
|
|
961
|
-
this.logger = logger;
|
|
962
|
-
this.fileSystem = fileSystem;
|
|
963
|
-
this.name = "feature";
|
|
964
|
-
this.description = "Generates a feature directory containing a Wasp configuration file";
|
|
965
|
-
}
|
|
966
931
|
name;
|
|
967
932
|
description;
|
|
968
933
|
schema = schema;
|
|
934
|
+
constructor() {
|
|
935
|
+
super();
|
|
936
|
+
this.name = "feature";
|
|
937
|
+
this.description = "Generates a feature directory containing a Wasp configuration file";
|
|
938
|
+
}
|
|
969
939
|
getDefaultTemplatePath(templateName) {
|
|
970
940
|
return this.templateUtility.resolveTemplatePath(
|
|
971
941
|
templateName,
|
|
@@ -981,18 +951,18 @@ var FeatureGenerator = class extends WaspGeneratorBase {
|
|
|
981
951
|
const { target } = args;
|
|
982
952
|
const segments = validateFeaturePath2(target);
|
|
983
953
|
const normalisedPath = normaliseFeaturePath(target);
|
|
984
|
-
const sourceRoot =
|
|
954
|
+
const sourceRoot = path5.join(findWaspRoot(this.fileSystem), "src");
|
|
985
955
|
if (segments.length > 1) {
|
|
986
956
|
const parentPath = segments.slice(0, -1).join("/");
|
|
987
957
|
const parentNormalisedPath = normaliseFeaturePath(parentPath);
|
|
988
|
-
const parentFeatureDir =
|
|
958
|
+
const parentFeatureDir = path5.join(sourceRoot, parentNormalisedPath);
|
|
989
959
|
if (!this.fileSystem.existsSync(parentFeatureDir)) {
|
|
990
960
|
handleFatalError2(
|
|
991
961
|
`Parent feature '${parentPath}' does not exist. Please create it first.`
|
|
992
962
|
);
|
|
993
963
|
}
|
|
994
964
|
}
|
|
995
|
-
const featureDir =
|
|
965
|
+
const featureDir = path5.join(sourceRoot, normalisedPath);
|
|
996
966
|
this.fileSystem.mkdirSync(featureDir, { recursive: true });
|
|
997
967
|
this.configGenerator.generate(normalisedPath);
|
|
998
968
|
this.logger.success(`Generated feature: ${normalisedPath}`);
|
|
@@ -1001,13 +971,6 @@ var FeatureGenerator = class extends WaspGeneratorBase {
|
|
|
1001
971
|
|
|
1002
972
|
// src/generators/base/component-generator.base.ts
|
|
1003
973
|
var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
1004
|
-
constructor(logger = singletonLogger4, fileSystem = realFileSystem, featureDirectoryGenerator = new FeatureGenerator(logger, fileSystem)) {
|
|
1005
|
-
super(fileSystem, logger);
|
|
1006
|
-
this.logger = logger;
|
|
1007
|
-
this.fileSystem = fileSystem;
|
|
1008
|
-
this.featureDirectoryGenerator = featureDirectoryGenerator;
|
|
1009
|
-
this.featureDirectoryGenerator = featureDirectoryGenerator;
|
|
1010
|
-
}
|
|
1011
974
|
getDefaultTemplatePath(templateName) {
|
|
1012
975
|
return this.templateUtility.resolveTemplatePath(
|
|
1013
976
|
templateName,
|
|
@@ -1015,6 +978,17 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
1015
978
|
import.meta.url
|
|
1016
979
|
);
|
|
1017
980
|
}
|
|
981
|
+
featureDirectoryGenerator;
|
|
982
|
+
constructor() {
|
|
983
|
+
super();
|
|
984
|
+
const runtime = GeneratorRuntime.current();
|
|
985
|
+
if (runtime.featureGeneratorFactory) {
|
|
986
|
+
const factoryResult = runtime.featureGeneratorFactory(runtime);
|
|
987
|
+
this.featureDirectoryGenerator = factoryResult;
|
|
988
|
+
} else {
|
|
989
|
+
this.featureDirectoryGenerator = new FeatureGenerator();
|
|
990
|
+
}
|
|
991
|
+
}
|
|
1018
992
|
get name() {
|
|
1019
993
|
return toKebabCase2(this.componentType);
|
|
1020
994
|
}
|
|
@@ -1029,7 +1003,7 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
1029
1003
|
const currentPath = pathSegments.join("/");
|
|
1030
1004
|
const featureName = pathSegments[pathSegments.length - 1];
|
|
1031
1005
|
const featureDir = getFeatureDir(this.fileSystem, currentPath);
|
|
1032
|
-
const configPath =
|
|
1006
|
+
const configPath = path6.join(featureDir, `feature.wasp.ts`);
|
|
1033
1007
|
if (this.fileSystem.existsSync(configPath)) {
|
|
1034
1008
|
return configPath;
|
|
1035
1009
|
}
|
|
@@ -1091,18 +1065,17 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
1091
1065
|
}
|
|
1092
1066
|
/**
|
|
1093
1067
|
* Gets the appropriate directory for a feature based on its path.
|
|
1094
|
-
* @param fileSystem - The filesystem abstraction
|
|
1095
1068
|
* @param featurePath - The full feature path
|
|
1096
1069
|
* @param type - The type of file being generated
|
|
1097
1070
|
* @returns The target directory and import path
|
|
1098
1071
|
*/
|
|
1099
|
-
getFeatureTargetDir(
|
|
1072
|
+
getFeatureTargetDir(featurePath, type) {
|
|
1100
1073
|
validateFeaturePath3(featurePath);
|
|
1101
1074
|
const normalisedPath = normaliseFeaturePath(featurePath);
|
|
1102
|
-
const featureDir = getFeatureDir(fileSystem, normalisedPath);
|
|
1075
|
+
const featureDir = getFeatureDir(this.fileSystem, normalisedPath);
|
|
1103
1076
|
const typeKey = type.toLowerCase();
|
|
1104
1077
|
const typeDirectory = TYPE_DIRECTORIES[typeKey];
|
|
1105
|
-
const targetDirectory =
|
|
1078
|
+
const targetDirectory = path6.join(featureDir, typeDirectory);
|
|
1106
1079
|
const importDirectory = `@src/${normalisedPath}/${typeDirectory}`;
|
|
1107
1080
|
return { targetDirectory, importDirectory };
|
|
1108
1081
|
}
|
|
@@ -1111,7 +1084,6 @@ var ComponentGeneratorBase = class extends WaspGeneratorBase {
|
|
|
1111
1084
|
*/
|
|
1112
1085
|
ensureTargetDirectory(featurePath, type) {
|
|
1113
1086
|
const { targetDirectory, importDirectory } = this.getFeatureTargetDir(
|
|
1114
|
-
this.fileSystem,
|
|
1115
1087
|
featurePath,
|
|
1116
1088
|
type
|
|
1117
1089
|
);
|
|
@@ -1550,7 +1522,7 @@ var ApiGenerator = class extends ComponentGeneratorBase {
|
|
|
1550
1522
|
force = false,
|
|
1551
1523
|
entities,
|
|
1552
1524
|
method,
|
|
1553
|
-
path:
|
|
1525
|
+
path: path9,
|
|
1554
1526
|
auth,
|
|
1555
1527
|
customMiddleware
|
|
1556
1528
|
} = args;
|
|
@@ -1560,7 +1532,7 @@ var ApiGenerator = class extends ComponentGeneratorBase {
|
|
|
1560
1532
|
feature,
|
|
1561
1533
|
Array.isArray(entities) ? entities : entities ? [entities] : [],
|
|
1562
1534
|
method,
|
|
1563
|
-
|
|
1535
|
+
path9,
|
|
1564
1536
|
apiFile,
|
|
1565
1537
|
auth,
|
|
1566
1538
|
importPath,
|
|
@@ -1616,7 +1588,7 @@ var ApiGenerator = class extends ComponentGeneratorBase {
|
|
|
1616
1588
|
|
|
1617
1589
|
// src/generators/api-namespace/api-namespace-generator.ts
|
|
1618
1590
|
import { toCamelCase as toCamelCase3 } from "@ingenyus/swarm";
|
|
1619
|
-
import
|
|
1591
|
+
import path7 from "path";
|
|
1620
1592
|
|
|
1621
1593
|
// src/generators/api-namespace/schema.ts
|
|
1622
1594
|
import { z as z5 } from "zod";
|
|
@@ -1664,7 +1636,7 @@ var ApiNamespaceGenerator = class extends ComponentGeneratorBase {
|
|
|
1664
1636
|
}
|
|
1665
1637
|
async updateConfigFile(namespaceName, importDirectory, namespacePath, args, configFilePath) {
|
|
1666
1638
|
const { force = false } = args;
|
|
1667
|
-
const importPath =
|
|
1639
|
+
const importPath = path7.join(importDirectory, namespaceName);
|
|
1668
1640
|
const definition = await this.getDefinition(
|
|
1669
1641
|
namespaceName,
|
|
1670
1642
|
importPath,
|
|
@@ -2226,8 +2198,6 @@ var RouteGenerator = class extends ComponentGeneratorBase {
|
|
|
2226
2198
|
// src/plugins/wasp.ts
|
|
2227
2199
|
var wasp = {
|
|
2228
2200
|
name: PLUGIN_NAME,
|
|
2229
|
-
version: getPluginVersion(),
|
|
2230
|
-
description: "Wasp Plugin for Swarm",
|
|
2231
2201
|
generators: [
|
|
2232
2202
|
new ActionGenerator(),
|
|
2233
2203
|
new ApiGenerator(),
|
|
@@ -2242,7 +2212,7 @@ var wasp = {
|
|
|
2242
2212
|
|
|
2243
2213
|
// src/wasp-config/app.ts
|
|
2244
2214
|
import fs3 from "fs";
|
|
2245
|
-
import
|
|
2215
|
+
import path8 from "path";
|
|
2246
2216
|
import {
|
|
2247
2217
|
App as WaspApp
|
|
2248
2218
|
} from "wasp-config";
|
|
@@ -2535,7 +2505,7 @@ var App = class _App extends WaspApp {
|
|
|
2535
2505
|
* Configures all feature modules by scanning the features directory
|
|
2536
2506
|
*/
|
|
2537
2507
|
async configureFeatures() {
|
|
2538
|
-
const featuresDir =
|
|
2508
|
+
const featuresDir = path8.join(process.cwd(), "src", "features");
|
|
2539
2509
|
if (!fs3.existsSync(featuresDir)) {
|
|
2540
2510
|
console.warn(
|
|
2541
2511
|
"Features directory not found, skipping feature configuration"
|
|
@@ -2546,11 +2516,11 @@ var App = class _App extends WaspApp {
|
|
|
2546
2516
|
let results = [];
|
|
2547
2517
|
const list = fs3.readdirSync(dir, { withFileTypes: true });
|
|
2548
2518
|
for (const entry of list) {
|
|
2549
|
-
const fullPath =
|
|
2519
|
+
const fullPath = path8.join(dir, entry.name);
|
|
2550
2520
|
if (entry.isDirectory()) {
|
|
2551
2521
|
results = results.concat(getAllFeatureFiles(fullPath));
|
|
2552
2522
|
} else if (entry.isFile() && entry.name.endsWith(".wasp.ts")) {
|
|
2553
|
-
results.push(
|
|
2523
|
+
results.push(path8.relative(featuresDir, fullPath));
|
|
2554
2524
|
}
|
|
2555
2525
|
}
|
|
2556
2526
|
return results;
|
|
@@ -2558,8 +2528,8 @@ var App = class _App extends WaspApp {
|
|
|
2558
2528
|
const featureFiles = getAllFeatureFiles(featuresDir);
|
|
2559
2529
|
for (const file of featureFiles) {
|
|
2560
2530
|
try {
|
|
2561
|
-
const featureName =
|
|
2562
|
-
const modulePath =
|
|
2531
|
+
const featureName = path8.dirname(file);
|
|
2532
|
+
const modulePath = path8.join(
|
|
2563
2533
|
process.cwd(),
|
|
2564
2534
|
".wasp",
|
|
2565
2535
|
"src",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasp.d.ts","sourceRoot":"","sources":["../../src/plugins/wasp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"wasp.d.ts","sourceRoot":"","sources":["../../src/plugins/wasp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAa9C,eAAO,MAAM,IAAI,EAAE,WAYlB,CAAC"}
|