neo-cmp-cli 1.7.6 → 1.7.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo-cmp-cli",
3
- "version": "1.7.6",
3
+ "version": "1.7.7",
4
4
  "description": "前端脚手架:自定义组件开发工具,支持react 和 vue2.0技术栈。",
5
5
  "keywords": [
6
6
  "neo-cli",
@@ -144,13 +144,52 @@ class NeoLoginService {
144
144
  /**
145
145
  * 打开浏览器访问授权 URL
146
146
  * @param {string} authUrl 授权 URL
147
+ * @param {boolean} incognito 是否使用无痕模式,默认为 true
147
148
  */
148
- async openBrowser(authUrl) {
149
+ async openBrowser(authUrl, incognito = true) {
149
150
  try {
150
- await open(authUrl);
151
+ const options = {};
152
+
153
+ if (incognito) {
154
+ const platform = process.platform;
155
+
156
+ // 根据不同平台和浏览器设置无痕模式参数
157
+ if (platform === 'darwin') {
158
+ // macOS: 优先使用 Chrome,其次 Safari
159
+ options.app = {
160
+ name: 'google chrome',
161
+ arguments: ['--incognito']
162
+ };
163
+ } else if (platform === 'win32') {
164
+ // Windows: 优先使用 Chrome,其次 Edge
165
+ options.app = {
166
+ name: 'chrome',
167
+ arguments: ['--incognito']
168
+ };
169
+ } else {
170
+ // Linux 或其他平台
171
+ options.app = {
172
+ name: 'google-chrome',
173
+ arguments: ['--incognito']
174
+ };
175
+ }
176
+ }
177
+
178
+ await open(authUrl, options);
151
179
  } catch (error) {
152
- errorLog(`无法自动打开浏览器: ${error.message}`);
153
- console.log(`\n请手动访问以下 URL 进行授权:\n${authUrl}\n`);
180
+ // 如果指定的浏览器打开失败,尝试使用默认浏览器
181
+ if (incognito && error.message && error.message.includes('spawn')) {
182
+ try {
183
+ console.log('无法使用无痕模式打开指定浏览器,尝试使用默认浏览器...');
184
+ await open(authUrl);
185
+ } catch (fallbackError) {
186
+ errorLog(`无法自动打开浏览器: ${fallbackError.message}`);
187
+ console.log(`\n请手动访问以下 URL 进行授权:\n${authUrl}\n`);
188
+ }
189
+ } else {
190
+ errorLog(`无法自动打开浏览器: ${error.message}`);
191
+ console.log(`\n请手动访问以下 URL 进行授权:\n${authUrl}\n`);
192
+ }
154
193
  }
155
194
  }
156
195