@nstudio/focus
Version:
Focus helpers for monorepos in various IDEs
104 lines (103 loc) • 4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
const schematics_1 = require("@angular-devkit/schematics");
// import { updateTsConfig, XplatHelpers } from '@nstudio/xplat';
const xplat_utils_1 = require("@nstudio/xplat-utils");
const utils_1 = require("../../utils");
let name;
function default_1(options) {
if (!options.name) {
name = 'fullstack';
const extraNote = (0, xplat_utils_1.isXplatWorkspace)()
? ` Currently supported: fullstack,${xplat_utils_1.supportedPlatformsWithNx}. Example: nx g mode nativescript`
: '';
console.warn(`Defaulting to 'fullstack' and showing everything since no focus was specified.${extraNote}`);
}
else {
name = options.name;
}
return (0, schematics_1.chain)([
// init xplat settings
(0, xplat_utils_1.prerun)(),
// update tsconfig based on mode
// (tree: Tree) => {
// return isXplatWorkspace() ? updateExcludes(name)(tree) : noop();
// },
// update IDE settings
(tree, context) => {
// apps
const appPaths = (0, xplat_utils_1.getAppPaths)(tree);
const allApps = [];
for (const appPath of appPaths) {
allApps.push(`**${appPath}`);
}
// console.log('allApps:', allApps);
// libs
const libsDir = tree.getDir('libs');
const allLibs = [];
if (libsDir && libsDir.subdirs) {
const libsFolders = libsDir.subdirs;
for (const dir of libsFolders) {
allLibs.push(`**${libsDir.path}/${dir}`);
}
}
// packages
const packagesDir = tree.getDir('packages');
const allPackages = [];
if (packagesDir && packagesDir.subdirs) {
const packagesFolders = packagesDir.subdirs;
for (const dir of packagesFolders) {
allPackages.push(`**${packagesDir.path}/${dir}`);
}
}
// project handling
let focusOnApps = [];
if (name !== 'fullstack' && options.projects) {
focusOnApps = options.projects.split(',').map((p) => p.trim());
if ((0, xplat_utils_1.isXplatWorkspace)()) {
// allows for shorthand project/app names omitting platform from the app name
// just add platform to the name to be specific
for (let i = 0; i < focusOnApps.length; i++) {
const projectName = focusOnApps[i];
focusOnApps[i] = `**/apps/${projectName}`;
}
}
}
// targets and mode should be the same
return utils_1.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');
// }
// }
// }
// });
// };
// }