@azure-net/cli 5.1.1 → 6.0.0-next.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/README.md +189 -0
- package/bin/azure-net.js +236 -221
- package/dist/bin/azure-net.d.ts +2 -0
- package/dist/src/checks/architecture.d.ts +20 -0
- package/dist/src/checks/checkDomain.d.ts +1 -0
- package/dist/src/checks/checkFoldersStructure.d.ts +1 -0
- package/dist/src/checks/checkHooks.d.ts +1 -0
- package/dist/src/checks/checkImports.d.ts +1 -0
- package/dist/src/checks/checkInternal.d.ts +1 -0
- package/dist/src/checks/checkLayerBoundaries.d.ts +1 -0
- package/dist/src/checks/checkLayerImports.d.ts +1 -0
- package/dist/src/checks/checkPresenterNames.d.ts +1 -0
- package/dist/src/checks/checkProject.d.ts +1 -0
- package/dist/src/checks/checkProviderGraph.d.ts +1 -0
- package/dist/src/checks/checkProviderNames.d.ts +1 -0
- package/dist/src/generate/layers/generateRepository.d.ts +1 -0
- package/dist/src/generate/layers/generateRepositoryMethod.d.ts +1 -0
- package/dist/src/generate/layers/generateUseCases.d.ts +1 -0
- package/dist/src/generate/module/generateDomain.d.ts +8 -0
- package/dist/src/generate/module/generateModule.d.ts +1 -0
- package/dist/src/generate/module/generateModulePreset.d.ts +1 -0
- package/dist/src/generate/module/generatePresenter.d.ts +29 -0
- package/dist/src/generate/module/generateRepository.d.ts +15 -0
- package/dist/src/generate/module/generateRepositoryMethod.d.ts +2 -0
- package/dist/src/generate/module/generateSchemaFromType.d.ts +9 -0
- package/dist/src/generate/module/generateStore.d.ts +1 -0
- package/dist/src/generate/module/generateTypesJson.d.ts +2 -0
- package/dist/src/generate/module/generateUseCases.d.ts +1 -0
- package/dist/src/generate/module/repositoryModuleShared.d.ts +89 -0
- package/dist/src/generate/routes/generateRoutes.d.ts +14 -0
- package/dist/src/generate/ui/generateComponent.d.ts +1 -0
- package/dist/src/generate/ui/generateDesignComponent.d.ts +1 -0
- package/dist/src/generate/ui/generateWidget.d.ts +1 -0
- package/dist/src/git/commit.d.ts +23 -0
- package/dist/src/git/push.d.ts +11 -0
- package/dist/src/git/runGit.d.ts +2 -0
- package/dist/src/init/initAliases.d.ts +12 -0
- package/dist/src/init/initEdges.d.ts +2 -0
- package/dist/src/init/initStructure.d.ts +1 -0
- package/dist/src/install/configureCommitTools.d.ts +1 -0
- package/dist/src/install/installFresh.d.ts +1 -0
- package/dist/src/migrate/migrate.d.ts +22 -0
- package/dist/src/migrate/presenters.d.ts +7 -0
- package/dist/src/plugins/addLint.d.ts +5 -0
- package/dist/src/scaffolds/createCoreSchema.d.ts +1 -0
- package/dist/src/scaffolds/createDatasource.d.ts +1 -0
- package/dist/src/scaffolds/createProgram.d.ts +1 -0
- package/dist/src/scaffolds/createResponse.d.ts +1 -0
- package/dist/src/scaffolds/createSchemaRule.d.ts +1 -0
- package/dist/src/scaffolds/createTranslationManager.d.ts +1 -0
- package/{src/scaffolds/index.ts → dist/src/scaffolds/index.d.ts} +0 -2
- package/dist/src/scaffolds/registerDatasource.d.ts +2 -0
- package/dist/src/scaffolds/updateDefaultFactoryConfig.d.ts +1 -0
- package/dist/src/utils/architecture.d.ts +31 -0
- package/dist/src/utils/contextUtils.d.ts +6 -0
- package/dist/src/utils/fileUtils.d.ts +5 -0
- package/dist/src/utils/flattenConfig.d.ts +2 -0
- package/dist/src/utils/legacyAliases.d.ts +1 -0
- package/dist/src/utils/loadConfig.d.ts +16 -0
- package/dist/src/utils/packageImports.d.ts +4 -0
- package/dist/src/utils/sharedFoundation.d.ts +20 -0
- package/dist/src/utils/viteConfig.d.ts +9 -0
- package/package.json +48 -36
- package/src/checks/architecture.js +154 -0
- package/src/checks/checkDomain.js +124 -154
- package/src/checks/checkFoldersStructure.js +64 -52
- package/src/checks/checkHooks.js +12 -12
- package/src/checks/checkImports.js +26 -142
- package/src/checks/checkInternal.js +27 -24
- package/src/checks/checkLayerBoundaries.js +22 -197
- package/src/checks/checkLayerImports.js +14 -134
- package/src/checks/checkPresenterNames.js +156 -143
- package/src/checks/checkProject.js +27 -26
- package/src/checks/checkProviderGraph.js +182 -166
- package/src/checks/checkProviderNames.js +123 -112
- package/src/generate/layers/generateRepository.js +1 -109
- package/src/generate/layers/generateRepositoryMethod.js +1 -90
- package/src/generate/layers/generateUseCases.js +1 -44
- package/src/generate/module/generateDomain.js +81 -105
- package/src/generate/module/generateModule.js +34 -68
- package/src/generate/module/generateModulePreset.js +188 -248
- package/src/generate/module/generatePresenter.js +441 -369
- package/src/generate/module/generateRepository.js +102 -121
- package/src/generate/module/generateRepositoryMethod.js +117 -0
- package/src/generate/module/generateSchemaFromType.js +283 -280
- package/src/generate/module/generateStore.js +41 -0
- package/src/generate/module/generateTypesJson.js +196 -195
- package/src/generate/module/generateUseCases.js +47 -55
- package/src/generate/module/repositoryModuleShared.js +480 -459
- package/src/generate/routes/generateRoutes.js +4 -7
- package/src/generate/ui/generateComponent.js +44 -64
- package/src/generate/ui/generateDesignComponent.js +21 -41
- package/src/generate/ui/generateWidget.js +21 -41
- package/src/git/commit.js +67 -0
- package/src/git/push.js +19 -0
- package/src/git/runGit.js +11 -0
- package/src/init/initAliases.js +19 -135
- package/src/init/initEdges.js +79 -54
- package/src/init/initStructure.js +31 -145
- package/src/install/configureCommitTools.js +1 -0
- package/src/install/installFresh.js +39 -68
- package/src/migrate/migrate.js +914 -0
- package/src/migrate/presenters.js +265 -0
- package/src/plugins/addLint.js +52 -219
- package/src/scaffolds/createCoreSchema.js +65 -91
- package/src/scaffolds/createDatasource.js +67 -101
- package/src/scaffolds/createProgram.js +8 -8
- package/src/scaffolds/createResponse.js +29 -29
- package/src/scaffolds/createSchemaRule.js +19 -19
- package/src/scaffolds/createTranslationManager.js +84 -37
- package/src/scaffolds/index.js +0 -2
- package/src/scaffolds/registerDatasource.js +59 -0
- package/src/scaffolds/updateDefaultFactoryConfig.js +31 -0
- package/src/utils/architecture.js +145 -0
- package/src/utils/contextUtils.js +32 -65
- package/src/utils/fileUtils.js +69 -50
- package/src/utils/flattenConfig.js +38 -0
- package/src/utils/legacyAliases.js +75 -0
- package/src/utils/loadConfig.js +76 -40
- package/src/utils/packageImports.js +63 -0
- package/src/utils/sharedFoundation.js +36 -42
- package/src/utils/viteConfig.js +295 -0
- package/.prettierrc +0 -7
- package/bin/azure-net.ts +0 -308
- package/eslint.config.js +0 -34
- package/src/checks/checkDomain.ts +0 -223
- package/src/checks/checkFoldersStructure.ts +0 -85
- package/src/checks/checkHooks.ts +0 -22
- package/src/checks/checkImports.ts +0 -193
- package/src/checks/checkInternal.ts +0 -48
- package/src/checks/checkLayerBoundaries.ts +0 -255
- package/src/checks/checkLayerImports.ts +0 -185
- package/src/checks/checkPresenterNames.ts +0 -203
- package/src/checks/checkProject.ts +0 -45
- package/src/checks/checkProviderGraph.ts +0 -234
- package/src/checks/checkProviderNames.ts +0 -165
- package/src/generate/layers/generateRepository.ts +0 -123
- package/src/generate/layers/generateRepositoryMethod.ts +0 -102
- package/src/generate/layers/generateUseCases.ts +0 -50
- package/src/generate/layers/repositoryShared.js +0 -506
- package/src/generate/layers/repositoryShared.ts +0 -662
- package/src/generate/module/generateDomain.ts +0 -147
- package/src/generate/module/generateModule.ts +0 -84
- package/src/generate/module/generateModulePreset.ts +0 -338
- package/src/generate/module/generatePresenter.ts +0 -498
- package/src/generate/module/generateRepository.ts +0 -158
- package/src/generate/module/generateSchemaFromType.ts +0 -368
- package/src/generate/module/generateTypesJson.ts +0 -259
- package/src/generate/module/generateUseCases.ts +0 -67
- package/src/generate/module/repositoryModuleShared.ts +0 -669
- package/src/generate/routes/generateRoutes.ts +0 -275
- package/src/generate/ui/generateComponent.ts +0 -100
- package/src/generate/ui/generateDesignComponent.ts +0 -71
- package/src/generate/ui/generateWidget.ts +0 -71
- package/src/init/initAliases.ts +0 -172
- package/src/init/initEdges.ts +0 -74
- package/src/init/initStructure.ts +0 -172
- package/src/install/installFresh.ts +0 -93
- package/src/plugins/addLint.ts +0 -274
- package/src/scaffolds/createCoreSchema.ts +0 -130
- package/src/scaffolds/createDatasource.ts +0 -161
- package/src/scaffolds/createDatasourceProvider.js +0 -127
- package/src/scaffolds/createDatasourceProvider.ts +0 -161
- package/src/scaffolds/createPresenterFactory.js +0 -83
- package/src/scaffolds/createPresenterFactory.ts +0 -102
- package/src/scaffolds/createProgram.ts +0 -19
- package/src/scaffolds/createResponse.ts +0 -66
- package/src/scaffolds/createSchemaRule.ts +0 -44
- package/src/scaffolds/createTranslationManager.ts +0 -80
- package/src/utils/contextUtils.ts +0 -88
- package/src/utils/fileUtils.ts +0 -74
- package/src/utils/loadConfig.ts +0 -68
- package/src/utils/sharedFoundation.ts +0 -70
- package/tsconfig.json +0 -19
- /package/{src/checks/index.ts → dist/src/checks/index.d.ts} +0 -0
- /package/{src/plugins/index.ts → dist/src/plugins/index.d.ts} +0 -0
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import prompts from 'prompts';
|
|
4
|
+
import ts from 'typescript';
|
|
5
|
+
import { formatConfig } from '../utils/viteConfig.js';
|
|
6
|
+
import { toPascalCase } from '../utils/contextUtils.js';
|
|
4
7
|
import { writeIfNotExists } from '../utils/fileUtils.js';
|
|
5
8
|
import { getLocalizationPath, getSharedState } from '../utils/sharedFoundation.js';
|
|
6
9
|
const parseLocales = (rawLocales) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const parsed = String(rawLocales ?? '')
|
|
11
|
+
.split(',')
|
|
12
|
+
.map((item) => item.trim())
|
|
13
|
+
.filter((locale) => /^[A-Za-z]+(?:-[A-Za-z0-9]+)*$/.test(locale));
|
|
14
|
+
const unique = Array.from(new Set(parsed));
|
|
15
|
+
return unique.length ? unique : ['en', 'ru'];
|
|
13
16
|
};
|
|
14
|
-
const createTranslationIndexTemplate = (defaultLocale) => `import { messages } from './
|
|
15
|
-
import { createTranslations
|
|
17
|
+
const createTranslationIndexTemplate = (defaultLocale) => `import { messages } from './Locales';
|
|
18
|
+
import { createTranslations } from '@azure-net/kit/i18n';
|
|
19
|
+
import type { Path } from '@azure-net/kit/i18n';
|
|
16
20
|
|
|
21
|
+
// program.ts: createApp((app) => app.useTranslations(TranslationManager))
|
|
17
22
|
export const TranslationManager = createTranslations({
|
|
18
23
|
\tmessages,
|
|
19
24
|
\tinitLang: '${defaultLocale}',
|
|
@@ -29,39 +34,81 @@ export type TranslationParam = MessageKeys | string | TranslationExtended;
|
|
|
29
34
|
export type AvailableLocales = keyof typeof messages;
|
|
30
35
|
`;
|
|
31
36
|
const createLocalesIndexTemplate = (locales) => {
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
const lines = locales.map((locale) => `\t'${locale}': () => import('./${toPascalCase(locale)}').then((res) => res.default)`);
|
|
38
|
+
return `export const messages = {\n${lines.join(',\n')}\n};\n`;
|
|
34
39
|
};
|
|
35
40
|
const createLocaleTemplate = () => `export default {
|
|
36
41
|
\ttest: 'test'
|
|
37
42
|
};
|
|
38
43
|
`;
|
|
44
|
+
async function connectTranslations(translationRoot) {
|
|
45
|
+
const file = path.join(process.cwd(), 'src/program.ts');
|
|
46
|
+
let specifier = path.relative(path.dirname(file), translationRoot).split(path.sep).join('/');
|
|
47
|
+
if (!specifier.startsWith('.'))
|
|
48
|
+
specifier = `./${specifier}`;
|
|
49
|
+
let content;
|
|
50
|
+
try {
|
|
51
|
+
content = await fs.readFile(file, 'utf8');
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (error.code !== 'ENOENT')
|
|
55
|
+
throw error;
|
|
56
|
+
content = "import { createApp } from '@azure-net/kit';\nexport const { register } = createApp((app) => app);\n";
|
|
57
|
+
}
|
|
58
|
+
const source = ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true);
|
|
59
|
+
let body;
|
|
60
|
+
const visit = (node) => {
|
|
61
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'createApp') {
|
|
62
|
+
const callback = node.arguments[0];
|
|
63
|
+
if (callback &&
|
|
64
|
+
ts.isArrowFunction(callback) &&
|
|
65
|
+
ts.isIdentifier(callback.body) &&
|
|
66
|
+
callback.parameters[0]?.name.getText(source) === callback.body.text)
|
|
67
|
+
body = callback.body;
|
|
68
|
+
}
|
|
69
|
+
ts.forEachChild(node, visit);
|
|
70
|
+
};
|
|
71
|
+
visit(source);
|
|
72
|
+
// Only modify the empty generated bootstrap, not application-specific pipelines/imports.
|
|
73
|
+
if (!body || /\bTranslationManager\b/.test(content)) {
|
|
74
|
+
console.log(`Connect translations in ${file}: app.useTranslations(TranslationManager), imported from '${specifier}'. Existing bootstrap preserved.`);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
content =
|
|
78
|
+
`import { TranslationManager } from '${specifier}';\n` +
|
|
79
|
+
content.slice(0, body.end) +
|
|
80
|
+
'.useTranslations(TranslationManager)' +
|
|
81
|
+
content.slice(body.end);
|
|
82
|
+
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
83
|
+
await fs.writeFile(file, await formatConfig(content, file));
|
|
84
|
+
}
|
|
39
85
|
export default async function createTranslationManager() {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
86
|
+
const { localesRaw } = await prompts({
|
|
87
|
+
type: 'text',
|
|
88
|
+
name: 'localesRaw',
|
|
89
|
+
message: 'Enter locales (comma separated):',
|
|
90
|
+
initial: 'en, ru'
|
|
91
|
+
});
|
|
92
|
+
const locales = parseLocales(String(localesRaw ?? 'en, ru'));
|
|
93
|
+
const { defaultLocale } = await prompts({
|
|
94
|
+
type: 'select',
|
|
95
|
+
name: 'defaultLocale',
|
|
96
|
+
message: 'Choose default locale:',
|
|
97
|
+
choices: locales.map((locale) => ({ title: locale, value: locale })),
|
|
98
|
+
initial: 0
|
|
99
|
+
});
|
|
100
|
+
const selectedDefaultLocale = String(defaultLocale ?? locales[0] ?? 'en');
|
|
101
|
+
const { sharedContext } = await getSharedState();
|
|
102
|
+
const translationRoot = getLocalizationPath(sharedContext.name);
|
|
103
|
+
const localesRoot = path.join(translationRoot, 'Locales');
|
|
104
|
+
await fs.mkdir(localesRoot, { recursive: true });
|
|
105
|
+
await writeIfNotExists(path.join(translationRoot, 'index.ts'), createTranslationIndexTemplate(selectedDefaultLocale));
|
|
106
|
+
await writeIfNotExists(path.join(localesRoot, 'index.ts'), createLocalesIndexTemplate(locales));
|
|
107
|
+
for (const locale of locales) {
|
|
108
|
+
const localeDir = path.join(localesRoot, toPascalCase(locale));
|
|
109
|
+
await fs.mkdir(localeDir, { recursive: true });
|
|
110
|
+
await writeIfNotExists(path.join(localeDir, 'index.ts'), createLocaleTemplate());
|
|
111
|
+
}
|
|
112
|
+
await connectTranslations(translationRoot);
|
|
113
|
+
console.log(`✅ Translation manager created: ${translationRoot}`);
|
|
67
114
|
}
|
package/src/scaffolds/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export { default as createCoreSchema } from './createCoreSchema.js';
|
|
2
2
|
export { default as createTranslationManager } from './createTranslationManager.js';
|
|
3
|
-
export { default as createPresenterFactory } from './createPresenterFactory.js';
|
|
4
3
|
export { default as createSchemaRule } from './createSchemaRule.js';
|
|
5
4
|
export { default as createResponse } from './createResponse.js';
|
|
6
5
|
export { default as createDatasource } from './createDatasource.js';
|
|
7
|
-
export { default as createDatasourceProvider } from './createDatasourceProvider.js';
|
|
8
6
|
export { default as createProgram } from './createProgram.js';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
import { formatConfig } from '../utils/viteConfig.js';
|
|
5
|
+
import { getPlatformPath } from '../utils/architecture.js';
|
|
6
|
+
/** Only initialize an empty generated DI; never replace application-specific registrations. */
|
|
7
|
+
export async function registerDatasource(className) {
|
|
8
|
+
const file = path.join(getPlatformPath(), 'Foundation/DI/ApplicationProvider.ts');
|
|
9
|
+
let content;
|
|
10
|
+
try {
|
|
11
|
+
content = await fs.readFile(file, 'utf8');
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
if (error.code !== 'ENOENT')
|
|
15
|
+
throw error;
|
|
16
|
+
console.warn(`Register ${className} inside ApplicationProvider.register.`);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const source = ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true);
|
|
20
|
+
let body;
|
|
21
|
+
const visit = (n) => {
|
|
22
|
+
if (ts.isPropertyAssignment(n) &&
|
|
23
|
+
ts.isIdentifier(n.name) &&
|
|
24
|
+
n.name.text === 'register' &&
|
|
25
|
+
ts.isArrowFunction(n.initializer) &&
|
|
26
|
+
!ts.isBlock(n.initializer.body)) {
|
|
27
|
+
let value = n.initializer.body;
|
|
28
|
+
while (ts.isParenthesizedExpression(value))
|
|
29
|
+
value = value.expression;
|
|
30
|
+
if (ts.isObjectLiteralExpression(value) && !value.properties.length)
|
|
31
|
+
body = n.initializer.body;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
for (const statement of source.statements) {
|
|
35
|
+
if (!ts.isVariableStatement(statement))
|
|
36
|
+
continue;
|
|
37
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
38
|
+
if (!ts.isIdentifier(declaration.name) ||
|
|
39
|
+
declaration.name.text !== 'ApplicationProvider' ||
|
|
40
|
+
!declaration.initializer ||
|
|
41
|
+
!ts.isCallExpression(declaration.initializer))
|
|
42
|
+
continue;
|
|
43
|
+
const options = declaration.initializer.arguments[1];
|
|
44
|
+
if (options && ts.isObjectLiteralExpression(options))
|
|
45
|
+
for (const property of options.properties)
|
|
46
|
+
visit(property);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (!body || content.includes(className)) {
|
|
50
|
+
console.warn(`Existing DI preserved. Add const datasource = new ${className}({}) inside ApplicationProvider.register and pass it to repositories.`);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
content =
|
|
54
|
+
content.slice(0, body.getStart(source)) +
|
|
55
|
+
`{\nconst datasource = new ${className}({});\n// Pass datasource to repositories and return UseCases factories below.\nreturn {};\n}` +
|
|
56
|
+
content.slice(body.end);
|
|
57
|
+
content = `import { ${className} } from '#platform/Foundation/Datasource';\n` + content;
|
|
58
|
+
await fs.writeFile(file, await formatConfig(content, file));
|
|
59
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { flattenConfigLiterals } from '../utils/flattenConfig.js';
|
|
3
|
+
export function updateDefaultFactoryConfig(content, key, name) {
|
|
4
|
+
content = flattenConfigLiterals(content);
|
|
5
|
+
if (!content.trim())
|
|
6
|
+
return `export default {\n\t${key}: ${JSON.stringify(name)}\n};\n`;
|
|
7
|
+
const source = ts.createSourceFile('azure-net.config.ts', content, ts.ScriptTarget.Latest, true);
|
|
8
|
+
const exported = source.statements.find(ts.isExportAssignment);
|
|
9
|
+
if (!exported || exported.isExportEquals)
|
|
10
|
+
throw new Error('Cannot update factory default: expected a default-exported config.');
|
|
11
|
+
const expression = exported.expression;
|
|
12
|
+
if (ts.isObjectLiteralExpression(expression)) {
|
|
13
|
+
const lastSpread = expression.properties.reduce((last, item, index) => (ts.isSpreadAssignment(item) ? index : last), -1);
|
|
14
|
+
const property = [...expression.properties.slice(lastSpread + 1)]
|
|
15
|
+
.reverse()
|
|
16
|
+
.find((item) => ts.isPropertyAssignment(item) && (ts.isIdentifier(item.name) || ts.isStringLiteral(item.name)) && item.name.text === key);
|
|
17
|
+
if (property && ts.isPropertyAssignment(property)) {
|
|
18
|
+
if (ts.isStringLiteral(property.initializer) && property.initializer.text === name)
|
|
19
|
+
return content;
|
|
20
|
+
return content.slice(0, property.initializer.getStart(source)) + JSON.stringify(name) + content.slice(property.initializer.end);
|
|
21
|
+
}
|
|
22
|
+
const last = expression.properties.at(-1);
|
|
23
|
+
let result = content.slice(0, expression.end - 1) + `\n\t${key}: ${JSON.stringify(name)}\n` + content.slice(expression.end - 1);
|
|
24
|
+
if (last && !expression.properties.hasTrailingComma)
|
|
25
|
+
result = result.slice(0, last.end) + ',' + result.slice(last.end);
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
// Preserve custom config expressions without executing or reconstructing their contents.
|
|
29
|
+
const replacement = `{ ...(${expression.getText(source)}), ${key}: ${JSON.stringify(name)} }`;
|
|
30
|
+
return content.slice(0, expression.getStart(source)) + replacement + content.slice(expression.end);
|
|
31
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import prompts from 'prompts';
|
|
4
|
+
import { writeIfNotExists } from './fileUtils.js';
|
|
5
|
+
export const SHARED_CONTEXT = 'SharedKernel';
|
|
6
|
+
export const SHARED_WORKSPACE = 'Shared';
|
|
7
|
+
export const ARCHITECTURE_ALIASES = {
|
|
8
|
+
'#contexts': './src/app/Contexts',
|
|
9
|
+
'#presentation': './src/app/Presentation',
|
|
10
|
+
'#platform': './src/app/Platform'
|
|
11
|
+
};
|
|
12
|
+
export const CONTEXT_DIRS = [
|
|
13
|
+
'Domain/Entities',
|
|
14
|
+
'Domain/Ports',
|
|
15
|
+
'Domain/Enums',
|
|
16
|
+
'Application/UseCases',
|
|
17
|
+
'Infrastructure/Repositories'
|
|
18
|
+
];
|
|
19
|
+
export const PRESENTATION_DIRS = ['Ui', 'Scopes', 'Shell'];
|
|
20
|
+
export function normalizePascalName(value) {
|
|
21
|
+
const raw = value.trim();
|
|
22
|
+
if (!/^[A-Za-z][A-Za-z0-9 _-]*$/.test(raw))
|
|
23
|
+
throw new Error(`Invalid architecture name: "${value}". Use letters, numbers, spaces, hyphens or underscores.`);
|
|
24
|
+
return raw
|
|
25
|
+
.split(/[-_\s]+/)
|
|
26
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
27
|
+
.join('');
|
|
28
|
+
}
|
|
29
|
+
export const getAppPath = (cwd = process.cwd()) => path.join(cwd, 'src', 'app');
|
|
30
|
+
export const getContextsPath = (cwd = process.cwd()) => path.join(getAppPath(cwd), 'Contexts');
|
|
31
|
+
export const getContextPath = (context, cwd = process.cwd()) => path.join(getContextsPath(cwd), normalizePascalName(context));
|
|
32
|
+
export const getPresentationPath = (workspace, cwd = process.cwd()) => workspace ? path.join(getAppPath(cwd), 'Presentation', normalizePascalName(workspace)) : path.join(getAppPath(cwd), 'Presentation');
|
|
33
|
+
export const getPlatformPath = (cwd = process.cwd()) => path.join(getAppPath(cwd), 'Platform');
|
|
34
|
+
export const getContextImportPath = (context) => `#contexts/${normalizePascalName(context)}`;
|
|
35
|
+
export const getPresentationImportPath = (workspace) => workspace ? `#presentation/${normalizePascalName(workspace)}` : '#presentation';
|
|
36
|
+
async function directories(root) {
|
|
37
|
+
try {
|
|
38
|
+
return (await fs.readdir(root, { withFileTypes: true }))
|
|
39
|
+
.filter((entry) => entry.isDirectory())
|
|
40
|
+
.map((entry) => entry.name)
|
|
41
|
+
.sort();
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (error.code === 'ENOENT')
|
|
45
|
+
return [];
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export const discoverContexts = async (cwd = process.cwd()) => (await directories(getContextsPath(cwd))).filter((name) => /^[A-Z][A-Za-z0-9]*$/.test(name));
|
|
50
|
+
export const discoverPresentationWorkspaces = async (cwd = process.cwd()) => (await directories(getPresentationPath(undefined, cwd))).filter((name) => !PRESENTATION_DIRS.includes(name) && /^[A-Z][A-Za-z0-9]*$/.test(name));
|
|
51
|
+
export async function ensureContextStructure(context, cwd = process.cwd()) {
|
|
52
|
+
const name = normalizePascalName(context);
|
|
53
|
+
for (const dir of CONTEXT_DIRS) {
|
|
54
|
+
await writeIfNotExists(path.join(getContextPath(name, cwd), dir, 'index.ts'), 'export {};\n');
|
|
55
|
+
}
|
|
56
|
+
return name;
|
|
57
|
+
}
|
|
58
|
+
export async function ensurePresentationStructure(workspace, cwd = process.cwd()) {
|
|
59
|
+
for (const dir of PRESENTATION_DIRS)
|
|
60
|
+
await fs.mkdir(path.join(getPresentationPath(workspace, cwd), dir), { recursive: true });
|
|
61
|
+
}
|
|
62
|
+
export async function selectContext(message = 'Select context:') {
|
|
63
|
+
await ensureContextStructure(SHARED_CONTEXT);
|
|
64
|
+
const names = await discoverContexts();
|
|
65
|
+
const result = await prompts({
|
|
66
|
+
type: 'select',
|
|
67
|
+
name: 'context',
|
|
68
|
+
message,
|
|
69
|
+
choices: [...names.map((name) => ({ title: name, value: name })), { title: 'Create new context', value: '__create__' }]
|
|
70
|
+
});
|
|
71
|
+
if (!result.context)
|
|
72
|
+
return null;
|
|
73
|
+
if (result.context !== '__create__')
|
|
74
|
+
return String(result.context);
|
|
75
|
+
const answer = await prompts({
|
|
76
|
+
type: 'text',
|
|
77
|
+
name: 'name',
|
|
78
|
+
message: 'Context name:',
|
|
79
|
+
validate: (value) => {
|
|
80
|
+
try {
|
|
81
|
+
normalizePascalName(value);
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
return error.message;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return answer.name ? ensureContextStructure(String(answer.name)) : null;
|
|
90
|
+
}
|
|
91
|
+
/** null means cancelled; undefined means the flat Presentation layout. */
|
|
92
|
+
export async function selectPresentationWorkspace(message = 'Select presentation workspace:') {
|
|
93
|
+
const workspaces = await discoverPresentationWorkspaces();
|
|
94
|
+
if (!workspaces.length)
|
|
95
|
+
return undefined;
|
|
96
|
+
await ensurePresentationStructure(SHARED_WORKSPACE);
|
|
97
|
+
if (!workspaces.includes(SHARED_WORKSPACE))
|
|
98
|
+
workspaces.push(SHARED_WORKSPACE);
|
|
99
|
+
const answer = await prompts({
|
|
100
|
+
type: 'select',
|
|
101
|
+
name: 'workspace',
|
|
102
|
+
message,
|
|
103
|
+
choices: workspaces.sort().map((name) => ({ title: name, value: name }))
|
|
104
|
+
});
|
|
105
|
+
return answer.workspace ? String(answer.workspace) : null;
|
|
106
|
+
}
|
|
107
|
+
export async function selectWorkspace() {
|
|
108
|
+
const name = await selectPresentationWorkspace();
|
|
109
|
+
if (name === null)
|
|
110
|
+
return null;
|
|
111
|
+
return { name: name ?? '', path: getPresentationPath(name), alias: getPresentationImportPath(name) };
|
|
112
|
+
}
|
|
113
|
+
export async function selectScope(workspace) {
|
|
114
|
+
const root = path.join(workspace.path, 'Scopes');
|
|
115
|
+
const scopes = (await directories(root)).filter((name) => /^[A-Z][A-Za-z0-9]*$/.test(name));
|
|
116
|
+
const answer = await prompts({
|
|
117
|
+
type: 'select',
|
|
118
|
+
name: 'scope',
|
|
119
|
+
message: 'Select scope:',
|
|
120
|
+
choices: [...scopes.map((name) => ({ title: name, value: name })), { title: 'Create new scope', value: '__create__' }]
|
|
121
|
+
});
|
|
122
|
+
if (!answer.scope)
|
|
123
|
+
return null;
|
|
124
|
+
if (answer.scope !== '__create__')
|
|
125
|
+
return String(answer.scope);
|
|
126
|
+
const created = await prompts({
|
|
127
|
+
type: 'text',
|
|
128
|
+
name: 'name',
|
|
129
|
+
message: 'Scope name:',
|
|
130
|
+
validate: (value) => {
|
|
131
|
+
try {
|
|
132
|
+
normalizePascalName(value);
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
return error.message;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
if (!created.name)
|
|
141
|
+
return null;
|
|
142
|
+
const name = normalizePascalName(String(created.name));
|
|
143
|
+
await fs.mkdir(path.join(root, name), { recursive: true });
|
|
144
|
+
return name;
|
|
145
|
+
}
|
|
@@ -1,73 +1,40 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
const APP_PATH = path.join(process.cwd(), 'src/app');
|
|
6
|
-
function normalizeContextNames(rawContexts) {
|
|
7
|
-
if (!Array.isArray(rawContexts)) return [];
|
|
8
|
-
return rawContexts
|
|
9
|
-
.map((item) => {
|
|
10
|
-
if (typeof item === 'string') {
|
|
11
|
-
return item.trim();
|
|
12
|
-
}
|
|
13
|
-
if (!item || typeof item !== 'object') return '';
|
|
14
|
-
return String(item.name ?? '').trim();
|
|
15
|
-
})
|
|
16
|
-
.filter(Boolean);
|
|
17
|
-
}
|
|
18
|
-
export async function selectContext(message = 'Select context:') {
|
|
19
|
-
const config = await loadUserConfig();
|
|
20
|
-
const contexts = normalizeContextNames(config.contexts);
|
|
21
|
-
const { context } = await prompts({
|
|
22
|
-
type: 'select',
|
|
23
|
-
name: 'context',
|
|
24
|
-
message,
|
|
25
|
-
choices: contexts.map((c) => ({ title: c, value: c }))
|
|
26
|
-
});
|
|
27
|
-
return context ? String(context) : null;
|
|
28
|
-
}
|
|
29
|
-
export function getContextPath(context) {
|
|
30
|
-
return path.join(APP_PATH, context, 'layers');
|
|
31
|
-
}
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { getPlatformPath, normalizePascalName } from './architecture.js';
|
|
4
|
+
export { getContextPath, selectContext, selectPresentationWorkspace, discoverContexts, discoverPresentationWorkspaces, normalizePascalName } from './architecture.js';
|
|
32
5
|
export async function getAvailableFiles(dir, pattern = '.ts') {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
} catch {
|
|
55
|
-
return [];
|
|
56
|
-
}
|
|
6
|
+
try {
|
|
7
|
+
return (await fs.readdir(dir))
|
|
8
|
+
.filter((file) => file.endsWith(pattern) && file !== 'index.ts')
|
|
9
|
+
.map((file) => file.slice(0, -pattern.length));
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
if (error.code === 'ENOENT')
|
|
13
|
+
return [];
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export async function getApplicationProviderServices() {
|
|
18
|
+
try {
|
|
19
|
+
const content = await fs.readFile(path.join(getPlatformPath(), 'Foundation/DI/ApplicationProvider.ts'), 'utf8');
|
|
20
|
+
return Array.from(content.matchAll(/(\w+Service):\s*\(/g), (match) => match[1]);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
if (error.code === 'ENOENT')
|
|
24
|
+
return [];
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
57
27
|
}
|
|
58
28
|
export function toPascalCase(str) {
|
|
59
|
-
|
|
60
|
-
.split(/[-_\s]+/)
|
|
61
|
-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
62
|
-
.join('');
|
|
29
|
+
return str.trim() ? normalizePascalName(str) : '';
|
|
63
30
|
}
|
|
64
31
|
export function toCamelCase(str) {
|
|
65
|
-
|
|
66
|
-
|
|
32
|
+
const pascal = toPascalCase(str);
|
|
33
|
+
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
|
|
67
34
|
}
|
|
68
35
|
export function toKebabCase(str) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
36
|
+
return str
|
|
37
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
38
|
+
.replace(/([A-Z])([A-Z][a-z])/g, '$1-$2')
|
|
39
|
+
.toLowerCase();
|
|
73
40
|
}
|
package/src/utils/fileUtils.js
CHANGED
|
@@ -1,60 +1,79 @@
|
|
|
1
1
|
import fs from 'fs/promises';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
export async function writeIfNotExists(filepath, content) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
await fs.mkdir(path.dirname(filepath), { recursive: true });
|
|
5
|
+
try {
|
|
6
|
+
await fs.writeFile(filepath, content, { encoding: 'utf8', flag: 'wx' });
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
if (error.code !== 'EEXIST')
|
|
10
|
+
throw error;
|
|
11
|
+
console.log(`Skip existing: ${filepath}`);
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
console.log(`Created: ${filepath}`);
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
export async function appendBarrelExports(filepath, sources) {
|
|
18
|
+
let content = '';
|
|
19
|
+
try {
|
|
20
|
+
content = await fs.readFile(filepath, 'utf8');
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
if (error.code !== 'ENOENT')
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
const additions = sources
|
|
27
|
+
.filter((source) => !content.includes("from '" + source + "'") && !content.includes('from "' + source + '"'))
|
|
28
|
+
.map((source) => 'export * from ' + JSON.stringify(source) + ';');
|
|
29
|
+
if (!additions.length && content.trim())
|
|
30
|
+
return;
|
|
31
|
+
await fs.mkdir(path.dirname(filepath), { recursive: true });
|
|
32
|
+
await fs.writeFile(filepath, content + (content && !content.endsWith('\n') ? '\n' : '') + (additions.length ? additions.join('\n') : 'export {};') + '\n');
|
|
14
33
|
}
|
|
15
34
|
export async function updateIndexTs(dir, filePattern = '.ts', ignore = ['index.ts']) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} catch {
|
|
21
|
-
// Directory doesn't exist yet
|
|
22
|
-
}
|
|
35
|
+
const files = (await fs.readdir(dir))
|
|
36
|
+
.filter((file) => file.endsWith(filePattern) && !file.endsWith('.d.ts') && !ignore.includes(file))
|
|
37
|
+
.sort();
|
|
38
|
+
await appendBarrelExports(path.join(dir, 'index.ts'), files.map((file) => './' + file.slice(0, -filePattern.length)));
|
|
23
39
|
}
|
|
24
40
|
export async function ensureIndexExports(layerPath) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
try {
|
|
42
|
+
const subdirs = await fs.readdir(layerPath, { withFileTypes: true });
|
|
43
|
+
const exportLines = subdirs.filter((d) => d.isDirectory()).map((d) => `export * from './${d.name}';`);
|
|
44
|
+
if (exportLines.length > 0) {
|
|
45
|
+
await fs.writeFile(path.join(layerPath, 'index.ts'), exportLines.join('\n') + '\n', 'utf-8');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// Directory doesn't exist
|
|
50
|
+
}
|
|
34
51
|
}
|
|
35
52
|
export async function injectIntoFile(filepath, searchPattern, newContent, position = 'after') {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
try {
|
|
54
|
+
let content = await fs.readFile(filepath, 'utf-8');
|
|
55
|
+
const index = content.indexOf(searchPattern);
|
|
56
|
+
if (index === -1) {
|
|
57
|
+
console.warn(`Pattern not found in ${filepath}`);
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
if (content.includes(newContent.trim())) {
|
|
61
|
+
console.log(`Content already exists in ${filepath}`);
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
if (position === 'after') {
|
|
65
|
+
const insertIndex = index + searchPattern.length;
|
|
66
|
+
content = content.slice(0, insertIndex) + '\n' + newContent + content.slice(insertIndex);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
content = content.slice(0, index) + newContent + '\n' + content.slice(index);
|
|
70
|
+
}
|
|
71
|
+
await fs.writeFile(filepath, content, 'utf-8');
|
|
72
|
+
console.log(`✅ Updated: ${filepath}`);
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
console.error(`Failed to update ${filepath}:`, error instanceof Error ? error.message : String(error));
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
60
79
|
}
|