@nstudio/focus 15.0.3 → 15.0.4-rc.1

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 (2) hide show
  1. package/package.json +2 -2
  2. package/src/utils/index.js +65 -63
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nstudio/focus",
3
- "version": "15.0.3",
3
+ "version": "15.0.4-rc.1",
4
4
  "description": "Focus helpers for monorepos in various IDEs",
5
5
  "homepage": "https://nstudio.io/xplat",
6
6
  "repository": {
@@ -32,7 +32,7 @@
32
32
  "dependencies": {
33
33
  "@angular-devkit/core": "^15.0.0",
34
34
  "@angular-devkit/schematics": "^15.0.0",
35
- "@nstudio/xplat-utils": "15.0.3",
35
+ "@nstudio/xplat-utils": "15.0.4-rc.1",
36
36
  "xml2js": "~0.4.23"
37
37
  }
38
38
  }
@@ -113,7 +113,7 @@ var FocusHelpers;
113
113
  }
114
114
  // VS Code
115
115
  const isVsCode = updateVSCode({
116
- userUpdates,
116
+ workspaceUpdates: userUpdates,
117
117
  allApps: options.allApps,
118
118
  focusOnApps: options.focusOnApps,
119
119
  appWildcards,
@@ -187,6 +187,63 @@ var FocusHelpers;
187
187
  };
188
188
  }
189
189
  FocusHelpers.updateIDESettings = updateIDESettings;
190
+ function generateVSCodeUpdatedSettings(currentSettings, updates, options) {
191
+ const newSettings = {
192
+ 'files.exclude': {},
193
+ 'search.exclude': {},
194
+ };
195
+ let exclude = currentSettings['files.exclude'] || {};
196
+ let searchExclude = currentSettings['search.exclude'] || {};
197
+ newSettings['files.exclude'] = Object.assign(Object.assign({}, exclude), updates);
198
+ newSettings['search.exclude'] = Object.assign(Object.assign({}, searchExclude), updates);
199
+ if ((0, xplat_utils_1.isXplatWorkspace)()) {
200
+ if (options.allApps.length) {
201
+ // always reset specific app filters
202
+ for (const app of options.allApps) {
203
+ delete newSettings['files.exclude'][app];
204
+ delete newSettings['search.exclude'][app];
205
+ }
206
+ }
207
+ if (!options.isFullstack &&
208
+ options.focusOnApps.length &&
209
+ options.allApps.length) {
210
+ // when focusing on projects, clear all specific app wildcards first if they exist
211
+ for (const wildcard of options.appWildcards) {
212
+ delete newSettings['files.exclude'][wildcard];
213
+ delete newSettings['search.exclude'][wildcard];
214
+ }
215
+ for (const focusApp of options.focusOnApps) {
216
+ newSettings['files.exclude'][focusApp] = false;
217
+ newSettings['search.exclude'][focusApp] = false;
218
+ }
219
+ // ensure all other apps are excluded (except for the one that's being focused on)
220
+ // also support focusing on apps/{subfolder}/*
221
+ // if focusing on specific apps but there's no direct match of the focus target in allApps listing, it's a subfolder
222
+ const isFocusingOnAppSubFolder = options.focusOnApps.filter((a) => options.allApps.includes(a))
223
+ .length === 0;
224
+ for (const app of options.allApps) {
225
+ if (!options.focusOnApps.includes(app)) {
226
+ let skipExcluding = false;
227
+ if (isFocusingOnAppSubFolder) {
228
+ // see if beginning path of app is in the focused subfolder
229
+ for (const focus of options.focusOnApps) {
230
+ if (app.indexOf(focus) === 0) {
231
+ // console.log('found app in focused folder:', app)
232
+ skipExcluding = true;
233
+ }
234
+ }
235
+ }
236
+ if (!skipExcluding) {
237
+ // console.log('hiding app:', app)
238
+ newSettings['files.exclude'][app] = true;
239
+ newSettings['search.exclude'][app] = true;
240
+ }
241
+ }
242
+ }
243
+ }
244
+ }
245
+ return Object.assign(Object.assign({}, currentSettings), newSettings);
246
+ }
190
247
  function updateVSCode(options) {
191
248
  // VS Code support
192
249
  let isVsCode;
@@ -215,63 +272,8 @@ var FocusHelpers;
215
272
  });
