@azure-net/cli 2.3.62 → 4.0.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.
Files changed (91) hide show
  1. package/.prettierrc +7 -0
  2. package/bin/azure-net.js +247 -157
  3. package/bin/azure-net.ts +253 -0
  4. package/eslint.config.js +19 -0
  5. package/package.json +12 -5
  6. package/src/commands/generate/generateCrudBase.js +95 -114
  7. package/src/commands/generate/generateCrudPresenter.js +135 -142
  8. package/src/commands/generate/generateModule.js +21 -21
  9. package/src/commands/generate/generateModuleBase.js +92 -114
  10. package/src/commands/generate/generateModulePresenter.js +73 -80
  11. package/src/commands/generate/generatePresenter.js +38 -44
  12. package/src/commands/generate/generateRepository.js +41 -47
  13. package/src/commands/generate/generateSchema.js +74 -70
  14. package/src/commands/generate/generateService.js +32 -37
  15. package/src/commands/generate/index.js +0 -5
  16. package/src/generate/layers/generateRepository.js +124 -0
  17. package/src/generate/layers/generateRepositoryMethod.js +102 -0
  18. package/src/generate/layers/generateUseCases.js +50 -0
  19. package/src/generate/layers/repositoryShared.js +569 -0
  20. package/src/generate/module/generateDomain.js +146 -0
  21. package/src/generate/module/generateDomain.ts +147 -0
  22. package/src/generate/module/generateModule.js +84 -0
  23. package/src/generate/module/generateModule.ts +84 -0
  24. package/src/generate/module/generatePresenter.js +419 -0
  25. package/src/generate/module/generatePresenter.ts +442 -0
  26. package/src/generate/module/generateRepository.js +144 -0
  27. package/src/generate/module/generateRepository.ts +158 -0
  28. package/src/generate/module/generateSchemaFromType.js +320 -0
  29. package/src/generate/module/generateSchemaFromType.ts +325 -0
  30. package/src/generate/module/generateTypesJson.js +252 -0
  31. package/src/generate/module/generateTypesJson.ts +259 -0
  32. package/src/generate/module/generateUseCases.js +67 -0
  33. package/src/generate/module/generateUseCases.ts +67 -0
  34. package/src/generate/module/repositoryModuleShared.js +598 -0
  35. package/src/generate/ui/generateComponent.js +98 -0
  36. package/src/generate/ui/generateComponent.ts +100 -0
  37. package/src/generate/ui/generateDesignComponent.js +71 -0
  38. package/src/generate/ui/generateDesignComponent.ts +71 -0
  39. package/src/generate/ui/generateWidget.js +71 -0
  40. package/src/generate/ui/generateWidget.ts +71 -0
  41. package/src/init/initAliases.js +159 -0
  42. package/src/init/initAliases.ts +167 -0
  43. package/src/init/initEdges.js +74 -0
  44. package/src/init/initEdges.ts +74 -0
  45. package/src/init/initStructure.js +122 -0
  46. package/src/init/initStructure.ts +124 -0
  47. package/src/install/installFresh.js +101 -0
  48. package/src/install/installFresh.ts +101 -0
  49. package/src/plugins/addLint.js +257 -0
  50. package/src/plugins/addLint.ts +274 -0
  51. package/src/plugins/index.js +1 -0
  52. package/src/plugins/index.ts +1 -0
  53. package/src/scaffolds/createCoreMiddleware.js +27 -0
  54. package/src/scaffolds/createCoreMiddleware.ts +27 -0
  55. package/src/scaffolds/createCoreSchema.js +141 -0
  56. package/src/scaffolds/createCoreSchema.ts +142 -0
  57. package/src/scaffolds/createDatasource.js +173 -0
  58. package/src/scaffolds/createDatasource.ts +175 -0
  59. package/src/scaffolds/createDatasourceProvider.js +164 -0
  60. package/src/scaffolds/createDatasourceProvider.ts +175 -0
  61. package/src/scaffolds/createMiddleware.js +105 -0
  62. package/src/scaffolds/createMiddleware.ts +105 -0
  63. package/src/scaffolds/createPresenterFactory.js +112 -0
  64. package/src/scaffolds/createPresenterFactory.ts +114 -0
  65. package/src/scaffolds/createResponse.js +64 -0
  66. package/src/scaffolds/createResponse.ts +64 -0
  67. package/src/scaffolds/createSchemaRule.js +40 -0
  68. package/src/scaffolds/createSchemaRule.ts +42 -0
  69. package/src/scaffolds/createTranslationManager.js +78 -0
  70. package/src/scaffolds/createTranslationManager.ts +78 -0
  71. package/src/scaffolds/index.js +9 -0
  72. package/src/scaffolds/index.ts +9 -0
  73. package/src/utils/contextUtils.js +56 -49
  74. package/src/utils/fileUtils.js +72 -84
  75. package/src/utils/loadConfig.js +57 -13
  76. package/tsconfig.json +19 -0
  77. package/src/commands/generate/generateComponent.js +0 -53
  78. package/src/commands/generate/generateDatasource.js +0 -84
  79. package/src/commands/generate/generateDesignComponent.js +0 -53
  80. package/src/commands/generate/generateResponse.js +0 -41
  81. package/src/commands/generate/generateWidget.js +0 -53
  82. package/src/commands/init/index.js +0 -9
  83. package/src/commands/init/initAliases.js +0 -52
  84. package/src/commands/init/initEdges.js +0 -42
  85. package/src/commands/init/initLint.js +0 -138
  86. package/src/commands/init/initMiddleware.js +0 -21
  87. package/src/commands/init/initPresenter.js +0 -25
  88. package/src/commands/init/initSchema.js +0 -22
  89. package/src/commands/init/initStructure.js +0 -140
  90. package/src/commands/init/initTranslations.js +0 -59
  91. package/src/commands/init/migrateStructure.js +0 -144
