@slingr/cli 0.0.3 ā 0.0.4
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/LICENSE.txt +202 -0
- package/README.md +490 -319
- package/bin/dev.cmd +2 -2
- package/bin/dev.js +5 -5
- package/bin/run.cmd +2 -2
- package/bin/run.js +4 -4
- package/bin/slingr +1 -0
- package/dist/commands/build.d.ts +20 -0
- package/dist/commands/build.d.ts.map +1 -0
- package/dist/commands/build.js +206 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/create-app.d.ts +0 -1
- package/dist/commands/create-app.d.ts.map +1 -1
- package/dist/commands/create-app.js +38 -57
- package/dist/commands/create-app.js.map +1 -1
- package/dist/commands/debug.d.ts +28 -0
- package/dist/commands/debug.d.ts.map +1 -0
- package/dist/commands/debug.js +474 -0
- package/dist/commands/debug.js.map +1 -0
- package/dist/commands/ds.d.ts +14 -1
- package/dist/commands/ds.d.ts.map +1 -1
- package/dist/commands/ds.js +450 -121
- package/dist/commands/ds.js.map +1 -1
- package/dist/commands/gql.d.ts +1 -1
- package/dist/commands/gql.d.ts.map +1 -1
- package/dist/commands/gql.js +190 -184
- package/dist/commands/gql.js.map +1 -1
- package/dist/commands/infra/down.d.ts.map +1 -1
- package/dist/commands/infra/down.js +8 -7
- package/dist/commands/infra/down.js.map +1 -1
- package/dist/commands/infra/up.d.ts.map +1 -1
- package/dist/commands/infra/up.js +8 -7
- package/dist/commands/infra/up.js.map +1 -1
- package/dist/commands/infra/update.d.ts +1 -0
- package/dist/commands/infra/update.d.ts.map +1 -1
- package/dist/commands/infra/update.js +33 -69
- package/dist/commands/infra/update.js.map +1 -1
- package/dist/commands/run.d.ts +29 -2
- package/dist/commands/run.d.ts.map +1 -1
- package/dist/commands/run.js +628 -130
- package/dist/commands/run.js.map +1 -1
- package/dist/commands/setup.d.ts +1 -1
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +34 -71
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/sync-metadata.d.ts +15 -0
- package/dist/commands/sync-metadata.d.ts.map +1 -0
- package/dist/commands/sync-metadata.js +225 -0
- package/dist/commands/sync-metadata.js.map +1 -0
- package/dist/commands/users.d.ts +30 -0
- package/dist/commands/users.d.ts.map +1 -0
- package/dist/commands/users.js +472 -0
- package/dist/commands/users.js.map +1 -0
- package/dist/commands/views.d.ts +11 -0
- package/dist/commands/views.d.ts.map +1 -0
- package/dist/commands/views.js +73 -0
- package/dist/commands/views.js.map +1 -0
- package/dist/projectStructure.d.ts +2 -2
- package/dist/projectStructure.d.ts.map +1 -1
- package/dist/projectStructure.js +281 -69
- package/dist/projectStructure.js.map +1 -1
- package/dist/scripts/generate-metadata.d.ts +13 -0
- package/dist/scripts/generate-metadata.d.ts.map +1 -0
- package/dist/scripts/generate-metadata.js +412 -0
- package/dist/scripts/generate-metadata.js.map +1 -0
- package/dist/scripts/generate-metadata.ts +498 -0
- package/dist/scripts/generate-schema.d.ts +1 -1
- package/dist/scripts/generate-schema.js +168 -74
- package/dist/scripts/generate-schema.js.map +1 -1
- package/dist/scripts/generate-schema.ts +258 -143
- package/dist/templates/.env.template +23 -0
- package/dist/templates/.firebaserc.template +5 -0
- package/dist/templates/.github/copilot-instructions.md.template +652 -17
- package/dist/templates/backend/Dockerfile.template +30 -0
- package/dist/templates/config/datasource.ts.template +12 -9
- package/dist/templates/config/jest.config.ts +30 -30
- package/dist/templates/config/jest.setup.ts +1 -1
- package/dist/templates/config/tsconfig.json.template +50 -29
- package/dist/templates/dataSources/mysql.ts.template +16 -13
- package/dist/templates/dataSources/postgres.ts.template +15 -13
- package/dist/templates/dataset-generator-script.ts.template +139 -139
- package/dist/templates/datasets/mysql-default/.slingr-schema.json.template +5 -0
- package/dist/templates/datasets/mysql-default/Address.jsonl.template +3 -3
- package/dist/templates/datasets/mysql-default/App.jsonl.template +4 -4
- package/dist/templates/datasets/mysql-default/Company.jsonl.template +3 -3
- package/dist/templates/datasets/mysql-default/Person.jsonl.template +2 -2
- package/dist/templates/datasets/mysql-default/User.jsonl.template +1 -0
- package/dist/templates/datasets/mysql-default/instructions.md.template +1 -0
- package/dist/templates/datasets/postgres-default/.slingr-schema.json.template +5 -0
- package/dist/templates/datasets/postgres-default/Address.jsonl.template +3 -3
- package/dist/templates/datasets/postgres-default/App.jsonl.template +4 -4
- package/dist/templates/datasets/postgres-default/Company.jsonl.template +3 -3
- package/dist/templates/datasets/postgres-default/Person.jsonl.template +2 -2
- package/dist/templates/datasets/postgres-default/User.jsonl.template +1 -0
- package/dist/templates/datasets/postgres-default/instructions.md.template +1 -0
- package/dist/templates/docker-compose.prod-test.yml.template +32 -0
- package/dist/templates/docker-compose.yml.template +24 -0
- package/dist/templates/docs/app-description.md.template +33 -33
- package/dist/templates/firebase.json.template +68 -0
- package/dist/templates/frontend/.umirc.ts.template +23 -0
- package/dist/templates/frontend/package.json.template +45 -0
- package/dist/templates/frontend/public/config.json +6 -0
- package/dist/templates/frontend/public/logo.svg +6 -0
- package/dist/templates/frontend/src/app.tsx.template +44 -0
- package/dist/templates/frontend/src/global.less.template +117 -0
- package/dist/templates/frontend/src/layouts/MainLayout.tsx.template +75 -0
- package/dist/templates/frontend/src/types/graphql-augmentation.d.ts.template +44 -0
- package/dist/templates/frontend/src/views/customViews/user/UserCreateView.tsx.template +18 -0
- package/dist/templates/frontend/src/views/customViews/user/UserEditView.tsx.template +29 -0
- package/dist/templates/frontend/src/views/customViews/user/UserReadView.tsx.template +24 -0
- package/dist/templates/frontend/src/views/customViews/user/UserTableView.tsx.template +38 -0
- package/dist/templates/frontend/src/views/customViews/welcome.tsx.template +34 -0
- package/dist/templates/frontend/tsconfig.json.template +50 -0
- package/dist/templates/gql/codegen.yml.template +25 -25
- package/dist/templates/gql/index.ts.template +17 -24
- package/dist/templates/gql/operations.graphql.template +30 -30
- package/dist/templates/ops/README.md.template +1045 -0
- package/dist/templates/ops/cloudbuild.yaml.template +161 -0
- package/dist/templates/ops/scripts/_utils.js.template +217 -0
- package/dist/templates/ops/scripts/deploy.js.template +145 -0
- package/dist/templates/ops/scripts/setup-gcp.js.template +330 -0
- package/dist/templates/ops/scripts/setup-secrets.js.template +76 -0
- package/dist/templates/ops/scripts/test-prod-local.js.template +49 -0
- package/dist/templates/package.json.template +50 -38
- package/dist/templates/pnpm-workspace.yaml.template +3 -0
- package/dist/templates/prompt-analysis.md.template +110 -110
- package/dist/templates/prompt-script-generation.md.template +258 -258
- package/dist/templates/src/Address.ts.template +28 -31
- package/dist/templates/src/App.ts.template +17 -61
- package/dist/templates/src/Company.ts.template +41 -47
- package/dist/templates/src/Models.test.ts.template +654 -654
- package/dist/templates/src/Person.test.ts.template +289 -289
- package/dist/templates/src/Person.ts.template +90 -105
- package/dist/templates/src/actions/index.ts.template +11 -11
- package/dist/templates/src/auth/permissions.ts.template +34 -0
- package/dist/templates/src/data/App.ts.template +48 -0
- package/dist/templates/src/data/User.ts.template +35 -0
- package/dist/templates/src/types/gql.d.ts.template +17 -17
- package/dist/templates/vscode/extensions.json +4 -3
- package/dist/templates/vscode/settings.json +17 -11
- package/dist/templates/workspace-package.json.template +21 -0
- package/dist/utils/buildCache.d.ts +12 -0
- package/dist/utils/buildCache.d.ts.map +1 -0
- package/dist/utils/buildCache.js +102 -0
- package/dist/utils/buildCache.js.map +1 -0
- package/dist/utils/checkFramework.d.ts +27 -0
- package/dist/utils/checkFramework.d.ts.map +1 -0
- package/dist/utils/checkFramework.js +104 -0
- package/dist/utils/checkFramework.js.map +1 -0
- package/dist/utils/datasourceParser.d.ts +11 -0
- package/dist/utils/datasourceParser.d.ts.map +1 -1
- package/dist/utils/datasourceParser.js +154 -56
- package/dist/utils/datasourceParser.js.map +1 -1
- package/dist/utils/dockerManager.d.ts +25 -0
- package/dist/utils/dockerManager.d.ts.map +1 -0
- package/dist/utils/dockerManager.js +281 -0
- package/dist/utils/dockerManager.js.map +1 -0
- package/dist/utils/infraFileParser.d.ts +26 -0
- package/dist/utils/infraFileParser.d.ts.map +1 -0
- package/dist/utils/infraFileParser.js +75 -0
- package/dist/utils/infraFileParser.js.map +1 -0
- package/dist/utils/jsonlLoader.d.ts +91 -12
- package/dist/utils/jsonlLoader.d.ts.map +1 -1
- package/dist/utils/jsonlLoader.js +674 -63
- package/dist/utils/jsonlLoader.js.map +1 -1
- package/dist/utils/model-analyzer.d.ts.map +1 -1
- package/dist/utils/model-analyzer.js +67 -13
- package/dist/utils/model-analyzer.js.map +1 -1
- package/dist/utils/userManagement.d.ts +57 -0
- package/dist/utils/userManagement.d.ts.map +1 -0
- package/dist/utils/userManagement.js +288 -0
- package/dist/utils/userManagement.js.map +1 -0
- package/dist/utils/viewsGenerator.d.ts +15 -0
- package/dist/utils/viewsGenerator.d.ts.map +1 -0
- package/dist/utils/viewsGenerator.js +311 -0
- package/dist/utils/viewsGenerator.js.map +1 -0
- package/oclif.manifest.json +445 -20
- package/package.json +29 -26
- package/src/templates/.env.template +23 -0
- package/src/templates/.firebaserc.template +5 -0
- package/src/templates/.github/copilot-instructions.md.template +652 -17
- package/src/templates/backend/Dockerfile.template +30 -0
- package/src/templates/config/datasource.ts.template +12 -9
- package/src/templates/config/jest.config.ts +30 -30
- package/src/templates/config/jest.setup.ts +1 -1
- package/src/templates/config/tsconfig.json.template +50 -29
- package/src/templates/dataSources/mysql.ts.template +16 -13
- package/src/templates/dataSources/postgres.ts.template +15 -13
- package/src/templates/dataset-generator-script.ts.template +139 -139
- package/src/templates/datasets/mysql-default/.slingr-schema.json.template +5 -0
- package/src/templates/datasets/mysql-default/Address.jsonl.template +3 -3
- package/src/templates/datasets/mysql-default/App.jsonl.template +4 -4
- package/src/templates/datasets/mysql-default/Company.jsonl.template +3 -3
- package/src/templates/datasets/mysql-default/Person.jsonl.template +2 -2
- package/src/templates/datasets/mysql-default/User.jsonl.template +1 -0
- package/src/templates/datasets/mysql-default/instructions.md.template +1 -0
- package/src/templates/datasets/postgres-default/.slingr-schema.json.template +5 -0
- package/src/templates/datasets/postgres-default/Address.jsonl.template +3 -3
- package/src/templates/datasets/postgres-default/App.jsonl.template +4 -4
- package/src/templates/datasets/postgres-default/Company.jsonl.template +3 -3
- package/src/templates/datasets/postgres-default/Person.jsonl.template +2 -2
- package/src/templates/datasets/postgres-default/User.jsonl.template +1 -0
- package/src/templates/datasets/postgres-default/instructions.md.template +1 -0
- package/src/templates/docker-compose.prod-test.yml.template +32 -0
- package/src/templates/docker-compose.yml.template +24 -0
- package/src/templates/docs/app-description.md.template +33 -33
- package/src/templates/firebase.json.template +68 -0
- package/src/templates/frontend/.umirc.ts.template +23 -0
- package/src/templates/frontend/package.json.template +45 -0
- package/src/templates/frontend/public/config.json +6 -0
- package/src/templates/frontend/public/logo.svg +6 -0
- package/src/templates/frontend/src/app.tsx.template +44 -0
- package/src/templates/frontend/src/global.less.template +117 -0
- package/src/templates/frontend/src/layouts/MainLayout.tsx.template +75 -0
- package/src/templates/frontend/src/types/graphql-augmentation.d.ts.template +44 -0
- package/src/templates/frontend/src/views/customViews/user/UserCreateView.tsx.template +18 -0
- package/src/templates/frontend/src/views/customViews/user/UserEditView.tsx.template +29 -0
- package/src/templates/frontend/src/views/customViews/user/UserReadView.tsx.template +24 -0
- package/src/templates/frontend/src/views/customViews/user/UserTableView.tsx.template +38 -0
- package/src/templates/frontend/src/views/customViews/welcome.tsx.template +34 -0
- package/src/templates/frontend/tsconfig.json.template +50 -0
- package/src/templates/gql/codegen.yml.template +25 -25
- package/src/templates/gql/index.ts.template +17 -24
- package/src/templates/gql/operations.graphql.template +30 -30
- package/src/templates/ops/README.md.template +1045 -0
- package/src/templates/ops/cloudbuild.yaml.template +161 -0
- package/src/templates/ops/scripts/_utils.js.template +217 -0
- package/src/templates/ops/scripts/deploy.js.template +145 -0
- package/src/templates/ops/scripts/setup-gcp.js.template +330 -0
- package/src/templates/ops/scripts/setup-secrets.js.template +76 -0
- package/src/templates/ops/scripts/test-prod-local.js.template +49 -0
- package/src/templates/package.json.template +50 -38
- package/src/templates/pnpm-workspace.yaml.template +3 -0
- package/src/templates/prompt-analysis.md.template +110 -110
- package/src/templates/prompt-script-generation.md.template +258 -258
- package/src/templates/src/Address.ts.template +28 -31
- package/src/templates/src/App.ts.template +17 -61
- package/src/templates/src/Company.ts.template +41 -47
- package/src/templates/src/Models.test.ts.template +654 -654
- package/src/templates/src/Person.test.ts.template +289 -289
- package/src/templates/src/Person.ts.template +90 -105
- package/src/templates/src/actions/index.ts.template +11 -11
- package/src/templates/src/auth/permissions.ts.template +34 -0
- package/src/templates/src/data/App.ts.template +48 -0
- package/src/templates/src/data/User.ts.template +35 -0
- package/src/templates/src/types/gql.d.ts.template +17 -17
- package/src/templates/vscode/extensions.json +4 -3
- package/src/templates/vscode/settings.json +17 -11
- package/src/templates/workspace-package.json.template +21 -0
- package/dist/templates/src/index.ts +0 -66
- package/src/templates/src/index.ts +0 -66
|
@@ -1,143 +1,258 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Script to generate GraphQL schema from slingr-
|
|
4
|
-
* This script is executed in the context of a user's Slingr application
|
|
5
|
-
*
|
|
6
|
-
* By default, the script generates the schema and exits immediately.
|
|
7
|
-
* Use --no-exit flag to start Apollo Server for schema exploration.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import fs from 'fs';
|
|
11
|
-
import path from 'path';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Script to generate GraphQL schema from @slingr/framework-backend
|
|
4
|
+
* This script is executed in the context of a user's Slingr application
|
|
5
|
+
*
|
|
6
|
+
* By default, the script generates the schema and exits immediately.
|
|
7
|
+
* Use --no-exit flag to start Apollo Server for schema exploration.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import fs from 'fs';
|
|
11
|
+
import path from 'path';
|
|
12
|
+
// Load generated view type registries if they exist so declare global augmentations are active
|
|
13
|
+
// during schema compilation. The file may not exist yet on the first run.
|
|
14
|
+
const generatedViewsPath = path.join(process.cwd(), 'generated', 'views');
|
|
15
|
+
if (fs.existsSync(generatedViewsPath + '.ts') || fs.existsSync(generatedViewsPath + '.js')) {
|
|
16
|
+
require(generatedViewsPath);
|
|
17
|
+
}
|
|
18
|
+
// @ts-ignore - temp-generate-metadata.ts is copied at runtime by the CLI
|
|
19
|
+
import { generateMetadataFile } from './temp-generate-metadata';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Load data sources from src/dataSources directory.
|
|
23
|
+
* Loads directly from TypeScript source files using ts-node.
|
|
24
|
+
*/
|
|
25
|
+
async function loadDataSources() {
|
|
26
|
+
const dataSourcesPath = path.join(process.cwd(), 'src', 'dataSources');
|
|
27
|
+
|
|
28
|
+
if (!fs.existsSync(dataSourcesPath)) {
|
|
29
|
+
console.log('ā¹ļø No dataSources directory found. Schema will be generated without CRUD operations.');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
console.log('š¦ Loading data sources from TypeScript source files...');
|
|
34
|
+
|
|
35
|
+
// Get all data source files
|
|
36
|
+
const files = fs.readdirSync(dataSourcesPath).filter(file => file.endsWith('.ts') && !file.endsWith('.d.ts'));
|
|
37
|
+
|
|
38
|
+
if (files.length === 0) {
|
|
39
|
+
console.log('ā¹ļø No data source files found.');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Import each data source file using CommonJS require
|
|
44
|
+
for (const file of files) {
|
|
45
|
+
const filePath = path.join(dataSourcesPath, file);
|
|
46
|
+
require(filePath);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
console.log(`ā
Loaded ${files.length} data source(s)`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Recursively collect all files matching an extension from a directory.
|
|
54
|
+
*/
|
|
55
|
+
function collectFilesRecursively(dir: string, extension: string): string[] {
|
|
56
|
+
const results: string[] = [];
|
|
57
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
58
|
+
for (const entry of entries) {
|
|
59
|
+
const fullPath = path.join(dir, entry.name);
|
|
60
|
+
if (entry.isDirectory()) {
|
|
61
|
+
results.push(...collectFilesRecursively(fullPath, extension));
|
|
62
|
+
} else if (
|
|
63
|
+
entry.isFile() &&
|
|
64
|
+
entry.name.endsWith(extension) &&
|
|
65
|
+
!entry.name.endsWith('.d.ts') &&
|
|
66
|
+
!/\.test\.|\.spec\./i.test(entry.name)
|
|
67
|
+
) {
|
|
68
|
+
results.push(fullPath);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return results;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Load model files from src/data directory (including subdirectories).
|
|
76
|
+
* Loads directly from TypeScript source files using tsx to avoid double decorator execution.
|
|
77
|
+
* @returns Array of loaded model classes
|
|
78
|
+
*/
|
|
79
|
+
async function loadModels(): Promise<Array<new (...args: any[]) => any>> {
|
|
80
|
+
const loadedModels: Array<new (...args: any[]) => any> = [];
|
|
81
|
+
|
|
82
|
+
const modelsPath = path.join(process.cwd(), 'src', 'data');
|
|
83
|
+
|
|
84
|
+
if (!fs.existsSync(modelsPath)) {
|
|
85
|
+
console.log('ā¹ļø No data directory found. Schema will be generated without model CRUD operations.');
|
|
86
|
+
return loadedModels;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
console.log('š¦ Loading models from TypeScript source files...');
|
|
90
|
+
|
|
91
|
+
// Recursively get all model files, excluding tests/specs and declaration files
|
|
92
|
+
const files = collectFilesRecursively(modelsPath, '.ts');
|
|
93
|
+
|
|
94
|
+
if (files.length === 0) {
|
|
95
|
+
console.log('ā¹ļø No model files found.');
|
|
96
|
+
return loadedModels;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Import each model file (which will trigger @DataModel decorators and register CRUD operations)
|
|
100
|
+
for (const filePath of files) {
|
|
101
|
+
const moduleExports = require(filePath);
|
|
102
|
+
|
|
103
|
+
// Extract model classes from the module exports
|
|
104
|
+
for (const exportName of Object.keys(moduleExports)) {
|
|
105
|
+
const exported = moduleExports[exportName];
|
|
106
|
+
if (typeof exported === 'function' && exported.prototype) {
|
|
107
|
+
loadedModels.push(exported as new (...args: any[]) => any);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
console.log(`ā
Loaded ${files.length} model(s)`);
|
|
113
|
+
|
|
114
|
+
return loadedModels;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async function generateSchema() {
|
|
118
|
+
try {
|
|
119
|
+
console.log('š Generating GraphQL schema from your Slingr application...');
|
|
120
|
+
|
|
121
|
+
// Dynamic import to avoid compile-time dependency on @slingr/framework-backend
|
|
122
|
+
// This script runs in the user's project context where @slingr/framework-backend is installed
|
|
123
|
+
// @ts-ignore
|
|
124
|
+
const slingrFramework = await import('@slingr/framework-backend');
|
|
125
|
+
const { generateActionsIndex, getGraphQLSchema, printSchema, rebuildGraphQLSchema, startGraphQLServer } =
|
|
126
|
+
slingrFramework;
|
|
127
|
+
|
|
128
|
+
// Import framework functions first to get access to rebuildGraphQLSchema
|
|
129
|
+
// We must use printSchema from the same GraphQL instance as the framework
|
|
130
|
+
// to avoid "Cannot use GraphQLType from another module or realm" errors
|
|
131
|
+
|
|
132
|
+
// Destructure directly from the imported module (works for both ESM and CJS)
|
|
133
|
+
// The named exports are available directly on the module namespace object
|
|
134
|
+
|
|
135
|
+
// Rebuild the schema FIRST to clear any previous state before loading anything
|
|
136
|
+
// This ensures we start with a clean slate
|
|
137
|
+
rebuildGraphQLSchema();
|
|
138
|
+
|
|
139
|
+
// IMPORTANT: Load actions AFTER rebuilding the schema
|
|
140
|
+
// When actions are imported, they will register themselves in the clean schema builder
|
|
141
|
+
|
|
142
|
+
// Check if actions directory exists
|
|
143
|
+
const actionsDir = path.join(process.cwd(), 'src', 'actions');
|
|
144
|
+
let hasActions = false;
|
|
145
|
+
|
|
146
|
+
if (fs.existsSync(actionsDir)) {
|
|
147
|
+
// Generate the actions index at generated/actions/index.ts
|
|
148
|
+
console.log('š¦ Generating actions index...');
|
|
149
|
+
|
|
150
|
+
// Generate the actions index
|
|
151
|
+
await generateActionsIndex(process.cwd(), 'src/actions');
|
|
152
|
+
|
|
153
|
+
// Check if the generated index exists
|
|
154
|
+
const generatedActionsIndexPath = path.resolve(process.cwd(), 'generated', 'actions', 'index.ts');
|
|
155
|
+
if (fs.existsSync(generatedActionsIndexPath)) {
|
|
156
|
+
hasActions = true;
|
|
157
|
+
console.log('š¦ Loading actions from generated TypeScript index...');
|
|
158
|
+
|
|
159
|
+
require(generatedActionsIndexPath);
|
|
160
|
+
} else {
|
|
161
|
+
console.log('ā ļø Failed to generate actions index.');
|
|
162
|
+
hasActions = false;
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
console.log('ā¹ļø No actions directory found. Schema will be generated with framework base types only.');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (!hasActions) {
|
|
169
|
+
console.log('š¦ No actions to load. Generating schema with framework base types...');
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Load data sources and models (which will register CRUD operations)
|
|
173
|
+
|
|
174
|
+
// Import framework functions and printSchema from slingr-framework
|
|
175
|
+
// We must use printSchema from the same GraphQL instance as the framework
|
|
176
|
+
// to avoid "Cannot use GraphQLType from another module or realm" errors
|
|
177
|
+
const { registerAllUiGraphQL, registerCrudOperations, generateCrudActions } = slingrFramework;
|
|
178
|
+
|
|
179
|
+
// Load data sources and models
|
|
180
|
+
// Actions will be generated but NOT registered in GraphQL during model import
|
|
181
|
+
await loadDataSources();
|
|
182
|
+
const loadedModels = await loadModels();
|
|
183
|
+
console.log('š¦ Registering UI operations for all UI-enabled models...');
|
|
184
|
+
await registerAllUiGraphQL();
|
|
185
|
+
console.log('ā
UI operations registered');
|
|
186
|
+
|
|
187
|
+
// Register CRUD GraphQL operations for models with crud configuration
|
|
188
|
+
if (loadedModels.length > 0) {
|
|
189
|
+
for (const modelClass of loadedModels) {
|
|
190
|
+
const modelOptions = (Reflect as any).getMetadata('model:options', modelClass);
|
|
191
|
+
const crudOptions = modelOptions?.crud;
|
|
192
|
+
|
|
193
|
+
if (crudOptions && crudOptions.api === 'gql' && crudOptions.generate) {
|
|
194
|
+
const dataSource = (Reflect as any).getMetadata('model:dataSource', modelClass);
|
|
195
|
+
if (dataSource) {
|
|
196
|
+
// First generate CRUD actions (normally done by decorator)
|
|
197
|
+
generateCrudActions(modelClass, dataSource, crudOptions);
|
|
198
|
+
// Then register GraphQL operations
|
|
199
|
+
registerCrudOperations(modelClass);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Get schema (which will build it with all registered operations)
|
|
206
|
+
const schema = getGraphQLSchema();
|
|
207
|
+
if (!schema) {
|
|
208
|
+
throw new Error('Could not generate GraphQL schema. Please ensure @slingr/framework-backend is properly installed.');
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const schemaString = printSchema(schema);
|
|
212
|
+
|
|
213
|
+
// Ensure generated/gql directory exists
|
|
214
|
+
const generatedDir = path.join(process.cwd(), 'generated', 'gql');
|
|
215
|
+
if (!fs.existsSync(generatedDir)) {
|
|
216
|
+
fs.mkdirSync(generatedDir, { recursive: true });
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Write schema to file
|
|
220
|
+
const schemaFilePath = path.join(generatedDir, 'schema.graphql');
|
|
221
|
+
try {
|
|
222
|
+
fs.writeFileSync(schemaFilePath, schemaString, 'utf8');
|
|
223
|
+
} catch (writeError: unknown) {
|
|
224
|
+
const msg = writeError instanceof Error ? writeError.message : String(writeError);
|
|
225
|
+
console.error(`ā Failed to write schema file at ${schemaFilePath}: ${msg}`);
|
|
226
|
+
throw writeError instanceof Error ? writeError : new Error(msg);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Verify file creation and log size
|
|
230
|
+
try {
|
|
231
|
+
const stats = fs.statSync(schemaFilePath);
|
|
232
|
+
console.log(`ā
GraphQL schema written: ${schemaFilePath} (${stats.size} bytes)`);
|
|
233
|
+
} catch (statError: unknown) {
|
|
234
|
+
const msg = statError instanceof Error ? statError.message : String(statError);
|
|
235
|
+
console.warn(`ā ļø Schema file write succeeded but verification failed: ${msg}`);
|
|
236
|
+
console.log(`ā¹ļø Please check that the path exists and you have write permissions: ${schemaFilePath}`);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Show a preview of the generated schema
|
|
240
|
+
const lines = schemaString.split('\n');
|
|
241
|
+
if (lines.length > 0) {
|
|
242
|
+
console.log('\nš Schema preview:');
|
|
243
|
+
console.log(lines.slice(0, Math.min(15, lines.length)).join('\n'));
|
|
244
|
+
if (lines.length > 15) {
|
|
245
|
+
console.log(`... (${lines.length - 15} more lines)`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
await generateMetadataFile();
|
|
249
|
+
console.log('\nā
Schema generation completed. Script will terminate now.');
|
|
250
|
+
process.exit(0);
|
|
251
|
+
} catch (error: any) {
|
|
252
|
+
console.error(`Failed to generate schema: ${error.message}`);
|
|
253
|
+
console.error(error);
|
|
254
|
+
process.exit(1);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
generateSchema();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Slingr Application Configuration
|
|
2
|
+
# This file contains environment-specific configuration for your Slingr app.
|
|
3
|
+
# Copy this file to .env and customize the values as needed.
|
|
4
|
+
|
|
5
|
+
# GraphQL Server Configuration
|
|
6
|
+
GRAPHQL_HOST=localhost
|
|
7
|
+
GRAPHQL_PORT=3000
|
|
8
|
+
GRAPHQL_ENABLE_EXPLORER=true
|
|
9
|
+
|
|
10
|
+
# Note: These values can be overridden by:
|
|
11
|
+
# 1. app.configure() method in your code
|
|
12
|
+
# 2. app.run() options parameter
|
|
13
|
+
# Configuration priority: .env < configure() < run(options)
|
|
14
|
+
|
|
15
|
+
# JWT Configuration
|
|
16
|
+
JWT_SECRET=your-secret-key-change-in-production
|
|
17
|
+
|
|
18
|
+
# Database Configuration
|
|
19
|
+
DB_HOST=localhost
|
|
20
|
+
DB_PORT=5432
|
|
21
|
+
DB_USER=postgres
|
|
22
|
+
DB_PASSWORD=postgres
|
|
23
|
+
DB_NAME={{APP_NAME}}
|