@slingr/cli 0.0.1
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/README.md +320 -0
- package/bin/dev.cmd +3 -0
- package/bin/dev.js +5 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +5 -0
- package/dist/commands/cli-build.d.ts +9 -0
- package/dist/commands/cli-build.d.ts.map +1 -0
- package/dist/commands/cli-build.js +36 -0
- package/dist/commands/cli-build.js.map +1 -0
- package/dist/commands/create-app.d.ts +20 -0
- package/dist/commands/create-app.d.ts.map +1 -0
- package/dist/commands/create-app.js +246 -0
- package/dist/commands/create-app.js.map +1 -0
- package/dist/commands/ds.d.ts +28 -0
- package/dist/commands/ds.d.ts.map +1 -0
- package/dist/commands/ds.js +529 -0
- package/dist/commands/ds.js.map +1 -0
- package/dist/commands/gql.d.ts +22 -0
- package/dist/commands/gql.d.ts.map +1 -0
- package/dist/commands/gql.js +340 -0
- package/dist/commands/gql.js.map +1 -0
- package/dist/commands/infra/down.d.ts +13 -0
- package/dist/commands/infra/down.d.ts.map +1 -0
- package/dist/commands/infra/down.js +80 -0
- package/dist/commands/infra/down.js.map +1 -0
- package/dist/commands/infra/up.d.ts +13 -0
- package/dist/commands/infra/up.d.ts.map +1 -0
- package/dist/commands/infra/up.js +69 -0
- package/dist/commands/infra/up.js.map +1 -0
- package/dist/commands/infra/update.d.ts +14 -0
- package/dist/commands/infra/update.d.ts.map +1 -0
- package/dist/commands/infra/update.js +321 -0
- package/dist/commands/infra/update.js.map +1 -0
- package/dist/commands/run.d.ts +19 -0
- package/dist/commands/run.d.ts.map +1 -0
- package/dist/commands/run.js +315 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/commands/setup.d.ts +18 -0
- package/dist/commands/setup.d.ts.map +1 -0
- package/dist/commands/setup.js +189 -0
- package/dist/commands/setup.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/projectStructure.d.ts +10 -0
- package/dist/projectStructure.d.ts.map +1 -0
- package/dist/projectStructure.js +153 -0
- package/dist/projectStructure.js.map +1 -0
- package/dist/scripts/generate-schema.d.ts +10 -0
- package/dist/scripts/generate-schema.d.ts.map +1 -0
- package/dist/scripts/generate-schema.js +130 -0
- package/dist/scripts/generate-schema.js.map +1 -0
- package/dist/scripts/generate-schema.ts +143 -0
- package/dist/templates/.github/copilot-instructions.md.template +17 -0
- package/dist/templates/config/datasource.ts.template +9 -0
- package/dist/templates/config/jest.config.ts +30 -0
- package/dist/templates/config/jest.setup.ts +1 -0
- package/dist/templates/config/tsconfig.json.template +30 -0
- package/dist/templates/dataSources/mysql.ts.template +13 -0
- package/dist/templates/dataSources/postgres.ts.template +13 -0
- package/dist/templates/dataset-generator-script.ts.template +140 -0
- package/dist/templates/datasets/mysql-default/Address.jsonl.template +4 -0
- package/dist/templates/datasets/mysql-default/App.jsonl.template +5 -0
- package/dist/templates/datasets/mysql-default/Company.jsonl.template +4 -0
- package/dist/templates/datasets/mysql-default/Person.jsonl.template +3 -0
- package/dist/templates/datasets/postgres-default/Address.jsonl.template +4 -0
- package/dist/templates/datasets/postgres-default/App.jsonl.template +5 -0
- package/dist/templates/datasets/postgres-default/Company.jsonl.template +4 -0
- package/dist/templates/datasets/postgres-default/Person.jsonl.template +3 -0
- package/dist/templates/docs/app-description.md.template +34 -0
- package/dist/templates/gql/codegen.yml.template +25 -0
- package/dist/templates/gql/index.ts.template +24 -0
- package/dist/templates/gql/operations.graphql.template +30 -0
- package/dist/templates/package.json.template +38 -0
- package/dist/templates/prompt-analysis.md.template +111 -0
- package/dist/templates/prompt-script-generation.md.template +259 -0
- package/dist/templates/src/Address.ts.template +31 -0
- package/dist/templates/src/App.ts.template +61 -0
- package/dist/templates/src/Company.ts.template +48 -0
- package/dist/templates/src/Models.test.ts.template +655 -0
- package/dist/templates/src/Person.test.ts.template +289 -0
- package/dist/templates/src/Person.ts.template +105 -0
- package/dist/templates/src/actions/index.ts.template +12 -0
- package/dist/templates/src/index.ts +66 -0
- package/dist/templates/src/types/gql.d.ts.template +18 -0
- package/dist/templates/vscode/extensions.json +3 -0
- package/dist/templates/vscode/settings.json +11 -0
- package/dist/utils/datasourceParser.d.ts +12 -0
- package/dist/utils/datasourceParser.d.ts.map +1 -0
- package/dist/utils/datasourceParser.js +91 -0
- package/dist/utils/datasourceParser.js.map +1 -0
- package/dist/utils/jsonlLoader.d.ts +140 -0
- package/dist/utils/jsonlLoader.d.ts.map +1 -0
- package/dist/utils/jsonlLoader.js +583 -0
- package/dist/utils/jsonlLoader.js.map +1 -0
- package/dist/utils/model-analyzer.d.ts +86 -0
- package/dist/utils/model-analyzer.d.ts.map +1 -0
- package/dist/utils/model-analyzer.js +458 -0
- package/dist/utils/model-analyzer.js.map +1 -0
- package/dist/utils/portChecker.d.ts +36 -0
- package/dist/utils/portChecker.d.ts.map +1 -0
- package/dist/utils/portChecker.js +308 -0
- package/dist/utils/portChecker.js.map +1 -0
- package/dist/utils/synthetic-data-generator.d.ts +74 -0
- package/dist/utils/synthetic-data-generator.d.ts.map +1 -0
- package/dist/utils/synthetic-data-generator.js +443 -0
- package/dist/utils/synthetic-data-generator.js.map +1 -0
- package/oclif.manifest.json +435 -0
- package/package.json +118 -0
- package/src/templates/.github/copilot-instructions.md.template +17 -0
- package/src/templates/config/datasource.ts.template +9 -0
- package/src/templates/config/jest.config.ts +30 -0
- package/src/templates/config/jest.setup.ts +1 -0
- package/src/templates/config/tsconfig.json.template +30 -0
- package/src/templates/dataSources/mysql.ts.template +13 -0
- package/src/templates/dataSources/postgres.ts.template +13 -0
- package/src/templates/dataset-generator-script.ts.template +140 -0
- package/src/templates/datasets/mysql-default/Address.jsonl.template +4 -0
- package/src/templates/datasets/mysql-default/App.jsonl.template +5 -0
- package/src/templates/datasets/mysql-default/Company.jsonl.template +4 -0
- package/src/templates/datasets/mysql-default/Person.jsonl.template +3 -0
- package/src/templates/datasets/postgres-default/Address.jsonl.template +4 -0
- package/src/templates/datasets/postgres-default/App.jsonl.template +5 -0
- package/src/templates/datasets/postgres-default/Company.jsonl.template +4 -0
- package/src/templates/datasets/postgres-default/Person.jsonl.template +3 -0
- package/src/templates/docs/app-description.md.template +34 -0
- package/src/templates/gql/codegen.yml.template +25 -0
- package/src/templates/gql/index.ts.template +24 -0
- package/src/templates/gql/operations.graphql.template +30 -0
- package/src/templates/package.json.template +38 -0
- package/src/templates/prompt-analysis.md.template +111 -0
- package/src/templates/prompt-script-generation.md.template +259 -0
- package/src/templates/src/Address.ts.template +31 -0
- package/src/templates/src/App.ts.template +61 -0
- package/src/templates/src/Company.ts.template +48 -0
- package/src/templates/src/Models.test.ts.template +655 -0
- package/src/templates/src/Person.test.ts.template +289 -0
- package/src/templates/src/Person.ts.template +105 -0
- package/src/templates/src/actions/index.ts.template +12 -0
- package/src/templates/src/index.ts +66 -0
- package/src/templates/src/types/gql.d.ts.template +18 -0
- package/src/templates/vscode/extensions.json +3 -0
- package/src/templates/vscode/settings.json +11 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createProjectStructure = createProjectStructure;
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
async function copyTemplateFile(templatePath, targetPath, replacements) {
|
|
10
|
+
let content = await fs_extra_1.default.readFile(templatePath, 'utf8');
|
|
11
|
+
// Apply replacements if provided
|
|
12
|
+
if (replacements) {
|
|
13
|
+
for (const [placeholder, value] of Object.entries(replacements)) {
|
|
14
|
+
content = content.replaceAll(placeholder, value);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
await fs_extra_1.default.outputFile(targetPath, content);
|
|
18
|
+
}
|
|
19
|
+
async function createProjectStructure(appName, answers) {
|
|
20
|
+
const targetDir = node_path_1.default.join(process.cwd(), appName);
|
|
21
|
+
// Use __dirname instead of import.meta.url
|
|
22
|
+
const currentDir = __dirname;
|
|
23
|
+
// When running from dist/, we need to go up one level to reach the project root
|
|
24
|
+
const projectRoot = node_path_1.default.resolve(currentDir, '..');
|
|
25
|
+
const templatesDir = node_path_1.default.join(projectRoot, 'src', 'templates');
|
|
26
|
+
// Create directory structure
|
|
27
|
+
await fs_extra_1.default.ensureDir(targetDir);
|
|
28
|
+
await fs_extra_1.default.ensureDir(node_path_1.default.join(targetDir, '.vscode'));
|
|
29
|
+
await fs_extra_1.default.ensureDir(node_path_1.default.join(targetDir, '.github'));
|
|
30
|
+
await fs_extra_1.default.ensureDir(node_path_1.default.join(targetDir, 'src', 'data'));
|
|
31
|
+
await fs_extra_1.default.ensureDir(node_path_1.default.join(targetDir, 'src', 'dataSources'));
|
|
32
|
+
await fs_extra_1.default.ensureDir(node_path_1.default.join(targetDir, 'src', 'actions'));
|
|
33
|
+
await fs_extra_1.default.ensureDir(node_path_1.default.join(targetDir, 'docs'));
|
|
34
|
+
await fs_extra_1.default.ensureDir(node_path_1.default.join(targetDir, 'src', 'datasets'));
|
|
35
|
+
// Copy .vscode files from templates
|
|
36
|
+
await fs_extra_1.default.copy(node_path_1.default.join(templatesDir, 'vscode', 'extensions.json'), node_path_1.default.join(targetDir, '.vscode', 'extensions.json'));
|
|
37
|
+
await fs_extra_1.default.copy(node_path_1.default.join(templatesDir, 'vscode', 'settings.json'), node_path_1.default.join(targetDir, '.vscode', 'settings.json'));
|
|
38
|
+
// Copy tsconfig.json from templates
|
|
39
|
+
await copyTemplateFile(node_path_1.default.join(templatesDir, 'config', 'tsconfig.json.template'), node_path_1.default.join(targetDir, 'tsconfig.json'));
|
|
40
|
+
// Copy .gitignore from templates
|
|
41
|
+
await fs_extra_1.default.copy(node_path_1.default.join(templatesDir, 'config', '.gitignore'), node_path_1.default.join(targetDir, '.gitignore'));
|
|
42
|
+
// Copy jest.config.ts from templates
|
|
43
|
+
await fs_extra_1.default.copy(node_path_1.default.join(templatesDir, 'config', 'jest.config.ts'), node_path_1.default.join(targetDir, 'jest.config.ts'));
|
|
44
|
+
// Copy jest.setup.ts from templates
|
|
45
|
+
await fs_extra_1.default.copy(node_path_1.default.join(templatesDir, 'config', 'jest.setup.ts'), node_path_1.default.join(targetDir, 'jest.setup.ts'));
|
|
46
|
+
// Copy and process src files from templates
|
|
47
|
+
const replacements = {
|
|
48
|
+
'{{APP_NAME}}': appName,
|
|
49
|
+
};
|
|
50
|
+
await copyTemplateFile(node_path_1.default.join(templatesDir, 'src', 'index.ts'), node_path_1.default.join(targetDir, 'src', 'index.ts'), replacements);
|
|
51
|
+
// Create actions index file
|
|
52
|
+
await copyTemplateFile(node_path_1.default.join(templatesDir, 'src', 'actions', 'index.ts.template'), node_path_1.default.join(targetDir, 'src', 'actions', 'index.ts'), replacements);
|
|
53
|
+
// Create temporary @gql type declaration to avoid compilation errors
|
|
54
|
+
await fs_extra_1.default.ensureDir(node_path_1.default.join(targetDir, 'src', 'types'));
|
|
55
|
+
await copyTemplateFile(node_path_1.default.join(templatesDir, 'src', 'types', 'gql.d.ts.template'), node_path_1.default.join(targetDir, 'src', 'types', 'gql.d.ts'));
|
|
56
|
+
// Determine datasource details based on database type
|
|
57
|
+
const dbType = answers.database.toLowerCase();
|
|
58
|
+
let datasourceName = '';
|
|
59
|
+
let datasourceFile = '';
|
|
60
|
+
switch (dbType) {
|
|
61
|
+
case 'postgres':
|
|
62
|
+
case 'postgresql':
|
|
63
|
+
datasourceName = 'postgresDataSource';
|
|
64
|
+
datasourceFile = 'postgres';
|
|
65
|
+
break;
|
|
66
|
+
case 'mysql':
|
|
67
|
+
datasourceName = 'mysqlDataSource';
|
|
68
|
+
datasourceFile = 'mysql';
|
|
69
|
+
break;
|
|
70
|
+
default:
|
|
71
|
+
datasourceName = 'postgresDataSource';
|
|
72
|
+
datasourceFile = 'postgres';
|
|
73
|
+
}
|
|
74
|
+
// Copy the corresponding datasource template based on database type
|
|
75
|
+
if (answers.hasBackend) {
|
|
76
|
+
let templateFile = '';
|
|
77
|
+
let targetFile = '';
|
|
78
|
+
switch (dbType) {
|
|
79
|
+
case 'postgres':
|
|
80
|
+
case 'postgresql':
|
|
81
|
+
templateFile = node_path_1.default.join(templatesDir, 'dataSources', 'postgres.ts.template');
|
|
82
|
+
targetFile = node_path_1.default.join(targetDir, 'src', 'dataSources', 'postgres.ts');
|
|
83
|
+
break;
|
|
84
|
+
case 'mysql':
|
|
85
|
+
templateFile = node_path_1.default.join(templatesDir, 'dataSources', 'mysql.ts.template');
|
|
86
|
+
targetFile = node_path_1.default.join(targetDir, 'src', 'dataSources', 'mysql.ts');
|
|
87
|
+
break;
|
|
88
|
+
// Add more cases if there are more templates
|
|
89
|
+
default:
|
|
90
|
+
templateFile = node_path_1.default.join(templatesDir, 'dataSources', 'postgres.ts.template');
|
|
91
|
+
targetFile = node_path_1.default.join(targetDir, 'src', 'dataSources', 'postgres.ts');
|
|
92
|
+
}
|
|
93
|
+
await copyTemplateFile(templateFile, targetFile, { '{{APP_NAME}}': appName });
|
|
94
|
+
}
|
|
95
|
+
// Copy sample model files with datasource replacements
|
|
96
|
+
if (answers.includeTemplates) {
|
|
97
|
+
const modelReplacements = {
|
|
98
|
+
'{{DATASOURCE_NAME}}': 'mainDs',
|
|
99
|
+
'{{DATASOURCE_FILE}}': datasourceFile,
|
|
100
|
+
};
|
|
101
|
+
await copyTemplateFile(node_path_1.default.join(templatesDir, 'src', 'Person.ts.template'), node_path_1.default.join(targetDir, 'src', 'data', 'Person.ts'), modelReplacements);
|
|
102
|
+
await copyTemplateFile(node_path_1.default.join(templatesDir, 'src', 'Company.ts.template'), node_path_1.default.join(targetDir, 'src', 'data', 'Company.ts'), modelReplacements);
|
|
103
|
+
await copyTemplateFile(node_path_1.default.join(templatesDir, 'src', 'App.ts.template'), node_path_1.default.join(targetDir, 'src', 'data', 'App.ts'), modelReplacements);
|
|
104
|
+
await copyTemplateFile(node_path_1.default.join(templatesDir, 'src', 'Address.ts.template'), node_path_1.default.join(targetDir, 'src', 'data', 'Address.ts'), modelReplacements);
|
|
105
|
+
// Copy test files
|
|
106
|
+
await copyTemplateFile(node_path_1.default.join(templatesDir, 'src', 'Person.test.ts.template'), node_path_1.default.join(targetDir, 'src', 'data', 'Person.test.ts'));
|
|
107
|
+
await copyTemplateFile(node_path_1.default.join(templatesDir, 'src', 'Models.test.ts.template'), node_path_1.default.join(targetDir, 'src', 'data', 'Models.test.ts'));
|
|
108
|
+
}
|
|
109
|
+
// Copy templated .github/copilot-instructions.md
|
|
110
|
+
await copyTemplateFile(node_path_1.default.join(templatesDir, '.github', 'copilot-instructions.md.template'), node_path_1.default.join(targetDir, '.github', 'copilot-instructions.md'), {
|
|
111
|
+
'{{APP_NAME}}': appName,
|
|
112
|
+
'{{APP_TYPE}}': answers.appType,
|
|
113
|
+
'{{DESCRIPTION}}': answers.description,
|
|
114
|
+
'{{HAS_BACKEND}}': answers.hasBackend ? 'Yes' : 'No',
|
|
115
|
+
'{{HAS_FRONTEND}}': answers.hasFrontend ? 'Yes' : 'No',
|
|
116
|
+
'{{DB_TYPE}}': answers.database,
|
|
117
|
+
});
|
|
118
|
+
// Copy package.json template
|
|
119
|
+
const dbDriverDependency = answers.hasBackend
|
|
120
|
+
? answers.database === 'mysql'
|
|
121
|
+
? ',\n "mysql2": "^3.11.3"'
|
|
122
|
+
: ',\n "pg": "^8.16.3"'
|
|
123
|
+
: '';
|
|
124
|
+
await copyTemplateFile(node_path_1.default.join(templatesDir, 'package.json.template'), node_path_1.default.join(targetDir, 'package.json'), {
|
|
125
|
+
'{{APP_NAME}}': appName,
|
|
126
|
+
'{{DB_DRIVER_DEPENDENCY}}': dbDriverDependency,
|
|
127
|
+
'{{DESCRIPTION}}': answers.description,
|
|
128
|
+
'{{APP_KEYWORD}}': answers.appType.toLowerCase().replaceAll(/\s+/g, '-'),
|
|
129
|
+
});
|
|
130
|
+
// Copy docs/app-description.md template
|
|
131
|
+
await copyTemplateFile(node_path_1.default.join(templatesDir, 'docs', 'app-description.md.template'), node_path_1.default.join(targetDir, 'docs', 'app-description.md'), {
|
|
132
|
+
'{{APP_NAME}}': appName,
|
|
133
|
+
'{{DESCRIPTION}}': answers.description,
|
|
134
|
+
'{{APP_TYPE}}': answers.appType,
|
|
135
|
+
'{{HAS_BACKEND}}': answers.hasBackend ? 'Included' : 'Not included',
|
|
136
|
+
'{{HAS_FRONTEND}}': answers.hasFrontend ? 'Included' : 'Not included',
|
|
137
|
+
'{{DB_TYPE}}': answers.database,
|
|
138
|
+
});
|
|
139
|
+
// Copy dataset templates if backend is enabled and templates are included
|
|
140
|
+
if (answers.hasBackend && answers.includeTemplates) {
|
|
141
|
+
const dbType = answers.database.toLowerCase();
|
|
142
|
+
const datasetSourcePath = node_path_1.default.join(templatesDir, 'datasets', `${dbType}-default`);
|
|
143
|
+
const datasetTargetPath = node_path_1.default.join(targetDir, 'src', 'datasets', `${dbType}-default`);
|
|
144
|
+
// Create the dataset directory
|
|
145
|
+
await fs_extra_1.default.ensureDir(datasetTargetPath);
|
|
146
|
+
// Copy the JSONL templates without the .template extension
|
|
147
|
+
await copyTemplateFile(node_path_1.default.join(datasetSourcePath, 'Person.jsonl.template'), node_path_1.default.join(datasetTargetPath, 'Person.jsonl'));
|
|
148
|
+
await copyTemplateFile(node_path_1.default.join(datasetSourcePath, 'Company.jsonl.template'), node_path_1.default.join(datasetTargetPath, 'Company.jsonl'));
|
|
149
|
+
await copyTemplateFile(node_path_1.default.join(datasetSourcePath, 'App.jsonl.template'), node_path_1.default.join(datasetTargetPath, 'App.jsonl'));
|
|
150
|
+
await copyTemplateFile(node_path_1.default.join(datasetSourcePath, 'Address.jsonl.template'), node_path_1.default.join(datasetTargetPath, 'Address.jsonl'));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingUR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CAAC,IAAI,CAAC,iBAAiB,EAAE,cAAc,CAAC,CAC7C,CAAC;QAEF,MAAM,gBAAgB,CACpB,mBAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,wBAAwB,CAAC,EACtD,mBAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,eAAe,CAAC,CAC9C,CAAC;QAEF,MAAM,gBAAgB,CACpB,mBAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,EAClD,mBAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAC1C,CAAC;QAEF,MAAM,gBAAgB,CACpB,mBAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,wBAAwB,CAAC,EACtD,mBAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,eAAe,CAAC,CAC9C,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Script to generate GraphQL schema from slingr-framework
|
|
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
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=generate-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-schema.d.ts","sourceRoot":"","sources":["../../src/scripts/generate-schema.ts"],"names":[],"mappings":";AACA;;;;;;GAMG"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* Script to generate GraphQL schema from slingr-framework
|
|
5
|
+
* This script is executed in the context of a user's Slingr application
|
|
6
|
+
*
|
|
7
|
+
* By default, the script generates the schema and exits immediately.
|
|
8
|
+
* Use --no-exit flag to start Apollo Server for schema exploration.
|
|
9
|
+
*/
|
|
10
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
const fs_1 = __importDefault(require("fs"));
|
|
15
|
+
const path_1 = __importDefault(require("path"));
|
|
16
|
+
const url_1 = require("url");
|
|
17
|
+
async function generateSchema() {
|
|
18
|
+
try {
|
|
19
|
+
console.log('š Generating GraphQL schema from your Slingr application...');
|
|
20
|
+
// IMPORTANT: Import actions BEFORE importing slingr-framework
|
|
21
|
+
// This ensures action decorators are executed before the schema is built
|
|
22
|
+
// Try to load the compiled JavaScript version first, then fallback to TypeScript
|
|
23
|
+
// Note: TypeScript compilation with rootDir inferred from src/ will output to dist/actions/
|
|
24
|
+
// (without the src folder in the path)
|
|
25
|
+
let actionsIndexPath = path_1.default.join(process.cwd(), 'dist', 'actions', 'index.js');
|
|
26
|
+
let usingCompiledVersion = true;
|
|
27
|
+
let hasActions = false;
|
|
28
|
+
if (fs_1.default.existsSync(actionsIndexPath)) {
|
|
29
|
+
hasActions = true;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
// Also check the alternative path (dist/src/actions/index.js) for backwards compatibility
|
|
33
|
+
const altActionsIndexPath = path_1.default.join(process.cwd(), 'dist', 'src', 'actions', 'index.js');
|
|
34
|
+
if (fs_1.default.existsSync(altActionsIndexPath)) {
|
|
35
|
+
actionsIndexPath = altActionsIndexPath;
|
|
36
|
+
hasActions = true;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// Fallback to TypeScript source
|
|
40
|
+
actionsIndexPath = path_1.default.join(process.cwd(), 'src', 'actions', 'index.ts');
|
|
41
|
+
usingCompiledVersion = false;
|
|
42
|
+
if (fs_1.default.existsSync(actionsIndexPath)) {
|
|
43
|
+
hasActions = true;
|
|
44
|
+
console.log('ā ļø TypeScript source files detected. For best compatibility, run "npm run build" to compile your application first.');
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
// Check if actions directory exists at all
|
|
48
|
+
const actionsDir = path_1.default.join(process.cwd(), 'src', 'actions');
|
|
49
|
+
if (fs_1.default.existsSync(actionsDir)) {
|
|
50
|
+
console.log('ā ļø Actions directory found but no index file. Please ensure src/actions/index.ts exists or run "slingr run" to generate it automatically.');
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
console.log('ā¹ļø No actions directory found. Schema will be generated with framework base types only.');
|
|
54
|
+
}
|
|
55
|
+
hasActions = false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (hasActions) {
|
|
60
|
+
console.log(`š¦ Loading actions from ${usingCompiledVersion ? 'compiled' : 'source'} files...`);
|
|
61
|
+
// If using TypeScript files, show a warning and try to continue
|
|
62
|
+
if (!usingCompiledVersion) {
|
|
63
|
+
throw new Error('TypeScript source files found but not compiled. Please run "npm run build" to compile your application first, then try again.');
|
|
64
|
+
}
|
|
65
|
+
// Import the actions index which will register all actions via @Action decorators
|
|
66
|
+
// Convert Windows paths to file:// URLs for ESM compatibility
|
|
67
|
+
const actionsIndexUrl = (0, url_1.pathToFileURL)(actionsIndexPath).href;
|
|
68
|
+
await import(actionsIndexUrl);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
console.log('š¦ No actions to load. Generating schema with framework base types...');
|
|
72
|
+
} // Import framework functions and printSchema from slingr-framework
|
|
73
|
+
// We must use printSchema from the same GraphQL instance as the framework
|
|
74
|
+
// to avoid "Cannot use GraphQLType from another module or realm" errors
|
|
75
|
+
const slingrFramework = await import('slingr-framework');
|
|
76
|
+
const { getGraphQLSchema, rebuildGraphQLSchema, printSchema } = slingrFramework;
|
|
77
|
+
// Force rebuild the schema to include all registered actions
|
|
78
|
+
rebuildGraphQLSchema();
|
|
79
|
+
const schema = getGraphQLSchema();
|
|
80
|
+
if (!schema) {
|
|
81
|
+
throw new Error('Could not generate GraphQL schema. Please ensure slingr-framework is properly installed.');
|
|
82
|
+
}
|
|
83
|
+
const schemaString = printSchema(schema);
|
|
84
|
+
// Ensure generated/gql directory exists
|
|
85
|
+
const generatedDir = path_1.default.join(process.cwd(), 'generated', 'gql');
|
|
86
|
+
if (!fs_1.default.existsSync(generatedDir)) {
|
|
87
|
+
fs_1.default.mkdirSync(generatedDir, { recursive: true });
|
|
88
|
+
}
|
|
89
|
+
// Write schema to file
|
|
90
|
+
const schemaFilePath = path_1.default.join(generatedDir, 'schema.graphql');
|
|
91
|
+
fs_1.default.writeFileSync(schemaFilePath, schemaString, 'utf8');
|
|
92
|
+
console.log(`ā
GraphQL schema generated successfully at: ${schemaFilePath}`);
|
|
93
|
+
// Show a preview of the generated schema
|
|
94
|
+
const lines = schemaString.split('\n');
|
|
95
|
+
if (lines.length > 0) {
|
|
96
|
+
console.log('\nš Schema preview:');
|
|
97
|
+
console.log(lines.slice(0, Math.min(15, lines.length)).join('\n'));
|
|
98
|
+
if (lines.length > 15) {
|
|
99
|
+
console.log(`... (${lines.length - 15} more lines)`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Check for --no-exit parameter
|
|
103
|
+
const noExit = process.argv.includes('--no-exit');
|
|
104
|
+
if (noExit) {
|
|
105
|
+
console.log('\n Starting Apollo Server to explore the schema...');
|
|
106
|
+
console.log('š” Remove --no-exit parameter to exit immediately after generating schema.');
|
|
107
|
+
// Start Apollo Server for schema exploration
|
|
108
|
+
const { startGraphQLServer } = slingrFramework;
|
|
109
|
+
await startGraphQLServer({
|
|
110
|
+
port: 4000,
|
|
111
|
+
enableExplorer: true,
|
|
112
|
+
});
|
|
113
|
+
console.log('š Apollo Explorer available at: http://localhost:4000/graphql');
|
|
114
|
+
console.log('š GraphQL schema introspection enabled');
|
|
115
|
+
console.log('ā¹ļø Press Ctrl+C to stop the server');
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
console.log('\nā
Schema generation completed. Script will terminate now.');
|
|
119
|
+
console.log('š” Use --no-exit parameter to start Apollo Server and explore the schema.');
|
|
120
|
+
process.exit(0);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
console.error(`Failed to generate schema: ${error.message}`);
|
|
125
|
+
console.error(error);
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
generateSchema();
|
|
130
|
+
//# sourceMappingURL=generate-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-schema.js","sourceRoot":"","sources":["../../src/scripts/generate-schema.ts"],"names":[],"mappings":";;AACA;;;;;;GAMG;;;;;AAEH,4CAAoB;AACpB,gDAAwB;AACxB,6BAAoC;AAEpC,KAAK,UAAU,cAAc;IAC3B,IAAI,CAAC;QACH,OAAO,CAAC,GAAG,CAAC,8DAA8D,CAAC,CAAC;QAE5E,8DAA8D;QAC9D,yEAAyE;QAEzE,iFAAiF;QACjF,4FAA4F;QAC5F,uCAAuC;QACvC,IAAI,gBAAgB,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;QAC/E,IAAI,oBAAoB,GAAG,IAAI,CAAC;QAChC,IAAI,UAAU,GAAG,KAAK,CAAC;QAEvB,IAAI,YAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE,CAAC;YACpC,UAAU,GAAG,IAAI,CAAC;QACpB,CAAC;aAAM,CAAC;YACN,0FAA0F;YAC1F,MAAM,mBAAmB,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;YAC3F,IAAI,YAAE,CAAC,UAAU,CAAC,mBAAmB,CAAC,EAAE,CAAC;gBACvC,gBAAgB,GAAG,mBAAmB,CAAC;gBACvC,UAAU,GAAG,IAAI,CAAC;YACpB,CAA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|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Script to generate GraphQL schema from slingr-framework
|
|
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
|
+
import { pathToFileURL } from 'url';
|
|
13
|
+
|
|
14
|
+
async function generateSchema() {
|
|
15
|
+
try {
|
|
16
|
+
console.log('š Generating GraphQL schema from your Slingr application...');
|
|
17
|
+
|
|
18
|
+
// IMPORTANT: Import actions BEFORE importing slingr-framework
|
|
19
|
+
// This ensures action decorators are executed before the schema is built
|
|
20
|
+
|
|
21
|
+
// Try to load the compiled JavaScript version first, then fallback to TypeScript
|
|
22
|
+
// Note: TypeScript compilation with rootDir inferred from src/ will output to dist/actions/
|
|
23
|
+
// (without the src folder in the path)
|
|
24
|
+
let actionsIndexPath = path.join(process.cwd(), 'dist', 'actions', 'index.js');
|
|
25
|
+
let usingCompiledVersion = true;
|
|
26
|
+
let hasActions = false;
|
|
27
|
+
|
|
28
|
+
if (fs.existsSync(actionsIndexPath)) {
|
|
29
|
+
hasActions = true;
|
|
30
|
+
} else {
|
|
31
|
+
// Also check the alternative path (dist/src/actions/index.js) for backwards compatibility
|
|
32
|
+
const altActionsIndexPath = path.join(process.cwd(), 'dist', 'src', 'actions', 'index.js');
|
|
33
|
+
if (fs.existsSync(altActionsIndexPath)) {
|
|
34
|
+
actionsIndexPath = altActionsIndexPath;
|
|
35
|
+
hasActions = true;
|
|
36
|
+
} else {
|
|
37
|
+
// Fallback to TypeScript source
|
|
38
|
+
actionsIndexPath = path.join(process.cwd(), 'src', 'actions', 'index.ts');
|
|
39
|
+
usingCompiledVersion = false;
|
|
40
|
+
|
|
41
|
+
if (fs.existsSync(actionsIndexPath)) {
|
|
42
|
+
hasActions = true;
|
|
43
|
+
console.log(
|
|
44
|
+
'ā ļø TypeScript source files detected. For best compatibility, run "npm run build" to compile your application first.'
|
|
45
|
+
);
|
|
46
|
+
} else {
|
|
47
|
+
// Check if actions directory exists at all
|
|
48
|
+
const actionsDir = path.join(process.cwd(), 'src', 'actions');
|
|
49
|
+
if (fs.existsSync(actionsDir)) {
|
|
50
|
+
console.log(
|
|
51
|
+
'ā ļø Actions directory found but no index file. Please ensure src/actions/index.ts exists or run "slingr run" to generate it automatically.'
|
|
52
|
+
);
|
|
53
|
+
} else {
|
|
54
|
+
console.log('ā¹ļø No actions directory found. Schema will be generated with framework base types only.');
|
|
55
|
+
}
|
|
56
|
+
hasActions = false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (hasActions) {
|
|
62
|
+
console.log(`š¦ Loading actions from ${usingCompiledVersion ? 'compiled' : 'source'} files...`);
|
|
63
|
+
|
|
64
|
+
// If using TypeScript files, show a warning and try to continue
|
|
65
|
+
if (!usingCompiledVersion) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
'TypeScript source files found but not compiled. Please run "npm run build" to compile your application first, then try again.'
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Import the actions index which will register all actions via @Action decorators
|
|
72
|
+
// Convert Windows paths to file:// URLs for ESM compatibility
|
|
73
|
+
const actionsIndexUrl = pathToFileURL(actionsIndexPath).href;
|
|
74
|
+
await import(actionsIndexUrl);
|
|
75
|
+
} else {
|
|
76
|
+
console.log('š¦ No actions to load. Generating schema with framework base types...');
|
|
77
|
+
} // Import framework functions and printSchema from slingr-framework
|
|
78
|
+
// We must use printSchema from the same GraphQL instance as the framework
|
|
79
|
+
// to avoid "Cannot use GraphQLType from another module or realm" errors
|
|
80
|
+
const slingrFramework = await import('slingr-framework');
|
|
81
|
+
const { getGraphQLSchema, rebuildGraphQLSchema, printSchema } = slingrFramework;
|
|
82
|
+
|
|
83
|
+
// Force rebuild the schema to include all registered actions
|
|
84
|
+
rebuildGraphQLSchema();
|
|
85
|
+
const schema = getGraphQLSchema();
|
|
86
|
+
|
|
87
|
+
if (!schema) {
|
|
88
|
+
throw new Error('Could not generate GraphQL schema. Please ensure slingr-framework is properly installed.');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const schemaString = printSchema(schema);
|
|
92
|
+
|
|
93
|
+
// Ensure generated/gql directory exists
|
|
94
|
+
const generatedDir = path.join(process.cwd(), 'generated', 'gql');
|
|
95
|
+
if (!fs.existsSync(generatedDir)) {
|
|
96
|
+
fs.mkdirSync(generatedDir, { recursive: true });
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Write schema to file
|
|
100
|
+
const schemaFilePath = path.join(generatedDir, 'schema.graphql');
|
|
101
|
+
fs.writeFileSync(schemaFilePath, schemaString, 'utf8');
|
|
102
|
+
|
|
103
|
+
console.log(`ā
GraphQL schema generated successfully at: ${schemaFilePath}`);
|
|
104
|
+
|
|
105
|
+
// Show a preview of the generated schema
|
|
106
|
+
const lines = schemaString.split('\n');
|
|
107
|
+
if (lines.length > 0) {
|
|
108
|
+
console.log('\nš Schema preview:');
|
|
109
|
+
console.log(lines.slice(0, Math.min(15, lines.length)).join('\n'));
|
|
110
|
+
if (lines.length > 15) {
|
|
111
|
+
console.log(`... (${lines.length - 15} more lines)`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Check for --no-exit parameter
|
|
116
|
+
const noExit = process.argv.includes('--no-exit');
|
|
117
|
+
if (noExit) {
|
|
118
|
+
console.log('\n Starting Apollo Server to explore the schema...');
|
|
119
|
+
console.log('š” Remove --no-exit parameter to exit immediately after generating schema.');
|
|
120
|
+
|
|
121
|
+
// Start Apollo Server for schema exploration
|
|
122
|
+
const { startGraphQLServer } = slingrFramework;
|
|
123
|
+
await startGraphQLServer({
|
|
124
|
+
port: 4000,
|
|
125
|
+
enableExplorer: true,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
console.log('š Apollo Explorer available at: http://localhost:4000/graphql');
|
|
129
|
+
console.log('š GraphQL schema introspection enabled');
|
|
130
|
+
console.log('ā¹ļø Press Ctrl+C to stop the server');
|
|
131
|
+
} else {
|
|
132
|
+
console.log('\nā
Schema generation completed. Script will terminate now.');
|
|
133
|
+
console.log('š” Use --no-exit parameter to start Apollo Server and explore the schema.');
|
|
134
|
+
process.exit(0);
|
|
135
|
+
}
|
|
136
|
+
} catch (error: any) {
|
|
137
|
+
console.error(`Failed to generate schema: ${error.message}`);
|
|
138
|
+
console.error(error);
|
|
139
|
+
process.exit(1);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
generateSchema();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# GitHub Copilot Instructions for {{APP_NAME}}
|
|
2
|
+
|
|
3
|
+
This is a {{APP_TYPE}} application built with Slingr.
|
|
4
|
+
|
|
5
|
+
## Project Description
|
|
6
|
+
{{DESCRIPTION}}
|
|
7
|
+
|
|
8
|
+
## Architecture
|
|
9
|
+
- Backend: {{HAS_BACKEND}}
|
|
10
|
+
- Frontend: {{HAS_FRONTEND}}
|
|
11
|
+
- Database: {{DB_TYPE}}
|
|
12
|
+
|
|
13
|
+
## Development Guidelines
|
|
14
|
+
- Use TypeScript for all code
|
|
15
|
+
- Follow Slingr conventions and patterns
|
|
16
|
+
- Maintain clean, readable code with proper documentation
|
|
17
|
+
- Use the provided data models as starting points
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Config } from 'jest';
|
|
2
|
+
|
|
3
|
+
const config: Config = {
|
|
4
|
+
coverageProvider: 'v8',
|
|
5
|
+
moduleDirectories: ['node_modules', '<rootDir>'],
|
|
6
|
+
moduleNameMapper: {
|
|
7
|
+
'#(.*)': '<rootDir>/node_modules/$1',
|
|
8
|
+
'slingr-framework': '<rootDir>/node_modules/slingr-framework',
|
|
9
|
+
},
|
|
10
|
+
modulePaths: ['<rootDir>'],
|
|
11
|
+
preset: 'ts-jest',
|
|
12
|
+
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
|
|
13
|
+
testEnvironment: 'node',
|
|
14
|
+
testMatch: ['<rootDir>/src/**/*.test.ts'],
|
|
15
|
+
transform: {
|
|
16
|
+
'^.+\\.(ts|tsx|js|jsx)$': [
|
|
17
|
+
'ts-jest',
|
|
18
|
+
{
|
|
19
|
+
tsconfig: {
|
|
20
|
+
module: 'commonjs',
|
|
21
|
+
allowJs: true,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
'^.+\\.[j]sx?$': 'babel-jest',
|
|
26
|
+
},
|
|
27
|
+
transformIgnorePatterns: ['/node_modules/(?!slingr-framework)'],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
module.exports = config;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "NodeNext",
|
|
4
|
+
"moduleResolution": "nodenext",
|
|
5
|
+
"target": "es2020",
|
|
6
|
+
"types": ["node", "jest"],
|
|
7
|
+
"sourceMap": true,
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"declarationMap": true,
|
|
10
|
+
"noUncheckedIndexedAccess": false,
|
|
11
|
+
"exactOptionalPropertyTypes": false,
|
|
12
|
+
"strict": true,
|
|
13
|
+
"jsx": "react-jsx",
|
|
14
|
+
"verbatimModuleSyntax": false,
|
|
15
|
+
"isolatedModules": true,
|
|
16
|
+
"noUncheckedSideEffectImports": true,
|
|
17
|
+
"moduleDetection": "force",
|
|
18
|
+
"skipLibCheck": true,
|
|
19
|
+
"experimentalDecorators": true,
|
|
20
|
+
"emitDecoratorMetadata": true,
|
|
21
|
+
"esModuleInterop": true,
|
|
22
|
+
"outDir": "./dist",
|
|
23
|
+
"paths": {
|
|
24
|
+
"@gql": ["./generated/gql/index.ts"],
|
|
25
|
+
"@gql/*": ["./generated/gql/*"]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"include": ["src/**/*", "test/**/*", "jest.config.js", "index.ts"],
|
|
29
|
+
"exclude": ["node_modules", "dist"]
|
|
30
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TypeOrmSqlDataSource } from 'slingr-framework';
|
|
2
|
+
|
|
3
|
+
export const mainDs = new TypeOrmSqlDataSource({
|
|
4
|
+
type: 'mysql',
|
|
5
|
+
host: 'localhost',
|
|
6
|
+
port: 3306,
|
|
7
|
+
username: 'root',
|
|
8
|
+
password: 'root',
|
|
9
|
+
database: '{{APP_NAME}}',
|
|
10
|
+
synchronize: true,
|
|
11
|
+
logging: true,
|
|
12
|
+
managed: true
|
|
13
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TypeOrmSqlDataSource } from 'slingr-framework';
|
|
2
|
+
|
|
3
|
+
export const mainDs = new TypeOrmSqlDataSource({
|
|
4
|
+
type: 'postgres',
|
|
5
|
+
host: 'localhost',
|
|
6
|
+
port: 5433,
|
|
7
|
+
username: 'postgres',
|
|
8
|
+
password: 'postgres',
|
|
9
|
+
database: '{{APP_NAME}}',
|
|
10
|
+
synchronize: true,
|
|
11
|
+
logging: true,
|
|
12
|
+
managed: true
|
|
13
|
+
});
|