Skip to content

Commit 6495331

Browse files
committed
feat: introduce CreateUC command to the CLI
1 parent eb97582 commit 6495331

File tree

23 files changed

+267
-25
lines changed

23 files changed

+267
-25
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export declare const LIB_NAME = "libmodulor";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const LIB_NAME = 'libmodulor';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
import type { FileName } from '../../../../dt/index.js';
2+
import type { Creatable } from './types.js';
23
export declare function fileImportName(name: FileName): FileName;
4+
export declare function successMessage(item: Creatable): string;
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
export function fileImportName(name) {
2-
return name.replaceAll('.ts', '.js');
2+
if (name.endsWith('.ts')) {
3+
return name.replaceAll('.ts', '.js');
4+
}
5+
return `${name}.js`;
6+
}
7+
export function successMessage(item) {
8+
return `${item} created successfully !`;
39
}

dist/esm/apps/Helper/src/lib/layers/app.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import { APP_I18N_FILE_NAME, APP_I18N_NAME, APP_INDEX_FILE_NAME, APP_MANIFEST_FILE_NAME, APP_MANIFEST_NAME, APP_SRC_DIR_NAME, } from '../../../../../convention.js';
22
import { I18N_DEFAULT_LANG } from '../../../../../i18n/index.js';
3+
import { LIB_NAME } from '../consts.js';
34
import { fileImportName } from '../funcs.js';
45
const INDEX_TS = `// Expose only what's necessary
56
67
export { ${APP_I18N_NAME} } from './${APP_SRC_DIR_NAME}/${fileImportName(APP_I18N_FILE_NAME)}';
78
export { ${APP_MANIFEST_NAME} } from './${APP_SRC_DIR_NAME}/${fileImportName(APP_MANIFEST_FILE_NAME)}';
89
`;
9-
const I18N_TS = `import type { AppI18n } from 'libmodulor';
10+
const I18N_TS = `import type { AppI18n } from '${LIB_NAME}';
1011
1112
export const ${APP_I18N_NAME} = {
1213
${I18N_DEFAULT_LANG}: {},
1314
} satisfies AppI18n;
1415
`;
15-
const MANIFEST_TS = (name) => `import type { AppManifest } from 'libmodulor';
16+
const MANIFEST_TS = (name) => `import type { AppManifest } from '${LIB_NAME}';
1617
1718
export const ${APP_MANIFEST_NAME} = {
1819
languageCodes: ['${I18N_DEFAULT_LANG}'],

dist/esm/apps/Helper/src/lib/layers/product.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { PRODUCT_I18N_FILE_NAME, PRODUCT_I18N_NAME, PRODUCT_MANIFEST_FILE_NAME, } from '../../../../../convention.js';
1+
import { PRODUCT_I18N_FILE_NAME, PRODUCT_I18N_NAME, PRODUCT_MANIFEST_FILE_NAME, PRODUCT_MANIFEST_NAME, } from '../../../../../convention.js';
22
import { I18N_DEFAULT_LANG } from '../../../../../i18n/index.js';
3-
const I18N_TS = `import type { ProductI18n } from 'libmodulor';
3+
import { LIB_NAME } from '../consts.js';
4+
const I18N_TS = `import type { ProductI18n } from '${LIB_NAME}';
45
import { I18n${I18N_DEFAULT_LANG.toLocaleUpperCase()} } from 'libmodulor/locales/${I18N_DEFAULT_LANG}';
56
67
export const ${PRODUCT_I18N_NAME} = {
@@ -11,9 +12,9 @@ export const ${PRODUCT_I18N_NAME} = {
1112
},
1213
} satisfies ProductI18n;
1314
`;
14-
const MANIFEST_TS = (name) => `import type { ProductManifest } from 'libmodulor';
15+
const MANIFEST_TS = (name) => `import type { ProductManifest } from '${LIB_NAME}';
1516
16-
export const Manifest = {
17+
export const ${PRODUCT_MANIFEST_NAME} = {
1718
appReg: [],
1819
name: '${name}',
1920
} satisfies ProductManifest;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { UCName } from '../../../../../uc/index.js';
2+
import type { Files } from '../SrcFilesGenerator.js';
3+
export declare function files(name: UCName): Files;
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import { APP_MANIFEST_FILE_NAME, APP_MANIFEST_NAME, UC_DEF_FILE_NAME_SUFFIX, UC_DEF_SUFFIX, UC_DEF_TYPE, UC_INPUT_SUFFIX, UC_MAIN_SERVER_FILE_NAME_SUFFIX, UC_MAIN_SERVER_SUFFIX, UC_OPI0_SUFFIX, } from '../../../../../convention.js';
2+
import { LIB_NAME } from '../consts.js';
3+
import { fileImportName } from '../funcs.js';
4+
const TODO = '// TODO : Replace me';
5+
const FIELD_NAME = 'foo';
6+
const UCD_TS = (name) => `import {
7+
type FreeTextShort,
8+
NobodyUCPolicy,
9+
SendClientMain,
10+
TFreeTextShort,
11+
type UCDef,
12+
type UCInput,
13+
type UCInputFieldValue,
14+
type UCOPIBase,
15+
} from '${LIB_NAME}';
16+
17+
import { ${APP_MANIFEST_NAME} } from '../${fileImportName(APP_MANIFEST_FILE_NAME)}';
18+
import { ${name}${UC_MAIN_SERVER_SUFFIX} } from './${fileImportName(`${name}${UC_MAIN_SERVER_SUFFIX}`)}';
19+
20+
export interface ${name}${UC_INPUT_SUFFIX} extends UCInput {
21+
${TODO}
22+
${FIELD_NAME}: UCInputFieldValue<FreeTextShort>;
23+
}
24+
25+
export interface ${name}${UC_OPI0_SUFFIX} extends UCOPIBase {
26+
${TODO}
27+
${FIELD_NAME}: FreeTextShort;
28+
}
29+
30+
export const ${name}${UC_DEF_SUFFIX}: ${UC_DEF_TYPE}<${name}${UC_INPUT_SUFFIX}, ${name}${UC_OPI0_SUFFIX}> = {
31+
io: {
32+
i: {
33+
fields: {
34+
${FIELD_NAME}: {
35+
${TODO}
36+
type: new TFreeTextShort(),
37+
},
38+
},
39+
},
40+
o: {
41+
parts: {
42+
_0: {
43+
fields: {
44+
${FIELD_NAME}: {
45+
${TODO}
46+
type: new TFreeTextShort(),
47+
},
48+
},
49+
},
50+
},
51+
},
52+
},
53+
lifecycle: {
54+
client: {
55+
main: SendClientMain,
56+
policy: NobodyUCPolicy,
57+
},
58+
server: {
59+
main: ${name}${UC_MAIN_SERVER_SUFFIX},
60+
policy: NobodyUCPolicy,
61+
},
62+
},
63+
metadata: ${APP_MANIFEST_NAME}.ucReg.${name},
64+
};
65+
`;
66+
const SERVER_MAIN_TS = (name) => `import { inject, injectable } from 'inversify';
67+
import {
68+
type UCMain,
69+
type UCMainInput,
70+
type UCManager,
71+
type UCOutput,
72+
UCOutputBuilder,
73+
} from '${LIB_NAME}';
74+
75+
import type {
76+
${name}${UC_INPUT_SUFFIX},
77+
${name}${UC_OPI0_SUFFIX},
78+
} from './${fileImportName(`${name}${UC_DEF_SUFFIX}`)}';
79+
80+
@injectable()
81+
export class ${name}${UC_MAIN_SERVER_SUFFIX}
82+
implements UCMain<${name}${UC_INPUT_SUFFIX}, ${name}${UC_OPI0_SUFFIX}>
83+
{
84+
constructor(@inject('UCManager') private ucManager: UCManager) {}
85+
86+
public async exec({
87+
uc,
88+
}: UCMainInput<${name}${UC_INPUT_SUFFIX}, ${name}${UC_OPI0_SUFFIX}>): Promise<
89+
UCOutput<${name}${UC_OPI0_SUFFIX}>
90+
> {
91+
const ${FIELD_NAME} = uc.reqVal0('${FIELD_NAME}');
92+
93+
// >=> Save in data store
94+
const { aggregateId } = await this.ucManager.persist(uc);
95+
96+
return new UCOutputBuilder<${name}${UC_OPI0_SUFFIX}>()
97+
.add({
98+
${FIELD_NAME},
99+
id: aggregateId,
100+
})
101+
.get();
102+
}
103+
}
104+
`;
105+
export function files(name) {
106+
return new Map([
107+
[['.', `${name}${UC_DEF_FILE_NAME_SUFFIX}`], UCD_TS(name)],
108+
[
109+
['.', `${name}${UC_MAIN_SERVER_FILE_NAME_SUFFIX}`],
110+
SERVER_MAIN_TS(name),
111+
],
112+
]);
113+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
import type { FilePath } from '../../../../dt/index.js';
2+
export type Creatable = 'App' | 'Project' | 'Product' | 'Use case';
23
export type Files = Map<FilePath[], string>;

dist/esm/apps/Helper/src/manifest.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ export declare const Manifest: {
1717
icon: string;
1818
name: "CreateProject";
1919
};
20+
CreateUC: {
21+
action: "Create";
22+
icon: string;
23+
name: "CreateUC";
24+
};
2025
DeleteGeneratedAppsTests: {
2126
action: "Delete";
2227
icon: string;

0 commit comments

Comments
 (0)