216
273
  if (userSettings) {
217
274
  const userSettingsJson = (0, xplat_utils_1.jsonParse)(userSettings);
218
- let exclude = userSettingsJson['files.exclude'];
219
- if (!exclude) {
220
- exclude = {};
221
- }
222
- let searchExclude = userSettingsJson['search.exclude'];
223
- if (!searchExclude) {
224
- searchExclude = {};
225
- }
226
- userSettingsJson['files.exclude'] = Object.assign(exclude, options.userUpdates);
227
- userSettingsJson['search.exclude'] = Object.assign(searchExclude, options.userUpdates);
228
- if ((0, xplat_utils_1.isXplatWorkspace)()) {
229
- if (options.allApps.length) {
230
- // always reset specific app filters
231
- for (const app of options.allApps) {
232
- delete userSettingsJson['files.exclude'][app];
233
- delete userSettingsJson['search.exclude'][app];
234
- }
235
- }
236
- if (!options.isFullstack &&
237
- options.focusOnApps.length &&
238
- options.allApps.length) {
239
- // when focusing on projects, clear all specific app wildcards first if they exist
240
- for (const wildcard of options.appWildcards) {
241
- delete userSettingsJson['files.exclude'][wildcard];
242
- delete userSettingsJson['search.exclude'][wildcard];
243
- }
244
- for (const focusApp of options.focusOnApps) {
245
- userSettingsJson['files.exclude'][focusApp] = false;
246
- userSettingsJson['search.exclude'][focusApp] = false;
247
- }
248
- // ensure all other apps are excluded (except for the one that's being focused on)
249
- // also support focusing on apps/{subfolder}/*
250
- // if focusing on specific apps but there's no direct match of the focus target in allApps listing, it's a subfolder
251
- const isFocusingOnAppSubFolder = options.focusOnApps.filter((a) => options.allApps.includes(a))
252
- .length === 0;
253
- for (const app of options.allApps) {
254
- if (!options.focusOnApps.includes(app)) {
255
- let skipExcluding = false;
256
- if (isFocusingOnAppSubFolder) {
257
- // see if beginning path of app is in the focused subfolder
258
- for (const focus of options.focusOnApps) {
259
- if (app.indexOf(focus) === 0) {
260
- // console.log('found app in focused folder:', app)
261
- skipExcluding = true;
262
- }
263
- }
264
- }
265
- if (!skipExcluding) {
266
- // console.log('hiding app:', app)
267
- userSettingsJson['files.exclude'][app] = true;
268
- userSettingsJson['search.exclude'][app] = true;
269
- }
270
- }
271
- }
272
- }
273
- }
274
- (0, fs_1.writeFileSync)(userSettingsVSCodePath, (0, devkit_1.serializeJson)(userSettingsJson));
275
+ const newSettings = generateVSCodeUpdatedSettings(userSettingsJson, options.userUpdates, options);
276
+ (0, fs_1.writeFileSync)(userSettingsVSCodePath, (0, devkit_1.serializeJson)(newSettings));
275
277
  // TODO: print out the updates made
276
278
  // Example of how the updates are represented
277
279
  // true === hidden
@@ -311,15 +313,15 @@ var FocusHelpers;
311
313
  encoding: 'utf-8',
312
314
  });
313
315
  workspaceSettingsJson = (0, xplat_utils_1.jsonParse)(workspaceSettings);
314
- const exclude = workspaceSettingsJson['files.exclude'];
315
- workspaceSettingsJson['files.exclude'] = Object.assign(exclude, options.workspaceUpdates);
316
316
  }
317
317
  else {
318
318
  // console.log('creating workspace settings...');
319
- (0, fs_1.mkdirSync)('.vscode');
320
- workspaceSettingsJson['files.exclude'] = options.workspaceUpdates;
319
+ (0, fs_1.mkdirSync)('.vscode', {
320
+ recursive: true // ignore error if exists
321
+ });
321
322
  }
322
- (0, fs_1.writeFileSync)(workspaceSettingsPath, (0, devkit_1.serializeJson)(workspaceSettingsJson));
323
+ const newSettings = generateVSCodeUpdatedSettings(workspaceSettingsJson, options.workspaceUpdates, options);
324
+ (0, fs_1.writeFileSync)(workspaceSettingsPath, (0, devkit_1.serializeJson)(newSettings));
323
325
  }
324
326
  return isVsCode;
325
327
  }