@@ -2,106 +2,94 @@ import fs from 'fs/promises';
2
2
  import path from 'path';
3
3
 
4
4
  export async function writeIfNotExists(filepath, content) {
5
- try {
6
- await fs.access(filepath);
7
- console.log(`āš ļø Skip existing: ${filepath}`);
8
- return false;
9
- } catch {
10
- await fs.mkdir(path.dirname(filepath), { recursive: true });
11
- await fs.writeFile(filepath, content, 'utf-8');
12
- console.log(`āœ… Created: ${filepath}`);
13
- return true;
14
- }
5
+ try {
6
+ await fs.access(filepath);
7
+ console.log(`āš ļø Skip existing: ${filepath}`);
8
+ return false;
9
+ } catch {
10
+ await fs.mkdir(path.dirname(filepath), { recursive: true });
11
+ await fs.writeFile(filepath, content, 'utf-8');
12
+ console.log(`āœ… Created: ${filepath}`);
13
+ return true;
14
+ }
15
15
  }
16
16
 
17
17
  export async function updateIndexTs(dir, filePattern = '.ts', ignore = ['index.ts']) {
18
- try {
19
- const files = (await fs.readdir(dir)).filter(f =>
20
- f.endsWith(filePattern) && !ignore.includes(f)
21
- );
22
- const content = files
23
- .map(f => `export * from './${f.replace('.ts', '')}';`)
24
- .join('\n') + '\n';
25
- await fs.writeFile(path.join(dir, 'index.ts'), content, 'utf-8');
26
- } catch (error) {
27
- // Directory doesn't exist yet
28
- }
18
+ try {
19
+ const files = (await fs.readdir(dir)).filter((f) => f.endsWith(filePattern) && !ignore.includes(f));
20
+ const content = files.map((f) => `export * from './${f.replace('.ts', '')}';`).join('\n') + '\n';
21
+ await fs.writeFile(path.join(dir, 'index.ts'), content, 'utf-8');
22
+ } catch (error) {
23
+ // Directory doesn't exist yet
24
+ }
29
25
  }
