slicejs-cli 3.6.2 → 3.6.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.
@@ -1,169 +1,169 @@
1
- // commands/utils/VersionChecker.js
2
-
3
- import fs from "fs-extra";
4
- import path from "path";
5
- import { fileURLToPath } from "url";
6
- import Print from "../Print.js";
7
- import { getProjectRoot, getPath } from "../utils/PathHelper.js";
8
- import { resolvePackageManager } from "../utils/PackageManager.js";
9
-
10
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
11
-
12
- class VersionChecker {
13
- constructor() {
14
- this.currentCliVersion = null;
15
- this.currentFrameworkVersion = null;
16
- this.latestCliVersion = null;
17
- this.latestFrameworkVersion = null;
18
- }
19
-
20
- async getCurrentVersions() {
21
- try {
22
- // Get CLI version
23
- const cliPackagePath = path.join(__dirname, '../../package.json');
24
- const cliPackage = await fs.readJson(cliPackagePath);
25
- this.currentCliVersion = cliPackage.version;
26
-
27
- // Get Framework version from project node_modules
28
- const projectRoot = getProjectRoot(import.meta.url);
29
- const frameworkPackagePath = getPath(import.meta.url, 'node_modules', 'slicejs-web-framework', 'package.json');
30
- if (await fs.pathExists(frameworkPackagePath)) {
31
- const frameworkPackage = await fs.readJson(frameworkPackagePath);
32
- this.currentFrameworkVersion = frameworkPackage.version;
33
- }
34
-
35
- // Get Project's CLI version
36
- const projectPackagePath = getPath(import.meta.url, 'package.json');
37
- if (await fs.pathExists(projectPackagePath)) {
38
- const projectPackage = await fs.readJson(projectPackagePath);
39
- if (projectPackage.dependencies && projectPackage.dependencies['slicejs-cli']) {
40
- // This could be different from the currently running CLI version
41
- }
42
- }
43
-
44
- return {
45
- cli: this.currentCliVersion,
46
- framework: this.currentFrameworkVersion
47
- };
48
- } catch (error) {
49
- return null;
50
- }
51
- }
52
-
53
- async getLatestVersions() {
54
- try {
55
- // Check CLI version
56
- const cliResponse = await fetch('https://registry.npmjs.org/slicejs-cli/latest', {
57
- headers: { 'Accept': 'application/json' }
58
- });
59
-
60
- if (cliResponse.ok) {
61
- const cliData = await cliResponse.json();
62
- this.latestCliVersion = cliData.version;
63
- }
64
-
65
- // Check Framework version
66
- const frameworkResponse = await fetch('https://registry.npmjs.org/slicejs-web-framework/latest', {
67
- headers: { 'Accept': 'application/json' }
68
- });
69
-
70
- if (frameworkResponse.ok) {
71
- const frameworkData = await frameworkResponse.json();
72
- this.latestFrameworkVersion = frameworkData.version;
73
- }
74
-
75
- return {
76
- cli: this.latestCliVersion,
77
- framework: this.latestFrameworkVersion
78
- };
79
- } catch (error) {
80
- // Silent fail - don't interrupt commands for version check failures
81
- return null;
82
- }
83
- }
84
-
85
- compareVersions(current, latest) {
86
- if (!current || !latest) return null;
87
-
88
- const currentParts = current.split('.').map(Number);
89
- const latestParts = latest.split('.').map(Number);
90
-
91
- for (let i = 0; i < Math.max(currentParts.length, latestParts.length); i++) {
92
- const currentPart = currentParts[i] || 0;
93
- const latestPart = latestParts[i] || 0;
94
-
95
- if (latestPart > currentPart) return 'outdated';
96
- if (currentPart > latestPart) return 'newer';
97
- }
98
-
99
- return 'current';
100
- }
101
-
102
- async checkForUpdates(silent = false) {
103
- try {
104
- const current = await this.getCurrentVersions();
105
- if (!current) return;
106
-
107
- const latest = await this.getLatestVersions();
108
- if (!latest) return;
109
-
110
- const cliStatus = this.compareVersions(current.cli, latest.cli);
111
- const frameworkStatus = this.compareVersions(current.framework, latest.framework);
112
-
113
- if (!silent && (cliStatus === 'outdated' || frameworkStatus === 'outdated')) {
114
- const pm = resolvePackageManager(getProjectRoot(import.meta.url)).name;
115
- console.log(''); // Line break
116
- Print.warning('šŸ“¦ Available Updates:');
117
-
118
- if (cliStatus === 'outdated') {
119
- console.log(` šŸ”§ CLI: ${current.cli} → ${latest.cli}`);
120
- console.log(` ${pm} update slicejs-cli`);
121
- }
122
-
123
- if (frameworkStatus === 'outdated') {
124
- console.log(` ⚔ Framework: ${current.framework} → ${latest.framework}`);
125
- console.log(` ${pm} update slicejs-web-framework`);
126
- }
127
-
128
- console.log(' šŸ“š Changelog: https://github.com/VKneider/slice.js/releases');
129
- console.log(''); // Line break
130
- }
131
-
132
- return {
133
- cli: { current: current.cli, latest: latest.cli, status: cliStatus },
134
- framework: { current: current.framework, latest: latest.framework, status: frameworkStatus }
135
- };
136
-
137
- } catch (error) {
138
- // Silent fail - don't interrupt commands
139
- return null;
140
- }
141
- }
142
-
143
- async showVersionInfo() {
144
- const current = await this.getCurrentVersions();
145
- const latest = await this.getLatestVersions();
146
-
147
- console.log('\nšŸ“‹ Version Information:');
148
- console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
149
-
150
- if (current?.cli) {
151
- const cliStatus = this.compareVersions(current.cli, latest?.cli);
152
- const statusIcon = cliStatus === 'current' ? 'āœ…' : cliStatus === 'outdated' ? 'šŸ”„' : 'šŸ†•';
153
- console.log(`${statusIcon} CLI: v${current.cli}${latest?.cli && latest.cli !== current.cli ? ` (latest: v${latest.cli})` : ''}`);
154
- }
155
-
156
- if (current?.framework) {
157
- const frameworkStatus = this.compareVersions(current.framework, latest?.framework);
158
- const statusIcon = frameworkStatus === 'current' ? 'āœ…' : frameworkStatus === 'outdated' ? 'šŸ”„' : 'šŸ†•';
159
- console.log(`${statusIcon} Framework: v${current.framework}${latest?.framework && latest.framework !== current.framework ? ` (latest: v${latest.framework})` : ''}`);
160
- }
161
-
162
- console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n');
163
- }
164
- }
165
-
166
- // Singleton instance
167
- const versionChecker = new VersionChecker();
168
-
169
- export default versionChecker;
1
+ // commands/utils/VersionChecker.js
2
+
3
+ import fs from "fs-extra";
4
+ import path from "path";
5
+ import { fileURLToPath } from "url";
6
+ import Print from "../Print.js";
7
+ import { getProjectRoot, getPath } from "../utils/PathHelper.js";
8
+ import { resolvePackageManager } from "../utils/PackageManager.js";
9
+
10
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
11
+
12
+ class VersionChecker {
13
+ constructor() {
14
+ this.currentCliVersion = null;
15
+ this.currentFrameworkVersion = null;
16
+ this.latestCliVersion = null;
17
+ this.latestFrameworkVersion = null;
18
+ }
19
+
20
+ async getCurrentVersions() {
21
+ try {
22
+ // Get CLI version
23
+ const cliPackagePath = path.join(__dirname, '../../package.json');
24
+ const cliPackage = await fs.readJson(cliPackagePath);
25
+ this.currentCliVersion = cliPackage.version;
26
+
27
+ // Get Framework version from project node_modules
28
+ const projectRoot = getProjectRoot(import.meta.url);
29
+ const frameworkPackagePath = getPath(import.meta.url, 'node_modules', 'slicejs-web-framework', 'package.json');
30
+ if (await fs.pathExists(frameworkPackagePath)) {
31
+ const frameworkPackage = await fs.readJson(frameworkPackagePath);
32
+ this.currentFrameworkVersion = frameworkPackage.version;
33
+ }
34
+
35
+ // Get Project's CLI version
36
+ const projectPackagePath = getPath(import.meta.url, 'package.json');
37
+ if (await fs.pathExists(projectPackagePath)) {
38
+ const projectPackage = await fs.readJson(projectPackagePath);
39
+ if (projectPackage.dependencies && projectPackage.dependencies['slicejs-cli']) {
40
+ // This could be different from the currently running CLI version
41
+ }
42
+ }
43
+
44
+ return {
45
+ cli: this.currentCliVersion,
46
+ framework: this.currentFrameworkVersion
47
+ };
48
+ } catch (error) {
49
+ return null;
50
+ }
51
+ }
52
+
53
+ async getLatestVersions() {
54
+ try {
55
+ // Check CLI version
56
+ const cliResponse = await fetch('https://registry.npmjs.org/slicejs-cli/latest', {
57
+ headers: { 'Accept': 'application/json' }
58
+ });
59
+
60
+ if (cliResponse.ok) {
61
+ const cliData = await cliResponse.json();
62
+ this.latestCliVersion = cliData.version;
63
+ }
64
+
65
+ // Check Framework version
66
+ const frameworkResponse = await fetch('https://registry.npmjs.org/slicejs-web-framework/latest', {
67
+ headers: { 'Accept': 'application/json' }
68
+ });
69
+
70
+ if (frameworkResponse.ok) {
71
+ const frameworkData = await frameworkResponse.json();
72
+ this.latestFrameworkVersion = frameworkData.version;
73
+ }
74
+
75
+ return {
76
+ cli: this.latestCliVersion,
77
+ framework: this.latestFrameworkVersion
78
+ };
79
+ } catch (error) {
80
+ // Silent fail - don't interrupt commands for version check failures
81
+ return null;
82
+ }
83
+ }
84
+
85
+ compareVersions(current, latest) {
86
+ if (!current || !latest) return null;
87
+
88
+ const currentParts = current.split('.').map(Number);
89
+ const latestParts = latest.split('.').map(Number);
90
+
91
+ for (let i = 0; i < Math.max(currentParts.length, latestParts.length); i++) {
92
+ const currentPart = currentParts[i] || 0;
93
+ const latestPart = latestParts[i] || 0;
94
+
95
+ if (latestPart > currentPart) return 'outdated';
96
+ if (currentPart > latestPart) return 'newer';
97
+ }
98
+
99
+ return 'current';
100
+ }
101
+
102
+ async checkForUpdates(silent = false) {
103
+ try {
104
+ const current = await this.getCurrentVersions();
105
+ if (!current) return;
106
+
107
+ const latest = await this.getLatestVersions();
108
+ if (!latest) return;
109
+
110
+ const cliStatus = this.compareVersions(current.cli, latest.cli);
111
+ const frameworkStatus = this.compareVersions(current.framework, latest.framework);
112
+
113
+ if (!silent && (cliStatus === 'outdated' || frameworkStatus === 'outdated')) {
114
+ const pm = resolvePackageManager(getProjectRoot(import.meta.url)).name;
115
+ console.log(''); // Line break
116
+ Print.warning('šŸ“¦ Available Updates:');
117
+
118
+ if (cliStatus === 'outdated') {
119
+ console.log(` šŸ”§ CLI: ${current.cli} → ${latest.cli}`);
120
+ console.log(` ${pm} update slicejs-cli`);
121
+ }
122
+
123
+ if (frameworkStatus === 'outdated') {
124
+ console.log(` ⚔ Framework: ${current.framework} → ${latest.framework}`);
125
+ console.log(` ${pm} update slicejs-web-framework`);
126
+ }
127
+
128
+ console.log(' šŸ“š Changelog: https://github.com/VKneider/slice.js/releases');
129
+ console.log(''); // Line break
130
+ }
131
+
132
+ return {
133
+ cli: { current: current.cli, latest: latest.cli, status: cliStatus },
134
+ framework: { current: current.framework, latest: latest.framework, status: frameworkStatus }
135
+ };
136
+
137
+ } catch (error) {
138
+ // Silent fail - don't interrupt commands
139
+ return null;
140
+ }
141
+ }
142
+
143
+ async showVersionInfo() {
144
+ const current = await this.getCurrentVersions();
145
+ const latest = await this.getLatestVersions();
146
+
147
+ console.log('\nšŸ“‹ Version Information:');
148
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
149
+
150
+ if (current?.cli) {
151
+ const cliStatus = this.compareVersions(current.cli, latest?.cli);
152
+ const statusIcon = cliStatus === 'current' ? 'āœ…' : cliStatus === 'outdated' ? 'šŸ”„' : 'šŸ†•';
153
+ console.log(`${statusIcon} CLI: v${current.cli}${latest?.cli && latest.cli !== current.cli ? ` (latest: v${latest.cli})` : ''}`);
154
+ }
155
+
156
+ if (current?.framework) {
157
+ const frameworkStatus = this.compareVersions(current.framework, latest?.framework);
158
+ const statusIcon = frameworkStatus === 'current' ? 'āœ…' : frameworkStatus === 'outdated' ? 'šŸ”„' : 'šŸ†•';
159
+ console.log(`${statusIcon} Framework: v${current.framework}${latest?.framework && latest.framework !== current.framework ? ` (latest: v${latest.framework})` : ''}`);
160
+ }
161
+
162
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n');
163
+ }
164
+ }
165
+
166
+ // Singleton instance
167
+ const versionChecker = new VersionChecker();
168
+
169
+ export default versionChecker;