Skip to content

Commit

Permalink
feat(@angular-devkit/schematics-cli): add package manager option to b…
Browse files Browse the repository at this point in the history
…lank schematic
  • Loading branch information
sidhanshamil authored and clydin committed Aug 13, 2024
1 parent 7af63b4 commit 37693c4
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 17 deletions.
4 changes: 3 additions & 1 deletion packages/angular_devkit/schematics_cli/bin/schematics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

// symbol polyfill must go first
import 'symbol-observable';
import type { JsonValue, logging, schema } from '@angular-devkit/core';
import { JsonValue, logging, schema } from '@angular-devkit/core';
import { ProcessOutput, createConsoleLogger } from '@angular-devkit/core/node';
import { UnsuccessfulWorkflowExecution } from '@angular-devkit/schematics';
import { NodeWorkflow } from '@angular-devkit/schematics/tools';
Expand Down Expand Up @@ -338,6 +338,8 @@ export async function main({
}
});

workflow.registry.addPostTransform(schema.transforms.addUndefinedDefaults);

// Show usage of deprecated options
workflow.registry.useXDeprecatedProvider((msg) => logger.warn(msg));

Expand Down
7 changes: 6 additions & 1 deletion packages/angular_devkit/schematics_cli/blank/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ export default function (options: Schema): Rule {
move(options.name),
]);

context.addTask(new NodePackageInstallTask(options.name));
context.addTask(
new NodePackageInstallTask({
workingDirectory: options.name,
packageManager: options.packageManager,
}),
);
}

return chain([
Expand Down
6 changes: 6 additions & 0 deletions packages/angular_devkit/schematics_cli/blank/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"index": 0
}
},
"packageManager": {
"description": "The package manager used to install dependencies.",
"type": "string",
"enum": ["npm", "yarn", "pnpm", "cnpm", "bun"],
"default": "npm"
},
"author": {
"type": "string",
"description": "Author for the new schematic."
Expand Down
7 changes: 6 additions & 1 deletion packages/angular_devkit/schematics_cli/schematic/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ export default function (options: Schema): Rule {
const coreVersion = require('@angular-devkit/core/package.json').version;

return (_, context) => {
context.addTask(new NodePackageInstallTask(options.name));
context.addTask(
new NodePackageInstallTask({
workingDirectory: options.name,
packageManager: options.packageManager,
}),
);

return mergeWith(
apply(url('./files'), [
Expand Down
6 changes: 6 additions & 0 deletions packages/angular_devkit/schematics_cli/schematic/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
"author": {
"type": "string",
"description": "Author for the new schematic."
},
"packageManager": {
"description": "The package manager used to install dependencies.",
"type": "string",
"enum": ["npm", "yarn", "pnpm", "cnpm", "bun"],
"default": "npm"
}
},
"required": ["name"]
Expand Down
11 changes: 7 additions & 4 deletions tests/legacy-cli/e2e/tests/schematics_cli/basic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as path from 'path';
import { join } from 'node:path';
import { getGlobalVariable } from '../../utils/env';
import { exec, execAndWaitForOutputToMatch, silentNpm } from '../../utils/process';
import { rimraf } from '../../utils/fs';
Expand All @@ -14,13 +14,13 @@ export default async function () {
await exec(process.platform.startsWith('win') ? 'where' : 'which', 'schematics');

const startCwd = process.cwd();
const schematicPath = path.join(startCwd, 'test-schematic');
const schematicPath = join(startCwd, 'test-schematic');

try {
// create blank schematic
await exec('schematics', 'schematic', '--name', 'test-schematic');

process.chdir(path.join(startCwd, 'test-schematic'));
process.chdir(join(startCwd, 'test-schematic'));
await execAndWaitForOutputToMatch(
'schematics',
['.:', '--list-schematics'],
Expand All @@ -29,6 +29,9 @@ export default async function () {
} finally {
// restore path
process.chdir(startCwd);
await rimraf(schematicPath);
await Promise.all([
rimraf(schematicPath),
silentNpm('uninstall', '-g', '@angular-devkit/schematics-cli'),
]);
}
}
11 changes: 6 additions & 5 deletions tests/legacy-cli/e2e/tests/schematics_cli/blank-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as fs from 'fs';
import * as path from 'path';
import { join } from 'node:path';
import { getGlobalVariable } from '../../utils/env';
import { exec, silentNpm } from '../../utils/process';
import { rimraf } from '../../utils/fs';
Expand All @@ -15,19 +14,21 @@ export default async function () {
await exec(process.platform.startsWith('win') ? 'where' : 'which', 'schematics');

const startCwd = process.cwd();
const schematicPath = path.join(startCwd, 'test-schematic');
const schematicPath = join(startCwd, 'test-schematic');

try {
// create schematic
await exec('schematics', 'blank', '--name', 'test-schematic');

process.chdir(schematicPath);

await silentNpm('install');
await silentNpm('test');
} finally {
// restore path
process.chdir(startCwd);
await rimraf(schematicPath);
await Promise.all([
rimraf(schematicPath),
silentNpm('uninstall', '-g', '@angular-devkit/schematics-cli'),
]);
}
}
11 changes: 6 additions & 5 deletions tests/legacy-cli/e2e/tests/schematics_cli/schematic-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as fs from 'fs';
import * as path from 'path';
import { join } from 'node:path';
import { getGlobalVariable } from '../../utils/env';
import { exec, silentNpm } from '../../utils/process';
import { rimraf } from '../../utils/fs';
Expand All @@ -15,19 +14,21 @@ export default async function () {
await exec(process.platform.startsWith('win') ? 'where' : 'which', 'schematics');

const startCwd = process.cwd();
const schematicPath = path.join(startCwd, 'test-schematic');
const schematicPath = join(startCwd, 'test-schematic');

try {
// create schematic
await exec('schematics', 'schematic', '--name', 'test-schematic');

process.chdir(schematicPath);

await silentNpm('install');
await silentNpm('test');
} finally {
// restore path
process.chdir(startCwd);
await rimraf(schematicPath);
await Promise.all([
rimraf(schematicPath),
silentNpm('uninstall', '-g', '@angular-devkit/schematics-cli'),
]);
}
}

0 comments on commit 37693c4

Please sign in to comment.