@azure-net/cli 2.3.3 → 2.3.61

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 CHANGED
@@ -9,7 +9,8 @@ import {
9
9
  initTranslations,
10
10
  initSchema,
11
11
  initLint,
12
- initPresenter
12
+ initPresenter,
13
+ migrateStructure
13
14
  } from '../src/commands/init/index.js';
14
15
  import {
15
16
  generateDatasource,
@@ -71,6 +72,11 @@ program
71
72
  .description('Initialize presenter factory')
72
73
  .action(initPresenter);
73
74
 
75
+ program
76
+ .command('migrate:structure')
77
+ .description('Migrate existing contexts to new structure with layers and ui folders')
78
+ .action(migrateStructure);
79
+
74
80
  program
75
81
  .command('init')
76
82
  .description('Run all initialization steps')
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@azure-net/cli",
3
- "version": "2.3.3",
3
+ "version": "2.3.61",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "azure-net": "bin/azure-net.js"
7
7
  },
8
8
  "peerDependencies": {
9
- "@azure-net/kit": "^1.3.3"
9
+ "@azure-net/kit": "^1.3.7"
10
10
  },
11
11
  "dependencies": {
12
- "@azure-net/kit": "^1.3.3",
12
+ "@azure-net/kit": "^1.3.7",
13
13
  "commander": "^11",
14
14
  "prompts": "^2"
15
15
  },
