Skip to content

Commit

Permalink
fix(@schematics/angular): replace clientProject with project
Browse files Browse the repository at this point in the history
(cherry picked from commit 4ed1c4f)
  • Loading branch information
alan-agius4 authored and clydin committed May 5, 2021
1 parent bc01593 commit ec7f3ad
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 33 deletions.
12 changes: 6 additions & 6 deletions packages/schematics/angular/app-shell/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function addAppShellConfigToWorkspace(options: AppShellOptions): Rule {
}

return updateWorkspace((workspace) => {
const project = workspace.projects.get(options.clientProject);
const project = workspace.projects.get(options.project);
if (!project) {
return;
}
Expand Down Expand Up @@ -187,8 +187,8 @@ function addAppShellConfigToWorkspace(options: AppShellOptions): Rule {
}

configurations[key] = {
browserTarget: `${options.clientProject}:build:${key}`,
serverTarget: `${options.clientProject}:server:${key}`,
browserTarget: `${options.project}:build:${key}`,
serverTarget: `${options.project}:server:${key}`,
};
}

Expand Down Expand Up @@ -239,7 +239,7 @@ function addServerRoutes(options: AppShellOptions): Rule {
return async (host: Tree) => {
// The workspace gets updated so this needs to be reloaded
const workspace = await getWorkspace(host);
const clientProject = workspace.projects.get(options.clientProject);
const clientProject = workspace.projects.get(options.project);
if (!clientProject) {
throw new Error('Universal schematic removed client project.');
}
Expand Down Expand Up @@ -309,7 +309,7 @@ function addShellComponent(options: AppShellOptions): Rule {
const componentOptions: ComponentOptions = {
name: 'app-shell',
module: options.rootModuleFileName,
project: options.clientProject,
project: options.project,
};

return schematic('component', componentOptions);
Expand All @@ -318,7 +318,7 @@ function addShellComponent(options: AppShellOptions): Rule {
export default function (options: AppShellOptions): Rule {
return async (tree) => {
const workspace = await getWorkspace(tree);
const clientProject = workspace.projects.get(options.clientProject);
const clientProject = workspace.projects.get(options.project);
if (!clientProject || clientProject.extensions.projectType !== 'application') {
throw new SchematicsException(`A client project type of "application" is required.`);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/schematics/angular/app-shell/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"additionalProperties": false,
"long-description": "./app-shell-long.md",
"properties": {
"clientProject": {
"project": {
"type": "string",
"description": "The name of the related client app.",
"$default": {
Expand Down Expand Up @@ -50,5 +50,5 @@
"default": "AppServerModule"
}
},
"required": ["clientProject"]
"required": ["project"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ describe('Migration to version 9', () => {
require.resolve('../../collection.json'),
'universal',
{
clientProject: 'migration-test',
project: 'migration-test',
},
tree,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Migration to version 9', () => {
require.resolve('../../collection.json'),
'universal',
{
clientProject: 'migration-test',
project: 'migration-test',
},
tree,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ describe('Migration to version 9', () => {
require.resolve('../../collection.json'),
'universal',
{
clientProject: 'migration-test',
project: 'migration-test',
},
tree,
)
Expand Down
8 changes: 4 additions & 4 deletions packages/schematics/angular/universal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { Schema as UniversalOptions } from './schema';

function updateConfigFile(options: UniversalOptions, tsConfigDirectory: Path): Rule {
return updateWorkspace((workspace) => {
const clientProject = workspace.projects.get(options.clientProject);
const clientProject = workspace.projects.get(options.project);

if (clientProject) {
// In case the browser builder hashes the assets
Expand All @@ -59,7 +59,7 @@ function updateConfigFile(options: UniversalOptions, tsConfigDirectory: Path): R

const buildTarget = clientProject.targets.get('build');
if (buildTarget?.options) {
buildTarget.options.outputPath = `dist/${options.clientProject}/browser`;
buildTarget.options.outputPath = `dist/${options.project}/browser`;
}

const buildConfigurations = buildTarget?.configurations;
Expand All @@ -77,7 +77,7 @@ function updateConfigFile(options: UniversalOptions, tsConfigDirectory: Path): R
builder: Builders.Server,
defaultConfiguration: 'production',
options: {
outputPath: `dist/${options.clientProject}/server`,
outputPath: `dist/${options.project}/server`,
main: join(
normalize(clientProject.root),
'src',
Expand Down Expand Up @@ -226,7 +226,7 @@ export default function (options: UniversalOptions): Rule {
return async (host: Tree, context: SchematicContext) => {
const workspace = await getWorkspace(host);

const clientProject = workspace.projects.get(options.clientProject);
const clientProject = workspace.projects.get(options.project);
if (!clientProject || clientProject.extensions.projectType !== 'application') {
throw new SchematicsException(`Universal requires a project type of "application".`);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/schematics/angular/universal/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ describe('Universal Schematic', () => {
require.resolve('../collection.json'),
);
const defaultOptions: UniversalOptions = {
clientProject: 'bar',
project: 'bar',
};
const workspaceUniversalOptions: UniversalOptions = {
clientProject: 'workspace',
project: 'workspace',
};

const workspaceOptions: WorkspaceOptions = {
Expand Down
9 changes: 6 additions & 3 deletions packages/schematics/angular/universal/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
"additionalProperties": false,
"description": "Pass this schematic to the \"run\" command to set up server-side rendering for an app.",
"properties": {
"clientProject": {
"project": {
"type": "string",
"description": "The name of the related client app. Required in place of \"project\"."
"description": "The name of the project.",
"$default": {
"$source": "projectName"
}
},
"appId": {
"type": "string",
Expand Down Expand Up @@ -45,5 +48,5 @@
"default": false
}
},
"required": ["clientProject"]
"required": ["project"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const snapshots = require('../../ng-snapshot/package.json');

export default async function () {
await appendToFile('src/app/app.component.html', '<router-outlet></router-outlet>');
await ng('generate', 'appShell', '--client-project', 'test-project');
await ng('generate', 'appShell', '--project', 'test-project');

const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];
if (isSnapshotBuild) {
Expand Down
7 changes: 5 additions & 2 deletions tests/legacy-cli/e2e/tests/build/platform-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { updateJsonFile } from '../../utils/project';
const snapshots = require('../../ng-snapshot/package.json');

export default async function () {
await ng('generate', 'universal', '--client-project', 'test-project');
await ng('generate', 'universal', '--project', 'test-project');

const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];
if (isSnapshotBuild) {
Expand Down Expand Up @@ -48,7 +48,10 @@ export default async function () {

await ng('run', 'test-project:server', '--optimization', 'false');

await expectFileToMatch('dist/test-project/server/main.js', /exports.*AppServerModule|"AppServerModule":/);
await expectFileToMatch(
'dist/test-project/server/main.js',
/exports.*AppServerModule|"AppServerModule":/,
);
await exec(normalize('node'), 'dist/test-project/server/main.js');
await expectFileToMatch(
'dist/test-project/server/index.html',
Expand Down
2 changes: 0 additions & 2 deletions tests/legacy-cli/e2e/tests/generate/schematic-defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export default async function () {
// Generate component in application to verify that it's minimal
const { stdout } = await ng('generate', 'component', 'foo');
if (!stdout.includes('foo.component.scss')) {
console.log(stdout);
throw new Error('Expected "foo.component.scss" to exist.');
}

Expand All @@ -36,7 +35,6 @@ export default async function () {
'test-project-two',
);
if (!stdout2.includes('foo.component.less')) {
console.log(stdout2);
throw new Error('Expected "foo.component.less" to exist.');
}
}
13 changes: 5 additions & 8 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize-app-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ export default async function () {

const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];

await updateJsonFile('package.json', packageJson => {
await updateJsonFile('package.json', (packageJson) => {
const dependencies = packageJson['dependencies'];
dependencies['@angular/localize'] = isSnapshotBuild
? snapshots.dependencies['@angular/localize']
: readNgVersion();
});

await appendToFile('src/app/app.component.html', '<router-outlet></router-outlet>');
await ng('generate', 'appShell', '--client-project', 'test-project');
await ng('generate', 'appShell', '--project', 'test-project');

if (isSnapshotBuild) {
await updateJsonFile('package.json', packageJson => {
await updateJsonFile('package.json', (packageJson) => {
const dependencies = packageJson['dependencies'];
dependencies['@angular/platform-server'] = snapshots.dependencies['@angular/platform-server'];
dependencies['@angular/router'] = snapshots.dependencies['@angular/router'];
Expand All @@ -49,7 +49,7 @@ export default async function () {
{ lang: 'fr', translation: 'Bonjour i18n!' },
];

await updateJsonFile('angular.json', workspaceJson => {
await updateJsonFile('angular.json', (workspaceJson) => {
const appProject = workspaceJson.projects['test-project'];
const appArchitect = appProject.architect || appProject.targets;
const buildOptions = appArchitect['build'].options;
Expand Down Expand Up @@ -111,10 +111,7 @@ export default async function () {

// Clean up app.component.html so that we can easily
// find the translation text
await writeFile(
'src/app/app.component.html',
'<router-outlet></router-outlet>',
);
await writeFile('src/app/app.component.html', '<router-outlet></router-outlet>');

for (const { lang, translation } of langTranslations) {
if (lang != 'en-US') {
Expand Down

0 comments on commit ec7f3ad

Please sign in to comment.