@compilr-dev/sdk 0.2.5 → 0.2.6

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 (29) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +12 -0
  3. package/dist/project-generator/detection.d.ts +42 -0
  4. package/dist/project-generator/detection.js +401 -0
  5. package/dist/project-generator/generator.d.ts +14 -0
  6. package/dist/project-generator/generator.js +245 -0
  7. package/dist/project-generator/index.d.ts +11 -0
  8. package/dist/project-generator/index.js +13 -0
  9. package/dist/project-generator/templates/coding-standards.d.ts +7 -0
  10. package/dist/project-generator/templates/coding-standards.js +299 -0
  11. package/dist/project-generator/templates/compilr-md-import.d.ts +8 -0
  12. package/dist/project-generator/templates/compilr-md-import.js +241 -0
  13. package/dist/project-generator/templates/compilr-md.d.ts +7 -0
  14. package/dist/project-generator/templates/compilr-md.js +141 -0
  15. package/dist/project-generator/templates/config-json.d.ts +13 -0
  16. package/dist/project-generator/templates/config-json.js +39 -0
  17. package/dist/project-generator/templates/gitignore.d.ts +7 -0
  18. package/dist/project-generator/templates/gitignore.js +85 -0
  19. package/dist/project-generator/templates/index.d.ts +11 -0
  20. package/dist/project-generator/templates/index.js +11 -0
  21. package/dist/project-generator/templates/package-json.d.ts +7 -0
  22. package/dist/project-generator/templates/package-json.js +111 -0
  23. package/dist/project-generator/templates/readme-md.d.ts +7 -0
  24. package/dist/project-generator/templates/readme-md.js +165 -0
  25. package/dist/project-generator/templates/tsconfig.d.ts +7 -0
  26. package/dist/project-generator/templates/tsconfig.js +61 -0
  27. package/dist/project-generator/types.d.ts +95 -0
  28. package/dist/project-generator/types.js +24 -0
  29. package/package.json +1 -1
