@azure-net/cli 1.3.9 → 1.3.10
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/package.json
CHANGED
|
@@ -2,9 +2,10 @@ import prompts from 'prompts';
|
|
|
2
2
|
import fs from 'fs/promises';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import ejs from 'ejs';
|
|
5
|
-
import { loadUserConfig } from
|
|
5
|
+
import { loadUserConfig } from '../utils/loadConfig.js';
|
|
6
6
|
|
|
7
7
|
const __dirname = path.dirname(new URL(import.meta.url).pathname);
|
|
8
|
+
const CORE_DATASOURCES_PATH = path.join(process.cwd(), 'src/app/core/datasources');
|
|
8
9
|
|
|
9
10
|
async function writeIfNotExists(filepath, content) {
|
|
10
11
|
try {
|
|
@@ -23,8 +24,20 @@ async function updateIndexTs(dir, filePattern = '.ts', ignore = ['index.ts']) {
|
|
|
23
24
|
await fs.writeFile(path.join(dir, 'index.ts'), content, 'utf-8');
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
async function getAvailableDatasources() {
|
|
28
|
+
try {
|
|
29
|
+
const files = await fs.readdir(CORE_DATASOURCES_PATH);
|
|
30
|
+
return files
|
|
31
|
+
.filter(f => f.endsWith('.ts') && !f.startsWith('_'))
|
|
32
|
+
.map(f => f.replace('.ts', ''));
|
|
33
|
+
} catch {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
26
38
|
export default async function generateCrud() {
|
|
27
39
|
const config = await loadUserConfig();
|
|
40
|
+
const datasources = await getAvailableDatasources();
|
|
28
41
|
|
|
29
42
|
const answers = await prompts([
|
|
30
43
|
config.modules?.length
|
|
@@ -40,7 +53,12 @@ export default async function generateCrud() {
|
|
|
40
53
|
: null,
|
|
41
54
|
{ type: 'text', name: 'className', message: 'Class name (PascalCase):' },
|
|
42
55
|
{ type: 'text', name: 'endpoint', message: 'API endpoint:' },
|
|
43
|
-
{
|
|
56
|
+
{
|
|
57
|
+
type: 'select',
|
|
58
|
+
name: 'datasource',
|
|
59
|
+
message: 'Select datasource:',
|
|
60
|
+
choices: datasources.map(d => ({ title: d, value: d }))
|
|
61
|
+
}
|
|
44
62
|
].filter(Boolean));
|
|
45
63
|
|
|
46
64
|
const rawName = answers.className.trim();
|
|
@@ -70,10 +88,10 @@ export default async function generateCrud() {
|
|
|
70
88
|
endpoint,
|
|
71
89
|
datasource,
|
|
72
90
|
aliasDomain: `${aliasCurrent}/Domain`,
|
|
73
|
-
aliasShared
|
|
91
|
+
aliasShared,
|
|
74
92
|
aliasApplication: `${aliasCurrent}/Application`,
|
|
75
93
|
aliasInfra: `${aliasCurrent}/Infra`,
|
|
76
|
-
aliasRepo: `${aliasCurrent}/Infra/Repo
|
|
94
|
+
aliasRepo: `${aliasCurrent}/Infra/Repo`
|
|
77
95
|
};
|
|
78
96
|
|
|
79
97
|
// === 1) Abstracts
|
|
@@ -103,8 +121,9 @@ export default async function generateCrud() {
|
|
|
103
121
|
// === 4) Domain Index
|
|
104
122
|
await writeIfNotExists(
|
|
105
123
|
path.join(domainPath, 'index.ts'),
|
|
106
|
-
[`export * from './Abstracts';`, `export * from './Request';`].join('\n')
|
|
124
|
+
[`export * from './Abstracts';`, `export * from './Request';`].join('\n')
|
|
107
125
|
);
|
|
126
|
+
await updateIndexTs(domainPath);
|
|
108
127
|
|
|
109
128
|
// === 5) Repo
|
|
110
129
|
const repoTpl = await fs.readFile(path.join(__dirname, '../templates/data/repo/ClassRepo.ejs'), 'utf-8');
|
|
@@ -113,4 +132,4 @@ export default async function generateCrud() {
|
|
|
113
132
|
await updateIndexTs(repoPath);
|
|
114
133
|
|
|
115
134
|
console.log(`✅ CRUD for ${capital} generated in ${selectedModule || 'app-context'} structure`);
|
|
116
|
-
}
|
|
135
|
+
}
|
|
@@ -5,6 +5,7 @@ import { loadUserConfig } from '../utils/loadConfig.js';
|
|
|
5
5
|
const BASE_STRUCTURE = ['Domain', 'Infra', 'Application', 'Presentation'];
|
|
6
6
|
const APP_ROOT = path.join(process.cwd(), 'src', 'app');
|
|
7
7
|
const CONTEXTS_PATH = path.join(APP_ROOT, 'contexts');
|
|
8
|
+
const CORE_PATH = path.join(APP_ROOT, 'core');
|
|
8
9
|
|
|
9
10
|
async function createDirIfNotExists(dirPath) {
|
|
10
11
|
try {
|
|
@@ -20,10 +21,10 @@ async function createBaseStructure(root) {
|
|
|
20
21
|
const sectionPath = path.join(root, section);
|
|
21
22
|
await createDirIfNotExists(sectionPath);
|
|
22
23
|
|
|
23
|
-
if (section === '
|
|
24
|
+
if (section === 'Infra') {
|
|
24
25
|
await createDirIfNotExists(path.join(sectionPath, 'Repo'));
|
|
25
26
|
}
|
|
26
|
-
if (section === '
|
|
27
|
+
if (section === 'Application') {
|
|
27
28
|
await createDirIfNotExists(path.join(sectionPath, 'Services'));
|
|
28
29
|
await createDirIfNotExists(path.join(sectionPath, 'Orchestrators'));
|
|
29
30
|
}
|
|
@@ -37,7 +38,7 @@ export default async function initStructure() {
|
|
|
37
38
|
|
|
38
39
|
console.log('📦 Generating architecture in: /contexts');
|
|
39
40
|
|
|
40
|
-
// всегда shared-
|
|
41
|
+
// всегда shared-context
|
|
41
42
|
const sharedKernelPath = path.join(CONTEXTS_PATH, 'shared-context');
|
|
42
43
|
await createBaseStructure(sharedKernelPath);
|
|
43
44
|
|
|
@@ -50,13 +51,14 @@ export default async function initStructure() {
|
|
|
50
51
|
}
|
|
51
52
|
} else {
|
|
52
53
|
// fallback-контекст
|
|
53
|
-
console.log('🧱 No modules found — using default "app"
|
|
54
|
-
const
|
|
55
|
-
await createBaseStructure(
|
|
54
|
+
console.log('🧱 No modules found — using default "app-context"...');
|
|
55
|
+
const fallbackPath = path.join(CONTEXTS_PATH, 'app-context');
|
|
56
|
+
await createBaseStructure(fallbackPath);
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
//
|
|
59
|
-
await createDirIfNotExists(
|
|
59
|
+
// Доп. слои вне contexts
|
|
60
|
+
await createDirIfNotExists(CORE_PATH);
|
|
61
|
+
await createDirIfNotExists(path.join(CORE_PATH, 'datasources'));
|
|
60
62
|
await createDirIfNotExists(path.join(APP_ROOT, 'ui'));
|
|
61
63
|
|
|
62
64
|
console.log('✅ Structure initialization complete!');
|
|
@@ -12,13 +12,19 @@ function generateAliases(config) {
|
|
|
12
12
|
if (hasModules) {
|
|
13
13
|
config.modules.push('shared-context');
|
|
14
14
|
return Object.fromEntries(
|
|
15
|
-
|
|
15
|
+
[
|
|
16
|
+
...config.modules.map(m => [`$${m}`, `./src/app/contexts/${m}`]),
|
|
17
|
+
['$core', './src/app/core'],
|
|
18
|
+
['$ui', './src/app/ui']
|
|
19
|
+
]
|
|
16
20
|
);
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
return {
|
|
20
24
|
'$app-context': './src/app/contexts/app-context',
|
|
21
|
-
'$shared-context': './src/app/contexts/shared-context'
|
|
25
|
+
'$shared-context': './src/app/contexts/shared-context',
|
|
26
|
+
'$core': './src/app/core',
|
|
27
|
+
'$ui': './src/app/ui'
|
|
22
28
|
};
|
|
23
29
|
}
|
|
24
30
|
|