Skip to content

Commit

Permalink
fix(mode): app focus mode
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanWalker committed Mar 10, 2019
1 parent c13914b commit ebe01cd
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 46 deletions.
50 changes: 27 additions & 23 deletions src/mode/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
updateIDESettings,
supportedPlatforms,
updateTsConfig,
prerun
prerun,
getGroupByName
} from "../utils";
import { Schema as xPlatOptions } from "./schema";

Expand All @@ -19,25 +20,6 @@ export default function(options: xPlatOptions) {
} else {
name = options.name;
}
let projectNames: string[] = [];
if (name !== "fullstack" && options.projects) {
projectNames = options.projects.split(",");
for (let i = 0; i < projectNames.length; i++) {
const projectName = projectNames[i];
const nameParts = projectName.split("-");
let containsPlatform = false;
for (const n of nameParts) {
if (supportedPlatforms.includes(n)) {
containsPlatform = true;
}
}
if (!containsPlatform) {
// allows for shorthand project/app names omitting platform
// just add platform to the name
projectNames[i] = `${name}-${nameParts.join("-")}`;
}
}
}

return chain([
// init xplat settings
Expand All @@ -48,12 +30,34 @@ export default function(options: xPlatOptions) {
(tree: Tree) => {
const appsDir = tree.getDir("apps");
const appFolders = appsDir.subdirs;
const apps = [];
const allApps = [];
for (const dir of appFolders) {
apps.push(`**${appsDir.path}/${dir}`);
allApps.push(`**${appsDir.path}/${dir}`);
}

// project handling
let focusOnApps: string[] = [];
if (name !== "fullstack" && options.projects) {
focusOnApps = options.projects.split(",");
for (let i = 0; i < focusOnApps.length; i++) {
const projectName = focusOnApps[i];
const nameParts = projectName.split("-");
let containsPlatform = false;
for (const n of nameParts) {
if (supportedPlatforms.includes(n)) {
containsPlatform = true;
}
}
if (!containsPlatform) {
// allows for shorthand project/app names omitting platform
// just add platform to the name
const appName = getGroupByName() ? `${nameParts.join("-")}-${name}` : `${name}-${nameParts.join("-")}`;
focusOnApps[i] = `**/apps/${appName}`;
}
}
}
// targets and mode should be the same
return updateIDESettings(tree, name, name, projectNames, apps);
return updateIDESettings(tree, name, name, allApps, focusOnApps);
}
]);
}
Expand Down
3 changes: 2 additions & 1 deletion src/mode/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
},
"projects": {
"type": "string",
"description": "Project names to focus on."
"description": "Project/app names to focus on.",
"alias": "apps"
}
}
}
59 changes: 37 additions & 22 deletions src/utils/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -920,8 +920,8 @@ export function updateIDESettings(
tree: Tree,
platformArg: string,
devMode?: PlatformTypes,
projectNames?: string[],
apps?: string[]
allApps?: string[],
focusOnApps?: string[],
) {
if (isTest) {
// ignore node file modifications when just testing
Expand All @@ -932,39 +932,28 @@ export function updateIDESettings(
const cwd = process.cwd();
// console.log('workspace dir:', process.cwd());
// const dirName = cwd.split('/').slice(-1);
let isFullstack = false;
let isExcluding = false;
let appWildcards = [];
const userUpdates: any = {};
if (!devMode || devMode === "fullstack") {
// show all
isFullstack = true;
for (const p of supportedPlatforms) {
const appFilter = groupByName ? `*-${p}` : `${p}-*`;
userUpdates[`**/apps/${appFilter}`] = false;
userUpdates[`**/xplat/${p}`] = false;
}
if (apps.length) {
// clear all specific app filters
for (const app of apps) {
delete userUpdates[app];
}
}
} else if (platformArg) {
const platforms = sanitizeCommaDelimitedArg(platformArg);
if (projectNames.length && apps.length) {
// if focusing on projects, clear all specific app filters first if they exist
for (const app of apps) {
userUpdates[app] = true;
}
for (const project of projectNames) {
userUpdates[`**/apps/${project}`] = false;
}
}
// switch on/off platforms
for (const p of supportedPlatforms) {
const excluded = platforms.includes(p) ? false : true;
const appFilter = groupByName ? `*-${p}` : `${p}-*`;
if (projectNames.length) {
// clear app wildcard
delete userUpdates[`**/apps/${appFilter}`];
if (focusOnApps.length) {
// focusing on apps
// fill up wildcards to use below (we will clear all app wildcards when focusing on apps)
appWildcards.push(`**/apps/${appFilter}`);
} else {
// use wildcards for apps only if no project names were specified
userUpdates[`**/apps/${appFilter}`] = excluded;
Expand Down Expand Up @@ -1005,17 +994,43 @@ export function updateIDESettings(
if (!exclude) {
exclude = {};
}
userSettingsJson["files.exclude"] = Object.assign(exclude, userUpdates);

let searchExclude = userSettingsJson["search.exclude"];
if (!searchExclude) {
searchExclude = {};
}

userSettingsJson["files.exclude"] = Object.assign(exclude, userUpdates);
userSettingsJson["search.exclude"] = Object.assign(
searchExclude,
userUpdates
);

if (allApps.length) {
// always reset specific app filters
for (const app of allApps) {
delete userSettingsJson["files.exclude"][app];
delete userSettingsJson["search.exclude"][app];
}
}
if (!isFullstack && focusOnApps.length && allApps.length) {
// when focusing on projects, clear all specific app wildcards first if they exist
for (const wildcard of appWildcards) {
delete userSettingsJson["files.exclude"][wildcard];
delete userSettingsJson["search.exclude"][wildcard];
}
for (const focusApp of 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 allApps) {
if (!focusOnApps.includes(app)) {
userSettingsJson["files.exclude"][app] = true;
userSettingsJson["search.exclude"][app] = true;
}
}
}

fs.writeFileSync(
userSettingsVSCodePath,
JSON.stringify(userSettingsJson, null, 2)
Expand Down

0 comments on commit ebe01cd

Please sign in to comment.