Skip to content

Commit

Permalink
feat(focus): flexibility with targeting for vs code
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanWalker committed Aug 20, 2020
1 parent 38418ae commit 6aedf1b
Show file tree
Hide file tree
Showing 9 changed files with 1,498 additions and 2,057 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@nstudio/xplat-source",
"version": "10.0.2",
"version": "10.0.6",
"description": "Cross-platform (xplat) tools for Nx workspaces.",
"homepage": "https://nstudio.io/xplat",
"private": true,
"scripts": {
"build": "./scripts/package.sh --local",
"clean": "npx rimraf -- package-lock.json node_modules",
"clean": "npx rimraf package-lock.json node_modules",
"commit": "git-cz",
"checkcommit": "node ./scripts/commit-lint.js",
"e2e": "./scripts/e2e.sh",
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"migrations": "./migrations.json"
},
"dependencies": {
"@nrwl/angular": "^9.0.0"
"@nrwl/angular": "^10.0.0"
},
"peerDependencies": {
"@nstudio/xplat": "*"
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/utils/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ export function adjustRouting(
path: '${featureName}',
loadChildren: () => import('./features/${featureName}/${featureName}.module').then(m => m.${stringUtils.classify(
featureName
)}Module)'
)}Module)
}`
)
);
Expand Down
90 changes: 48 additions & 42 deletions packages/focus/src/schematics/mode/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { chain, Tree, SchematicContext, noop } from '@angular-devkit/schematics';
import {
chain,
Tree,
SchematicContext,
noop,
} from '@angular-devkit/schematics';

import { updateTsConfig, XplatHelpers } from '@nstudio/xplat';
// import { updateTsConfig, XplatHelpers } from '@nstudio/xplat';
import {
PlatformTypes,
supportedPlatforms,
Expand All @@ -18,8 +23,11 @@ let name: PlatformModes;
export default function (options: Schema) {
if (!options.name) {
name = 'fullstack';
const extraNote = isXplatWorkspace()
? ` Currently supported: fullstack,${supportedPlatformsWithNx}. Example: nx g mode nativescript`
: '';
console.warn(
`Using 'fullstack' since no mode was specified. Currently supported: fullstack,${supportedPlatformsWithNx}. Example: nx g mode nativescript`
`Defaulting to 'fullstack' and showing everything since no focus was specified.${extraNote}`
);
} else {
name = <PlatformModes>options.name;
Expand All @@ -29,9 +37,9 @@ export default function (options: Schema) {
// init xplat settings
prerun(),
// update tsconfig based on mode
(tree: Tree) => {
return isXplatWorkspace() ? updateExcludes(name)(tree) : noop()
},
// (tree: Tree) => {
// return isXplatWorkspace() ? updateExcludes(name)(tree) : noop();
// },
// update IDE settings
(tree: Tree, context: SchematicContext) => {
// apps
Expand Down Expand Up @@ -67,7 +75,7 @@ export default function (options: Schema) {
// project handling
let focusOnApps: string[] = [];
if (name !== 'fullstack' && options.projects) {
focusOnApps = options.projects.split(',');
focusOnApps = options.projects.split(',').map((p) => p.trim());
if (isXplatWorkspace()) {
// allows for shorthand project/app names omitting platform from the app name
// just add platform to the name to be specific
Expand All @@ -92,42 +100,40 @@ export default function (options: Schema) {
}
}
// targets and mode should be the same
return FocusHelpers.updateIDESettings(
{
platforms: name,
devMode: name,
allApps,
focusOnApps,
allLibs,
allPackages
},
)(tree, context);
return FocusHelpers.updateIDESettings({
platforms: name,
devMode: name,
allApps,
focusOnApps,
allLibs,
allPackages,
})(tree, context);
},
]);
}

function updateExcludes(devMode: PlatformModes) {
return (tree: Tree) => {
return updateTsConfig(tree, (tsConfig: any) => {
if (tsConfig) {
if (!tsConfig.exclude) {
tsConfig.exclude = [];
}
const tnsRefs = 'references.d.ts';
if (devMode === 'nativescript' || devMode === 'fullstack') {
const index = tsConfig.exclude.findIndex(
(entry) => entry === tnsRefs
);
if (index > -1) {
tsConfig.exclude.splice(index, 1);
}
} else {
// when not doing {N} development, alleviate pressue on TS resolution
if (!tsConfig.exclude.includes(tnsRefs)) {
tsConfig.exclude.push('references.d.ts');
}
}
}
});
};
}
// function updateExcludes(devMode: PlatformModes) {
// return (tree: Tree) => {
// return updateTsConfig(tree, (tsConfig: any) => {
// if (tsConfig) {
// if (!tsConfig.exclude) {
// tsConfig.exclude = [];
// }
// const tnsRefs = 'references.d.ts';
// if (devMode === 'nativescript' || devMode === 'fullstack') {
// const index = tsConfig.exclude.findIndex(
// (entry) => entry === tnsRefs
// );
// if (index > -1) {
// tsConfig.exclude.splice(index, 1);
// }
// } else {
// // when not doing {N} development, alleviate pressue on TS resolution
// if (!tsConfig.exclude.includes(tnsRefs)) {
// tsConfig.exclude.push('references.d.ts');
// }
// }
// }
// });
// };
// }
135 changes: 86 additions & 49 deletions packages/focus/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ import { serializeJson } from '@nrwl/workspace';
import * as xml2js from 'xml2js';

export namespace FocusHelpers {
export function updateIDESettings(
options: {
platforms?: string;
devMode?: PlatformModes;
allApps?: string[];
focusOnApps?: string[];
allLibs?: string[];
allPackages?: string[];
}
) {
export function updateIDESettings(options: {
platforms?: string;
devMode?: PlatformModes;
allApps?: string[];
focusOnApps?: string[];
allLibs?: string[];
allPackages?: string[];
}) {
return (tree: Tree, context: SchematicContext) => {
if (isTesting()) {
// ignore node file modifications when just testing
Expand Down Expand Up @@ -69,13 +67,13 @@ export namespace FocusHelpers {
}
} else {
for (const p of options.allApps) {
userUpdates[`**/apps/${p}`] = false;
userUpdates[p] = false;
}
for (const p of options.allLibs) {
userUpdates[`**/libs/${p}`] = false;
userUpdates[p] = false;
}
for (const p of options.allPackages) {
userUpdates[`**/packages/${p}`] = false;
userUpdates[p] = false;
}
}
} else if (options.platforms) {
Expand All @@ -97,29 +95,46 @@ export namespace FocusHelpers {
if (frameworkSuffix) {
userUpdates[`**/xplat/${p}${frameworkSuffix}`] = excluded;
}

if (excluded) {
// if excluding any platform at all, set the flag
// this is used for WebStorm support below
isExcluding = true;
}
}
} else {
// switch on/off apps/libs/packages
// switch on/off apps
for (const p of options.allApps) {
userUpdates[`**/apps/${p}`] = options.focusOnApps && options.focusOnApps.length && options.focusOnApps.includes(p) ? false : true;
}
for (const p of options.allLibs) {
userUpdates[`**/libs/${p}`] = platforms.includes(p) ? false : true;
const appName = p.replace('**/apps/', '');
// first reset all in case no focusing
userUpdates[p] = false;
if (options.focusOnApps && options.focusOnApps.length) {
userUpdates[p] =
options.focusOnApps &&
options.focusOnApps.length &&
options.focusOnApps.includes(appName)
? false
: true;
}
}
for (const p of options.allPackages) {
userUpdates[`**/packages/${p}`] = platforms.includes(p) ? false : true;
// switch on/off libs/packages
for (const target of platforms) {
for (const p of options.allLibs) {
const libName = p.replace('**/libs/', '');
userUpdates[p] = libName === target ? false : true;
}
for (const p of options.allPackages) {
const packageName = p.replace('**/packages/', '');
userUpdates[p] = packageName === target ? false : true;
}
}
}
}

// always ensure hidden xplat files are hidden from view
userUpdates['**/xplat/*/.xplatframework'] = true;
if (isXplatWorkspace()) {
// always ensure hidden xplat files are hidden from view
userUpdates['**/xplat/*/.xplatframework'] = true;
}

// VS Code
const isVsCode = updateVSCode({
Expand All @@ -143,7 +158,7 @@ export namespace FocusHelpers {
isFullstack,
});

if (!options.devMode) {
if (isXplatWorkspace() && !options.devMode) {
// only when not specifying a dev mode
const workspaceUpdates: any = {
'**/node_modules': true,
Expand Down Expand Up @@ -265,32 +280,34 @@ export namespace FocusHelpers {
options.userUpdates
);

if (options.allApps.length) {
// always reset specific app filters
for (const app of options.allApps) {
delete userSettingsJson['files.exclude'][app];
delete userSettingsJson['search.exclude'][app];
}
}
if (
!options.isFullstack &&
options.focusOnApps.length &&
options.allApps.length
) {
// when focusing on projects, clear all specific app wildcards first if they exist
for (const wildcard of options.appWildcards) {
delete userSettingsJson['files.exclude'][wildcard];
delete userSettingsJson['search.exclude'][wildcard];
}
for (const focusApp of options.focusOnApps) {
userSettingsJson['files.exclude'][focusApp] = false;
userSettingsJson['search.exclude'][focusApp] = false;
if (isXplatWorkspace()) {
if (options.allApps.length) {
// always reset specific app filters
for (const app of options.allApps) {
delete userSettingsJson['files.exclude'][app];
delete userSettingsJson['search.exclude'][app];
}
}
// ensure all other apps are excluded (except for the one that's being focused on)
for (const app of options.allApps) {
if (!options.focusOnApps.includes(app)) {
userSettingsJson['files.exclude'][app] = true;
userSettingsJson['search.exclude'][app] = true;
if (
!options.isFullstack &&
options.focusOnApps.length &&
options.allApps.length
) {
// when focusing on projects, clear all specific app wildcards first if they exist
for (const wildcard of options.appWildcards) {
delete userSettingsJson['files.exclude'][wildcard];
delete userSettingsJson['search.exclude'][wildcard];
}
for (const focusApp of options.focusOnApps) {
userSettingsJson['files.exclude'][focusApp] = false;
userSettingsJson['search.exclude'][focusApp] = false;
}
// ensure all other apps are excluded (except for the one that's being focused on)
for (const app of options.allApps) {
if (!options.focusOnApps.includes(app)) {
userSettingsJson['files.exclude'][app] = true;
userSettingsJson['search.exclude'][app] = true;
}
}
}
}
Expand All @@ -299,6 +316,26 @@ export namespace FocusHelpers {
userSettingsVSCodePath,
serializeJson(userSettingsJson)
);

// TODO: print out the updates made
// Example of how the updates are represented
// true === hidden
// false === show
// {
// '**/apps/automated': false,
// '**/apps/toolbox': false,
// '**/apps/ui': false,
// '**/packages/core': true,
// '**/packages/core-compat': true,
// '**/packages/types-android': true,
// '**/packages/types-ios': true,
// '**/packages/ui-mobile-base': true,
// '**/packages/webpack': false
// }

// console.log(
// `VS Code Updated.`
// );
} else {
console.warn(
`Warning: xplat could not read your VS Code settings.json file therefore development mode has not been set. ${vscodeCreateSettingsNote}`
Expand Down
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"migrations": "./migrations.json"
},
"dependencies": {
"@nrwl/web": "^9.0.0"
"@nrwl/web": "^10.0.0"
},
"peerDependencies": {
"@nstudio/xplat": "*"
Expand Down
Loading

0 comments on commit 6aedf1b

Please sign in to comment.