@@ -116,7 +116,7 @@ export default async function generateCrudBase() {
116
116
  // Get available datasources
117
117
  const contextPath = getContextPath(context);
118
118
  const coreDatasources = await getAvailableFiles(
119
- path.join(process.cwd(), 'src/app/core/datasources')
119
+ path.join(process.cwd(), 'src/core/datasources')
120
120
  );
121
121
  const contextDatasources = await getAvailableFiles(
122
122
  path.join(contextPath, 'infrastructure/http/datasources')
@@ -114,7 +114,7 @@ export default async function generateCrudPresenter() {
114
114
 
115
115
  // Get schema factory
116
116
  const coreSchemas = await getAvailableFiles(
117
- path.join(process.cwd(), 'src/app/core/schemas')
117
+ path.join(process.cwd(), 'src/core/schemas')
118
118
  );
119
119
 
120
120
  const { schemaType } = await prompts({
@@ -129,7 +129,7 @@ export default async function generateCrudPresenter() {
129
129
 
130
130
  // Get presenter factory
131
131
  const corePresenters = await getAvailableFiles(
132
- path.join(process.cwd(), 'src/app/core/presenters')
132
+ path.join(process.cwd(), 'src/core/presenters')
133
133
  );
134
134
 
135
135
  const { presenterType } = await prompts({
@@ -23,12 +23,12 @@ export default async function generateDatasource() {
23
23
 
24
24
  const pascalName = toPascalCase(name);
25
25
  const contextPath = context === 'core'
26
- ? path.join(process.cwd(), 'src/app/core')
26
+ ? path.join(process.cwd(), 'src/core')
27
27
  : getContextPath(context);
28
28
 
29
29
  // Get available responses
30
30
  const coreResponses = await getAvailableFiles(
31
- path.join(process.cwd(), 'src/app/core/responses')
31
+ path.join(process.cwd(), 'src/core/responses')
32
32
  );
33
33
 
34
34
  const contextResponses = context !== 'core'
@@ -42,7 +42,7 @@ export default async function generatePresenter() {
42
42
 
43
43
  // Check for core presenters
44
44
  const corePresenters = await getAvailableFiles(
45
- path.join(process.cwd(), 'src/app/core/presenters')
45
+ path.join(process.cwd(), 'src/core/presenters')
46
46
  );
47
47
 
48
48
  const presenterChoices = [
@@ -27,7 +27,7 @@ export default async function generateRepository() {
27
27
  // Get available datasources
28
28
  const contextPath = getContextPath(context);
29
29
  const coreDatasources = await getAvailableFiles(
30
- path.join(process.cwd(), 'src/app/core/datasources')
30
+ path.join(process.cwd(), 'src/core/datasources')
31
31
  );
32
32
  const contextDatasources = await getAvailableFiles(
33
33
  path.join(contextPath, 'infrastructure/http/datasources')
@@ -19,7 +19,7 @@ export default async function generateResponse() {
19
19
 
20
20
  const pascalName = toPascalCase(name);
21
21
  const contextPath = context === 'core'
22
- ? path.join(process.cwd(), 'src/app/core')
22
+ ? path.join(process.cwd(), 'src/core')
23
23
  : getContextPath(context);
24
24
 
25
25
  const responsePath = context === 'core'
@@ -45,7 +45,7 @@ export default async function generateSchema() {
45
45
 
46
46
  // Check for core schemas
47
47
  const coreSchemas = await getAvailableFiles(
48
- path.join(process.cwd(), 'src/app/core/schemas')
48
+ path.join(process.cwd(), 'src/core/schemas')
49
49
  );
50
50
 
51
51
  const choices = [
@@ -5,4 +5,5 @@ export { default as initEdges } from './initEdges.js';
5
5
  export { default as initTranslations } from './initTranslations.js';
6
6
  export { default as initSchema } from './initSchema.js';
7
7
  export { default as initLint } from './initLint.js';
8
- export { default as initPresenter } from './initPresenter.js';
8
+ export { default as initPresenter } from './initPresenter.js';
9
+ export { default as migrateStructure } from './migrateStructure.js';
@@ -9,9 +9,11 @@ function generateAliases(config) {
9
9
  const contexts = config.contexts || ['app'];
10
10
 
11
11
  return Object.fromEntries([
12
- ...contexts.map(c => [`$${c}`, `./src/app/contexts/${c}`]),
13
- ['$shared', './src/app/shared'],
14
- ['$core', './src/app/core']
12
+ ...contexts.flatMap(c => [
13
+ [`$${c}`, `./src/app/${c}/layers`],
14
+ [`$${c}/ui`, `./src/app/${c}/ui`]
15
+ ]),
16
+ ['$core', './src/core']
15
17
  ]);
16
18
  }
17
19
 
@@ -1,7 +1,7 @@
1
1
  import { writeIfNotExists, updateCoreIndex } from '../../utils/fileUtils.js';
2
2
  import path from 'path';
3
3
 
4
- const middlewarePath = path.join(process.cwd(), 'src/app/core/middleware/MiddlewareManager.ts');
4
+ const middlewarePath = path.join(process.cwd(), 'src/core/middleware/MiddlewareManager.ts');
5
5
 
6
6
  const middlewareTemplate = `import { createMiddlewareManager } from '@azure-net/kit';
7
7
 
@@ -10,7 +10,7 @@ export const { clientMiddleware, serverMiddleware } = createMiddlewareManager([]
10
10
  export default async function initMiddleware() {
11
11
  await writeIfNotExists(middlewarePath, middlewareTemplate);
12
12
  await writeIfNotExists(
13
- path.join(process.cwd(), 'src/app/core/middleware/index.ts'),
13
+ path.join(process.cwd(), 'src/core/middleware/index.ts'),
14
14
  `export * from './MiddlewareManager';`
15
15
  );
16
16
 
@@ -1,7 +1,7 @@
1
1
  import {updateCoreIndex, writeIfNotExists} from '../../utils/fileUtils.js';
2
2
  import path from 'path';
3
3
 
4
- const presenterPath = path.join(process.cwd(), 'src/app/core/presenters/AppPresenter.ts');
4
+ const presenterPath = path.join(process.cwd(), 'src/core/presenters/AppPresenter.ts');
5
5
 
6
6
  const presenterTemplate = `import { createPresenterFactory } from '@azure-net/kit/edges';
7
7
  import { createAsyncHelpers, createErrorParser } from '@azure-net/kit';
@@ -14,7 +14,7 @@ export const AppPresenter = createPresenterFactory({ ...AsyncHelpers, handleErro
14
14
  export default async function initPresenter() {
15
15
  await writeIfNotExists(presenterPath, presenterTemplate);
16
16
  await writeIfNotExists(
17
- path.join(process.cwd(), 'src/app/core/presenters/index.ts'),
17
+ path.join(process.cwd(), 'src/core/presenters/index.ts'),
18
18
  `export * from './AppPresenter';`
19
19
  );
20
20
 
@@ -1,7 +1,7 @@
1
1
  import { writeIfNotExists, updateCoreIndex } from '../../utils/fileUtils.js';
2
2
  import path from 'path';
3
3
 
4
- const schemaPath = path.join(process.cwd(), 'src/app/core/schemas/Schema.ts');
4
+ const schemaPath = path.join(process.cwd(), 'src/core/schemas/Schema.ts');
5
5
 
6
6
  const schemaTemplate = `import { createSchemaFactory } from '@azure-net/kit';
7
7
  import { createRules, validationMessagesI18n } from '@azure-net/kit/schema';
@@ -11,7 +11,7 @@ export const Schema = createSchemaFactory(createRules(validationMessagesI18n));`
11
11
  export default async function initSchema() {
12
12
  await writeIfNotExists(schemaPath, schemaTemplate);
13
13
  await writeIfNotExists(
14
- path.join(process.cwd(), 'src/app/core/schemas/index.ts'),
14
+ path.join(process.cwd(), 'src/core/schemas/index.ts'),
15
15
  `export * from './Schema';`
16
16
  );
17
17
 
@@ -3,10 +3,8 @@ import path from 'path';
3
3
  import { loadUserConfig } from '../../utils/loadConfig.js';
4
4
  import { updateCoreIndex } from '../../utils/fileUtils.js';
5
5
 
6
- const APP_ROOT = path.join(process.cwd(), 'src', 'app');
7
- const CONTEXTS_PATH = path.join(APP_ROOT, 'contexts');
8
- const SHARED_PATH = path.join(APP_ROOT, 'shared');
9
- const CORE_PATH = path.join(APP_ROOT, 'core');
6
+ const APP_PATH = path.join(process.cwd(), 'src', 'app');
7
+ const CORE_PATH = path.join(process.cwd(), 'src', 'core');
10
8
 
11
9
  async function createDirIfNotExists(dirPath) {
12
10
  try {
@@ -26,12 +24,19 @@ async function createIndexFile(dirPath, exportPatterns = []) {
26
24
  }
27
25
 
28
26
  async function createBaseStructure(root, contextName, contextAlias) {
27
+ // Create layers and ui folders
28
+ const layersPath = path.join(root, 'layers');
29
+ const uiPath = path.join(root, 'ui');
30
+
31
+ await createDirIfNotExists(layersPath);
32
+ await createDirIfNotExists(uiPath);
33
+
29
34
  // Domain - новая структура
30
- const domainPath = path.join(root, 'domain');
35
+ const domainPath = path.join(layersPath, 'domain');
31
36
  await createDirIfNotExists(domainPath);
32
37
 
33
38
  // Infrastructure
34
- const infraPath = path.join(root, 'infrastructure');
39
+ const infraPath = path.join(layersPath, 'infrastructure');
35
40
  await createDirIfNotExists(path.join(infraPath, 'http', 'repositories'));
36
41
  await createDirIfNotExists(path.join(infraPath, 'http', 'datasources'));
37
42
  await createDirIfNotExists(path.join(infraPath, 'providers'));
@@ -63,7 +68,7 @@ export const InfrastructureProvider = createBoundaryProvider(
63
68
  );
64
69
 
65
70
  // Application
66
- const appPath = path.join(root, 'application');
71
+ const appPath = path.join(layersPath, 'application');
67
72
  await createDirIfNotExists(path.join(appPath, 'services'));
68
73
  await createDirIfNotExists(path.join(appPath, 'providers'));
69
74
 
@@ -101,7 +106,7 @@ export const ApplicationProvider = createBoundaryProvider(
101
106
  );
102
107
 
103
108
  // Delivery - organized by modules
104
- const deliveryPath = path.join(root, 'delivery');
109
+ const deliveryPath = path.join(layersPath, 'delivery');
105
110
  await createDirIfNotExists(deliveryPath);
106
111
  }
107
112
 
@@ -111,17 +116,14 @@ export default async function initStructure() {
111
116
 
112
117
  console.log('📦 Generating architecture...');
113
118
 
114
- // Create contexts
119
+ // Create contexts directly in src/app
115
120
  for (const context of contexts) {
116
- const contextPath = path.join(CONTEXTS_PATH, context);
121
+ const contextPath = path.join(APP_PATH, context);
117
122
  const contextName = context.charAt(0).toUpperCase() + context.slice(1);
118
123
  await createBaseStructure(contextPath, contextName, context);
119
124
  }
120
125
 
121
- // Create empty shared folder
122
- await createDirIfNotExists(SHARED_PATH);
123
-
124
- // Create core structure with all functionality
126
+ // Create core structure with all functionality (in src/core, not src/app/core)
125
127
  await createDirIfNotExists(CORE_PATH);
126
128
  await createDirIfNotExists(path.join(CORE_PATH, 'datasources'));
127
129
  await createDirIfNotExists(path.join(CORE_PATH, 'responses'));
@@ -129,6 +131,7 @@ export default async function initStructure() {
129
131
  await createDirIfNotExists(path.join(CORE_PATH, 'middleware'));
130
132
  await createDirIfNotExists(path.join(CORE_PATH, 'presenters'));
131
133
  await createDirIfNotExists(path.join(CORE_PATH, 'translations'));
134
+ await createDirIfNotExists(path.join(CORE_PATH, 'providers'));
132
135
 
133
136
  // Update core index
134
137
  await updateCoreIndex();
@@ -1,7 +1,7 @@
1
1
  import { writeIfNotExists, updateCoreIndex } from '../../utils/fileUtils.js';
2
2
  import path from 'path';
3
3
 
4
- const translationsPath = path.join(process.cwd(), 'src/app/core/translations');
4
+ const translationsPath = path.join(process.cwd(), 'src/core/translations');
5
5
 
6
6
  const translationProviderTemplate = `import { messages } from './locales';
7
7
  import { createTranslations } from '@azure-net/kit/i18n';
@@ -0,0 +1,144 @@
1
+ import fs from 'fs/promises';
2
+ import path from 'path';
3
+ import { loadUserConfig } from '../../utils/loadConfig.js';
4
+
5
+ const APP_PATH = path.join(process.cwd(), 'src/app');
6
+ const OLD_CONTEXTS_PATH = path.join(APP_PATH, 'contexts');
7
+ const OLD_CORE_PATH = path.join(APP_PATH, 'core');
8
+ const NEW_CORE_PATH = path.join(process.cwd(), 'src/core');
9
+
10
+ async function directoryExists(dirPath) {
11
+ try {
12
+ const stat = await fs.stat(dirPath);
13
+ return stat.isDirectory();
14
+ } catch {
15
+ return false;
16
+ }
17
+ }
18
+
19
+ async function moveDirectory(source, destination) {
20
+ try {
21
+ // Check if source exists
22
+ if (!(await directoryExists(source))) {
23
+ return false;
24
+ }
25
+
26
+ // Create destination parent directory if needed
27
+ await fs.mkdir(path.dirname(destination), { recursive: true });
28
+
29
+ // Move the directory
30
+ await fs.rename(source, destination);
31
+ console.log(`✅ Moved: ${source} -> ${destination}`);
32
+ return true;
33
+ } catch (error) {
34
+ console.error(`❌ Failed to move ${source}:`, error.message);
35
+ return false;
36
+ }
37
+ }
38
+
39
+ async function removeEmptyDir(dirPath) {
40
+ try {
41
+ await fs.rmdir(dirPath);
42
+ console.log(`🗑️ Removed empty directory: ${dirPath}`);
43
+ } catch {
44
+ // Directory not empty or doesn't exist
45
+ }
46
+ }
47
+
48
+ export default async function migrateStructure() {
49
+ const config = await loadUserConfig();
50
+ const contexts = config.contexts || ['app'];
51
+
52
+ console.log('🔄 Starting structure migration...\n');
53
+ console.log('This will reorganize existing structure to the new format:\n');
54
+ console.log(' - src/app/contexts/{context} -> src/app/{context}');
55
+ console.log(' - src/app/core -> src/core');
56
+ console.log(' - Ensure layers and ui folders exist\n');
57
+
58
+ // Step 1: Migrate core from src/app/core to src/core
59
+ if (await directoryExists(OLD_CORE_PATH)) {
60
+ console.log('📦 Migrating core...');
61
+
62
+ // Check if new core already exists
63
+ if (await directoryExists(NEW_CORE_PATH)) {
64
+ console.log('⚠️ Core already exists at src/core, skipping core migration...');
65
+ } else {
66
+ await moveDirectory(OLD_CORE_PATH, NEW_CORE_PATH);
67
+ }
68
+ }
69
+
70
+ // Step 2: Migrate contexts
71
+ for (const context of contexts) {
72
+ console.log(`\n📁 Migrating context: ${context}`);
73
+
74
+ const oldContextPath = path.join(OLD_CONTEXTS_PATH, context);
75
+ const newContextPath = path.join(APP_PATH, context);
76
+
77
+ // Check if context exists in old location (src/app/contexts/{context})
78
+ if (await directoryExists(oldContextPath)) {
79
+ // Check if new location already exists
80
+ if (await directoryExists(newContextPath)) {
81
+ console.log(`⚠️ Context '${context}' already exists at src/app/${context}, skipping...`);
82
+ continue;
83
+ }
84
+
85
+ // Move from contexts/{context} to app/{context}
86
+ await moveDirectory(oldContextPath, newContextPath);
87
+ }
88
+
89
+ // Now ensure the context has layers and ui structure
90
+ const contextPath = newContextPath;
91
+
92
+ if (!(await directoryExists(contextPath))) {
93
+ console.log(`⚠️ Context '${context}' does not exist, skipping...`);
94
+ continue;
95
+ }
96
+
97
+ const layersPath = path.join(contextPath, 'layers');
98
+ const uiPath = path.join(contextPath, 'ui');
99
+
100
+ // Check if already has layers structure
101
+ if (await directoryExists(layersPath)) {
102
+ console.log(`✓ Context '${context}' already has layers structure`);
103
+
104
+ // Just ensure ui folder exists
105
+ if (!(await directoryExists(uiPath))) {
106
+ await fs.mkdir(uiPath, { recursive: true });
107
+ console.log(`✅ Created: ${uiPath}`);
108
+ }
109
+
110
+ continue;
111
+ }
112
+
113
+ // Need to create layers structure
114
+ console.log(`📦 Creating layers structure for '${context}'...`);
115
+
116
+ await fs.mkdir(layersPath, { recursive: true });
117
+ await fs.mkdir(uiPath, { recursive: true });
118
+ console.log(`✅ Created: ${layersPath}`);
119
+ console.log(`✅ Created: ${uiPath}`);
120
+
121
+ // Move existing layer folders to layers directory
122
+ const layerFolders = ['domain', 'infrastructure', 'application', 'delivery'];
123
+
124
+ for (const layer of layerFolders) {
125
+ const sourcePath = path.join(contextPath, layer);
126
+ const destPath = path.join(layersPath, layer);
127
+
128
+ await moveDirectory(sourcePath, destPath);
129
+ }
130
+
131
+ console.log(`✅ Context '${context}' migration completed!`);
132
+ }
133
+
134
+ // Step 3: Clean up old contexts folder if empty
135
+ if (await directoryExists(OLD_CONTEXTS_PATH)) {
136
+ await removeEmptyDir(OLD_CONTEXTS_PATH);
137
+ }
138
+
139
+ console.log('\n✅ Structure migration complete!');
140
+ console.log('\n💡 Next steps:');
141
+ console.log(' 1. Run "azure-net init:aliases" to update path aliases');
142
+ console.log(' 2. Verify all imports are working correctly');
143
+ console.log(' 3. Update any hardcoded paths in your code');
144
+ }
@@ -3,8 +3,8 @@ import path from 'path';
3
3
  import prompts from 'prompts';
4
4
  import { loadUserConfig } from './loadConfig.js';
5
5
 
6
- const CONTEXTS_PATH = path.join(process.cwd(), 'src/app/contexts');
7
- const CORE_PATH = path.join(process.cwd(), 'src/app/core');
6
+ const APP_PATH = path.join(process.cwd(), 'src/app');
7
+ const CORE_PATH = path.join(process.cwd(), 'src/core');
8
8
 
9
9
  export async function selectContext(message = 'Select context:') {
10
10
  const config = await loadUserConfig();
@@ -26,7 +26,7 @@ export async function selectContext(message = 'Select context:') {
26
26
  export function getContextPath(context) {
27
27
  return context === 'core'
28
28
  ? CORE_PATH
29
- : path.join(CONTEXTS_PATH, context);
29
+ : path.join(APP_PATH, context, 'layers');
30
30
  }
31
31
 
32
32
  export async function getAvailableFiles(dir, pattern = '.ts') {
@@ -29,7 +29,7 @@ export async function updateIndexTs(dir, filePattern = '.ts', ignore = ['index.t
29
29
  }
30
30
 
31
31
  export async function updateCoreIndex() {
32
- const corePath = path.join(process.cwd(), 'src/app/core');
32
+ const corePath = path.join(process.cwd(), 'src/core');
33
33
  try {
34
34
  const dirs = await fs.readdir(corePath, { withFileTypes: true });
35
35
  const validDirs = [];