Skip to content

Instantly share code, notes, and snippets.

Jonathan Campos jonbcampos

Block or report user

Report or block jonbcampos

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View schematics_simple-schematic_src_simple-schematic_index_spec.ts
import { Tree } from '@angular-devkit/schematics';
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import * as path from 'path';
const collectionPath = path.join(__dirname, '../collection.json');
describe('simple-schematic', () => {
it('works', () => {
const runner = new SchematicTestRunner('schematics', collectionPath);
const tree = runner.runSchematic('simple-schematic', {}, Tree.empty());
View schematics_simple-schematic_src_simple-schematic_index_spec_p3.ts
import {Schema as WorkspaceOptions} from '@schematics/angular/workspace/schema';
import {Schema as ApplicationOptions} from '@schematics/angular/application/schema';
...
const workspaceOptions: WorkspaceOptions = {
name: 'workspace',
newProjectRoot: 'projects',
version: '6.0.0',
};
View schematics_simple-schematic_src_simple-schematic_index_spec_p7.ts
it('works', () => {
const tree = testRunner.runSchematic('simple-schematic', {
name: "test"
}, appTree);
//[see assertions below]
});
View schematics_simple-schematic_src_simple-schematic_index_spec_p8.ts
expect(tree.files).toEqual([
"/README.md",
"/angular.json",
"/package.json",
"/tsconfig.json",
"/tslint.json",
"/.editorconfig",
"/.gitignore",
...
"/projects/bar/src/app/test/test.spec.ts",
View schematics_simple-schematic_src_simple-schematic_index_spec_p10.ts
expect(tree.readContent("/projects/bar/src/app/test/test.ts"))
.toContain(
"export class Test {\n" +
"\n" +
"}"
);
View schematics_simple-schematic_src_simple-schematic_index_p1.ts
const movePath = (options.flat) ?
normalize(options.path) :
normalize(options.path + '/' + strings.dasherize(options.name));
View schematics_simple-schematic_src_simple-schematic_index_p2.ts
const templateSource = apply(url('./files'), [
options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')),
template({
...strings,
...options,
}),
move(movePath),
]);
View schematics_simple-schematic_src_simple-schematic_index_p4.ts
export function simpleSchematic(options: any): Rule {
return (tree: Tree, _context: SchematicContext) => {
setupOptions(tree, options);
const movePath = (options.flat) ?
normalize(options.path) :
normalize(options.path + '/' + strings.dasherize(options.name));
const templateSource = apply(url('./files'), [
options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')),
You can’t perform that action at this time.