@azure-net/cli 5.0.0-3 → 5.0.0
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/bin/azure-net.js +5 -46
- package/bin/azure-net.ts +5 -5
- package/package.json +1 -1
- package/src/checks/checkDomain.js +8 -38
- package/src/checks/checkFoldersStructure.js +0 -14
- package/src/checks/checkHooks.js +0 -5
- package/src/checks/checkImports.js +0 -1
- package/src/checks/checkInternal.js +0 -1
- package/src/checks/checkLayerBoundaries.js +50 -54
- package/src/checks/checkLayerBoundaries.ts +55 -58
- package/src/checks/checkPresenterNames.js +1 -37
- package/src/checks/checkPresenterNames.ts +1 -6
- package/src/checks/checkProject.js +0 -6
- package/src/checks/checkProviderGraph.js +1 -38
- package/src/checks/checkProviderNames.js +0 -28
- package/src/checks/index.js +0 -1
- package/src/generate/layers/generateRepository.js +4 -19
- package/src/generate/layers/generateRepositoryMethod.js +0 -12
- package/src/generate/layers/generateUseCases.js +0 -6
- package/src/generate/layers/repositoryShared.js +41 -104
- package/src/generate/layers/repositoryShared.ts +17 -12
- package/src/generate/module/generateDomain.js +0 -25
- package/src/generate/module/generateModule.js +0 -10
- package/src/generate/module/generateModulePreset.js +10 -51
- package/src/generate/module/generateModulePreset.ts +9 -8
- package/src/generate/module/generatePresenter.js +29 -76
- package/src/generate/module/generatePresenter.ts +15 -10
- package/src/generate/module/generateRepository.js +0 -17
- package/src/generate/module/generateSchemaFromType.js +9 -58
- package/src/generate/module/generateSchemaFromType.ts +1 -2
- package/src/generate/module/generateTypesJson.js +4 -45
- package/src/generate/module/generateUseCases.js +0 -9
- package/src/generate/module/repositoryModuleShared.js +21 -98
- package/src/generate/module/repositoryModuleShared.ts +14 -10
- package/src/generate/ui/generateComponent.js +0 -16
- package/src/generate/ui/generateDesignComponent.js +0 -12
- package/src/generate/ui/generateWidget.js +0 -12
- package/src/init/initAliases.js +42 -64
- package/src/init/initAliases.ts +47 -42
- package/src/init/initEdges.js +0 -15
- package/src/init/initStructure.js +48 -21
- package/src/init/initStructure.ts +51 -3
- package/src/install/installFresh.js +0 -16
- package/src/plugins/addLint.js +11 -46
- package/src/scaffolds/createCoreSchema.js +6 -40
- package/src/scaffolds/createCoreSchema.ts +6 -18
- package/src/scaffolds/createDatasource.js +26 -61
- package/src/scaffolds/createDatasource.ts +26 -40
- package/src/scaffolds/createDatasourceProvider.js +19 -56
- package/src/scaffolds/createDatasourceProvider.ts +20 -34
- package/src/scaffolds/createPresenterFactory.js +5 -34
- package/src/scaffolds/createPresenterFactory.ts +5 -17
- package/src/scaffolds/createProgram.js +1 -5
- package/src/scaffolds/createResponse.js +3 -11
- package/src/scaffolds/createResponse.ts +3 -1
- package/src/scaffolds/createSchemaRule.js +3 -8
- package/src/scaffolds/createSchemaRule.ts +3 -1
- package/src/scaffolds/createTranslationManager.js +3 -14
- package/src/scaffolds/createTranslationManager.ts +3 -1
- package/src/utils/contextUtils.js +5 -20
- package/src/utils/contextUtils.ts +2 -3
- package/src/utils/fileUtils.js +3 -38
- package/src/utils/fileUtils.ts +0 -26
- package/src/utils/loadConfig.js +1 -14
- package/src/utils/loadConfig.ts +1 -3
- package/src/utils/sharedFoundation.js +48 -0
- package/src/utils/sharedFoundation.ts +70 -0
package/src/utils/fileUtils.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import fs from 'fs/promises';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
|
|
4
3
|
export async function writeIfNotExists(filepath, content) {
|
|
5
4
|
try {
|
|
6
5
|
await fs.access(filepath);
|
|
@@ -13,83 +12,49 @@ export async function writeIfNotExists(filepath, content) {
|
|
|
13
12
|
return true;
|
|
14
13
|
}
|
|
15
14
|
}
|
|
16
|
-
|
|
17
15
|
export async function updateIndexTs(dir, filePattern = '.ts', ignore = ['index.ts']) {
|
|
18
16
|
try {
|
|
19
17
|
const files = (await fs.readdir(dir)).filter((f) => f.endsWith(filePattern) && !ignore.includes(f));
|
|
20
18
|
const content = files.map((f) => `export * from './${f.replace('.ts', '')}';`).join('\n') + '\n';
|
|
21
19
|
await fs.writeFile(path.join(dir, 'index.ts'), content, 'utf-8');
|
|
22
|
-
} catch
|
|
20
|
+
} catch {
|
|
23
21
|
// Directory doesn't exist yet
|
|
24
22
|
}
|
|
25
23
|
}
|
|
26
|
-
|
|
27
|
-
export async function updateCoreIndex() {
|
|
28
|
-
const corePath = path.join(process.cwd(), 'src/core');
|
|
29
|
-
try {
|
|
30
|
-
const dirs = await fs.readdir(corePath, { withFileTypes: true });
|
|
31
|
-
const validDirs = [];
|
|
32
|
-
|
|
33
|
-
for (const dir of dirs) {
|
|
34
|
-
if (dir.isDirectory()) {
|
|
35
|
-
// Check if directory has any files
|
|
36
|
-
const dirPath = path.join(corePath, dir.name);
|
|
37
|
-
const files = await fs.readdir(dirPath);
|
|
38
|
-
if (files.length > 0) {
|
|
39
|
-
validDirs.push(dir.name);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (validDirs.length > 0) {
|
|
45
|
-
const content = validDirs.map((d) => `export * from './${d}';`).join('\n') + '\n';
|
|
46
|
-
await fs.writeFile(path.join(corePath, 'index.ts'), content, 'utf-8');
|
|
47
|
-
}
|
|
48
|
-
} catch (error) {
|
|
49
|
-
// Core directory doesn't exist
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
24
|
export async function ensureIndexExports(layerPath) {
|
|
54
25
|
try {
|
|
55
26
|
const subdirs = await fs.readdir(layerPath, { withFileTypes: true });
|
|
56
27
|
const exportLines = subdirs.filter((d) => d.isDirectory()).map((d) => `export * from './${d.name}';`);
|
|
57
|
-
|
|
58
28
|
if (exportLines.length > 0) {
|
|
59
29
|
await fs.writeFile(path.join(layerPath, 'index.ts'), exportLines.join('\n') + '\n', 'utf-8');
|
|
60
30
|
}
|
|
61
|
-
} catch
|
|
31
|
+
} catch {
|
|
62
32
|
// Directory doesn't exist
|
|
63
33
|
}
|
|
64
34
|
}
|
|
65
|
-
|
|
66
35
|
export async function injectIntoFile(filepath, searchPattern, newContent, position = 'after') {
|
|
67
36
|
try {
|
|
68
37
|
let content = await fs.readFile(filepath, 'utf-8');
|
|
69
38
|
const index = content.indexOf(searchPattern);
|
|
70
|
-
|
|
71
39
|
if (index === -1) {
|
|
72
40
|
console.warn(`Pattern not found in ${filepath}`);
|
|
73
41
|
return false;
|
|
74
42
|
}
|
|
75
|
-
|
|
76
43
|
if (content.includes(newContent.trim())) {
|
|
77
44
|
console.log(`Content already exists in ${filepath}`);
|
|
78
45
|
return false;
|
|
79
46
|
}
|
|
80
|
-
|
|
81
47
|
if (position === 'after') {
|
|
82
48
|
const insertIndex = index + searchPattern.length;
|
|
83
49
|
content = content.slice(0, insertIndex) + '\n' + newContent + content.slice(insertIndex);
|
|
84
50
|
} else {
|
|
85
51
|
content = content.slice(0, index) + newContent + '\n' + content.slice(index);
|
|
86
52
|
}
|
|
87
|
-
|
|
88
53
|
await fs.writeFile(filepath, content, 'utf-8');
|
|
89
54
|
console.log(`✅ Updated: ${filepath}`);
|
|
90
55
|
return true;
|
|
91
56
|
} catch (error) {
|
|
92
|
-
console.error(`Failed to update ${filepath}:`, error.message);
|
|
57
|
+
console.error(`Failed to update ${filepath}:`, error instanceof Error ? error.message : String(error));
|
|
93
58
|
return false;
|
|
94
59
|
}
|
|
95
60
|
}
|
package/src/utils/fileUtils.ts
CHANGED
|
@@ -24,32 +24,6 @@ export async function updateIndexTs(dir: string, filePattern = '.ts', ignore: st
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export async function updateCoreIndex(): Promise<void> {
|
|
28
|
-
const corePath = path.join(process.cwd(), 'src/core');
|
|
29
|
-
try {
|
|
30
|
-
const dirs = await fs.readdir(corePath, { withFileTypes: true });
|
|
31
|
-
const validDirs: string[] = [];
|
|
32
|
-
|
|
33
|
-
for (const dir of dirs) {
|
|
34
|
-
if (dir.isDirectory()) {
|
|
35
|
-
// Check if directory has any files
|
|
36
|
-
const dirPath = path.join(corePath, dir.name);
|
|
37
|
-
const files = await fs.readdir(dirPath);
|
|
38
|
-
if (files.length > 0) {
|
|
39
|
-
validDirs.push(dir.name);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (validDirs.length > 0) {
|
|
45
|
-
const content = validDirs.map((d) => `export * from './${d}';`).join('\n') + '\n';
|
|
46
|
-
await fs.writeFile(path.join(corePath, 'index.ts'), content, 'utf-8');
|
|
47
|
-
}
|
|
48
|
-
} catch {
|
|
49
|
-
// Core directory doesn't exist
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
27
|
export async function ensureIndexExports(layerPath: string): Promise<void> {
|
|
54
28
|
try {
|
|
55
29
|
const subdirs = await fs.readdir(layerPath, { withFileTypes: true });
|
package/src/utils/loadConfig.js
CHANGED
|
@@ -1,57 +1,44 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import fsSync from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
|
|
5
4
|
const DEFAULT_CONFIG = {
|
|
6
5
|
contexts: [],
|
|
7
|
-
defaultContext: 'web'
|
|
8
|
-
coreAlias: '$core'
|
|
6
|
+
defaultContext: 'web'
|
|
9
7
|
};
|
|
10
|
-
|
|
11
8
|
function toObjectFromDefaultExport(content) {
|
|
12
9
|
const source = String(content ?? '').trim();
|
|
13
10
|
if (!source.length) return {};
|
|
14
|
-
|
|
15
11
|
const replacedExport = source.replace(/^\s*export\s+default\s+/m, 'return ');
|
|
16
12
|
if (replacedExport === source) return {};
|
|
17
|
-
|
|
18
13
|
const withSemicolon = /;\s*$/.test(replacedExport) ? replacedExport : `${replacedExport};`;
|
|
19
|
-
|
|
20
14
|
try {
|
|
21
|
-
// eslint-disable-next-line no-new-func
|
|
22
15
|
return new Function(withSemicolon)() ?? {};
|
|
23
16
|
} catch {
|
|
24
17
|
return {};
|
|
25
18
|
}
|
|
26
19
|
}
|
|
27
|
-
|
|
28
20
|
export function resolveConfigFile(cwd = process.cwd()) {
|
|
29
21
|
const tsPath = path.join(cwd, 'azure-net.config.ts');
|
|
30
22
|
const jsPath = path.join(cwd, 'azure-net.config.js');
|
|
31
|
-
|
|
32
23
|
if (fsSync.existsSync(tsPath)) {
|
|
33
24
|
return { exists: true, filepath: tsPath, type: 'ts' };
|
|
34
25
|
}
|
|
35
26
|
if (fsSync.existsSync(jsPath)) {
|
|
36
27
|
return { exists: true, filepath: jsPath, type: 'js' };
|
|
37
28
|
}
|
|
38
|
-
|
|
39
29
|
return { exists: false, filepath: tsPath, type: 'ts' };
|
|
40
30
|
}
|
|
41
|
-
|
|
42
31
|
export async function loadUserConfig() {
|
|
43
32
|
const { exists, filepath } = resolveConfigFile();
|
|
44
33
|
if (!exists) {
|
|
45
34
|
return { ...DEFAULT_CONFIG };
|
|
46
35
|
}
|
|
47
|
-
|
|
48
36
|
try {
|
|
49
37
|
const content = await fs.readFile(filepath, 'utf-8');
|
|
50
38
|
const parsed = toObjectFromDefaultExport(content);
|
|
51
39
|
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
52
40
|
return { ...DEFAULT_CONFIG };
|
|
53
41
|
}
|
|
54
|
-
|
|
55
42
|
return { ...DEFAULT_CONFIG, ...parsed };
|
|
56
43
|
} catch {
|
|
57
44
|
return { ...DEFAULT_CONFIG };
|
package/src/utils/loadConfig.ts
CHANGED
|
@@ -5,7 +5,6 @@ import path from 'node:path';
|
|
|
5
5
|
export type AzureNetConfig = {
|
|
6
6
|
contexts: Array<string | { name?: string; alias?: string }>;
|
|
7
7
|
defaultContext: string;
|
|
8
|
-
coreAlias: string;
|
|
9
8
|
sharedAlias?: string;
|
|
10
9
|
packageManager?: string;
|
|
11
10
|
defaultSchemaFactory?: string;
|
|
@@ -15,8 +14,7 @@ export type AzureNetConfig = {
|
|
|
15
14
|
|
|
16
15
|
const DEFAULT_CONFIG: AzureNetConfig = {
|
|
17
16
|
contexts: [],
|
|
18
|
-
defaultContext: 'web'
|
|
19
|
-
coreAlias: '$core'
|
|
17
|
+
defaultContext: 'web'
|
|
20
18
|
};
|
|
21
19
|
|
|
22
20
|
function toObjectFromDefaultExport(content: string): Record<string, unknown> {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { normalizeContexts } from '../init/initAliases.js';
|
|
3
|
+
import { loadUserConfig, resolveConfigFile } from './loadConfig.js';
|
|
4
|
+
export const SHARED_ESSENTIALS_DIR_NAME = 'essentials';
|
|
5
|
+
const normalizeAlias = (value) => {
|
|
6
|
+
const raw = String(value ?? '').trim();
|
|
7
|
+
return raw.startsWith('$') ? raw : `$${raw}`;
|
|
8
|
+
};
|
|
9
|
+
const createMissingSharedAliasError = () =>
|
|
10
|
+
new Error(
|
|
11
|
+
'`sharedAlias` is missing in azure-net.config.ts/js. Add sharedAlias and make sure it points to one of `contexts`, for example: sharedAlias: "$shared-kernel".'
|
|
12
|
+
);
|
|
13
|
+
export const getSharedState = async () => {
|
|
14
|
+
const config = await loadUserConfig();
|
|
15
|
+
const contexts = normalizeContexts(config.contexts);
|
|
16
|
+
const sharedAliasRaw = String(config.sharedAlias ?? '').trim();
|
|
17
|
+
if (!sharedAliasRaw.length) throw createMissingSharedAliasError();
|
|
18
|
+
const sharedAlias = normalizeAlias(sharedAliasRaw);
|
|
19
|
+
const sharedContext = contexts.find((context) => normalizeAlias(context.alias) === sharedAlias);
|
|
20
|
+
if (!sharedContext) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
`sharedAlias "${sharedAlias}" does not point to any configured context. Add a context with alias "${sharedAlias}" in azure-net.config.ts/js.`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
contexts,
|
|
27
|
+
sharedAlias,
|
|
28
|
+
sharedContext
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export const hasSharedAliasConfig = async () => {
|
|
32
|
+
const config = await loadUserConfig();
|
|
33
|
+
return String(config.sharedAlias ?? '').trim().length > 0;
|
|
34
|
+
};
|
|
35
|
+
export const getSharedContextRootPath = (sharedContextName) => path.join(process.cwd(), 'src', 'app', sharedContextName);
|
|
36
|
+
export const getSharedEssentialsPath = (sharedContextName) =>
|
|
37
|
+
path.join(getSharedContextRootPath(sharedContextName), SHARED_ESSENTIALS_DIR_NAME);
|
|
38
|
+
export const getFoundationRootPath = (sharedContextName) =>
|
|
39
|
+
path.join(getSharedEssentialsPath(sharedContextName), 'foundation', 'constructs');
|
|
40
|
+
export const getFoundationConstructPath = (sharedContextName, construct) => path.join(getFoundationRootPath(sharedContextName), construct);
|
|
41
|
+
export const getFoundationConstructImportPath = (sharedAlias, construct) =>
|
|
42
|
+
`${sharedAlias}/${SHARED_ESSENTIALS_DIR_NAME}/foundation/constructs/${construct}`;
|
|
43
|
+
export const getLocalizationPath = (sharedContextName) => path.join(getSharedEssentialsPath(sharedContextName), 'localization');
|
|
44
|
+
export const getLocalizationImportPath = (sharedAlias) => `${sharedAlias}/${SHARED_ESSENTIALS_DIR_NAME}/localization`;
|
|
45
|
+
export const getConfigFileLabel = () => {
|
|
46
|
+
const config = resolveConfigFile();
|
|
47
|
+
return config.exists ? path.basename(config.filepath) : 'azure-net.config.ts/js';
|
|
48
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { normalizeContexts } from '../init/initAliases.js';
|
|
3
|
+
import { loadUserConfig, resolveConfigFile } from './loadConfig.js';
|
|
4
|
+
|
|
5
|
+
export type FoundationConstruct = 'datasource' | 'presenter' | 'provider' | 'response' | 'schema';
|
|
6
|
+
export type ContextConfig = { name: string; alias: string };
|
|
7
|
+
|
|
8
|
+
export const SHARED_ESSENTIALS_DIR_NAME = 'essentials';
|
|
9
|
+
|
|
10
|
+
const normalizeAlias = (value: unknown): string => {
|
|
11
|
+
const raw = String(value ?? '').trim();
|
|
12
|
+
return raw.startsWith('$') ? raw : `$${raw}`;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const createMissingSharedAliasError = (): Error =>
|
|
16
|
+
new Error(
|
|
17
|
+
'`sharedAlias` is missing in azure-net.config.ts/js. Add sharedAlias and make sure it points to one of `contexts`, for example: sharedAlias: "$shared-kernel".'
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export const getSharedState = async (): Promise<{ contexts: ContextConfig[]; sharedAlias: string; sharedContext: ContextConfig }> => {
|
|
21
|
+
const config = await loadUserConfig();
|
|
22
|
+
const contexts = normalizeContexts(config.contexts) as ContextConfig[];
|
|
23
|
+
const sharedAliasRaw = String(config.sharedAlias ?? '').trim();
|
|
24
|
+
|
|
25
|
+
if (!sharedAliasRaw.length) throw createMissingSharedAliasError();
|
|
26
|
+
|
|
27
|
+
const sharedAlias = normalizeAlias(sharedAliasRaw);
|
|
28
|
+
const sharedContext = contexts.find((context) => normalizeAlias(context.alias) === sharedAlias);
|
|
29
|
+
|
|
30
|
+
if (!sharedContext) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`sharedAlias "${sharedAlias}" does not point to any configured context. Add a context with alias "${sharedAlias}" in azure-net.config.ts/js.`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
contexts,
|
|
38
|
+
sharedAlias,
|
|
39
|
+
sharedContext
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const hasSharedAliasConfig = async (): Promise<boolean> => {
|
|
44
|
+
const config = await loadUserConfig();
|
|
45
|
+
return String(config.sharedAlias ?? '').trim().length > 0;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const getSharedContextRootPath = (sharedContextName: string): string => path.join(process.cwd(), 'src', 'app', sharedContextName);
|
|
49
|
+
|
|
50
|
+
export const getSharedEssentialsPath = (sharedContextName: string): string =>
|
|
51
|
+
path.join(getSharedContextRootPath(sharedContextName), SHARED_ESSENTIALS_DIR_NAME);
|
|
52
|
+
|
|
53
|
+
export const getFoundationRootPath = (sharedContextName: string): string =>
|
|
54
|
+
path.join(getSharedEssentialsPath(sharedContextName), 'foundation', 'constructs');
|
|
55
|
+
|
|
56
|
+
export const getFoundationConstructPath = (sharedContextName: string, construct: FoundationConstruct): string =>
|
|
57
|
+
path.join(getFoundationRootPath(sharedContextName), construct);
|
|
58
|
+
|
|
59
|
+
export const getFoundationConstructImportPath = (sharedAlias: string, construct: FoundationConstruct): string =>
|
|
60
|
+
`${sharedAlias}/${SHARED_ESSENTIALS_DIR_NAME}/foundation/constructs/${construct}`;
|
|
61
|
+
|
|
62
|
+
export const getLocalizationPath = (sharedContextName: string): string =>
|
|
63
|
+
path.join(getSharedEssentialsPath(sharedContextName), 'localization');
|
|
64
|
+
|
|
65
|
+
export const getLocalizationImportPath = (sharedAlias: string): string => `${sharedAlias}/${SHARED_ESSENTIALS_DIR_NAME}/localization`;
|
|
66
|
+
|
|
67
|
+
export const getConfigFileLabel = (): string => {
|
|
68
|
+
const config = resolveConfigFile();
|
|
69
|
+
return config.exists ? path.basename(config.filepath) : 'azure-net.config.ts/js';
|
|
70
|
+
};
|