Skip to content

Commit

Permalink
fix(core): workspace update handling on generation
Browse files Browse the repository at this point in the history
closes #237
  • Loading branch information
NathanWalker committed Jan 8, 2021
1 parent c8b3f60 commit 4059d50
Show file tree
Hide file tree
Showing 35 changed files with 553 additions and 494 deletions.
8 changes: 4 additions & 4 deletions packages/angular/src/schematics/application/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ describe('app', () => {

checkFile = getFileContent(tree, checkPath);
// console.log(checkFile);
const angularJson: any = jsonParse(checkFile);
expect(
angularJson.projects[`${appName}-e2e`].architect.e2e.configurations.ci
).toBeDefined();
// const angularJson: any = jsonParse(checkFile);
// expect(
// angularJson.projects[`${appName}-e2e`].architect.e2e.configurations.ci
// ).toBeDefined();
});

// it('should create app with --framework flag Ionic', async () => {
Expand Down
55 changes: 24 additions & 31 deletions packages/angular/src/schematics/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ import {
noop,
ExecutionOptions,
} from '@angular-devkit/schematics';
import { formatFiles } from '@nrwl/workspace';
import { formatFiles, updateWorkspace } from '@nrwl/workspace';
import {
stringUtils,
updatePackageScripts,
missingArgument,
getDefaultTemplateOptions,
XplatHelpers,
readWorkspaceJson,
updateWorkspace,
} from '@nstudio/xplat';
import {
prerun,
Expand Down Expand Up @@ -129,22 +128,18 @@ exports.config = defaultConfig;
const confFile = 'protractor.headless.js';
tree.create(`/apps/${directory}${e2eProjectName}/${confFile}`, config);

const workspaceConfig = readWorkspaceJson(tree);
if (workspaceConfig && workspaceConfig.projects) {
if (workspaceConfig.projects[e2eProjectName]) {
if (workspaceConfig.projects[e2eProjectName].architect) {
workspaceConfig.projects[
e2eProjectName
].architect.e2e.configurations.ci = {
return updateWorkspace((workspace) => {
if (workspace.projects.has(e2eProjectName)) {
const projectDef = workspace.projects.get(e2eProjectName);
const e2eDef = projectDef.targets.get('e2e');
if (e2eDef) {
e2eDef.configurations.ci = {
protractorConfig: `apps/${directory}${e2eProjectName}/${confFile}`,
};
projectDef.targets.set('e2e', e2eDef);
}
}
}
return updateWorkspace({ projects: workspaceConfig.projects })(
tree,
<any>context
);
});
};
}

Expand Down Expand Up @@ -220,24 +215,22 @@ function adjustAppFiles(options: Schema, tree: Tree): Rule {
appModuleContent(options)
);
// update cli config for shared web specific scss
const workspaceConfig = readWorkspaceJson(tree);
// find app
if (workspaceConfig && workspaceConfig.projects) {
if (workspaceConfig.projects[options.name]) {
if (workspaceConfig.projects[options.name].architect) {
workspaceConfig.projects[
options.name
].architect.build.options.styles = [
`libs/xplat/${XplatHelpers.getXplatFoldername(
'web',
'angular'
)}/scss/src/_index.scss`,
`apps/${directory}${options.name}/src/styles.scss`,
];
return updateWorkspace((workspace) => {
const projectDef = workspace.projects.get(options.name);
if (projectDef && projectDef.targets) {
const buildDef = projectDef.targets.get('build')
if (buildDef) {
buildDef.options.styles = [
`libs/xplat/${XplatHelpers.getXplatFoldername(
'web',
'angular'
)}/scss/src/_index.scss`,
`apps/${directory}${options.name}/src/styles.scss`,
];
projectDef.targets.set('build', buildDef);
}
}
}
}
return <any>updateWorkspace({ projects: workspaceConfig.projects });
});
}

function indexContent(name: string) {
Expand Down
3 changes: 2 additions & 1 deletion packages/angular/src/schematics/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ export default function (options: XplatComponentHelpers.Schema) {
: noop()(tree, context),

// add platform chains
...externalChains,
(tree: Tree, context: SchematicContext) =>
chain(externalChains),
formatFiles({ skipFormat: options.skipFormat }),
]);
}
97 changes: 53 additions & 44 deletions packages/angular/src/schematics/elements/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ import {
externalSchematic,
noop,
} from '@angular-devkit/schematics';
import { updateJsonInTree, formatFiles } from '@nrwl/workspace';
import {
updateJsonInTree,
formatFiles,
updateWorkspace,
} from '@nrwl/workspace';
import {
stringUtils,
updatePackageScripts,
missingArgument,
updateWorkspace,
getDefaultTemplateOptions,
XplatHelpers,
} from '@nstudio/xplat';
Expand Down Expand Up @@ -137,54 +140,60 @@ export default function (options: ElementsOptions) {
if (options.builderModule) {
return noop()(tree, context);
} else {
return updateWorkspace({
projects: {
'web-elements': {
root: '',
sourceRoot: 'libs/xplat/web/elements/builder',
projectType: 'application',
prefix: 'web-elements',
schematics: {},
architect: {
build: {
builder: 'ngx-build-plus:build',
options: {
outputPath: 'dist/ngelements',
index: 'libs/xplat/web/elements/builder/index.html',
main: 'libs/xplat/web/elements/builder/elements.ts',
polyfills: 'libs/xplat/web/elements/builder/polyfills.ts',
tsConfig:
'libs/xplat/web/elements/builder/tsconfig.elements.json',
},
configurations: {
production: {
optimization: true,
outputHashing: 'all',
sourceMap: false,
extractCss: true,
namedChunks: false,
aot: true,
extractLicenses: true,
vendorChunk: false,
buildOptimizer: true,
},
},
return updateWorkspace((workspace) => {
const projectDef: any = {
root: '',
sourceRoot: 'libs/xplat/web/elements/builder',
projectType: 'application',
prefix: 'web-elements',
schematics: {},
targets: {
build: {
builder: 'ngx-build-plus:build',
options: {
outputPath: 'dist/ngelements',
index: 'libs/xplat/web/elements/builder/index.html',
main: 'libs/xplat/web/elements/builder/elements.ts',
polyfills: 'libs/xplat/web/elements/builder/polyfills.ts',
tsConfig:
'libs/xplat/web/elements/builder/tsconfig.elements.json',
},
serve: {
builder: 'ngx-build-plus:dev-server',
options: {
browserTarget: 'web-elements:build',
configurations: {
production: {
optimization: true,
outputHashing: 'all',
sourceMap: false,
extractCss: true,
namedChunks: false,
aot: true,
extractLicenses: true,
vendorChunk: false,
buildOptimizer: true,
},
configurations: {
production: {
browserTarget: 'web-elements:build:production',
},
},
},
serve: {
builder: 'ngx-build-plus:dev-server',
options: {
browserTarget: 'web-elements:build',
},
configurations: {
production: {
browserTarget: 'web-elements:build:production',
},
},
},
},
},
})(tree, <any>context);
};
if (workspace.projects.has('web-elements')) {
workspace.projects.set('web-elements', projectDef);
} else {
workspace.projects.add({
name: `web-elements`,
...projectDef,
});
}
});
}
},
// update dependencies
Expand Down
3 changes: 2 additions & 1 deletion packages/angular/src/schematics/feature/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ export default function (options: XplatFeatureHelpers.Schema) {
'libs/xplat/features/src/lib/index.ts'
)(tree, context),
// external schematic handling
...externalChains,
(tree: Tree, context: SchematicContext) =>
chain(externalChains),
formatFiles({ skipFormat: options.skipFormat }),
]);
}
3 changes: 2 additions & 1 deletion packages/angular/src/schematics/xplat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export default function (options: XplatHelpers.Schema) {
XplatHelpers.cleanupLib(options, 'utils', 'xplat'),
XplatAngularHelpers.addLibFiles(options, './', 'utils'),
// cross platform support
...externalChains,
(tree: Tree, context: SchematicContext) =>
chain(externalChains),
XplatAngularHelpers.updateRootDeps(options),
// adjust root tsconfig
(tree: Tree, context: SchematicContext) => {
Expand Down
6 changes: 4 additions & 2 deletions packages/angular/src/utils/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,10 @@ export function generate(type: IGenerateType, options) {
: noop()(tree, context),

// project handling
...projectChains,
...externalChains,
(tree: Tree, context: SchematicContext) =>
chain(projectChains),
(tree: Tree, context: SchematicContext) =>
chain(externalChains),
// dependency updates
(tree: Tree, context: SchematicContext) =>
!options.projects && type === 'state'
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/utils/versions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const xplatVersion = '*';
export const nxVersion = '^11.0.0';
export const nxVersion = '^11.1.0';
export const angularVersion = '~11.0.0';
export const angularDevkitVersion = '~0.1100.5';
export const ngxTranslateVersion = '~13.0.0';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe('app', () => {
version: 1,
projects: {
'web-viewer': {
architect: {
targets: {
build: {
options: {
assets: [],
Expand Down
60 changes: 29 additions & 31 deletions packages/electron-angular/src/schematics/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import {
noop,
externalSchematic,
} from '@angular-devkit/schematics';
import { formatFiles } from '@nrwl/workspace';
import { formatFiles, updateWorkspace } from '@nrwl/workspace';
import {
stringUtils,
updateWorkspace,
updateNxProjects,
updatePackageScripts,
missingArgument,
Expand Down Expand Up @@ -91,39 +90,38 @@ export default function (options: XplatElectrontHelpers.SchemaApp) {
);
}

const projects = {};
const electronAppName = options.name;
projects[electronAppName] = targetConfig;
// update to use electron module
projects[
electronAppName
].architect.build.options.outputPath = `dist/apps/${electronAppName}`;
let targetProp = 'architect';
if (!targetConfig[targetProp]) {
targetProp = 'targets'; // nx 11 moved to 'targets'
}
if (targetConfig[targetProp]) {
// update to use electron module
targetConfig[targetProp].build.options.outputPath = `dist/apps/${electronAppName}`;

if (options.useXplat) {
projects[
electronAppName
].architect.build.options.main = `apps/${fullTargetAppName}/src/main.electron.ts`;
projects[
electronAppName
].architect.build.options.tsConfig = `apps/${fullTargetAppName}/tsconfig.electron.json`;
if (options.useXplat) {
targetConfig[targetProp].build.options.main = `apps/${fullTargetAppName}/src/main.electron.ts`;
targetConfig[targetProp].build.options.tsConfig = `apps/${fullTargetAppName}/tsconfig.electron.json`;
}
targetConfig[targetProp].build.options.assets.push({
glob: '**/*',
input: `apps/${electronAppName}/src/`,
ignore: ['**/*.ts'],
output: '',
});
targetConfig[targetProp].serve.options.browserTarget = `${electronAppName}:build`;
targetConfig[targetProp].serve.configurations.production.browserTarget = `${electronAppName}:build:production`;
// clear other settings (TODO: may need these in future), for now keep electron options minimal
delete targetConfig[targetProp]['extract-i18n'];
delete targetConfig[targetProp]['test'];
delete targetConfig[targetProp]['lint'];
}
projects[electronAppName].architect.build.options.assets.push({
glob: '**/*',
input: `apps/${electronAppName}/src/`,
ignore: ['**/*.ts'],
output: '',
return updateWorkspace((workspace) => {
workspace.projects.add({
name: electronAppName,
...targetConfig
});
});
projects[
electronAppName
].architect.serve.options.browserTarget = `${electronAppName}:build`;
projects[
electronAppName
].architect.serve.configurations.production.browserTarget = `${electronAppName}:build:production`;
// clear other settings (TODO: may need these in future), for now keep electron options minimal
delete projects[electronAppName].architect['extract-i18n'];
delete projects[electronAppName].architect['test'];
delete projects[electronAppName].architect['lint'];
return updateWorkspace({ projects })(tree, <any>context);
},
(tree: Tree) => {
const projects = {};
Expand Down
3 changes: 2 additions & 1 deletion packages/electron-angular/src/schematics/xplat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export default function (options: XplatHelpers.Schema) {
: XplatHelpers.addPlatformFiles(
options,
xplatFolderName,
'core'
'core',
'index.ts'
)(tree, context);
},
XplatElectronAngularHelpers.updateRootDeps(options),
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-angular/src/utils/versions.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const xplatVersion = '*';
export const nxVersion = '^11.0.0';
export const nxVersion = '^11.1.0';
Loading

0 comments on commit 4059d50

Please sign in to comment.