30
26
 
31
27
  export async function updateCoreIndex() {
32
- const corePath = path.join(process.cwd(), 'src/core');
33
- try {
34
- const dirs = await fs.readdir(corePath, { withFileTypes: true });
35
- const validDirs = [];
28
+ const corePath = path.join(process.cwd(), 'src/core');
29
+ try {
30
+ const dirs = await fs.readdir(corePath, { withFileTypes: true });
31
+ const validDirs = [];
36
32
 
37
- for (const dir of dirs) {
38
- if (dir.isDirectory()) {
39
- // Check if directory has any files
40
- const dirPath = path.join(corePath, dir.name);
41
- const files = await fs.readdir(dirPath);
42
- if (files.length > 0) {
43
- validDirs.push(dir.name);
44
- }
45
- }
46
- }
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
+ }
47
43
 
48
- if (validDirs.length > 0) {
49
- const content = validDirs
50
- .map(d => `export * from './${d}';`)
51
- .join('\n') + '\n';
52
- await fs.writeFile(path.join(corePath, 'index.ts'), content, 'utf-8');
53
- }
54
- } catch (error) {
55
- // Core directory doesn't exist
56
- }
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
+ }
57
51
  }
58
52
 
59
53
  export async function ensureIndexExports(layerPath) {
60
- try {
61
- const subdirs = await fs.readdir(layerPath, { withFileTypes: true });
62
- const exportLines = subdirs
63
- .filter(d => d.isDirectory())
64
- .map(d => `export * from './${d.name}';`);
54
+ try {
55
+ const subdirs = await fs.readdir(layerPath, { withFileTypes: true });
56
+ const exportLines = subdirs.filter((d) => d.isDirectory()).map((d) => `export * from './${d.name}';`);
65
57
 
66
- if (exportLines.length > 0) {
67
- await fs.writeFile(
68
- path.join(layerPath, 'index.ts'),
69
- exportLines.join('\n') + '\n',
70
- 'utf-8'
71
- );
72
- }
73
- } catch (error) {
74
- // Directory doesn't exist
75
- }
58
+ if (exportLines.length > 0) {
59
+ await fs.writeFile(path.join(layerPath, 'index.ts'), exportLines.join('\n') + '\n', 'utf-8');
60
+ }
61
+ } catch (error) {
62
+ // Directory doesn't exist
63
+ }
76
64
  }
77
65
 