@@ -0,0 +1,245 @@
1
+ /**
2
+ * Project Generator
3
+ *
4
+ * Main module for generating project scaffolding.
5
+ */
6
+ import * as fs from 'fs';
7
+ import * as path from 'path';
8
+ import { execSync } from 'child_process';
9
+ import { generateCompilrMd } from './templates/compilr-md.js';
10
+ import { generateCodingStandardsMd } from './templates/coding-standards.js';
11
+ import { generateConfigJson } from './templates/config-json.js';
12
+ import { generateReadmeMd } from './templates/readme-md.js';
13
+ import { generatePackageJson } from './templates/package-json.js';
14
+ import { generateGitignore } from './templates/gitignore.js';
15
+ import { generateTsconfig } from './templates/tsconfig.js';
16
+ // =============================================================================
17
+ // Main Generator
18
+ // =============================================================================
19
+ /**
20
+ * Generate a new project from configuration
21
+ */
22
+ export function generateProject(config, basePath) {
23
+ const filesCreated = [];
24
+ try {
25
+ if (config.repoPattern === 'single') {
26
+ return generateSingleRepoProject(config, basePath, filesCreated);
27
+ }
28
+ else {
29
+ return generateTwoRepoProject(config, basePath, filesCreated);
30
+ }
31
+ }
32
+ catch (error) {
33
+ return {
34
+ success: false,
35
+ projectPath: path.join(basePath, config.name),
36
+ filesCreated,
37
+ error: error instanceof Error ? error.message : String(error),
38
+ };
39
+ }
40
+ }
41
+ // =============================================================================
42
+ // Single Repo Pattern
43
+ // =============================================================================
44
+ function generateSingleRepoProject(config, basePath, filesCreated) {
45
+ const projectPath = path.join(basePath, config.name);
46
+ // Create directory structure
47
+ const dirs = [
48
+ projectPath,
49
+ path.join(projectPath, 'src'),
50
+ path.join(projectPath, '.compilr'),
51
+ path.join(projectPath, '.compilr', 'architecture'),
52
+ path.join(projectPath, '.compilr', 'architecture', 'decisions'),
53
+ path.join(projectPath, '.compilr', 'docs'),
54
+ path.join(projectPath, '.compilr', 'sessions'),
55
+ ];
56
+ for (const dir of dirs) {
57
+ fs.mkdirSync(dir, { recursive: true });
58
+ }
59
+ // Generate and write files
60
+ const files = [
61
+ { path: path.join(projectPath, 'COMPILR.md'), content: generateCompilrMd(config) },
62
+ { path: path.join(projectPath, 'README.md'), content: generateReadmeMd(config) },
63
+ { path: path.join(projectPath, 'package.json'), content: generatePackageJson(config) },
64
+ { path: path.join(projectPath, '.gitignore'), content: generateGitignore(config) },
65
+ { path: path.join(projectPath, 'tsconfig.json'), content: generateTsconfig(config) },
66
+ {
67
+ path: path.join(projectPath, '.compilr', 'config.json'),
68
+ content: generateConfigJson(config, projectPath),
69
+ },
70
+ { path: path.join(projectPath, '.compilr', 'roadmap.md'), content: generateRoadmapMd(config) },
71
+ {
72
+ path: path.join(projectPath, '.compilr', 'architecture', 'coding-standards.md'),
73
+ content: generateCodingStandardsMd(config),
74
+ },
75
+ {
76
+ path: path.join(projectPath, '.compilr', 'docs', 'README.md'),
77
+ content: '# Documentation\n\n*Add your documentation here*\n',
78
+ },
79
+ {
80
+ path: path.join(projectPath, '.compilr', 'sessions', 'README.md'),
81
+ content: '# Session Notes\n\n*Session notes will be auto-generated here*\n',
82
+ },
83
+ ];
84
+ for (const file of files) {
85
+ fs.writeFileSync(file.path, file.content, 'utf-8');
86
+ filesCreated.push(file.path);
87
+ }
88
+ // Initialize git if requested
89
+ if (config.initGit) {
90
+ initGit(projectPath);
91
+ }
92
+ return {
93
+ success: true,
94
+ projectPath,
95
+ filesCreated,
96
+ };
97
+ }
98
+ // =============================================================================
99
+ // Two Repo Pattern
100
+ // =============================================================================
101
+ function generateTwoRepoProject(config, basePath, filesCreated) {
102
+ const projectPath = path.join(basePath, config.name);
103
+ const docsPath = path.join(basePath, `${config.name}-docs`);
104
+ // Create code repo structure
105
+ const codeDirs = [projectPath, path.join(projectPath, 'src')];
106
+ for (const dir of codeDirs) {
107
+ fs.mkdirSync(dir, { recursive: true });
108
+ }
109
+ // Create docs repo structure
110
+ const docsDirs = [
111
+ docsPath,
112
+ path.join(docsPath, '.compilr'),
113
+ path.join(docsPath, '01-planning'),
114
+ path.join(docsPath, '02-architecture'),
115
+ path.join(docsPath, '02-architecture', 'decisions'),
116
+ path.join(docsPath, '03-documentation'),
117
+ path.join(docsPath, '04-session-notes'),
118
+ ];
119
+ for (const dir of docsDirs) {
120
+ fs.mkdirSync(dir, { recursive: true });
121
+ }
122
+ // Generate code repo files
123
+ const codeFiles = [
124
+ { path: path.join(projectPath, 'README.md'), content: generateReadmeMd(config) },
125
+ { path: path.join(projectPath, 'package.json'), content: generatePackageJson(config) },
126
+ { path: path.join(projectPath, '.gitignore'), content: generateGitignore(config) },
127
+ { path: path.join(projectPath, 'tsconfig.json'), content: generateTsconfig(config) },
128
+ ];
129
+ for (const file of codeFiles) {
130
+ fs.writeFileSync(file.path, file.content, 'utf-8');
131
+ filesCreated.push(file.path);
132
+ }
133
+ // Generate docs repo files
134
+ const docsFiles = [
135
+ { path: path.join(docsPath, 'COMPILR.md'), content: generateCompilrMd(config) },
136
+ {
137
+ path: path.join(docsPath, '.compilr', 'config.json'),
138
+ content: generateConfigJson(config, projectPath, docsPath),
139
+ },
140
+ { path: path.join(docsPath, '01-planning', 'roadmap.md'), content: generateRoadmapMd(config) },
141
+ {
142
+ path: path.join(docsPath, '02-architecture', 'coding-standards.md'),
143
+ content: generateCodingStandardsMd(config),
144
+ },
145
+ {
146
+ path: path.join(docsPath, '03-documentation', 'README.md'),
147
+ content: '# Documentation\n\n*Add your documentation here*\n',
148
+ },
149
+ {
150
+ path: path.join(docsPath, '04-session-notes', 'README.md'),
151
+ content: '# Session Notes\n\n*Session notes will be auto-generated here*\n',
152
+ },
153
+ ];
154
+ for (const file of docsFiles) {
155
+ fs.writeFileSync(file.path, file.content, 'utf-8');
156
+ filesCreated.push(file.path);
157
+ }
158
+ // Initialize git if requested
159
+ if (config.initGit) {
160
+ initGit(projectPath);
161
+ initGit(docsPath);
162
+ }
163
+ return {
164
+ success: true,
165
+ projectPath,
166
+ docsPath,
167
+ filesCreated,
168
+ };
169
+ }
170
+ // =============================================================================
171
+ // Helper Functions
172
+ // =============================================================================
173
+ /**
174
+ * Check if git user.name and user.email are configured
175
+ */
176
+ export function isGitConfigured() {
177
+ try {
178
+ const name = execSync('git config --global user.name', {
179
+ encoding: 'utf8',
180
+ stdio: ['pipe', 'pipe', 'pipe'],
181
+ }).trim();
182
+ const email = execSync('git config --global user.email', {
183
+ encoding: 'utf8',
184
+ stdio: ['pipe', 'pipe', 'pipe'],
185
+ }).trim();
186
+ return Boolean(name && email);
187
+ }
188
+ catch {
189
+ return false;
190
+ }
191
+ }
192
+ /**
193
+ * Initialize git repository
194
+ * If git config is not set, only runs git init (skips commit)
195
+ */
196
+ function initGit(projectPath) {
197
+ try {
198
+ execSync('git init', { cwd: projectPath, stdio: 'ignore' });
199
+ execSync('git add .', { cwd: projectPath, stdio: 'ignore' });
200
+ if (isGitConfigured()) {
201
+ execSync('git commit -m "Initial commit from compilr init"', {
202
+ cwd: projectPath,
203
+ stdio: 'ignore',
204
+ });
205
+ }
206
+ }
207
+ catch {
208
+ // Git init failed - not critical
209
+ }
210
+ }
211
+ function generateRoadmapMd(config) {
212
+ return `# Roadmap - ${config.name}
213
+
214
+ ## Vision
215
+
216
+ ${config.description}
217
+
218
+ ---
219
+
220
+ ## Milestones
221
+
222
+ ### Milestone 1: Foundation
223
+ - [ ] Project setup
224
+ - [ ] Development environment
225
+ - [ ] CI/CD pipeline
226
+
227
+ ### Milestone 2: Core Features
228
+ - [ ] *Define your core features*
229
+
230
+ ### Milestone 3: Launch
231
+ - [ ] Testing
232
+ - [ ] Documentation
233
+ - [ ] Deploy to production
234
+
235
+ ---
236
+
237
+ ## Timeline
238
+
239
+ *Add your timeline here*
240
+
241
+ ---
242
+
243
+ *Last Updated: ${new Date().toISOString().split('T')[0]}*
244
+ `;
245
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Project Generator — SDK module for creating and importing projects.
3
+ *
4
+ * Provides template generation, project scaffolding, and project detection
5
+ * shared by CLI and Desktop apps.
6
+ */
7
+ export type { TechStack, CodingStandards, GeneratorRepoPattern, ProjectConfig, GenerationResult, CompilrConfig, DetectedProject, GitInfo, ImportProjectConfig, } from './types.js';
8
+ export { TECH_STACK_LABELS, CODING_STANDARDS_LABELS, REPO_PATTERN_LABELS, WORKFLOW_VERSION, } from './types.js';
9
+ export { generateProject, isGitConfigured } from './generator.js';
10
+ export { generateCompilrMd, generateConfigJson, generateReadmeMd, generateCodingStandardsMd, generatePackageJson, generateTsconfig, generateGitignore, generateCompilrMdForImport, } from './templates/index.js';
11
+ export { detectProjectInfo, detectGitInfo, prettifyName, getLanguageLabel, getFrameworkLabel, validateImportPath, isValidProjectName, projectExists, } from './detection.js';
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Project Generator — SDK module for creating and importing projects.
3
+ *
4
+ * Provides template generation, project scaffolding, and project detection
5
+ * shared by CLI and Desktop apps.
6
+ */
7
+ export { TECH_STACK_LABELS, CODING_STANDARDS_LABELS, REPO_PATTERN_LABELS, WORKFLOW_VERSION, } from './types.js';
8
+ // Generator
9
+ export { generateProject, isGitConfigured } from './generator.js';
10
+ // Templates (individual generators for preview/customization)
11
+ export { generateCompilrMd, generateConfigJson, generateReadmeMd, generateCodingStandardsMd, generatePackageJson, generateTsconfig, generateGitignore, generateCompilrMdForImport, } from './templates/index.js';
12
+ // Detection
13
+ export { detectProjectInfo, detectGitInfo, prettifyName, getLanguageLabel, getFrameworkLabel, validateImportPath, isValidProjectName, projectExists, } from './detection.js';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Coding Standards Template Generator
3
+ *
4
+ * Generates the coding standards documentation.
5
+ */
6
+ import type { ProjectConfig } from '../types.js';
7
+ export declare function generateCodingStandardsMd(config: ProjectConfig): string;
@@ -0,0 +1,299 @@
1
+ /**
2
+ * Coding Standards Template Generator
3
+ *
4
+ * Generates the coding standards documentation.
5
+ */
6
+ export function generateCodingStandardsMd(config) {
7
+ if (config.codingStandards === 'custom') {
8
+ return generateCustomTemplate(config);
9
+ }
10
+ return config.codingStandards === 'strict'
11
+ ? generateStrictTemplate(config)
12
+ : generateRelaxedTemplate(config);
13
+ }
14
+ function generateCustomTemplate(config) {
15
+ return `# Coding Standards - ${config.name}
16
+
17
+ *Configure your coding standards here*
18
+
19
+ ---
20
+
21
+ ## TypeScript Configuration
22
+
23
+ \`\`\`json
24
+ // tsconfig.json - customize as needed
25
+ {
26
+ "compilerOptions": {
27
+ "target": "ES2022",
28
+ "module": "NodeNext",
29
+ "strict": true, // Adjust based on preference
30
+ "esModuleInterop": true,
31
+ "skipLibCheck": true,
32
+ "forceConsistentCasingInFileNames": true
33
+ }
34
+ }
35
+ \`\`\`
36
+
37
+ ---
38
+
39
+ ## Linting
40
+
41
+ *Add your ESLint configuration*
42
+
43
+ ---
44
+
45
+ ## Formatting
46
+
47
+ *Add your Prettier configuration*
48
+
49
+ ---
50
+
51
+ ## Git Workflow
52
+
53
+ *Define your branching strategy and commit conventions*
54
+
55
+ ---
56
+
57
+ ## Code Review
58
+
59
+ *Define your code review process*
60
+
61
+ ---
62
+
63
+ *Last Updated: ${new Date().toISOString().split('T')[0]}*
64
+ `;
65
+ }
66
+ function generateStrictTemplate(config) {
67
+ return `# Coding Standards - ${config.name}
68
+
69
+ **Preset:** TypeScript Strict
70
+
71
+ ---
72
+
73
+ ## TypeScript Configuration
74
+
75
+ \`\`\`json
76
+ // tsconfig.json
77
+ {
78
+ "compilerOptions": {
79
+ "target": "ES2022",
80
+ "module": "NodeNext",
81
+ "moduleResolution": "NodeNext",
82
+ "strict": true,
83
+ "noUncheckedIndexedAccess": true,
84
+ "noImplicitReturns": true,
85
+ "noFallthroughCasesInSwitch": true,
86
+ "noUnusedLocals": true,
87
+ "noUnusedParameters": true,
88
+ "exactOptionalPropertyTypes": true,
89
+ "esModuleInterop": true,
90
+ "skipLibCheck": true,
91
+ "forceConsistentCasingInFileNames": true,
92
+ "declaration": true,
93
+ "declarationMap": true,
94
+ "sourceMap": true
95
+ }
96
+ }
97
+ \`\`\`
98
+
99
+ ---
100
+
101
+ ## ESLint Configuration
102
+
103
+ \`\`\`javascript
104
+ // eslint.config.js
105
+ import eslint from '@eslint/js';
106
+ import tseslint from 'typescript-eslint';
107
+
108
+ export default tseslint.config(
109
+ eslint.configs.recommended,
110
+ ...tseslint.configs.strictTypeChecked,
111
+ {
112
+ languageOptions: {
113
+ parserOptions: {
114
+ projectService: true,
115
+ tsconfigRootDir: import.meta.dirname,
116
+ },
117
+ },
118
+ rules: {
119
+ '@typescript-eslint/explicit-function-return-type': 'error',
120
+ '@typescript-eslint/no-explicit-any': 'error',
121
+ '@typescript-eslint/prefer-readonly': 'error',
122
+ '@typescript-eslint/no-unused-vars': [
123
+ 'error',
124
+ { argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
125
+ ],
126
+ },
127
+ }
128
+ );
129
+ \`\`\`
130
+
131
+ ---
132
+
133
+ ## Prettier Configuration
134
+
135
+ \`\`\`json
136
+ // .prettierrc
137
+ {
138
+ "semi": true,
139
+ "singleQuote": true,
140
+ "tabWidth": 2,
141
+ "trailingComma": "es5",
142
+ "printWidth": 100
143
+ }
144
+ \`\`\`
145
+
146
+ ---
147
+
148
+ ## Git Workflow
149
+
150
+ ### Branch Naming
151
+
152
+ \`\`\`
153
+ feat/feature-name # New features
154
+ fix/bug-description # Bug fixes
155
+ docs/update-area # Documentation
156
+ refactor/area # Code refactoring
157
+ \`\`\`
158
+
159
+ ### Commit Messages (Conventional Commits)
160
+
161
+ \`\`\`
162
+ feat: add user authentication
163
+ fix: resolve login redirect issue
164
+ docs: update API documentation
165
+ refactor: simplify database queries
166
+ test: add unit tests for auth module
167
+ chore: update dependencies
168
+ \`\`\`
169
+
170
+ ---
171
+
172
+ ## Code Review Checklist
173
+
174
+ Before merging, verify:
175
+
176
+ - [ ] All tests pass
177
+ - [ ] No TypeScript errors
178
+ - [ ] ESLint passes with no errors
179
+ - [ ] Code follows project patterns
180
+ - [ ] Documentation updated if needed
181
+ - [ ] No sensitive data in commits
182
+
183
+ ---
184
+
185
+ ## File Organization
186
+
187
+ \`\`\`
188
+ src/
189
+ ├── components/ # UI components
190
+ ├── features/ # Feature modules
191
+ ├── lib/ # Shared utilities
192
+ ├── hooks/ # Custom hooks
193
+ ├── types/ # TypeScript types
194
+ └── index.ts # Entry point
195
+ \`\`\`
196
+
197
+ ---
198
+
199
+ *Last Updated: ${new Date().toISOString().split('T')[0]}*
200
+ `;
201
+ }
202
+ function generateRelaxedTemplate(config) {
203
+ return `# Coding Standards - ${config.name}
204
+
205
+ **Preset:** TypeScript Relaxed
206
+
207
+ ---
208
+
209
+ ## TypeScript Configuration
210
+
211
+ \`\`\`json
212
+ // tsconfig.json
213
+ {
214
+ "compilerOptions": {
215
+ "target": "ES2022",
216
+ "module": "NodeNext",
217
+ "moduleResolution": "NodeNext",
218
+ "strict": true,
219
+ "esModuleInterop": true,
220
+ "skipLibCheck": true,
221
+ "forceConsistentCasingInFileNames": true,
222
+ "declaration": true,
223
+ "sourceMap": true
224
+ }
225
+ }
226
+ \`\`\`
227
+
228
+ ---
229
+
230
+ ## ESLint Configuration
231
+
232
+ \`\`\`javascript
233
+ // eslint.config.js
234
+ import eslint from '@eslint/js';
235
+ import tseslint from 'typescript-eslint';
236
+
237
+ export default tseslint.config(
238
+ eslint.configs.recommended,
239
+ ...tseslint.configs.recommended,
240
+ {
241
+ languageOptions: {
242
+ parserOptions: {
243
+ projectService: true,
244
+ tsconfigRootDir: import.meta.dirname,
245
+ },
246
+ },
247
+ rules: {
248
+ '@typescript-eslint/no-unused-vars': [
249
+ 'warn',
250
+ { argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
251
+ ],
252
+ '@typescript-eslint/no-explicit-any': 'warn',
253
+ },
254
+ }
255
+ );
256
+ \`\`\`
257
+
258
+ ---
259
+
260
+ ## Prettier Configuration
261
+
262
+ \`\`\`json
263
+ // .prettierrc
264
+ {
265
+ "semi": true,
266
+ "singleQuote": true,
267
+ "tabWidth": 2,
268
+ "trailingComma": "es5",
269
+ "printWidth": 100
270
+ }
271
+ \`\`\`
272
+
273
+ ---
274
+
275
+ ## Git Workflow
276
+
277
+ ### Commit Messages
278
+
279
+ Use descriptive commit messages. Conventional commits encouraged but not required:
280
+
281
+ \`\`\`
282
+ feat: add user authentication
283
+ fix: resolve login redirect issue
284
+ Update README
285
+ \`\`\`
286
+
287
+ ---
288
+
289
+ ## Code Review
290
+
291
+ - Tests should pass before merging
292
+ - No TypeScript errors
293
+ - Code should be readable
294
+
295
+ ---
296
+
297
+ *Last Updated: ${new Date().toISOString().split('T')[0]}*
298
+ `;
299
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * COMPILR.md Template Generator for Imported Projects
3
+ *
4
+ * Generates the AI assistant context file for existing projects that are being imported.
5
+ * Different from the new project template - acknowledges existing codebase structure.
6
+ */
7
+ import type { ImportProjectConfig } from '../types.js';
8
+ export declare function generateCompilrMdForImport(config: ImportProjectConfig): string;