@diagramers/cli 1.0.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 (46) hide show
  1. package/README.md +91 -0
  2. package/dist/commands/extend.d.ts +3 -0
  3. package/dist/commands/extend.d.ts.map +1 -0
  4. package/dist/commands/extend.js +37 -0
  5. package/dist/commands/extend.js.map +1 -0
  6. package/dist/commands/init.d.ts +3 -0
  7. package/dist/commands/init.d.ts.map +1 -0
  8. package/dist/commands/init.js +31 -0
  9. package/dist/commands/init.js.map +1 -0
  10. package/dist/commands/update.d.ts +3 -0
  11. package/dist/commands/update.d.ts.map +1 -0
  12. package/dist/commands/update.js +29 -0
  13. package/dist/commands/update.js.map +1 -0
  14. package/dist/config/template-config.d.ts +21 -0
  15. package/dist/config/template-config.d.ts.map +1 -0
  16. package/dist/config/template-config.js +93 -0
  17. package/dist/config/template-config.js.map +1 -0
  18. package/dist/index.d.ts +3 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +30 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/services/project-extender.d.ts +15 -0
  23. package/dist/services/project-extender.d.ts.map +1 -0
  24. package/dist/services/project-extender.js +207 -0
  25. package/dist/services/project-extender.js.map +1 -0
  26. package/dist/services/project-initializer.d.ts +15 -0
  27. package/dist/services/project-initializer.d.ts.map +1 -0
  28. package/dist/services/project-initializer.js +240 -0
  29. package/dist/services/project-initializer.js.map +1 -0
  30. package/dist/services/project-updater.d.ts +16 -0
  31. package/dist/services/project-updater.d.ts.map +1 -0
  32. package/dist/services/project-updater.js +134 -0
  33. package/dist/services/project-updater.js.map +1 -0
  34. package/package.json +51 -0
  35. package/scripts/publish.sh +58 -0
  36. package/scripts/setup.sh +38 -0
  37. package/scripts/version.sh +80 -0
  38. package/src/commands/extend.ts +35 -0
  39. package/src/commands/init.ts +27 -0
  40. package/src/commands/update.ts +25 -0
  41. package/src/config/template-config.ts +111 -0
  42. package/src/index.ts +35 -0
  43. package/src/services/project-extender.ts +196 -0
  44. package/src/services/project-initializer.ts +224 -0
  45. package/src/services/project-updater.ts +125 -0
  46. package/tsconfig.json +19 -0
@@ -0,0 +1,125 @@
1
+ import * as fs from 'fs-extra';
2
+ import * as path from 'path';
3
+ import * as glob from 'glob';
4
+ import chalk from 'chalk';
5
+
6
+ export interface UpdateOptions {
7
+ force?: boolean;
8
+ backup?: boolean;
9
+ }
10
+
11
+ export class ProjectUpdater {
12
+ private templatePath: string;
13
+ private currentProjectPath: string;
14
+
15
+ constructor() {
16
+ this.templatePath = path.resolve(__dirname, '../../..');
17
+ this.currentProjectPath = process.cwd();
18
+ }
19
+
20
+ async update(options: UpdateOptions): Promise<void> {
21
+ // Check if we're in a valid project directory
22
+ if (!await this.isValidProject()) {
23
+ throw new Error('Not a valid project directory. Please run this command from your project root.');
24
+ }
25
+
26
+ // Create backup if requested
27
+ if (options.backup) {
28
+ await this.createBackup();
29
+ }
30
+
31
+ // Get list of files that can be updated
32
+ const updateableFiles = await this.getUpdateableFiles();
33
+
34
+ // Check for conflicts
35
+ const conflicts = await this.checkConflicts(updateableFiles);
36
+
37
+ if (conflicts.length > 0 && !options.force) {
38
+ console.log(chalk.yellow('⚠️ Conflicts detected in the following files:'));
39
+ conflicts.forEach(file => console.log(chalk.yellow(` - ${file}`)));
40
+ console.log(chalk.yellow('Use --force to overwrite these files'));
41
+ throw new Error('Update aborted due to conflicts');
42
+ }
43
+
44
+ // Perform the update
45
+ await this.performUpdate(updateableFiles);
46
+
47
+ console.log(chalk.green('✅ Project updated successfully!'));
48
+ }
49
+
50
+ private async isValidProject(): Promise<boolean> {
51
+ const packageJsonPath = path.join(this.currentProjectPath, 'package.json');
52
+ const mainTsPath = path.join(this.currentProjectPath, 'main.ts');
53
+
54
+ return await fs.pathExists(packageJsonPath) && await fs.pathExists(mainTsPath);
55
+ }
56
+
57
+ private async createBackup(): Promise<void> {
58
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
59
+ const backupPath = path.join(this.currentProjectPath, `backup-${timestamp}`);
60
+
61
+ await fs.copy(this.currentProjectPath, backupPath, {
62
+ filter: (src) => {
63
+ const relativePath = path.relative(this.currentProjectPath, src);
64
+ return !relativePath.startsWith('node_modules') &&
65
+ !relativePath.startsWith('.git') &&
66
+ !relativePath.startsWith('backup-');
67
+ }
68
+ });
69
+
70
+ console.log(chalk.blue(`📦 Backup created at: ${backupPath}`));
71
+ }
72
+
73
+ private async getUpdateableFiles(): Promise<string[]> {
74
+ const templateFiles = [
75
+ 'src/helpers/**/*',
76
+ 'src/config/**/*',
77
+ 'src/server/**/*',
78
+ 'webpack.config.js',
79
+ 'tsconfig.json'
80
+ ];
81
+
82
+ const files: string[] = [];
83
+
84
+ for (const pattern of templateFiles) {
85
+ const matches = glob.sync(pattern, { cwd: this.templatePath });
86
+ files.push(...matches);
87
+ }
88
+
89
+ return files;
90
+ }
91
+
92
+ private async checkConflicts(files: string[]): Promise<string[]> {
93
+ const conflicts: string[] = [];
94
+
95
+ for (const file of files) {
96
+ const templatePath = path.join(this.templatePath, file);
97
+ const projectPath = path.join(this.currentProjectPath, file);
98
+
99
+ if (await fs.pathExists(projectPath)) {
100
+ const templateContent = await fs.readFile(templatePath, 'utf8');
101
+ const projectContent = await fs.readFile(projectPath, 'utf8');
102
+
103
+ // Simple conflict detection - if files are different
104
+ if (templateContent !== projectContent) {
105
+ conflicts.push(file);
106
+ }
107
+ }
108
+ }
109
+
110
+ return conflicts;
111
+ }
112
+
113
+ private async performUpdate(files: string[]): Promise<void> {
114
+ for (const file of files) {
115
+ const templatePath = path.join(this.templatePath, file);
116
+ const projectPath = path.join(this.currentProjectPath, file);
117
+
118
+ if (await fs.pathExists(templatePath)) {
119
+ await fs.ensureDir(path.dirname(projectPath));
120
+ await fs.copy(templatePath, projectPath);
121
+ console.log(chalk.green(`✅ Updated: ${file}`));
122
+ }
123
+ }
124
+ }
125
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "lib": ["ES2020"],
6
+ "outDir": "./dist",
7
+ "rootDir": "./src",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "resolveJsonModule": true,
13
+ "declaration": true,
14
+ "declarationMap": true,
15
+ "sourceMap": true
16
+ },
17
+ "include": ["src/**/*"],
18
+ "exclude": ["node_modules", "dist"]
19
+ }