78
66
  export async function injectIntoFile(filepath, searchPattern, newContent, position = 'after') {
79
- try {
80
- let content = await fs.readFile(filepath, 'utf-8');
81
- const index = content.indexOf(searchPattern);
67
+ try {
68
+ let content = await fs.readFile(filepath, 'utf-8');
69
+ const index = content.indexOf(searchPattern);
82
70
 
83
- if (index === -1) {
84
- console.warn(`Pattern not found in ${filepath}`);
85
- return false;
86
- }
71
+ if (index === -1) {
72
+ console.warn(`Pattern not found in ${filepath}`);
73
+ return false;
74
+ }
87
75
 
88
- if (content.includes(newContent.trim())) {
89
- console.log(`Content already exists in ${filepath}`);
90
- return false;
91
- }
76
+ if (content.includes(newContent.trim())) {
77
+ console.log(`Content already exists in ${filepath}`);
78
+ return false;
79
+ }
92
80
 
93
- if (position === 'after') {
94
- const insertIndex = index + searchPattern.length;
95
- content = content.slice(0, insertIndex) + '\n' + newContent + content.slice(insertIndex);
96
- } else {
97
- content = content.slice(0, index) + newContent + '\n' + content.slice(index);
98
- }
81
+ if (position === 'after') {
82
+ const insertIndex = index + searchPattern.length;
83
+ content = content.slice(0, insertIndex) + '\n' + newContent + content.slice(insertIndex);
84
+ } else {
85
+ content = content.slice(0, index) + newContent + '\n' + content.slice(index);
86
+ }
99
87
 
100
- await fs.writeFile(filepath, content, 'utf-8');
101
- console.log(`āœ… Updated: ${filepath}`);
102
- return true;
103
- } catch (error) {
104
- console.error(`Failed to update ${filepath}:`, error.message);
105
- return false;
106
- }
107
- }
88
+ await fs.writeFile(filepath, content, 'utf-8');
89
+ console.log(`āœ… Updated: ${filepath}`);
90
+ return true;
91
+ } catch (error) {
92
+ console.error(`Failed to update ${filepath}:`, error.message);
93
+ return false;
94
+ }
95
+ }
@@ -1,15 +1,59 @@
1
- import path from 'path';
2
- import { pathToFileURL } from 'url';
1
+ import fs from 'node:fs/promises';
2
+ import fsSync from 'node:fs';
3
+ import path from 'node:path';
4
+
5
+ const DEFAULT_CONFIG = {
6
+ contexts: [],
7
+ defaultContext: 'web',
8
+ coreAlias: '$core'
9
+ };
10
+
11
+ function toObjectFromDefaultExport(content) {
12
+ const source = String(content ?? '').trim();
13
+ if (!source.length) return {};
14
+
15
+ const replacedExport = source.replace(/^\s*export\s+default\s+/m, 'return ');
16
+ if (replacedExport === source) return {};
17
+
18
+ const withSemicolon = /;\s*$/.test(replacedExport) ? replacedExport : `${replacedExport};`;
19
+
20
+ try {
21
+ // eslint-disable-next-line no-new-func
22
+ return new Function(withSemicolon)() ?? {};
23
+ } catch {
24
+ return {};
25
+ }
26
+ }
27
+
28
+ export function resolveConfigFile(cwd = process.cwd()) {
29
+ const tsPath = path.join(cwd, 'azure-net.config.ts');
30
+ const jsPath = path.join(cwd, 'azure-net.config.js');
31
+
32
+ if (fsSync.existsSync(tsPath)) {
33
+ return { exists: true, filepath: tsPath, type: 'ts' };
34
+ }
35
+ if (fsSync.existsSync(jsPath)) {
36
+ return { exists: true, filepath: jsPath, type: 'js' };
37
+ }
38
+
39
+ return { exists: false, filepath: tsPath, type: 'ts' };
40
+ }
3
41
 
