@jatinmourya/ng-init 1.0.0

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.
@@ -0,0 +1,169 @@
1
+ import { execa } from 'execa';
2
+ import chalk from 'chalk';
3
+ import semver from 'semver';
4
+
5
+ /**
6
+ * Get the current Node.js version
7
+ */
8
+ export async function getNodeVersion() {
9
+ try {
10
+ const { stdout } = await execa('node', ['--version']);
11
+ return stdout.trim().replace('v', '');
12
+ } catch (error) {
13
+ return null;
14
+ }
15
+ }
16
+
17
+ /**
18
+ * Get the current npm version
19
+ */
20
+ export async function getNpmVersion() {
21
+ try {
22
+ const { stdout } = await execa('npm', ['--version']);
23
+ return stdout.trim();
24
+ } catch (error) {
25
+ return null;
26
+ }
27
+ }
28
+
29
+ /**
30
+ * Get the current nvm version
31
+ */
32
+ export async function getNvmVersion() {
33
+ try {
34
+ const { stdout } = await execa('nvm', ['--version'], { shell: true });
35
+ return stdout.trim();
36
+ } catch (error) {
37
+ return null;
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Check if nvm is installed
43
+ */
44
+ export async function isNvmInstalled() {
45
+ const version = await getNvmVersion();
46
+ return version !== null;
47
+ }
48
+
49
+ /**
50
+ * Get the current Angular CLI version
51
+ */
52
+ export async function getAngularCliVersion() {
53
+ try {
54
+ const { stdout } = await execa('ng', ['version'], { shell: true });
55
+ const match = stdout.match(/Angular CLI: (\d+\.\d+\.\d+)/);
56
+ return match ? match[1] : null;
57
+ } catch (error) {
58
+ return null;
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Display all system versions
64
+ */
65
+ export async function displaySystemVersions() {
66
+ console.log(chalk.bold.cyan('\nšŸ” System Environment Check\n'));
67
+ console.log(chalk.gray('━'.repeat(50)));
68
+
69
+ const nodeVersion = await getNodeVersion();
70
+ const npmVersion = await getNpmVersion();
71
+ const nvmVersion = await getNvmVersion();
72
+ const ngVersion = await getAngularCliVersion();
73
+
74
+ console.log(chalk.white('Node.js: ') + (nodeVersion ? chalk.green(`v${nodeVersion}`) : chalk.red('Not installed')));
75
+ console.log(chalk.white('npm: ') + (npmVersion ? chalk.green(`v${npmVersion}`) : chalk.red('Not installed')));
76
+ console.log(chalk.white('nvm: ') + (nvmVersion ? chalk.green(`v${nvmVersion}`) : chalk.yellow('Not installed')));
77
+ console.log(chalk.white('Angular CLI: ') + (ngVersion ? chalk.green(`v${ngVersion}`) : chalk.yellow('Not installed')));
78
+
79
+ console.log(chalk.gray('━'.repeat(50)) + '\n');
80
+
81
+ return {
82
+ node: nodeVersion,
83
+ npm: npmVersion,
84
+ nvm: nvmVersion,
85
+ angularCli: ngVersion
86
+ };
87
+ }
88
+
89
+ /**
90
+ * Get available Node versions from nvm
91
+ */
92
+ export async function getAvailableNodeVersions() {
93
+ try {
94
+ const { stdout } = await execa('nvm', ['list', 'available'], { shell: true });
95
+ const versions = [];
96
+ const lines = stdout.split('\n');
97
+
98
+ for (const line of lines) {
99
+ const match = line.match(/(\d+\.\d+\.\d+)/);
100
+ if (match) {
101
+ versions.push(match[1]);
102
+ }
103
+ }
104
+
105
+ return versions;
106
+ } catch (error) {
107
+ return [];
108
+ }
109
+ }
110
+
111
+ /**
112
+ * Get installed Node versions from nvm
113
+ */
114
+ export async function getInstalledNodeVersions() {
115
+ try {
116
+ const { stdout } = await execa('nvm', ['list'], { shell: true });
117
+ const versions = [];
118
+ const lines = stdout.split('\n');
119
+
120
+ for (const line of lines) {
121
+ const match = line.match(/(\d+\.\d+\.\d+)/);
122
+ if (match) {
123
+ versions.push(match[1]);
124
+ }
125
+ }
126
+
127
+ return versions;
128
+ } catch (error) {
129
+ return [];
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Switch Node version using nvm
135
+ */
136
+ export async function switchNodeVersion(version) {
137
+ try {
138
+ await execa('nvm', ['use', version], { shell: true, stdio: 'inherit' });
139
+ return true;
140
+ } catch (error) {
141
+ return false;
142
+ }
143
+ }
144
+
145
+ /**
146
+ * Install Node version using nvm
147
+ */
148
+ export async function installNodeVersion(version) {
149
+ try {
150
+ await execa('nvm', ['install', version], { shell: true, stdio: 'inherit' });
151
+ return true;
152
+ } catch (error) {
153
+ return false;
154
+ }
155
+ }
156
+
157
+ /**
158
+ * Compare two semantic versions
159
+ */
160
+ export function compareVersions(v1, v2) {
161
+ return semver.compare(v1, v2);
162
+ }
163
+
164
+ /**
165
+ * Check if version satisfies range
166
+ */
167
+ export function satisfiesVersion(version, range) {
168
+ return semver.satisfies(version, range);
169
+ }