4
42
  export async function loadUserConfig() {
5
- try {
6
- const configPath = path.resolve(process.cwd(), 'azure-net.config.js');
7
- const userConfig = await import(pathToFileURL(configPath));
8
- return userConfig.default || {};
9
- } catch {
10
- return {
11
- contexts: ['web'],
12
- defaultContext: 'web'
13
- };
14
- }
15
- }
43
+ const { exists, filepath } = resolveConfigFile();
44
+ if (!exists) {
45
+ return { ...DEFAULT_CONFIG };
46
+ }
47
+
48
+ try {
49
+ const content = await fs.readFile(filepath, 'utf-8');
50
+ const parsed = toObjectFromDefaultExport(content);
51
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
52
+ return { ...DEFAULT_CONFIG };
53
+ }
54
+
55
+ return { ...DEFAULT_CONFIG, ...parsed };
56
+ } catch {
57
+ return { ...DEFAULT_CONFIG };
58
+ }
59
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "rootDir": ".",
7
+ "outDir": "dist",
8
+ "allowJs": true,
9
+ "checkJs": false,
10
+ "declaration": true,
11
+ "sourceMap": true,
12
+ "strict": true,
13
+ "noUncheckedIndexedAccess": true,
14
+ "esModuleInterop": true,
15
+ "skipLibCheck": true
16
+ },
17
+ "include": ["bin/**/*.ts", "src/**/*"],
18
+ "exclude": ["dist", "node_modules"]
19
+ }
@@ -1,53 +0,0 @@
1
- import prompts from 'prompts';
2
- import path from 'path';
3
- import { selectContext } from '../../utils/contextUtils.js';
4
- import { writeIfNotExists } from '../../utils/fileUtils.js';
5
-
6
- const componentTemplate = `<script lang="ts">
7
- \timport './style.scss';
8
- </script>
9
-
10
- {{componentName}}
11
- `;
12
-
13
- const styleTemplate = `// Add your styles here
14
- `;
15
-
16
- export default async function generateComponent() {
17
- const context = await selectContext('Select context for component:');
18
-
19
- const { componentPath } = await prompts({
20
- type: 'text',
21
- name: 'componentPath',
22
- message: 'Component path (e.g. reviews/modals/ReviewModal):',
23
- validate: value => value.length > 0 ? true : 'Path cannot be empty'
24
- });
25
-
26
- // Parse the path
27
- const normalizedPath = componentPath.replace(/\\/g, '/');
28
- const pathParts = normalizedPath.split('/');
29
- const componentName = pathParts[pathParts.length - 1];
30
-
31
- // Build the full path: src/app/{context}/ui/components/{path}
32
- const contextUiPath = path.join(process.cwd(), 'src/app', context, 'ui/components');
33
- const fullComponentPath = path.join(contextUiPath, normalizedPath);
34
-
35
- console.log(`\nšŸš€ Generating component: ${componentName}...\n`);
36
-
37
- // Create Component.svelte
38
- await writeIfNotExists(
39
- path.join(fullComponentPath, 'Component.svelte'),
40
- componentTemplate.replace(/{{componentName}}/g, componentName)
41
- );
42
-
43
- // Create style.scss
44
- await writeIfNotExists(
45
- path.join(fullComponentPath, 'style.scss'),
46
- styleTemplate
47
- );
48
-
49
- console.log(`āœ… Component created at: ${fullComponentPath}`);
50
- console.log(`\nšŸ’” Files created:`);
51
- console.log(` - Component.svelte`);
52
- console.log(` - style.scss`);
53
- }
@@ -1,84 +0,0 @@
1
- import prompts from 'prompts';
2
- import path from 'path';
3
- import { selectContext, getContextPath, toPascalCase, getAvailableFiles } from '../../utils/contextUtils.js';
4
- import { writeIfNotExists, updateIndexTs, updateCoreIndex } from '../../utils/fileUtils.js';
5
-
6
- const datasourceWithResponseTemplate = `import { BaseHttpDatasource, type CreateRequestCallbackType } from '@azure-net/kit/infra';
7
- import { {{responseClass}} } from '{{responseImport}}';
8
-
9
- export class {{name}}Datasource extends BaseHttpDatasource {
10
- \tasync createRequest<T>(callback: CreateRequestCallbackType<T>) {
11
- \t\treturn new {{responseClass}}<T>(await this.createRawRequest<T>(callback));
12
- \t}
13
- }`;
14
-
15
- export default async function generateDatasource() {
16
- const context = await selectContext('Select context for datasource (or core):');
17
-
18
- const { name } = await prompts({
19
- type: 'text',
20
- name: 'name',
21
- message: 'Datasource name (without "Datasource" suffix):'
22
- });
23
-
24
- const pascalName = toPascalCase(name);
25
- const contextPath = context === 'core'
26
- ? path.join(process.cwd(), 'src/core')
27
- : getContextPath(context);
28
-
29
- // Get available responses
30
- const coreResponses = await getAvailableFiles(
31
- path.join(process.cwd(), 'src/core/responses')
32
- );
33
-
34
- const contextResponses = context !== 'core'
35
- ? await getAvailableFiles(path.join(contextPath, 'infrastructure/responses'))
36
- : [];
37
-
38
- const allResponses = [
39
- ...coreResponses.map(r => ({
40
- title: `${r} (core)`,
41
- value: { name: r, from: 'core' }
42
- })),
43
- ...contextResponses.map(r => ({
44
- title: `${r} (${context})`,
45
- value: { name: r, from: context }
46
- }))
47
- ];
48
-
49
- if (allResponses.length === 0) {
50
- console.error('āŒ No responses available. Create a response first with make:response');
51
- return;
52
- }
53
-
54
- const { response } = await prompts({
55
- type: 'select',
56
- name: 'response',
57
- message: 'Select response for datasource:',
58
- choices: allResponses
59
- });
60
-
61
- const datasourcePath = context === 'core'
62
- ? path.join(contextPath, 'datasources')
63
- : path.join(contextPath, 'infrastructure/http/datasources');
64
-
65
- const responseImport = response.from === 'core'
66
- ? context === 'core' ? '../responses' : '$core/responses'
67
- : `\$${context}/infrastructure/responses`;
68
-
69
- const content = datasourceWithResponseTemplate
70
- .replace(/{{name}}/g, pascalName)
71
- .replace(/{{responseClass}}/g, response.name)
72
- .replace(/{{responseImport}}/g, responseImport);
73
-
74
- const filePath = path.join(datasourcePath, `${pascalName}Datasource.ts`);
75
- await writeIfNotExists(filePath, content);
76
- await updateIndexTs(datasourcePath);
77
-
78
- // Update core index if needed
79
- if (context === 'core') {
80
- await updateCoreIndex();
81
- }
82
-
83
- console.log(`āœ… Datasource created at ${filePath}`);
84
- }
@@ -1,53 +0,0 @@
1
- import prompts from 'prompts';
2
- import path from 'path';
3
- import { selectContext } from '../../utils/contextUtils.js';
4
- import { writeIfNotExists } from '../../utils/fileUtils.js';
5
-
6
- const designComponentTemplate = `<script lang="ts">
7
- \timport './style.scss';
8
- </script>
9
-
10
- {{componentName}}
11
- `;
12
-
13
- const styleTemplate = `// Add your styles here
14
- `;
15
-
16
- export default async function generateDesignComponent() {
17
- const context = await selectContext('Select context for design component:');
18
-
19
- const { componentPath } = await prompts({
20
- type: 'text',
21
- name: 'componentPath',
22
- message: 'Design component path (e.g. Button/Themes/PrimaryButton):',
23
- validate: value => value.length > 0 ? true : 'Path cannot be empty'
24
- });
25
-
26
- // Parse the path
27
- const normalizedPath = componentPath.replace(/\\/g, '/');
28
- const pathParts = normalizedPath.split('/');
29
- const componentName = pathParts[pathParts.length - 1];
30
-
31
- // Build the full path: src/app/{context}/ui/design/{path}
32
- const contextUiPath = path.join(process.cwd(), 'src/app', context, 'ui/design');
33
- const fullComponentPath = path.join(contextUiPath, normalizedPath);
34
-
35
- console.log(`\nšŸš€ Generating design component: ${componentName}...\n`);
36
-
37
- // Create Component.svelte
38
- await writeIfNotExists(
39
- path.join(fullComponentPath, 'Component.svelte'),
40
- designComponentTemplate.replace(/{{componentName}}/g, componentName)
41
- );
42
-
43
- // Create style.scss
44
- await writeIfNotExists(
45
- path.join(fullComponentPath, 'style.scss'),
46
- styleTemplate
47
- );
48
-
49
- console.log(`āœ… Design component created at: ${fullComponentPath}`);
50
- console.log(`\nšŸ’” Files created:`);
51
- console.log(` - Component.svelte`);
52
- console.log(` - style.scss`);
53
- }
@@ -1,41 +0,0 @@
1
- import prompts from 'prompts';
2
- import path from 'path';
3
- import { selectContext, getContextPath, toPascalCase } from '../../utils/contextUtils.js';
4
- import { writeIfNotExists, updateIndexTs, updateCoreIndex } from '../../utils/fileUtils.js';
5
-
6
- const responseTemplate = `import { ResponseBuilder } from '@azure-net/kit/infra';
7
-
8
- export class {{name}}Response<TData = unknown, TMeta = unknown> extends ResponseBuilder<TData, TMeta, TData> {
9
- }`;
10
-
11
- export default async function generateResponse() {
12
- const context = await selectContext('Select context for response (or core):');
13
-
14
- const { name } = await prompts({
15
- type: 'text',
16
- name: 'name',
17
- message: 'Response name (without "Response" suffix):'
18
- });
19
-
20
- const pascalName = toPascalCase(name);
21
- const contextPath = context === 'core'
22
- ? path.join(process.cwd(), 'src/core')
23
- : getContextPath(context);
24
-
25
- const responsePath = context === 'core'
26
- ? path.join(contextPath, 'responses')
27
- : path.join(contextPath, 'infrastructure/responses');
28
-
29
- const content = responseTemplate.replace(/{{name}}/g, pascalName);
30
- const filePath = path.join(responsePath, `${pascalName}Response.ts`);
31
-
32
- await writeIfNotExists(filePath, content);
33
- await updateIndexTs(responsePath);
34
-
35
- // Update core index if needed
36
- if (context === 'core') {
37
- await updateCoreIndex();
38
- }
39
-
40
- console.log(`āœ… Response created at ${filePath}`);
41
- }
@@ -1,53 +0,0 @@
1
- import prompts from 'prompts';
2
- import path from 'path';
3
- import { selectContext } from '../../utils/contextUtils.js';
4
- import { writeIfNotExists } from '../../utils/fileUtils.js';
5
-
6
- const widgetTemplate = `<script lang="ts">
7
- \timport './style.scss';
8
- </script>
9
-
10
- {{widgetName}}
11
- `;
12
-
13
- const styleTemplate = `// Add your styles here
14
- `;
15
-
16
- export default async function generateWidget() {
17
- const context = await selectContext('Select context for widget:');
18
-
19
- const { widgetPath } = await prompts({
20
- type: 'text',
21
- name: 'widgetPath',
22
- message: 'Widget path (e.g. modals/ConfirmModal):',
23
- validate: value => value.length > 0 ? true : 'Path cannot be empty'
24
- });
25
-
26
- // Parse the path
27
- const normalizedPath = widgetPath.replace(/\\/g, '/');
28
- const pathParts = normalizedPath.split('/');
29
- const widgetName = pathParts[pathParts.length - 1];
30
-
31
- // Build the full path: src/app/{context}/ui/widgets/{path}
32
- const contextUiPath = path.join(process.cwd(), 'src/app', context, 'ui/widgets');
33
- const fullWidgetPath = path.join(contextUiPath, normalizedPath);
34
-
35
- console.log(`\nšŸš€ Generating widget: ${widgetName}...\n`);
36
-
37
- // Create Component.svelte
38
- await writeIfNotExists(
39
- path.join(fullWidgetPath, 'Component.svelte'),
40
- widgetTemplate.replace(/{{widgetName}}/g, widgetName)
41
- );
42
-
43
- // Create style.scss
44
- await writeIfNotExists(
45
- path.join(fullWidgetPath, 'style.scss'),
46
- styleTemplate
47
- );
48
-
49
- console.log(`āœ… Widget created at: ${fullWidgetPath}`);
50
- console.log(`\nšŸ’” Files created:`);
51
- console.log(` - Component.svelte`);
52
- console.log(` - style.scss`);
53
- }
@@ -1,9 +0,0 @@
1
- export { default as initStructure } from './initStructure.js';
2
- export { default as initAliases } from './initAliases.js';
3
- export { default as initMiddleware } from './initMiddleware.js';
4
- export { default as initEdges } from './initEdges.js';
5
- export { default as initTranslations } from './initTranslations.js';
6
- export { default as initSchema } from './initSchema.js';
7
- export { default as initLint } from './initLint.js';
8
- export { default as initPresenter } from './initPresenter.js';
9
- export { default as migrateStructure } from './migrateStructure.js';
@@ -1,52 +0,0 @@
1
- import fs from 'fs/promises';
2
- import path from 'path';
3
- import { loadUserConfig } from '../../utils/loadConfig.js';
4
- import { execSync } from 'child_process';
5
-
6
- const svelteConfigPath = path.resolve('svelte.config.js');
7
-
8
- function generateAliases(config) {
9
- const contexts = config.contexts || ['app'];
10
-
11
- return Object.fromEntries([
12
- ...contexts.flatMap(c => [
13
- [`$${c}`, `./src/app/${c}/layers`],
14
- [`$${c}/ui`, `./src/app/${c}/ui`]
15
- ]),
16
- ['$core', './src/core']
17
- ]);
18
- }
19
-
20
- function serializeObjectLiteral(obj) {
21
- return Object.entries(obj)
22
- .map(([key, value]) => `\t\t\t'${key}': '${value}'`)
23
- .join(',\n');
24
- }
25
-
26
- export default async function initAliases() {
27
- const config = await loadUserConfig();
28
- const newAliases = generateAliases(config);
29
-
30
- let content = await fs.readFile(svelteConfigPath, 'utf-8');
31
-
32
- const aliasRegex = /alias:\s*{([\s\S]*?)}/m;
33
- const aliasMatch = content.match(aliasRegex);
34
-
35
- const newAliasBlock = `alias: {\n${serializeObjectLiteral(newAliases)}\n\t\t}`;
36
-
37
- if (aliasMatch) {
38
- content = content.replace(aliasRegex, newAliasBlock);
39
- } else {
40
- const kitRegex = /kit:\s*{/;
41
- content = content.replace(kitRegex, `kit: {\n\t\t${newAliasBlock},`);
42
- }
43
-
44
- await fs.writeFile(svelteConfigPath, content, 'utf-8');
45
- console.log('āœ… Aliases updated in svelte.config.js');
46
-
47
- try {
48
- execSync('npm run format', { stdio: 'inherit' });
49
- } catch {
50
- console.warn('āš ļø Failed to run format');
51
- }
52
- }
@@ -1,42 +0,0 @@
1
- import { injectIntoFile, writeIfNotExists } from '../../utils/fileUtils.js';
2
- import path from 'path';
3
-
4
- const hooksServerPath = path.join(process.cwd(), 'src/hooks.server.ts');
5
-
6
- const hooksTemplate = `import { dev } from '$app/environment';
7
- import { edgesHandle } from '@azure-net/kit/edges/server';
8
- import { type Handle } from '@sveltejs/kit';
9
-
10
- export const handle: Handle = async ({ event, resolve }) => {
11
- \treturn edgesHandle(
12
- \t\tevent,
13
- \t\tasync ({ edgesEvent, serialize }) => {
14
- \t\t\treturn resolve(edgesEvent, {
15
- \t\t\t\ttransformPageChunk: ({ html }) => serialize(html)
16
- \t\t\t});
17
- \t\t},
18
- \t\tdev
19
- \t);
20
- };`;
21
-
22
- export default async function initEdges() {
23
- const created = await writeIfNotExists(hooksServerPath, hooksTemplate);
24
-
25
- if (!created) {
26
- const importStatement = `import { edgesHandle } from '@azure-net/kit/edges/server';`;
27
- await injectIntoFile(hooksServerPath, 'import {', importStatement, 'before');
28
-
29
- const handleCode = `\treturn edgesHandle(
30
- \t\tevent,
31
- \t\tasync ({ edgesEvent, serialize }) => {`;
32
-
33
- await injectIntoFile(
34
- hooksServerPath,
35
- 'export const handle: Handle = async ({ event, resolve }) => {',
36
- handleCode,
37
- 'after'
38
- );
39
- }
40
-
41
- console.log('āœ… Edges-svelte initialized');
42
- }